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!

Splunk Observability for AI

Don’t miss out on an exciting Tech Talk on Splunk Observability for AI!Discover how Splunk’s agentic AI ...

Splunk Enterprise Security 8.x: The Essential Upgrade for Threat Detection, ...

Watch On Demand the Tech Talk on November 6 at 11AM PT, and empower your SOC to reach new heights! Duration: ...

Splunk Observability as Code: From Zero to Dashboard

For the details on what Self-Service Observability and Observability as Code is, we have some awesome content ...