Splunk Search

How do I combine my two searches to get expected results?

Joshua
Explorer

Hi,

Can someone help me?
I have the searches below and need to be combine the two to display the expected results:

    LastWKTotal ThisWKTotal Difference
ABC         
DEF         
GHI         
.

Searches:

index=xxx host=xxx sourcetype=ABC* Agent_NumberOfAgents=* earliest=-14d@d latest=-7d@d | dedup host | stats sum(Agent_NumberOfAgents) as LastWKTotal | appendcols [search index=XXX host=xxx sourcetype=ABC* Agent_NumberOfAgents=* earliest=-7d@d latest=now | dedup host | stats sum(Agent_NumberOfAgents) as ThisWKTotal] | eval Platform="ABC" | eval Difference=ThisWKTotal-LastWKTotal

and

index=XXX host=XXX sourcetype=ABC* Agent_NumberOfAgents=* earliest=-14d@d latest=-7d@d | dedup host | stats sum(Agent_NumberOfAgents) as LastWKTotal | appendcols [search index=XXX host=XXX sourcetype=ABC* Agent_NumberOfAgents=* earliest=-7d@d latest=now | dedup host | stats sum(Agent_NumberOfAgents) as ThisWKTotal ] | eval Platform="DEF" | eval Difference=ThisWKTotal-LastWKTotal

Thanks in Advance

0 Karma

somesoni2
Revered Legend

Give this a try

index=xxx host=xxx (sourcetype=ABC* OR sourcetype=DEF*) Agent_NumberOfAgents=* earliest=-14d@d latest=now 
| eval Platform=if(like(sourcetype,"ABC%"),"ABC","DEF") 
| eval week=if(_time>=relative_time(now(),"-7d@d"),"ThisWKTotal","LastWKTotal") 
| dedup week Platform host 
| chart sum(Agent_NumberOfAgents) over Platform by week | eval Difference=ThisWKTotal-LastWKTotal
0 Karma

gabriel_vasseur
Contributor

If I understand what you mean, you just want to daisy-chain results from different searches... you should be able to do that simply with:

<INSERT_FIRST_SEARCH_HERE> | append [ search <INSERT_SECOND_SEARCH_HERE> ] | append [ search <INSERT_THIRD_SEARCH_HERE> ]

Etc.

0 Karma

jkat54
SplunkTrust
SplunkTrust

should sourcetypes be DEF* in the 2nd search? ...

should both searches provided by combined together, or are they examples of you trying to combine 2 searches together?

I ask because they are the same exact search only in the 2nd one you eval Platform="DEF" at the very end.

Also, would be great if you provided example data.

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

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...