Splunk Search

Splunk Query to compute the count of consecutive hourly violations per day

iTechEvent
Explorer

I have data like this...

  • Date - Hour - Sample Number
  • 05/01/2014 - 10 - 200
  • 05/01/2014 - 11 - 201
  • 05/01/2014 - 12 - 202
  • 05/01/2014 - 15 - 205
  • 05/01/2014 - 16 - 206
  • 05/01/2014 - 20 - 210

On 05/01/2014 the max number of consecutive hourly violations i.e. sample 200,201,202 is 3 and occurred between hours 10 to 12.

I have data like this for each day for a month.

I need a splunk query to computer the per day max consecutive hourly violations and the time range between in which it occurred.

Similarly for the entire month I would like the date in which the max number of hourly violations occurred for the month and time range of day.

Any help will be appreciated.

Thanks in advance.

0 Karma
1 Solution

lguinn2
Legend

This solution assumes that your event timestamp (_time) corresponds to the Date and Hour in your events.

yoursearchhere
| transaction Date maxpause=61m
| eval earliestHour=strftime(_time,"%H")
| eval latestHour=strftime(_time+duration,"%H")
| eval errorCount = eventcount
| table Date earliestHour latestHour errorCount
| sort Date -errorCount
| dedup Date

This should work great as long as you have less than 1000 events per Date. Otherwise, Splunk can get a little picky about compiling the transactions - and at that point the solution might start to slow down anyway.

View solution in original post

0 Karma

lguinn2
Legend

This solution assumes that your event timestamp (_time) corresponds to the Date and Hour in your events.

yoursearchhere
| transaction Date maxpause=61m
| eval earliestHour=strftime(_time,"%H")
| eval latestHour=strftime(_time+duration,"%H")
| eval errorCount = eventcount
| table Date earliestHour latestHour errorCount
| sort Date -errorCount
| dedup Date

This should work great as long as you have less than 1000 events per Date. Otherwise, Splunk can get a little picky about compiling the transactions - and at that point the solution might start to slow down anyway.

0 Karma

manish_singh_77
Builder

@lguinn2

I have a query, there is a table where we have the job_result column, if we get consective 5 jobs failed then we need to be alerted.

0 Karma

iTechEvent
Explorer

Awesome lguinn! Works well. Great Insight.

0 Karma
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!

Why Splunk Customers Should Attend Cisco Live 2026 Las Vegas

Why Splunk Customers Should Attend Cisco Live 2026 Las Vegas     Cisco Live 2026 is almost here, and this ...

What Is the Name of the USB Key Inserted by Bob Smith? (BOTS Hint, Not the Answer)

Hello Splunkers,   So you searched, “what is the name of the usb key inserted by bob smith?”  Not gonna lie… ...

Automating Threat Operations and Threat Hunting with Recorded Future

    Automating Threat Operations and Threat Hunting with Recorded Future June 29, 2026 | Register   Is your ...