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
thanks and best regards,
Sekar

PS - If this or any post helped you in any way, pls consider upvoting, thanks for reading !

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
Get Updates on the Splunk Community!

Application management with Targeted Application Install for Victoria Experience

  Experience a new era of flexibility in managing your Splunk Cloud Platform apps! With Targeted Application ...

Index This | What goes up and never comes down?

January 2026 Edition  Hayyy Splunk Education Enthusiasts and the Eternally Curious!   We’re back with this ...

Splunkers, Pack Your Bags: Why Cisco Live EMEA is Your Next Big Destination

The Power of Two: Splunk &#43; Cisco at "Ludicrous Scale"   You know Splunk. You know Cisco. But have you seen ...