hi
I use the search below and I would like to have a 0 results displayed when there is no events corresponding
could you help me please?? Thanks
eventtype="x" Name="x"
| fields Name, host
| dedup host
| stats count by host
Hi @jip31
Try this and let me know
eventtype="x" Name="x"
| fields Name, host
| dedup host
| stats count by host
| appendpipe [stats count | where count=0 | eval host="Specify your text here"]
Hi @jip31
Try this and let me know
eventtype="x" Name="x"
| fields Name, host
| dedup host
| stats count by host
| appendpipe [stats count | where count=0 | eval host="Specify your text here"]
thanks
if i put only appendpipe [stats count | where count=0] its enough?
what is the use of eval host="Specify your text here"]??
yes its enough, but under host column it will display empty. If you want to add some text info, you can specify
ok its not a problem because I done a fields - host
if it works, please accept my answer.
sorry but I have an issue it works but even if there is results I have...........0 instead results...
@jip31, have you tried?
A more elegant way would be to use a combination of stats and eval. Please try this run anywhere example which I am sure can be customized for your use case. Also, instead of doing dedup and then count, dc(distinct count) can be used.
Try replacing log_level with DEBUG or any non standard type in the search to see it returns 0.
index=_internal sourcetype=splunkd log_level="ERROR"
|fields component,host
|stats dc(eval(if(isnull(host),0,host))) AS Count
Hope this helps!
This is one way to do it. First create a CSV of all the valid hosts you want to show with a zero value. Call this hosts.csv and make sure it has a column called "host". Then change the query to be like so:
eventtype="x" Name="x"
| fields Name, host
| dedup host
| stats count by host
| append [|inputlookup hosts.csv]
| stats sum(count) as count by host
thank but its impossible to use a lookup...
An elegant way to do this without lookups would be to use eval and stats as can be seen in this run anywhere example which I am sure can be customized for your use case.
Also, you won't require dedup followed by stats as dc(distinct count) does the same and fields can be used to return only the field you count upon as the filter has been done earlier.
index=_internal sourcetype=splunkd log_level="ERROR"
|fields host
|stats dc(eval(if(isnull(host),0,host))) AS Count
Thanks its interesting
@jip31
Which solution worked for you?
The stats or the lookup based solution?
Thé stats but if there is event i have also 0 instead résult...