Splunk Search

How to search for records between respective timezones?

ran_deep
New Member

We have logs from multiple region, but only want to report those between respective regions working hours.
Created following query which works fine when putting an absolute number, but doesn't filter by variables.

 

 

 

index=ovpm sourcetype=ovpm_global
| search "Service Name" = "WSB EXPRESS"
| eval region = case(substr(SYSTEMNAME, 1, 2) == "my", "AP", substr(SYSTEMNAME, 1, 2) == "cz", "EU", substr(SYSTEMNAME, 1, 2) == "us", "AM", true(), "Other")
| eval regionStartHour = tonumber(case(substr(SYSTEMNAME, 1, 2) == "my", 0, substr(SYSTEMNAME, 1, 2) == "cz", 8, substr(SYSTEMNAME, 1, 2) == "us", 16, true(), 0))
| eval regionEndHour = tonumber(case(substr(SYSTEMNAME, 1, 2) == "my", 8, substr(SYSTEMNAME, 1, 2) == "cz", 16, substr(SYSTEMNAME, 1, 2) == "us", 24, true(), 0))
| eval hr = strftime(_time, "%H") | search hr>=regionStartHour AND hr<=regionEndHour

 

 

 

 

Labels (2)
0 Karma

richgalloway
SplunkTrust
SplunkTrust

The search command cannot handle a field ("variable") name on both sides of the operator.  Use where, instead.

index=ovpm sourcetype=ovpm_global
| search "Service Name" = "WSB EXPRESS"
| eval region = case(substr(SYSTEMNAME, 1, 2) == "my", "AP", substr(SYSTEMNAME, 1, 2) == "cz", "EU", substr(SYSTEMNAME, 1, 2) == "us", "AM", true(), "Other")
| eval regionStartHour = tonumber(case(substr(SYSTEMNAME, 1, 2) == "my", 0, substr(SYSTEMNAME, 1, 2) == "cz", 8, substr(SYSTEMNAME, 1, 2) == "us", 16, true(), 0))
| eval regionEndHour = tonumber(case(substr(SYSTEMNAME, 1, 2) == "my", 8, substr(SYSTEMNAME, 1, 2) == "cz", 16, substr(SYSTEMNAME, 1, 2) == "us", 24, true(), 0))
| eval hr = strftime(_time, "%H") 
| where hr>=regionStartHour AND hr<=regionEndHour
---
If this reply helps you, Karma would be appreciated.
0 Karma
Get Updates on the Splunk Community!

Splunk Decoded: Service Maps vs Service Analyzer Tree View vs Flow Maps

It’s Monday morning, and your phone is buzzing with alert escalations – your customer-facing portal is running ...

What’s New in Splunk Observability – September 2025

What's NewWe are excited to announce the latest enhancements to Splunk Observability, designed to help ITOps ...

Fun with Regular Expression - multiples of nine

Fun with Regular Expression - multiples of nineThis challenge was first posted on Slack #regex channel ...