Splunk Search

duration calculator with current time

jerinvarghese
Communicator

Need help in find a query to get the duration of the alert w.r.t the current time.

Current code am using:

index=opennms "uei.opennms.org/nodes/nodeUp" OR "uei.opennms.org/nodes/nodeDown" AND ("*WANR*" OR "*LAN*") 
| search * 
| rex field=eventuei "uei.opennms.org/nodes/node(?<bgpPeerState>.+)"
 | stats max(_time) as Time_IST latest(bgpPeerState) as Status by nodelabel
 | where Status="Down"

 | lookup ONMS_nodes.csv nodelabel OUTPUT nodelabel
| lookup ONMS_nodes.csv nodelabel OUTPUT sitecode
| lookup GRDB_site_list.csv "Site Code" as sitecode OUTPUT Region, Country,"Precious Metal" as Metal, "Site Classification" as Class
| eval Region=mvindex(Region,0) 
| eval Country=mvindex(Country,0) 
| eval Metal=mvindex(Metal,0)
| eval sitecode=if(isnull(sitecode),"Unknown", sitecode) 
| eval Country=if(isnull(Country),"Unknown", Country) 
| eval Metal=if(isnull(Metal),"Unknown", Metal) 
| eval Class=if(isnull(Class),"Unknown", Class) 
| eval Region=if(isnull(Region),"Unknown", Region)
| search Country="*"

| rename nodelabel as "Hostname" ,   Class as Classification, sitecode as "Site Code"

| fieldformat Time_IST=strftime(Time_IST+10.5*3600,"%Y-%m-%d %l:%M:%S %p")
 | sort- Time_IST
 | table Hostname Status Classification "Site Code" Time_IST

Table of output below:

    Hostname    Status  Classification  Site Code   Time_IST
1   GBABO-1 Down    Silver  ABO 2020-05-05  1:33:37 PM
2   GBABO-2 Down    Silver  ABO 2020-05-05  1:33:15 PM

I am looking for a query to get the duration of the event.

Table am expecting.

Hostname    Status  Classification  Site Code   Time_IST    Duration

My splunk timing is in CST time zone.

0 Karma

richgalloway
SplunkTrust
SplunkTrust

Perhaps this will help.

...| sort- Time_IST
| eval Duration = tostring(now() - Time_IST, "duration")
| table Hostname Status Classification "Site Code" Time_IST Duration
---
If this reply helps you, Karma would be appreciated.
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!

[Puzzles] Solve, Learn, Repeat: Matching cron expressions

This puzzle (first published here) is based on matching timestamps to cron expressions.All the timestamps ...

Design, Compete, Win: Submit Your Best Splunk Dashboards for a .conf26 Pass

Hello Splunkers,  We’re excited to kick off a Splunk Dashboard contest! We know that dashboards are a primary ...

May 2026 Splunk Expert Sessions: Security & Observability

Level Up Your Operations: May 2026 Splunk Expert Sessions Whether you are refining your security posture or ...