<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to find event status changed in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-event-status-changed/m-p/455112#M128745</link>
    <description>&lt;P&gt;This solution works well for me.  I am able to get data from logs with multiple outage from different servers.  Thank you.&lt;/P&gt;</description>
    <pubDate>Thu, 16 May 2019 18:31:26 GMT</pubDate>
    <dc:creator>atpsplunk11</dc:creator>
    <dc:date>2019-05-16T18:31:26Z</dc:date>
    <item>
      <title>How to find event status changed</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-event-status-changed/m-p/455110#M128743</link>
      <description>&lt;P&gt;Hello everyone!&lt;/P&gt;

&lt;P&gt;We have a log file contains the following information, status 0 means server is up, 1 means down:&lt;BR /&gt;
Date/time Server Status&lt;BR /&gt;
2019/02/11 120000 server1 1&lt;BR /&gt;
2019/02/11 120000 server2 0&lt;BR /&gt;
2019/02/11 123000 server1 0&lt;/P&gt;

&lt;P&gt;This file contains many servers' status generated by a cron job. I want to write a Splunk query/search to show all servers which were down and for how long. My desire output would be similar to the following&lt;BR /&gt;
Server From To Duration&lt;BR /&gt;
server1 2019/02/11 120000 2019/02/11 123000 30&lt;/P&gt;

&lt;P&gt;Thus I would find a server status is "1", then need to find the immediate status "0" for the same server to calculate the outage time.  How do I write this search query?&lt;/P&gt;

&lt;P&gt;Since a server could be down for a long period, this log file could have multiple entries for same server continuously, such as&lt;BR /&gt;
2019/02/11 120000 server1 1&lt;BR /&gt;
2019/02/11 120000 server2 0&lt;BR /&gt;
2019/02/11 120300 server1 1&lt;BR /&gt;
2019/02/11 120300 server2 0&lt;BR /&gt;
2019/02/11 130000 server1 0&lt;/P&gt;

&lt;P&gt;Any help is appreciated!&lt;/P&gt;</description>
      <pubDate>Tue, 14 May 2019 15:47:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-event-status-changed/m-p/455110#M128743</guid>
      <dc:creator>atpsplunk11</dc:creator>
      <dc:date>2019-05-14T15:47:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to find event status changed</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-event-status-changed/m-p/455111#M128744</link>
      <description>&lt;P&gt;Try something like this:&lt;/P&gt;

&lt;P&gt;Notes:&lt;BR /&gt;
1) I'm assuming your date/time field is called "_time"; you didn't specify. I'm also assuming your date/time field is in the Splunk standard epoch time. If it's not, it's easy enough to change this to epoch time using the eval command and strptime function.&lt;/P&gt;

&lt;P&gt;2) You didn't list your search / filter criteria or how you are accessing the data, so the first line is vague.&lt;/P&gt;

&lt;P&gt;3) This assumes your data is up-to-date to the time of running this search. If you are missing data close to the time of search, some of the durations will not calculate properly (as they calculate based on the current time).&lt;/P&gt;

&lt;P&gt;4) I generally use all lowercase... everything below is lowercase except for what you specified above.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; index=foo sourcetype=bar, etc. 
 | sort 0 Server -_time 
 | autoregress Server as last_Server
 | streamstats count(eval(Status=0 OR (NOT Server=last_Server))) as unique_count
 | delta _time as Duration
 | search Status=1
 | eval Duration=if(isnull(Duration) OR (NOT Server=last_Server),now() - _time,abs(Duration))
 | stats earliest(_time) as From sum(Duration) as Duration by Server unique_count
 | sort 0 -From
 | eval To=strftime(From+Duration,"%c"), From=strftime(From,"%c")
 | fields Server From To Duration
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 14 May 2019 21:16:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-event-status-changed/m-p/455111#M128744</guid>
      <dc:creator>Tedesco1</dc:creator>
      <dc:date>2019-05-14T21:16:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to find event status changed</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-event-status-changed/m-p/455112#M128745</link>
      <description>&lt;P&gt;This solution works well for me.  I am able to get data from logs with multiple outage from different servers.  Thank you.&lt;/P&gt;</description>
      <pubDate>Thu, 16 May 2019 18:31:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-event-status-changed/m-p/455112#M128745</guid>
      <dc:creator>atpsplunk11</dc:creator>
      <dc:date>2019-05-16T18:31:26Z</dc:date>
    </item>
  </channel>
</rss>

