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!

Quantify Your Splunk Investment Impact: Introducing Savings Metrics to Value Insights

Building on the foundation established in our initial Value Insights releases, we are introducing the Savings ...

Event Series: Telemetry Pipeline Management

Balancing Scale and Spend: Gaining Control Over High-Volume Metrics in Splunk Observability Cloud As ...

Kick the Tires Before You Commit: A Hands-On Tour of the Splunk Observability Cloud ...

Evaluating an enterprise observability platform usually goes like this: fill out a form, get a free trial with ...