Splunk Search

Need help in writing query in Splunk

vn_g
Path Finder

Query required :

If a count of certain condition in the last rolling 12 hours exceeds 10% more than the avg daily number of count of certain condition for the last 7 days

Labels (2)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust
"with condition" earliest="-8d@d" latest="@d" 
| bin span=1d _time 
| stats count by _time 
| stats avg(count) as average 
| fields average 
| appendcols 
    [ search "with same condition" earliest="-12h@m"
    | stats count 
    | fields count ]
| eval high=1.1*average
| eval alert=if(count > high, "1", "0")

Set time period of search to be at least the past 8 days

View solution in original post

0 Karma

vn_g
Path Finder

Can you explain why earliest="-12h@m" is used?

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

The overall query has to cover the previous 8 days to get your average daily count, the earliest="-12h@m" is used to restrict this part of the search to be your rolling 12 hours i.e. -12 hours snapped to the minute. If you want it snapped to the hour, then use earliest="-12h@h". This is what I assumed you meant by "last rolling 12 hours"

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust
"with condition" earliest="-8d@d" latest="@d" 
| bin span=1d _time 
| stats count by _time 
| stats avg(count) as average 
| fields average 
| appendcols 
    [ search "with same condition" earliest="-12h@m"
    | stats count 
    | fields count ]
| eval high=1.1*average
| eval alert=if(count > high, "1", "0")

Set time period of search to be at least the past 8 days

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Tech Talk Recap | Mastering Threat Hunting

Mastering Threat HuntingDive into the world of threat hunting, exploring the key differences between ...

Observability for AI Applications: Troubleshooting Latency

If you’re working with proprietary company data, you’re probably going to have a locally hosted LLM or many ...

Splunk AI Assistant for SPL vs. ChatGPT: Which One is Better?

In the age of AI, every tool promises to make our lives easier. From summarizing content to writing code, ...