Feb 10 2020 07:21 AM - last edited on Nov 09 2023 11:10 AM by
Greetings Community,
I'm trying to come up with a way to query for multiple computers, but I have different strings to search for. For example:
Heartbeat | where TimeGenerated >= ago(1h) | where Computer contains 'ACOMPUTER1' | summarize max(TimeGenerated) by Computer
I can run this query but I have to execute it for a different string each time:
Heartbeat | where TimeGenerated >= ago(1h) | where Computer contains 'ACOMPUTER1' | summarize max(TimeGenerated) by Computer
Heartbeat | where TimeGenerated >= ago(1h) | where Computer contains 'SERVERABC' | summarize max(TimeGenerated) by Computer
Heartbeat | where TimeGenerated >= ago(1h) | where Computer contains 'THISMACHINE_B' | summarize max(TimeGenerated) by Computer
Is there a way to go through multiple "contains" or "has" statements in a single query? Was thinking that I'd have to build an array in a function or something... any help is appreciated.
Feb 10 2020 07:30 AM
Like this ?
Heartbeat
| where TimeGenerated >= ago(1h)
| where Computer in ('ACOMPUTER1', 'SERVERABC')
| summarize max(TimeGenerated) by Computer
or
let cList = dynamic(["ContosoASCAlert", "ContosoAzLnx1"]);
Heartbeat
| where TimeGenerated >= ago(1h)
| where Computer in (cList)
| summarize max(TimeGenerated) by Computer
or
Heartbeat
| where TimeGenerated >= ago(1h)
| where Computer startswith "cont"
| summarize max(TimeGenerated) by Computer
Feb 10 2020 07:51 AM
@CliveWatson No. I want to look in COMPUTER for multiple possible strings in a single query, much like the "contains" operator. For example, my "dream" query would have the following fake operator (contains_in):
Heartbeat | where TimeGenerated >= ago(1h) | where Computer contains_in ('ACOMPUTER1', 'SERVERABC') | summarize max(TimeGenerated) by Computer
I know this doesn't exist, but I was hoping to fake it.
For background, we have 15,000 computers across multiple domains (and growing) and the computers mostly show up as FQDNs, but some as short names. Also, they are added in multiple cases (some all lower, some all upper). So a "Computer in" statement will never work for this scenario if we don't know the FQDN or if it is even listed as FQDN. The best way is to just search for the short name using "contains" or "has", but again, for multiple strings (I have a current use case for about 12 different strings).
Feb 10 2020 08:06 AM
Heartbeat
| where Computer in ("ContosoASCAlert", "ContosoAzLnx1","ContosoWeb1.ContosoRetail.com")
| extend Computer = split(Computer,".").[0]
| summarize max(TimeGenerated) by tolower(tostring(Computer))
What if we lowercase all machines and ignore the FQDN?
Feb 10 2020 08:23 AM
Heartbeat
| where Computer in~ ("ContosoASCALERT", "ContosoAzLnx1","ContosoWeb1.ContosoRetail.com")
| extend Computer = split(Computer,".").[0]
| summarize max(TimeGenerated) by tostring(Computer)
Sorry, best practice would be to use "in~"
Feb 10 2020 08:39 AM
@CliveWatson
Returns zero results because the "in~" string operator means 'Equals to one of the elements' (according to documentation).
I do not need "equals"... I need "contains". I am not looking for full names--only partials. And again, about 12 different strings I want to search. If I could simply provide a list of strings to search, and then have the query look at each of those strings and find matches in the Computer column, that's all I need.
Feb 10 2020 08:58 AM
Solution
Sorry for being slow on the uptake, string is the search criteria (or pattern match you want) within the computer name column? e.g.
Heartbeat
| extend CompBucket = case(Computer contains "aks", Computer,
Computer contains "Con", Computer
,"")
| where isnotempty(CompBucket)
or
Heartbeat
| where Computer contains "aks"
or Computer contains "Con"
| project Computer
Feb 10 2020 10:16 AM
Oct 07 2020 07:55 AM
@Scott Allison I come across the same problem. Can you please share the solution based on array?
Oct 07 2020 10:43 PM
Maybe you can use the operator has_any.
let ComputerTerms = pack_array('abcd', 'xyz0');
datatable (Computer:string)['abcd.123.com', 'def.xyz0.org', 'ijk.com']
| where Computer has_any (ComputerTerms)
Links to the Kusto query documentation:
May 01 2023 03:29 PM
Feb 10 2020 08:58 AM
Solution
Sorry for being slow on the uptake, string is the search criteria (or pattern match you want) within the computer name column? e.g.
Heartbeat
| extend CompBucket = case(Computer contains "aks", Computer,
Computer contains "Con", Computer
,"")
| where isnotempty(CompBucket)
or
Heartbeat
| where Computer contains "aks"
or Computer contains "Con"
| project Computer