Splunk Search

Combining and summing the results of two searches

rajadatta
New Member

Hi -

I have two searches that have the same fields exactly but from different sources.

I would like to join and sum the results and output

The searches:
index="atti" sourcetype="strongmail" source="/data1/strongmail/log/strongmail-retryfailed.log" mailingclass="smtpvhost1.yp.com"|stats count as NumberFailed by MailingId,Bouncetype

MailingId, Bouncetype, NumberFailed
12121,2004,2
12058,3004,4

index="atti" sourcetype="strongmail" source="/data1/strongmail/log/strongmail-failed.log" mailingclass="smtpvhost1.yp.com" |stats count as NumberFailed by MailingId,Bouncetype

MailingId, Bouncetype, NumberFailed
12121,2004,4
12058,3004,6

They return exactly as you see the same columns, I want combine(Sum) the results and output:

MailingId, Bouncetype, NumberFailed
12121,2004,6
12058,3004,10

Thanks.

Tags (2)
0 Karma
1 Solution

woodcock
Esteemed Legend

Like this:

index="atti" sourcetype="strongmail" mailingclass="smtpvhost1.yp.com" (source="/data1/strongmail/log/strongmail-retryfailed.log" OR source="/data1/strongmail/log/strongmail-failed.log") |stats count as NumberFailed by MailingId,Bouncetype

View solution in original post

0 Karma

chimell
Motivator

Hi rajadatta
Try the following query :

    |set union [search index="atti" sourcetype="strongmail" source="/data1/strongmail/log/strongmail-retryfailed.log" mailingclass="smtpvhost1.yp.com"|stats count as NumberFailed by MailingId,Bouncetype  ] [search index="atti" sourcetype="strongmail" source="/data1/strongmail/log/strongmail-failed.log" mailingclass="smtpvhost1.yp.com" |stats count as NumberFailed by MailingId,Bouncetype ]|stats sum(NumberFailed) as total_NumberFailed 
0 Karma

rajadatta
New Member

Thanks for the help. I went with the first answer as it was what I was looking for.

0 Karma

rajadatta
New Member

Thanks this gives me the total failed as count. I can use this as well for another report.

0 Karma

woodcock
Esteemed Legend

Like this:

index="atti" sourcetype="strongmail" mailingclass="smtpvhost1.yp.com" (source="/data1/strongmail/log/strongmail-retryfailed.log" OR source="/data1/strongmail/log/strongmail-failed.log") |stats count as NumberFailed by MailingId,Bouncetype
0 Karma

rajadatta
New Member

Thanks this is what I needed.

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Thanks for the Memories! Splunk University, .conf25, and our Community

Thank you to everyone in the Splunk Community who joined us for .conf25, which kicked off with our iconic ...

Data Persistence in the OpenTelemetry Collector

This blog post is part of an ongoing series on OpenTelemetry. What happens if the OpenTelemetry collector ...

Introducing Splunk 10.0: Smarter, Faster, and More Powerful Than Ever

Now On Demand Whether you're managing complex deployments or looking to future-proof your data ...