Splunk Search

Possibly to alert based on previous sample comparison

Silah
Path Finder

Hi

Put simply, I am trying to wrap my head around how I can configure an alert to trigger is a metric is X% higher or lower than the same metric, say 1 day ago.

So for example if I search

index=my_index eventStatus=fault | stats count by eventStatus

Searching "Last 15 minutes", giving say 100 results, can I trigger an alert IF the same search in the same 15 minute timeframe 1 day ago is for example 10% higher or lower?

 

Thanks

Labels (2)
Tags (2)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust

Try something like this (note that if your time range spans midnight, then you will have to do something else with the bin _time)

index=my_index eventStatus=fault [| makeresults
    | eval row=mvrange(0,2) 
    | mvexpand row
    | addinfo
    | eval earliest=relative_time(info_min_time,(row*-1)."d")
    | eval latest=relative_time(info_max_time,(row*-1)."d")
    | table earliest latest]
| bin _time span=1d
| chart count by eventStatus _time
| foreach 1*
    [eval diff=if(isnull(diff),'<<FIELD>>',abs((diff-'<<FIELD>>')/diff))]
| where diff >0.15

View solution in original post

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Try something like this (note that if your time range spans midnight, then you will have to do something else with the bin _time)

index=my_index eventStatus=fault [| makeresults
    | eval row=mvrange(0,2) 
    | mvexpand row
    | addinfo
    | eval earliest=relative_time(info_min_time,(row*-1)."d")
    | eval latest=relative_time(info_max_time,(row*-1)."d")
    | table earliest latest]
| bin _time span=1d
| chart count by eventStatus _time
| foreach 1*
    [eval diff=if(isnull(diff),'<<FIELD>>',abs((diff-'<<FIELD>>')/diff))]
| where diff >0.15
0 Karma

Silah
Path Finder

Thanks, this seem to be producing something like what I am looking for.

Can I ask, what is the significance of this? I don't really understand it

'<<FIELD>>'

 Thanks

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

The foreach command goes through each field listed in the foreach command, in this instance, fieldnames beginning with 1 followed by anything. The time values are all epoch times, which are the number of seconds since the beginning of 1970. At present, these all start with 1. Eventually, in a about 9 years time, this will start with 2. So, within the subsearch of the foreach command (within the square brackets []), the <<FIELD>> value in the subsearch is replaced by the field name from the list. Since, in this case, this is a number, the <<FIELD>> is placed in single quotes '<<FIELD>>' to tell Splunk that it is to be interpreted as a field name (not a number).

0 Karma

bowesmana
SplunkTrust
SplunkTrust

If you search both time segments then work out which group the time belongs to, then compare the two

See this example

index=_audit (earliest=-1d@d latest=-1d@d+15m) OR (earliest=@d latest=@d+15m)
| eval group=if(_time>relative_time(now(),"@d"), "Prev", "Current")
| chart count over user by group
| eval alert=if(Current > Prev * 1.15, 1, 0)

So this sets group according to where _time sits then just chart over user and calculate excess

 

0 Karma

Silah
Path Finder

Thanks, I tried this but it only seems to list results that ocurred between 00:00 and 00:15 despite the search being "15 minutes ago"

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

That's why my solution uses addinfo which gives you the "earliest" and "latest" times from the timepicker

0 Karma
Get Updates on the Splunk Community!

Preparing your Splunk Environment for OpenSSL3

The Splunk platform will transition to OpenSSL version 3 in a future release. Actions are required to prepare ...

Unleash Unified Security and Observability with Splunk Cloud Platform

     Now Available on Microsoft AzureThursday, March 27, 2025  |  11AM PST / 2PM EST | Register NowStep boldly ...

Splunk AppDynamics with Cisco Secure Application

Web applications unfortunately present a target rich environment for security vulnerabilities and attacks. ...