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
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).
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~"
- ScottAllisonFeb 10, 2020Iron Contributor
CliveWatson
Returns zero results because the "in~" string operator means 'Equals to one of the elements' (according to https://docs.microsoft.com/en-us/azure/kusto/query/datatypes-string-operators).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.
- CliveWatsonFeb 10, 2020Silver Contributor
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