Splunk Search

Classify into a group

Kirthika
Path Finder

Example logs

2022-08-19 08:10:53.0593|**Starting**

2022-08-19 08:10:53.5905|fff

2022-08-19 08:10:53.6061|dd

2022-08-19 08:10:53.6218|Shutting down

2022-08-19 08:10:53.6218|**Starting**

2022-08-19 08:10:53.6374|fffff

2022-08-19 08:10:53.6686|ddd

2022-08-19 08:10:53.6843|**Starting**

2022-08-19 08:10:54.1530|aa

2022-08-19 08:10:54.1530|vv

 

From this I have created three columns Devicenumber,  _time ,Description

If ** Starting ** message has followed by "Shutting down" mean, it should classify as good and if Starting message has not Shutting down mean, it should classify as bad.

 

From the above example, there should be 2 bad and one good.

 

If there is only one row which has only Starting and no shutting down recorded, in that case also , it should classify as bad

0 Karma

inventsekar
SplunkTrust
SplunkTrust

Nice SPL @ITWhisperer .. 

Hi @Kirthika .. pls check this SPL.. (the stats logic may needs to be fine-tuned)

 

source="testlogrex.txt" host="laptop" sourcetype="nov12"
| rex field=_raw "\|(?<msg>.+)$"
| stats sum(eval(case(msg=="**Starting**",1,msg=="Shutting down",-1))) as bad count(eval(case(msg=="**Starting**",1))) as starts
| eval good=starts-bad

 

this SPL gives this result.. 

bad starts good

572



The Sample logs and rex used here:

source="testlogrex.txt" host="laptop" sourcetype="nov12"
| rex field=_raw "\|(?<msg>.+)$"
| table _raw msg

_raw msg

2022-08-19 08:10:04.6218|Shutting downShutting down
2022-08-19 08:10:03.6061|dd03dd03
2022-08-19 08:10:02.5905|ffffff
2022-08-19 08:10:01.0593|**Starting****Starting**
2022-08-19 08:10:08.6843|**Starting****Starting**
2022-08-19 08:10:07.6686|ddd07ddd07
2022-08-19 08:10:06.6374|fffff06fffff06
2022-08-19 08:10:05.6218|**Starting****Starting**
2022-08-19 08:10:12.5905|fff12fff12
2022-08-19 08:10:11.0593|**Starting****Starting**
2022-08-19 08:10:10.1530|vv10vv10
2022-08-19 08:10:09.1530|aa09aa09
2022-08-19 08:10:16.6374|fffff16fffff16
2022-08-19 08:10:15.6218|**Starting****Starting**
2022-08-19 08:10:14.6218|Shutting downShutting down
2022-08-19 08:10:13.6061|**Starting****Starting**
2022-08-19 08:10:19.15|aa19aa19
2022-08-19 08:10:18.6843|**Starting****Starting**
2022-08-19 08:10:17.6686|ddd17ddd17
2022-08-19 08:10:20.160|vv20vv20

ITWhisperer
SplunkTrust
SplunkTrust
| rex field=logs "\|(?<msg>.+)$"
| stats sum(eval(case(msg=="**Starting**",1,msg=="Shutting down",-1))) as bad count(eval(case(msg=="**Starting**",1))) as starts
| eval good=starts-bad
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!

Fuel Your Journey: What’s Waiting for You at the .conf26 Acceleration Station

Navigating the show floor at .conf26 isn't just about keynotes and technical breakout sessions; it's also ...

Join the Final Session of the Data Management & Federation Bootcamp Series

Over the past three sessions of the Data Management & Federation Bootcamp Series, we've explored how to build ...

From Data to Insight: Announcing the Winners of the Splunk Dashboard Contest

Hi Splunkers, First off, thank you to everyone who participated in our very first From Data to Insight: The ...