Knowledge Management

How to subtract outcome of count

rijk
Explorer

I have two saved searches, saved them as macros.

1: [search sourcetype="brem" sanl31 eham Successfully completed (cc*) | fields MessageTime] sanl31 eham Successfully completed cc* | stats count

This is saved as brem_correction_count

2: [search sourcetype="brem" sanl31 eham Successfully completed (cc*) | fields MessageTime] sanl31 eham Successfully completed NOT cc* | stats count

This is saved as brem_corrected_count

How can I use these searches to subtract the outcome of the 2 searches?

Tags (2)
0 Karma
1 Solution

lguinn2
Legend

First, I don't understand what the subsearch is doing in either one of these. I think you can simplify like this:

Search 1:

sourcetype="brem" sanl31 eham Successfully completed cc* | stats count

Search 2:

sourcetype="brem" sanl31 eham Successfully completed NOT cc* | stats count

The fastest search that would calculate the difference would probably be

sourcetype="brem" sanl31 eham Successfully completed
| eval ccType=if(match(_raw,"\bcc"),"Yes","No")
| stats count(eval(ccType="Yes")) as ccCount count(eval(ccType="No")) as NotCcCount
| eval diff =ccCount - NotCcCount

View solution in original post

rijk
Explorer

Many thanks for you answer, it does exactly what I needed. The subsearch is needed to find two related messages based on a field MessageTime. Sorry that I confused you, but the subsearch is needed.

0 Karma

lguinn2
Legend

First, I don't understand what the subsearch is doing in either one of these. I think you can simplify like this:

Search 1:

sourcetype="brem" sanl31 eham Successfully completed cc* | stats count

Search 2:

sourcetype="brem" sanl31 eham Successfully completed NOT cc* | stats count

The fastest search that would calculate the difference would probably be

sourcetype="brem" sanl31 eham Successfully completed
| eval ccType=if(match(_raw,"\bcc"),"Yes","No")
| stats count(eval(ccType="Yes")) as ccCount count(eval(ccType="No")) as NotCcCount
| eval diff =ccCount - NotCcCount
Get Updates on the Splunk Community!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...