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!

Unlocking Unified Insights: New Gigamon Federated Search App for Splunk

In today’s data-heavy environment, organizations are caught in a data distribution dilemma. As data volumes ...

GA: New Data Management App in Splunk Platform

Streamlining Data Management: Introducing a unified experience in Splunk Managing data at scale shouldn’t feel ...

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...