<?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: Calculate diff in timings of down and up consecutive events and show if more than 10 days in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Calculate-diff-in-timings-of-down-and-up-consecutive-events-and/m-p/341834#M101276</link>
    <description>&lt;P&gt;Hi atulitm,&lt;/P&gt;

&lt;P&gt;You can try transaction command here&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index= "neighbor"  | transaction startswith="neighbor is up" endswith="neighbor is down" | eval duration = (duration/60) | where duration &amp;gt; 14400 | table host  _time
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 08 Mar 2018 14:39:44 GMT</pubDate>
    <dc:creator>anjambha</dc:creator>
    <dc:date>2018-03-08T14:39:44Z</dc:date>
    <item>
      <title>Calculate diff in timings of down and up consecutive events and show if more than 10 days</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculate-diff-in-timings-of-down-and-up-consecutive-events-and/m-p/341833#M101275</link>
      <description>&lt;P&gt;Example Logs(ignore time format as it is as expected by splunk :&lt;BR /&gt;
1 jan neibhor is up&lt;BR /&gt;
10 jan jan neibhor is down&lt;BR /&gt;
20 jan neibhor is up&lt;BR /&gt;
30 jan neibhor is down&lt;BR /&gt;
1 feb neibhor is up&lt;/P&gt;

&lt;P&gt;I will like to see time diff between down log and up log and if its more than 10 days then show when it went down and came up in table . I was able to see last down event and since when but couldnt get it working what i need . &lt;/P&gt;

&lt;H2&gt;index= "neighbor" AND Up OR Down | rex "neighbor (?\d+.\d+.\d+.\d+) (?\w+") | dedup host | where status = "Down" |  eval "Down Since" = toString(date_mday) + " " + toString(date_month) + " " + toString(date_year)| table host ip status "Down Since"&lt;/H2&gt;</description>
      <pubDate>Tue, 29 Sep 2020 18:23:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculate-diff-in-timings-of-down-and-up-consecutive-events-and/m-p/341833#M101275</guid>
      <dc:creator>atulitm</dc:creator>
      <dc:date>2020-09-29T18:23:23Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate diff in timings of down and up consecutive events and show if more than 10 days</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculate-diff-in-timings-of-down-and-up-consecutive-events-and/m-p/341834#M101276</link>
      <description>&lt;P&gt;Hi atulitm,&lt;/P&gt;

&lt;P&gt;You can try transaction command here&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index= "neighbor"  | transaction startswith="neighbor is up" endswith="neighbor is down" | eval duration = (duration/60) | where duration &amp;gt; 14400 | table host  _time
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 08 Mar 2018 14:39:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculate-diff-in-timings-of-down-and-up-consecutive-events-and/m-p/341834#M101276</guid>
      <dc:creator>anjambha</dc:creator>
      <dc:date>2018-03-08T14:39:44Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate diff in timings of down and up consecutive events and show if more than 10 days</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculate-diff-in-timings-of-down-and-up-consecutive-events-and/m-p/341835#M101277</link>
      <description>&lt;P&gt;Please use strptime command eval MyDate=strptime(date,"date format") and find the difference between the epoch time to get the epoch values then put your condition like diff&amp;gt;15001&lt;BR /&gt;
i think this will surely help you.&lt;BR /&gt;
eg:&lt;BR /&gt;
your base query | eval MyDate=strptime(date,"%d %b %Y %H:%M:%S") | fieldformat StartTime=strptime(MyDate, "%Y-%m-%d %H:%M:%S") | eval Diff=tostring((StartTime-EndTime),"duration") | where Diff&amp;gt;15000&lt;/P&gt;</description>
      <pubDate>Thu, 08 Mar 2018 15:02:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculate-diff-in-timings-of-down-and-up-consecutive-events-and/m-p/341835#M101277</guid>
      <dc:creator>logloganathan</dc:creator>
      <dc:date>2018-03-08T15:02:18Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate diff in timings of down and up consecutive events and show if more than 10 days</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculate-diff-in-timings-of-down-and-up-consecutive-events-and/m-p/341836#M101278</link>
      <description>&lt;P&gt;Hi atulitm,&lt;BR /&gt;
you could use transpose command but it's very slow:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; index=neighbor
| transaction host startswith="is down" endswith="is up" 
| where duration &amp;gt; 864000 
| table host _time
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Bye.&lt;BR /&gt;
Giuseppe&lt;/P&gt;</description>
      <pubDate>Thu, 08 Mar 2018 15:08:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculate-diff-in-timings-of-down-and-up-consecutive-events-and/m-p/341836#M101278</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2018-03-08T15:08:35Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate diff in timings of down and up consecutive events and show if more than 10 days</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculate-diff-in-timings-of-down-and-up-consecutive-events-and/m-p/341837#M101279</link>
      <description>&lt;P&gt;Sorry , Actually this doesnt work because log exactly is like this which contains  which is variable , not sure how to get that variable things&lt;BR /&gt;
