Splunk Search

Stats with Join

doppiolover
Loves-to-Learn Lots

I have set of hosts that are installed with different versions of software but logging to the same index, and I need to create a report based on specific versions. Here is an example set of data that I have to deal with.

host

msgCode

msgText

qty

A

101

1.0.0

 

A

103

Nut

48

A

103

Widget

289

B

101

1.1.0

 

B

103

Nut

69

B

103

Widget

367

C

101

1.0.0

 

C

103

Nut

93

C

103

Widget

433

D

101

1.0.3

 

D

101

Nut

74

D

103

192

E

101

1.0.0

 

E

103

Nut

88

E

103

Widget

225


Given this set of data, I would like to get the sum of qty for the hosts that have msgCode=1.0.0. The caveat on this is that msgCode 101 is logged sporadically every couple of days, and when the host gets updated with the newer version,  so I only want to use the most recently logged value as is the case with host B. As such, the result should be something like the following which only sum qty values from hosts A, C E:

Nut

229

Widget

947

 

I can do sum of all qty, but I am not sure how I can filter out host B from it. I was doing something like the following, but then, I just get the result from the sub query.  

 

index=myIndex 
| eventstats sum(qty) by msgCode as partSum 
| table msgCode, partSum 
| join host type=inner [ search index=myIndex msgCode=101 msgText=1.0.0 earliest=-3d | stats count by host ]

 

Labels (5)
0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Assuming there is a typo in your example (host D Nut should be msgCode 103?)

| eval version=if(msgCode="101",msgText,null)
| eventstats values(version) as version by host
| where msgCode!="101" AND version="1.0.0"
| stats sum(qty) as total by msgText
0 Karma

doppiolover
Loves-to-Learn Lots

Thanks. Yes, that's a typo since I was making up the data. I will play around with your suggestion.

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Build the Future of Agentic AI: Join the Splunk Agentic Ops Hackathon

AI is changing how teams investigate incidents, detect threats, automate workflows, and build intelligent ...

[Puzzles] Solve, Learn, Repeat: Character substitutions with Regular Expressions

This challenge was first posted on Slack #puzzles channelFor BORE at .conf23, we had a puzzle question which ...

Splunk Community Badges!

  Hey everyone! Ready to earn some serious bragging rights in the community? Along with our existing badges ...