I have a search using stats count but it is not showing the result for an index that has 0 results. There is two columns, one for Log Source and the one for the count. I'd like to show the count of EACH index, even if there is 0 result.
example
log source count
A 20
B 10
C 0
index=A or index=B or index=C
| eval "Log Source"=case(index == "A", "indexA", index == "B", "indexB", index == "C", "IndexC")
| stats count by "Log Source"
Hi @tromero3
You can hard code the log source list to the end of your results. Using your initial example query something like this should work.
index=A or index=B or index=C
| eval "Log Source"=case(index == "A", "indexA", index == "B", "indexB", index == "C", "IndexC")
| stats count by "Log Source"
`comment("# ensure all log sources listed")`
| append [| makeresults | eval indexA="", indexB="", indexC="" | table indexA indexB indexC | transpose column_name="Log Source" ]
| stats max(count) AS count BY "Log Source"
| fillnull value=0 count
Hope this helps.
fillnull
already tried that, it doesn't work
| tstats count where index=A OR index=B OR index=C
| append [|makeresults
| eval index=split("ABC",""), count=0 | mvexpand index| table index count]
| dedup index
| eval "Log Source"=case(index == "A", "indexA", index == "B", "indexB", index == "C", "IndexC")
| table "Log Source" count
your sample is "index=A" , so it's difficult to use split() for actually log, I guess. you can do it.
Im confused about the split part, is that just combining the name of each index into one? (where you put
("ABC","")
And why is that part needed?
My index names are actually longer of course and with dashes in the name such as "first-index", "second-index', etc
Also the first part of my search is longer not just the individual index. But more like
(index=first-index event_type=security) OR (index=second-index rule_reason=IPblock)
and so on...
You asked what to do if you don't have index ABC, so I answered, but the conditions are totally different.
I can't answer this. Good luck.
Have you considered appending a dummy event for each log and then subtracting 1 from every count?
Hi @tromero3
You can hard code the log source list to the end of your results. Using your initial example query something like this should work.
index=A or index=B or index=C
| eval "Log Source"=case(index == "A", "indexA", index == "B", "indexB", index == "C", "IndexC")
| stats count by "Log Source"
`comment("# ensure all log sources listed")`
| append [| makeresults | eval indexA="", indexB="", indexC="" | table indexA indexB indexC | transpose column_name="Log Source" ]
| stats max(count) AS count BY "Log Source"
| fillnull value=0 count
Hope this helps.
wow that worked perfectly, thank you! 😀