Splunk Search

Two earliest queries - want search to pick based upon newest

htkhtk
Path Finder

I have a query where I need to determine the earliest time I want events from.. It is either (1) The last time jboss started or (2) 30 minutes since the last event in the logs. (Whichever is closest to current time.)

How do i do that in a query most efficiently?

Here are the subsearches.

[search sourcetype="server_log" 
    | head 1 
    | eval test = relative_time(_time, "-30m@m") 
    | rename test as earliest 
    | fields earliest
] 


[search sourcetype="server_log" "starting service(s)" 
    | head 1 
    | rename _time as earliest
    | fields earliest
]

Thanks!

Tags (1)
1 Solution

southeringtonp
Motivator

How about this?

[ search sourcetype="server_log"
    | head 1
    | eval eventtime = relative_time(_time, "-30m@m")
    | append [ 
         search sourcetype="server_log" "starting service(s)"
         | head 1
         | rename _time as eventtime 
      ]
    | stats max(eventtime) as earliest
]

View solution in original post

0 Karma

southeringtonp
Motivator

How about this?

[ search sourcetype="server_log"
    | head 1
    | eval eventtime = relative_time(_time, "-30m@m")
    | append [ 
         search sourcetype="server_log" "starting service(s)"
         | head 1
         | rename _time as eventtime 
      ]
    | stats max(eventtime) as earliest
]
0 Karma
Get Updates on the Splunk Community!

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...