Alerting

How to compare 2 values from Same field?

samjoshiacademi
Explorer

I am having one field and it has 2 values. Comparing them with each other I want to generate a message whether "Success" or "Failure".
Below are details:

// Search
| table _time, ErrorCount | sort 2 _time

It gives me result like

         _time                           ErrorCount
       2-Jan-20 16:35:00                  10
       2-Jan-20 16:34:00                  14  

I want to show "Success" if ErrorCount at latestTime < ErrorCount at earliestTime and failure if its otherwise.

Tags (1)
0 Karma
1 Solution

jpolvino
Builder

Here is one way to do it:

| makeresults 
| eval data="2-Jan-20 16:35:00,10;
2-Jan-20 16:34:00,14"
| makemv data delim=";" | mvexpand data | rex field=data "(\s|\n?)(?<data>.*)" | makemv data delim=","
| eval _time=strptime(mvindex(data,0),"%d-%b-%y %H:%M:%S"),
     ErrorCount=mvindex(data,1)
| fields _time ErrorCount
| autoregress ErrorCount p=1
| eval status=case(ErrorCount<ErrorCount_p1,"Success",ErrorCount>=ErrorCount_p1,"Failure",1==1,null())
| fields - ErrorCount_p1

This uses autoregress to allow comparison with earlier rows.

View solution in original post

jpolvino
Builder

Here is one way to do it:

| makeresults 
| eval data="2-Jan-20 16:35:00,10;
2-Jan-20 16:34:00,14"
| makemv data delim=";" | mvexpand data | rex field=data "(\s|\n?)(?<data>.*)" | makemv data delim=","
| eval _time=strptime(mvindex(data,0),"%d-%b-%y %H:%M:%S"),
     ErrorCount=mvindex(data,1)
| fields _time ErrorCount
| autoregress ErrorCount p=1
| eval status=case(ErrorCount<ErrorCount_p1,"Success",ErrorCount>=ErrorCount_p1,"Failure",1==1,null())
| fields - ErrorCount_p1

This uses autoregress to allow comparison with earlier rows.

samjoshiacademi
Explorer

Thanks:) worked swiftly

Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...