<?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: Need a little help converting seconds to days, hours, minutes in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Need-a-little-help-converting-seconds-to-days-hours-minutes/m-p/301619#M90821</link>
    <description>&lt;P&gt;This is somewhat incomplete, but you would put this in your search like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=windows sourcetype=WinEventLog* host!="*.xx.com" EventCode=6013 
| rex field=Message "The system uptime is\s+(?P&amp;lt;secs&amp;gt;\d+)\s+seconds" 
| eval strSecs=tostring(secs,"duration")
| rex field=strSecs mode=sed "s/(\d*)\+(\d*):(\d*):(\d*)/\1 day \2 hrs \3 min \4 sec/"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 11 Oct 2017 19:15:53 GMT</pubDate>
    <dc:creator>cpetterborg</dc:creator>
    <dc:date>2017-10-11T19:15:53Z</dc:date>
    <item>
      <title>Need a little help converting seconds to days, hours, minutes</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Need-a-little-help-converting-seconds-to-days-hours-minutes/m-p/301609#M90811</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;

&lt;P&gt;Windows reports everything in really long seconds uptime fields.  I want to convert that to days, hours, minutes.  Trying to get syntax provided in another post to work (and think I'm close) but now receiving "eval" command: Regex unmatched closing parens message that I can't seem to find.&lt;/P&gt;

&lt;P&gt;Here's my search:&lt;/P&gt;

&lt;P&gt;index=windows sourcetype=WinEventLog* host!="*.xx.com" EventCode=6013 |  rex "(?\d+)\ seconds.$" | convert rmunit(secs) as numSecs | eval stringSec=tostring(numSecs,"duration") | eval stringSecs=replace(stringSecs,"(\d+):(\d+)(\d+)","\1h \2min \3s") | stats avg(duration) AS "Windows AVG Uptime"&lt;/P&gt;

&lt;P&gt;Here's a sample of data:&lt;/P&gt;

&lt;P&gt;10/9/17&lt;BR /&gt;
12:01:44.000 PM &lt;BR /&gt;
10/09/2017 12:01:44 PM&lt;BR /&gt;
LogName=System&lt;BR /&gt;
SourceName=EventLog&lt;BR /&gt;
EventCode=6013&lt;BR /&gt;
EventType=4&lt;BR /&gt;
Type=Information&lt;BR /&gt;
ComputerName=TORBSIVWD01.xx.com&lt;BR /&gt;
TaskCategory=The operation completed successfully.&lt;BR /&gt;
OpCode=None&lt;BR /&gt;
RecordNumber=885007&lt;BR /&gt;
Keywords=Classic&lt;BR /&gt;
Message=The system uptime is 2132870 seconds.&lt;/P&gt;

&lt;P&gt;All help MUCH appreciated!&lt;/P&gt;

&lt;P&gt;Barry&lt;/P&gt;</description>
      <pubDate>Mon, 09 Oct 2017 20:25:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Need-a-little-help-converting-seconds-to-days-hours-minutes/m-p/301609#M90811</guid>
      <dc:creator>gabarrygowin</dc:creator>
      <dc:date>2017-10-09T20:25:34Z</dc:date>
    </item>
    <item>
      <title>Re: Need a little help converting seconds to days, hours, minutes</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Need-a-little-help-converting-seconds-to-days-hours-minutes/m-p/301610#M90812</link>
      <description>&lt;P&gt;@gabarrygowin&lt;/P&gt;

&lt;P&gt;try this,&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=windows sourcetype=WinEventLog* host!="*.xx.com" EventCode=6013 
| rex field=Message "The system uptime is\s+(?P&amp;lt;secs&amp;gt;\d+)\s+seconds" 
| convert rmunit(secs) as numSecs  
| eval stringSecs=tostring(numSecs,"duration")
| eval stringSecs = replace(stringSecs,"(\d+)\:(\d+)\:(\d+)","\1h \2min \3s") 
| stats avg(duration) AS "Windows AVG Uptime"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 09 Oct 2017 20:46:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Need-a-little-help-converting-seconds-to-days-hours-minutes/m-p/301610#M90812</guid>
      <dc:creator>sbbadri</dc:creator>
      <dc:date>2017-10-09T20:46:48Z</dc:date>
    </item>
    <item>
      <title>Re: Need a little help converting seconds to days, hours, minutes</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Need-a-little-help-converting-seconds-to-days-hours-minutes/m-p/301611#M90813</link>
      <description>&lt;P&gt;Thanks much for the replay.  I like your rex much more.  The search completes now, but with now data going to Statistics.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Oct 2017 20:52:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Need-a-little-help-converting-seconds-to-days-hours-minutes/m-p/301611#M90813</guid>
      <dc:creator>gabarrygowin</dc:creator>
      <dc:date>2017-10-09T20:52:51Z</dc:date>
    </item>
    <item>
      <title>Re: Need a little help converting seconds to days, hours, minutes</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Need-a-little-help-converting-seconds-to-days-hours-minutes/m-p/301612#M90814</link>
      <description>&lt;P&gt;To clarify, the search is executing now, but "No results found".  I know there are events there that match what we're trying to pull.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Oct 2017 21:15:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Need-a-little-help-converting-seconds-to-days-hours-minutes/m-p/301612#M90814</guid>
      <dc:creator>gabarrygowin</dc:creator>
      <dc:date>2017-10-09T21:15:48Z</dc:date>
    </item>
    <item>
      <title>Re: Need a little help converting seconds to days, hours, minutes</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Need-a-little-help-converting-seconds-to-days-hours-minutes/m-p/301613#M90815</link>
      <description>&lt;PRE&gt;
try this
index=wineventlog host!=xxx.com EventCode=6013 
| rex field=Message "The system uptime is\s+(?P&amp;lt;secs&amp;gt;\d+)\s+seconds" 
| stats avg(secs) AS secs by host 
| convert rmunit(secs) as numSecs 
| eval stringSecs=tostring(numSecs,"duration") 
| eval stringSecs = replace(stringSecs,"(\d+)\:(\d+)\:(\d+)","\1h \2min \3s") 
| fields - secs numSecs 
| rename stringSecs as "Windows AVG Uptime"

&lt;/PRE&gt;</description>
      <pubDate>Tue, 10 Oct 2017 13:36:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Need-a-little-help-converting-seconds-to-days-hours-minutes/m-p/301613#M90815</guid>
      <dc:creator>sbbadri</dc:creator>
      <dc:date>2017-10-10T13:36:35Z</dc:date>
    </item>
    <item>
      <title>Re: Need a little help converting seconds to days, hours, minutes</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Need-a-little-help-converting-seconds-to-days-hours-minutes/m-p/301614#M90816</link>
      <description>&lt;P&gt;I greatly appreciate the effort you're putting in and apologize for the difficulties.&lt;/P&gt;

&lt;P&gt;That recent code got me:&lt;BR /&gt;
Windows AVG Uptime  distinct_count(host)&lt;BR /&gt;
11+18h 13min 13s.500000 1&lt;BR /&gt;
6+04h 03min 59s.000000  1&lt;BR /&gt;
6+06h 45min 55s.000000&lt;/P&gt;

&lt;P&gt;I'm looking more for a simple counter that display the average uptime in days,hour,min for all our Windows hosts.  May be I didn't paint the requirement correctly?&lt;/P&gt;</description>
      <pubDate>Tue, 10 Oct 2017 16:54:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Need-a-little-help-converting-seconds-to-days-hours-minutes/m-p/301614#M90816</guid>
      <dc:creator>gabarrygowin</dc:creator>
      <dc:date>2017-10-10T16:54:40Z</dc:date>
    </item>
    <item>
      <title>Re: Need a little help converting seconds to days, hours, minutes</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Need-a-little-help-converting-seconds-to-days-hours-minutes/m-p/301615#M90817</link>
      <description>&lt;P&gt;Hmm, with your help, I think I'm really close now.&lt;/P&gt;

&lt;P&gt;Search:&lt;BR /&gt;
index=windows host!=*.xx.com EventCode=6013 | rex field=Message "The system uptime is\s+(?P\d+)\s+seconds" | eval secs=secs/86400 | stats avg(secs) as "Windows AVG Uptime"&lt;/P&gt;

&lt;P&gt;Results;&lt;BR /&gt;
Windows AVG Uptime&lt;BR /&gt;
23.887137&lt;/P&gt;

&lt;P&gt;Conclusion:  "IF" the functions are working correctly, our average time up is 23.8 days.  &lt;/P&gt;</description>
      <pubDate>Tue, 10 Oct 2017 18:08:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Need-a-little-help-converting-seconds-to-days-hours-minutes/m-p/301615#M90817</guid>
      <dc:creator>gabarrygowin</dc:creator>
      <dc:date>2017-10-10T18:08:50Z</dc:date>
    </item>
    <item>
      <title>Re: Need a little help converting seconds to days, hours, minutes</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Need-a-little-help-converting-seconds-to-days-hours-minutes/m-p/301616#M90818</link>
      <description>&lt;P&gt;[UPDATED]&lt;BR /&gt;
Following handles both scenarios where HH:MM:SS is within a Day or more than a day&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval secs=678393
| eval strSecs=tostring(secs,"duration")
| eval strFormatSecs=if(match(strSecs,"\+"),replace(strSecs,"(\d+)\+(\d+)\:(\d+)\:(\d+)","\1 Day \2 Hr \3 Min \4 Secs"),replace(strSecs,"(\d+)\:(\d+)\:(\d+)","\1 Hr \2 Min \3 Secs"))
| table secs strSecs strFormatSecs
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Try with differen values of secs like 3600, 54000, 86400 etc. &lt;/P&gt;

&lt;HR /&gt;

&lt;P&gt;Following is a run any where search based on answer by @lguinn [Splunk] : &lt;A href="https://answers.splunk.com/answers/61652/convert-seconds-into-hours-minutes-and-seconds.html#answer-338759"&gt;https://answers.splunk.com/answers/61652/convert-seconds-into-hours-minutes-and-seconds.html#answer-338759&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Only difference is that you have days in your time as well which is represented as &lt;CODE&gt;day+hour:minute:second&lt;/CODE&gt; format on converting &lt;CODE&gt;tostring()&lt;/CODE&gt; as duration. So you would need to replace day+ as well:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval secs=678393
| eval strSecs=tostring(secs,"duration")
| eval strFormatSecs=replace(strSecs,"(\d+)\+(\d+)\:(\d+)\:(\d+)","\1 days \2 Hr \3 Min \4 Secs")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;strSecs in second eval will result in &lt;CODE&gt;7+20:26:33&lt;/CODE&gt; and strFormatSec will evaluate after replace as &lt;CODE&gt;7 days 20 Hr 26 Min 33 Sec&lt;/CODE&gt;&lt;BR /&gt;
Needless to say this can also be done via &lt;CODE&gt;sed&lt;/CODE&gt; regular expression along &lt;CODE&gt;rex&lt;/CODE&gt; to give more control compared to final eval with &lt;CODE&gt;replace()&lt;/CODE&gt; command. @cpetterborg over to you &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Oct 2017 10:42:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Need-a-little-help-converting-seconds-to-days-hours-minutes/m-p/301616#M90818</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-10-11T10:42:34Z</dc:date>
    </item>
    <item>
      <title>Re: Need a little help converting seconds to days, hours, minutes</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Need-a-little-help-converting-seconds-to-days-hours-minutes/m-p/301617#M90819</link>
      <description>&lt;P&gt;[UPDATED to allow for shorter time periods]&lt;/P&gt;

&lt;P&gt;This should be faster:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
 | eval secs=678393
 | eval strSecs=tostring(secs,"duration")
 | rex field=strSecs mode=sed "s/((((\d*)\+)?(\d*):)?(\d*):)?(\d*)/\4 days \5 hrs \6 min \7 sec/"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The original would only work well if there were all 4 values. I updated the &lt;CODE&gt;rex&lt;/CODE&gt; to do shorter time periods (even down to less than 1 minute).  It isn't a complete  result with a result having &lt;CODE&gt;0 days&lt;/CODE&gt;, only &lt;CODE&gt;days&lt;/CODE&gt;, so it isn't perfect, but it is better than the original. With an additional &lt;CODE&gt;rex&lt;/CODE&gt;, it can fix that:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval secs=67839
| eval strSecs=tostring(secs,"duration")
| rex field=strSecs mode=sed "s/((((\d*)\+)?(\d*):)?(\d*):)?(\d*)/\4 days \5 hrs \6 min \7 sec/"
| rex field=strSecs mode=sed "s/^ days/0 days/"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 11 Oct 2017 17:53:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Need-a-little-help-converting-seconds-to-days-hours-minutes/m-p/301617#M90819</guid>
      <dc:creator>cpetterborg</dc:creator>
      <dc:date>2017-10-11T17:53:11Z</dc:date>
    </item>
    <item>
      <title>Re: Need a little help converting seconds to days, hours, minutes</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Need-a-little-help-converting-seconds-to-days-hours-minutes/m-p/301618#M90820</link>
      <description>&lt;P&gt;Hmm, fun.  I'm lost on where to insert this into my existing search as makeresults seems to want to be first in line before I even tell it what index to look at.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Oct 2017 18:00:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Need-a-little-help-converting-seconds-to-days-hours-minutes/m-p/301618#M90820</guid>
      <dc:creator>gabarrygowin</dc:creator>
      <dc:date>2017-10-11T18:00:00Z</dc:date>
    </item>
    <item>
      <title>Re: Need a little help converting seconds to days, hours, minutes</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Need-a-little-help-converting-seconds-to-days-hours-minutes/m-p/301619#M90821</link>
      <description>&lt;P&gt;This is somewhat incomplete, but you would put this in your search like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=windows sourcetype=WinEventLog* host!="*.xx.com" EventCode=6013 
| rex field=Message "The system uptime is\s+(?P&amp;lt;secs&amp;gt;\d+)\s+seconds" 
| eval strSecs=tostring(secs,"duration")
| rex field=strSecs mode=sed "s/(\d*)\+(\d*):(\d*):(\d*)/\1 day \2 hrs \3 min \4 sec/"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 11 Oct 2017 19:15:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Need-a-little-help-converting-seconds-to-days-hours-minutes/m-p/301619#M90821</guid>
      <dc:creator>cpetterborg</dc:creator>
      <dc:date>2017-10-11T19:15:53Z</dc:date>
    </item>
    <item>
      <title>Re: Need a little help converting seconds to days, hours, minutes</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Need-a-little-help-converting-seconds-to-days-hours-minutes/m-p/301620#M90822</link>
      <description>&lt;P&gt;@gabarrygowin, community members use &lt;CODE&gt;makeresults&lt;/CODE&gt; to mimic dummy data. You need to plug in your actual query. It should look like the following.  &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=windows host!=*.xx.com EventCode=6013 
| rex field=Message "The system uptime is\s+(?P&amp;lt;secs&amp;gt;\d+)\s+seconds"
| eval secs=tostring(secs,"duration")
| eval secs=if(match(secs,"\+"),replace(secs,"(\d+)\+(\d+)\:(\d+)\:(\d+)","\1 Day \2 Hr \3 Min \4 Secs"),replace(secs,"(\d+)\:(\d+)\:(\d+)","\1 Hr \2 Min \3 Secs"))
| table secs
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 12 Oct 2017 16:14:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Need-a-little-help-converting-seconds-to-days-hours-minutes/m-p/301620#M90822</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-10-12T16:14:30Z</dc:date>
    </item>
    <item>
      <title>Re: Need a little help converting seconds to days, hours, minutes</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Need-a-little-help-converting-seconds-to-days-hours-minutes/m-p/301621#M90823</link>
      <description>&lt;P&gt;Error in 'eval' command: The expression is malformed. Expected ).&lt;BR /&gt;
