Forum Discussion
query multiple "contains"
- Feb 10, 2020
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
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
- ScottAllisonFeb 10, 2020Iron Contributor
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).
- CliveWatsonFeb 10, 2020Silver Contributor
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?
- CliveWatsonFeb 10, 2020Silver Contributor
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~"