Splunk Search

last status changed time

roopeshetty
Path Finder

Hi Guys,

 

I have this query , which will provide me the list of “Name” on which ProtectionStatus is OFF.

index=altiris sourcetype=altiris source=altiris_BGP_Excluded_WithREGION OR source=mi_input://altiris_BGP_Excluded_WithREGION | eval ProtectionStatus = if(Protectionstatus == 0, "OFF", "ON") | dedup Name | where ProtectionStatus="OFF"

 

ProtectionStatus goes OFF and ON frequently ( we run the query in every 6 hours). Here we need to add one more field or column which should show us the time (Date and time) when the last ProtectionStatus change happened (it can be either OFF to ON or ON to OFF). Can some one please help us on this.

Labels (1)
0 Karma
1 Solution

rnowitzki
Builder

You filtered on "OFF"  events before the streamstats, so you don't have any status changes any more after your query...

I removed your where command:

index=altiris sourcetype=altiris source=altiris_BGP_Excluded_WithREGION OR source=mi_input://altiris_BGP_Excluded_WithREGION 
| eval ProtectionStatus = if(Protectionstatus == 0, "OFF", "ON") 
| dedup Name 

| streamstats current=f window=1 last(ProtectionStatus) as prev_status
| eval statuschange=if(ProtectionStatus!=prev_status,"true", "false")

 

You could now add a filter for statuschange=true, so you only see the events where a change of status happened. 

| where statuschange="true"

 

--
Karma and/or Solution tagging appreciated.

View solution in original post

0 Karma

rnowitzki
Builder

Hi @roopeshetty ,

This should give you a start:

| streamstats current=f window=1 last(ProtectionStatus) as prev_status
| eval statuschange=if(ProtectionStatus!=prev_status,"true", "false")


There was a similiar question recently. There is also another option using command "Delta" suggested by @manjunathmeti 

Cheers
Ralph

--
Karma and/or Solution tagging appreciated.
0 Karma

roopeshetty
Path Finder

Hi Ralph,

 

I added the your query at the end of my query (as pasted below) and ran it. It gave me a new field "statuschange" which has value as "false". But actually I want to see the date and time when the last ProtectionStatus change happened (it can be either OFF to ON or ON to OFF).

 

index=altiris sourcetype=altiris source=altiris_BGP_Excluded_WithREGION OR source=mi_input://altiris_BGP_Excluded_WithREGION | eval ProtectionStatus = if(Protectionstatus == 0, "OFF", "ON") | dedup Name | where ProtectionStatus="OFF" | streamstats current=f window=1 last(ProtectionStatus) as prev_status
| eval statuschange=if(ProtectionStatus!=prev_status,"true", "false")

 

0 Karma

rnowitzki
Builder

You filtered on "OFF"  events before the streamstats, so you don't have any status changes any more after your query...

I removed your where command:

index=altiris sourcetype=altiris source=altiris_BGP_Excluded_WithREGION OR source=mi_input://altiris_BGP_Excluded_WithREGION 
| eval ProtectionStatus = if(Protectionstatus == 0, "OFF", "ON") 
| dedup Name 

| streamstats current=f window=1 last(ProtectionStatus) as prev_status
| eval statuschange=if(ProtectionStatus!=prev_status,"true", "false")

 

You could now add a filter for statuschange=true, so you only see the events where a change of status happened. 

| where statuschange="true"

 

--
Karma and/or Solution tagging appreciated.
0 Karma

roopeshetty
Path Finder

thanks Ralph. I got the output now. I really appreciate your help on this.

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 ...