Splunk Search

How to combine results of two stats searches into one so summary information can be displayed in one pie-chart

TMazurek
New Member

I have two searches:

1st search:
index=main sourcetype=ab_alerts | rename ab_alerts.AlertID as AlertID, ab_alerts.SWArea as AVSWArea | stats dc(AlertID) by AVSWArea

that gives output:
alt text

2nd search:
index=main sourcetype=ab_siem_alarms | rename ab_siem_alarms.AlarmId as AlarmID, ab_siem_alarms.SWArea as SWArea | stats dc(AlarmID) by SWArea

that gives output:
alt text

My goal is to add results of both searches so I can display them on as summarized value of both parsed by SWArea

Tags (2)
0 Karma

sundareshr
Legend

How about this

 (index=main sourcetype=ab_alerts) OR (index=main sourcetype=ab_siem_alarms)
 | rename ab_alerts.AlertID as ID,  ab_alerts.SWArea as SWArea, ab_siem_alarms.AlarmId as ID,  ab_siem_alarms.SWArea as SWArea 
 | chart dc(ID) over SWArea by sourcetype
0 Karma

TMazurek
New Member

it give same result as javiergn search
only events from sourcetype=ab_siem_alarms are displayed

on top of that what if AlertID and AlarmId will have same value i.e. 11111 ? It should give me count two not one

0 Karma

javiergn
SplunkTrust
SplunkTrust

If I understand correctly you just want to combine the results of both searches into one table.
If that's the case this is what I would do:

(index=main sourcetype=ab_alerts) OR (index=main sourcetype=ab_siem_alarms)
| rename 
    ab_alerts.AlertID as ID, 
    ab_alerts.SWArea as SWArea, 
    ab_siem_alarms.AlarmId as ID, 
    ab_siem_alarms.SWArea as SWArea 
| stats dc(ID) by SWArea, sourcetype

Or you can simply remove the group by sourcetype if you don't want to display this field.

Thanks,
J

0 Karma

TMazurek
New Member

this one return only records from ab_siem_alarms
furthermore, imagine that AlertID and AlarmId are numeric value. If there will be i.e. Alert 11111 and Alarm 11111 it gives only 1 as distinct count and in fact there are two. Distinct count should show distinct values in sourcetype=ab_alerts and sourcetype=ab_siem_alarms

0 Karma

javiergn
SplunkTrust
SplunkTrust

That's the reason I was grouping by sourcetype too in the stats.

In any case, I can't really reproduce your issue without knowing a bit more about how your data looks like.
Would you be happy to post here 2-3 events from each sourcetype?

0 Karma

inventsekar
Ultra Champion

i hope stats can have more than one "by" clause.

index=main sourcetype=ab_alerts OR sourcetype=ab_siem_alarms
| rename ab_alerts.AlertID as AlertID, ab_alerts.SWArea as AVSWArea ab_siem_alarms.AlarmId as AlarmID, ab_siem_alarms.SWArea as SWArea
| stats dc(AlertID) by AVSWArea, dc(AlarmID) by SWArea
0 Karma

TMazurek
New Member

well it doesnt work at all - 0 results

0 Karma
Get Updates on the Splunk Community!

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

Splunk is officially part of Cisco

Revolutionizing how our customers build resilience across their entire digital footprint.   Splunk ...

Splunk APM & RUM | Planned Maintenance March 26 - March 28, 2024

There will be planned maintenance for Splunk APM and RUM between March 26, 2024 and March 28, 2024 as ...