The search job has failed due to an error. You may be able view the job in the Job Inspector.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Oct 2017 21:30:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Need-a-little-help-converting-seconds-to-days-hours-minutes/m-p/301621#M90823</guid>
      <dc:creator>gabarrygowin</dc:creator>
      <dc:date>2017-10-12T21:30:16Z</dc:date>
    </item>
    <item>
      <title>Re: Need a little help converting seconds to days, hours, minutes</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Need-a-little-help-converting-seconds-to-days-hours-minutes/m-p/301622#M90824</link>
      <description>&lt;P&gt;looks like it just needs one more parenthesis. I can't try this out completely because I don't have your data so the base search doesn't work, but it should fix the eval problem:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; index=windows host!=*.xx.com EventCode=6013 
 | rex field=Message "The system uptime is\s+(?P&amp;lt;secs&amp;gt;\d+)\s+seconds"
 | eval secs=tostring(secs,"duration")
 | eval secs=if(match(secs,"\+"),replace(secs,"(\d+)\+(\d+)\:(\d+)\:(\d+)","\1 Day \2 Hr \3 Min \4 Secs"),replace(secs,"(\d+)\:(\d+)\:(\d+)","\1 Hr \2 Min \3 Secs"))
 | table secs
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 12 Oct 2017 23:59:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Need-a-little-help-converting-seconds-to-days-hours-minutes/m-p/301622#M90824</guid>
      <dc:creator>cpetterborg</dc:creator>
      <dc:date>2017-10-12T23:59:46Z</dc:date>
    </item>
    <item>
      <title>Re: Need a little help converting seconds to days, hours, minutes</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Need-a-little-help-converting-seconds-to-days-hours-minutes/m-p/301623#M90825</link>
      <description>&lt;P&gt;@gabarrygowin, sorry I had missed out closing parenthesis in both Run Anywhere example and the updated query above. I have updated the same please try again.&lt;/P&gt;

&lt;P&gt;@cpetterborg, thanks again for helping out &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 15 Oct 2017 04:03:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Need-a-little-help-converting-seconds-to-days-hours-minutes/m-p/301623#M90825</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-10-15T04:03:43Z</dc:date>
    </item>
  </channel>
</rss>

