Splunk Search

help on stats count by command

jip31
Motivator

hello

I use the search below in order to do a total count by OS and by build
It mean that it counts only events which have a build AND an OS
I would like to do another count but this time I would like to do a total count of events which have a build OR an OS
Could you help me please??

eventtype="AppliEV" | fields Name, Level, host 
| dedup host 
| stats count by host 
| join host type="outer" 
    [ search index="x" sourcetype=x key_path="x" 
        OR 
        key_path="x" 
    | eval OS=if(key_path=="x"), 
        Build=if(key_path=="x" 
    | stats latest(OS) as OS latest(Build) as Build by host] 
| stats values(OS) as OS values(Build) as Build by host 
| stats count as Total by OS Build
Tags (1)
0 Karma
1 Solution

FrankVl
Ultra Champion

One way to approach that would be:

 eventtype="AppliEV" | fields Name, Level, host 
 | dedup host 
 | stats count by host 
 | join host type="outer" 
     [ search index="x" sourcetype=x key_path="x" 
         OR 
         key_path="x" 
     | eval OS=if(key_path=="x"), 
         Build=if(key_path=="x" 
     | stats latest(OS) as OS latest(Build) as Build by host] 
 | stats values(OS) as OS values(Build) as Build by host 
 | fillnull value="unknown" OS,Build
 | stats count as Total by OS Build

By using fillnull, every event will have an OS and a Build value (value is set to "unknown" when it did not have a value).

View solution in original post

0 Karma

FrankVl
Ultra Champion

One way to approach that would be:

 eventtype="AppliEV" | fields Name, Level, host 
 | dedup host 
 | stats count by host 
 | join host type="outer" 
     [ search index="x" sourcetype=x key_path="x" 
         OR 
         key_path="x" 
     | eval OS=if(key_path=="x"), 
         Build=if(key_path=="x" 
     | stats latest(OS) as OS latest(Build) as Build by host] 
 | stats values(OS) as OS values(Build) as Build by host 
 | fillnull value="unknown" OS,Build
 | stats count as Total by OS Build

By using fillnull, every event will have an OS and a Build value (value is set to "unknown" when it did not have a value).

0 Karma

jip31
Motivator

Many thanks franck

0 Karma
Get Updates on the Splunk Community!

Dashboards: Hiding charts while search is being executed and other uses for tokens

There are a couple of features of SimpleXML / Classic dashboards that can be used to enhance the user ...

Splunk Observability Cloud's AI Assistant in Action Series: Explaining Metrics and ...

This is the fourth post in the Splunk Observability Cloud’s AI Assistant in Action series that digs into how ...

Brains, Bytes, and Boston: Learn from the Best at .conf25

When you think of Boston, you might picture colonial charm, world-class universities, or even the crack of a ...