1 jan neibhor   up&lt;BR /&gt;
10 jan jan neibhor  down Notification Sent&lt;BR /&gt;
20 jan neibhor  up&lt;BR /&gt;
30 jan neibhor  down Notification Sent&lt;/P&gt;</description>
      <pubDate>Thu, 08 Mar 2018 15:43:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculate-diff-in-timings-of-down-and-up-consecutive-events-and/m-p/341837#M101279</guid>
      <dc:creator>atulitm</dc:creator>
      <dc:date>2018-03-08T15:43:22Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate diff in timings of down and up consecutive events and show if more than 10 days</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculate-diff-in-timings-of-down-and-up-consecutive-events-and/m-p/341838#M101280</link>
      <description>&lt;P&gt;@atulitm does your log always have up and down as consecutive events? Do you want the duration between each Down and Up status as Downtime trending or only if the latest status is Down then how long has it been down?&lt;/P&gt;</description>
      <pubDate>Thu, 08 Mar 2018 16:44:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculate-diff-in-timings-of-down-and-up-consecutive-events-and/m-p/341838#M101280</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2018-03-08T16:44:47Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate diff in timings of down and up consecutive events and show if more than 10 days</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculate-diff-in-timings-of-down-and-up-consecutive-events-and/m-p/341839#M101281</link>
      <description>&lt;P&gt;@niketnilay :&lt;BR /&gt;
Sorry for confusion , Actually i noticed this query is looking for first down event and then up event which occured after 10 days but instead i would like to have query to check time difference between 2 consecutive logs and see if time difference is more than days to check downtime  , As you said i want the duration between each Down and Up status as Downtime trending and check for duration between each cosequetive up and down event for downtime which is greater than 10 days .&lt;/P&gt;</description>
      <pubDate>Fri, 09 Mar 2018 09:57:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculate-diff-in-timings-of-down-and-up-consecutive-events-and/m-p/341839#M101281</guid>
      <dc:creator>atulitm</dc:creator>
      <dc:date>2018-03-09T09:57:47Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate diff in timings of down and up consecutive events and show if more than 10 days</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculate-diff-in-timings-of-down-and-up-consecutive-events-and/m-p/341840#M101282</link>
      <description>&lt;P&gt;Actually i noticed this query is looking for first down event and then up event which occured after 10 days but instead i would like to have query to check time difference between 2 consecutive logs and see if time difference is more than days to check downtime ,  i want the duration between each Down and Up status as Downtime trending and check for duration between each cosequetive up and down event for downtime which is greater than 10 days .&lt;/P&gt;</description>
      <pubDate>Fri, 09 Mar 2018 10:01:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculate-diff-in-timings-of-down-and-up-consecutive-events-and/m-p/341840#M101282</guid>
      <dc:creator>atulitm</dc:creator>
      <dc:date>2018-03-09T10:01:55Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate diff in timings of down and up consecutive events and show if more than 10 days</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculate-diff-in-timings-of-down-and-up-consecutive-events-and/m-p/341841#M101283</link>
      <description>&lt;P&gt;@atulitm, ideally Splunk shows up data in reverse chronological order, however, you sample has it in chronological order. In either case based on the description/clarification, each consecutive event will have a new status and you require the duration for which the status has been up or down. &lt;/P&gt;

&lt;P&gt;Following is a run anywhere search which finds the uptime or downtime using &lt;CODE&gt;streamstats&lt;/CODE&gt; command. Using &lt;CODE&gt;window=1&lt;/CODE&gt; you can get the previous event values with &lt;CODE&gt;last()&lt;/CODE&gt; statistical aggregate function. &lt;/P&gt;

&lt;P&gt;PS: streamstats is highly dependent on the sorted data based on time (unsorted data will give inconsistent results and based on the type of sort the calculations might need to be changed/reversed.&lt;/P&gt;

&lt;P&gt;Following is based on chronological order of data. If the same is in reverse chronological order you might have to use &lt;CODE&gt;| reverse&lt;/CODE&gt;, prior to &lt;CODE&gt;streamstats&lt;/CODE&gt; command.&lt;/P&gt;

&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/4524i8DB002E1ED972AA5/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval data="1 jan neibhor is up;10 jan neibhor is down;20 jan neibhor is up;30 jan neibhor is down;1 feb neibhor is up"
| makemv data delim=";"
| mvexpand data
| rename data as _raw
| rex "^(?&amp;lt;_time&amp;gt;[^\s]+\s[^\s]+)\sneibhor is\s(?&amp;lt;status&amp;gt;.*)$"
| eval _time=strptime(_time,"%d %b")
| streamstats last(_time) as prevTime last(status) as prevStatus  window=1 current=f
| eval duration=replace(tostring(_time-prevTime,"duration"),"^([^\+]+)(.*)","\1 days")
| fields - prevTime
| eval statusMsg= prevStatus." since ".duration
| fields - prevStatus status duration
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;PS: Commands from &lt;CODE&gt;makeresult&lt;/CODE&gt; to &lt;CODE&gt;rename&lt;/CODE&gt; generate mock data as per question. You would need to add your own query to fetch the data (as stated in your question).&lt;BR /&gt;
Once you test &lt;CODE&gt;rex&lt;/CODE&gt; to be working as expected, you should created a Field Extraction using the same Regular Expression for better maintenance and re-usability of the fields.&lt;/P&gt;

&lt;P&gt;You can remove pipes with &lt;CODE&gt;| field -&lt;/CODE&gt; to retain all the fields and understand how query is working.&lt;/P&gt;</description>
      <pubDate>Sat, 10 Mar 2018 17:49:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculate-diff-in-timings-of-down-and-up-consecutive-events-and/m-p/341841#M101283</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2018-03-10T17:49:39Z</dc:date>
    </item>
  </channel>
</rss>

