<?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: Adding increments of time to an event in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Adding-increments-of-time-to-an-event/m-p/544717#M154265</link>
    <description>&lt;P&gt;I don't think I totally understood your progression from time A to time B, so this may be wrong when you say you want to go from 13:37 to 14:07. What about 13:59 or 14:11?&lt;/P&gt;</description>
    <pubDate>Mon, 22 Mar 2021 04:06:20 GMT</pubDate>
    <dc:creator>bowesmana</dc:creator>
    <dc:date>2021-03-22T04:06:20Z</dc:date>
    <item>
      <title>Adding increments of time to an event</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Adding-increments-of-time-to-an-event/m-p/544278#M154173</link>
      <description>&lt;P&gt;Hi Splunkers,&lt;/P&gt;&lt;P&gt;I have gotten help on this type of problem and it has been very useful. However, I still stuck, but almost there, need some guidance.&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Scenario:&lt;/P&gt;&lt;P&gt;Ingestion_Time_Logged&amp;nbsp; which is the field I created should occur twice within 30 min, at min 7th and then min 37th.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;If event occurs at 6:00&amp;nbsp;&amp;nbsp;Ingestion_Time_Logged should be 6:07 and if event occurs at 6:30&amp;nbsp;Ingestion_Time_Logged should be 6:37. The min should always land on the next exact 7th min or the next exact&amp;nbsp; 37th. min.&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is what I have, there is an issue when min is before the 7th min and when min is shy from the 37 th min.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I am&amp;nbsp; open to any suggestions, perhaps I need a new approach here.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;(index=foo Type="black") OR (index="boo") 

| eval CreationTime=case(Type="creation", loggedEventTime)

| eval CreationTime_epoch=strptime(CreationTime, "%Y-%m-%d %H:%M:%S.%6N")

| eval latestCreated_hour=tonumber(strftime(CreationTime_epoch, "%H"))

| eval latestCreated_min=tonumber(strftime(CreationTime_epoch, "%M"))

| eval latestCreated_sec=round(CreationTime_epoch%60,6)


| eval Ingestion_Time_Logged=strftime(case(latestCreated_hour=23 OR latestCreated_min&amp;gt;07,CreationTime_epoch-CreationTime_epoch_epoch%1800+2220+latestCreated_sec,CreationTime_epoch=0,CreationTime_epoch+420,1=1,CreationTime_epoch),"%Y-%m-%d %H:%M:%S.%6N")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Mar 2021 03:26:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Adding-increments-of-time-to-an-event/m-p/544278#M154173</guid>
      <dc:creator>Mary666</dc:creator>
      <dc:date>2021-03-18T03:26:28Z</dc:date>
    </item>
    <item>
      <title>Re: Adding increments of time to an event</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Adding-increments-of-time-to-an-event/m-p/544283#M154178</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/226742"&gt;@Mary666&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;There are some confusion with variables in the case statement. But you are close;&lt;/P&gt;&lt;P&gt;I added 7 minutes if minutes is less than 7, otherwise 37 minutes. Also check if minutes is already 7 OR 37 to keep them as they are.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please try below;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;(index=foo Type="black") OR (index="boo") 
| eval CreationTime=case(Type="creation", loggedEventTime)
| eval CreationTime_epoch=strptime(CreationTime, "%Y-%m-%d %H:%M:%S.%6N")
| eval latestCreated_hour=tonumber(strftime(CreationTime_epoch, "%H"))
| eval latestCreated_min=tonumber(strftime(CreationTime_epoch, "%M"))
| eval latestCreated_sec=round(CreationTime_epoch%60,6)
| eval Ingestion_Time_Logged=strftime(case(latestCreated_min&amp;lt;7, CreationTime_epoch-CreationTime_epoch%1800+420+latestCreated_sec,latestCreated_min!=37 AND latestCreated_min!=7 , CreationTime_epoch-CreationTime_epoch%1800+2220+latestCreated_sec,1=1,CreationTime_epoch),"%Y-%m-%d %H:%M:%S.%6N")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Mar 2021 05:23:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Adding-increments-of-time-to-an-event/m-p/544283#M154178</guid>
      <dc:creator>scelikok</dc:creator>
      <dc:date>2021-03-18T05:23:39Z</dc:date>
    </item>
    <item>
      <title>Re: Adding increments of time to an event</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Adding-increments-of-time-to-an-event/m-p/544284#M154179</link>
      <description>&lt;P&gt;This is a run anywhere, but the last 2 eval statements will do what you want I believe&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults count=10
| eval _time=_time - random() % 14400
| sort _time
| eval mins=floor(tonumber(strftime(_time, "%M"))/30)*30*60
| eval Ingestion_Time_Logged=strftime(relative_time(_time, "@h+7m")+mins, "%F %T")
| table _time Ingestion_Time_Logged&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Mar 2021 05:23:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Adding-increments-of-time-to-an-event/m-p/544284#M154179</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2021-03-18T05:23:41Z</dc:date>
    </item>
    <item>
      <title>Re: Adding increments of time to an event</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Adding-increments-of-time-to-an-event/m-p/544395#M154187</link>
      <description>&lt;P&gt;Hi scelikok,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I see one small issue with the time if its 2:30 it gives me 3:07 instead of&amp;nbsp; 2:37 or if its 00:36 it will give me 1:07 instead of 00:37, everything else looks good. I tried playing with the numbers, but no luck yet.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Mar 2021 19:11:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Adding-increments-of-time-to-an-event/m-p/544395#M154187</guid>
      <dc:creator>Mary666</dc:creator>
      <dc:date>2021-03-18T19:11:29Z</dc:date>
    </item>
    <item>
      <title>Re: Adding increments of time to an event</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Adding-increments-of-time-to-an-event/m-p/544409#M154192</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/226742"&gt;@Mary666&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;It was working work between 30 and 37 minutes , I made a change on first case condition to cover the minutes between &amp;nbsp;0-7 and 30-37, please try below;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;(index=foo Type="black") OR (index="boo") 
| eval CreationTime=case(Type="creation", loggedEventTime)
| eval CreationTime_epoch=strptime(CreationTime, "%Y-%m-%d %H:%M:%S.%6N") 
| eval latestCreated_hour=tonumber(strftime(CreationTime_epoch, "%H")) 
| eval latestCreated_min=tonumber(strftime(CreationTime_epoch, "%M")) 
| eval latestCreated_sec=round(CreationTime_epoch%60,6) 
| eval Ingestion_Time_Logged=strftime(case(latestCreated_min%30 &amp;lt; 7, CreationTime_epoch-CreationTime_epoch%1800+420+latestCreated_sec, latestCreated_min!=37 AND latestCreated_min!=7, CreationTime_epoch-CreationTime_epoch%1800+2220+latestCreated_sec,1=1,CreationTime_epoch),"%Y-%m-%d %H:%M:%S.%6N")&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 18 Mar 2021 21:35:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Adding-increments-of-time-to-an-event/m-p/544409#M154192</guid>
      <dc:creator>scelikok</dc:creator>
      <dc:date>2021-03-18T21:35:31Z</dc:date>
    </item>
    <item>
      <title>Re: Adding increments of time to an event</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Adding-increments-of-time-to-an-event/m-p/544421#M154196</link>
      <description>&lt;P&gt;Thank You! You have been very helpful. If you don't mind would like to pick your brain a bit so I can understand your changes:&lt;/P&gt;&lt;P&gt;We are looking for in between 30 min and less than 7 min? Also, what is the % doing here ?&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;latestComposed_min%30 &amp;lt; 7&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Why are we excluding min 37 and 7&amp;nbsp; -- and why the use of AND here instead of OR?&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;latestComposed_min!=37 AND latestComposed_min!=7&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Mar 2021 00:42:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Adding-increments-of-time-to-an-event/m-p/544421#M154196</guid>
      <dc:creator>Mary666</dc:creator>
      <dc:date>2021-03-19T00:42:53Z</dc:date>
    </item>
    <item>
      <title>Re: Adding increments of time to an event</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Adding-increments-of-time-to-an-event/m-p/544562#M154242</link>
      <description>&lt;P&gt;Sure&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":grinning_face:"&gt;😀&lt;/span&gt;&lt;/P&gt;&lt;P&gt;% is the modulo operator which is a way to determine the remainder of a division operation. Instead of returning the result of the division, the modulo operation returns the whole number remainder.&lt;/P&gt;&lt;P&gt;latestComposed_min%30 will divide the minutes by 30 and result in the reminder. I used it to find if the minute is between 0 - 7 or 30 - 37.&amp;nbsp;&amp;nbsp;It is the same as below but much easier and efficient.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;if(latestComposed_min &amp;lt; 7 OR (latestComposed_min&amp;gt;30 AND latestComposed_min &amp;lt; 37))&lt;/LI-CODE&gt;&lt;P&gt;I excluded 37 and 7 to keep them as they are since they are already ok, if we do not exclude them, they will be added 37 minutes. Since both are NOT comparisons AND should be used between them otherwise with OR the result will be always true (which is wrong)&lt;/P&gt;&lt;P&gt;I hope I could explain and help you.&lt;/P&gt;</description>
      <pubDate>Fri, 19 Mar 2021 19:02:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Adding-increments-of-time-to-an-event/m-p/544562#M154242</guid>
      <dc:creator>scelikok</dc:creator>
      <dc:date>2021-03-19T19:02:38Z</dc:date>
    </item>
    <item>
      <title>Re: Adding increments of time to an event</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Adding-increments-of-time-to-an-event/m-p/544712#M154262</link>
      <description>&lt;P&gt;Thanks so much for your explanation it has been very helpful.&lt;/P&gt;</description>
      <pubDate>Mon, 22 Mar 2021 03:38:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Adding-increments-of-time-to-an-event/m-p/544712#M154262</guid>
      <dc:creator>Mary666</dc:creator>
      <dc:date>2021-03-22T03:38:58Z</dc:date>
    </item>
    <item>
      <title>Re: Adding increments of time to an event</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Adding-increments-of-time-to-an-event/m-p/544713#M154263</link>
      <description>&lt;P&gt;Hi bowesmana,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your suggestion. I was not able to manipulate the numbers here quite yet. It seems to work, but it does not go up to the next hour - lets say if its 3:37 I need it then to go to 4:07. I see with your code this can easily be manipulated. Perhaps if I understand this a bit more I can get it to work. Would you be able to explain what these two lines of code are doing here?&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval mins=floor(tonumber(strftime(_time, "%M"))/30)*30*60
| eval Ingestion_Time_Logged=strftime(relative_time(_time, "@h+7m")+mins, "%F %T")&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 22 Mar 2021 03:43:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Adding-increments-of-time-to-an-event/m-p/544713#M154263</guid>
      <dc:creator>Mary666</dc:creator>
      <dc:date>2021-03-22T03:43:14Z</dc:date>
    </item>
    <item>
      <title>Re: Adding increments of time to an event</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Adding-increments-of-time-to-an-event/m-p/544715#M154264</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/226742"&gt;@Mary666&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;| eval mins=floor(tonumber(strftime(_time, "%M"))/30)*30*60&lt;/PRE&gt;&lt;UL&gt;&lt;LI&gt;takes the minute part of the event time and converts it to a number&lt;/LI&gt;&lt;LI&gt;Divides that by 30 and rounds down to the nearest integer - result will always be 0 or 1&lt;/LI&gt;&lt;LI&gt;Multiplies by 30 then 60 (1800) - result will always be 0 or 1800&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;So this is saying if&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;time is 14:58 then floor(58/30) = 1 * 1800 = 1800 (seconds)&lt;/LI&gt;&lt;LI&gt;time is 14:03 then floor (3/30) - 0 * 1800 - 0&amp;nbsp;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;which is essentially a way of calculating which half of the hour the current time is in&lt;/P&gt;&lt;PRE&gt;| eval Ingestion_Time_Logged=strftime(relative_time(_time, "@h+7m")+mins, "%F %T")&lt;/PRE&gt;&lt;P&gt;and this now says&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;round the current hour down to the 00 minutes and then add 7 minutes and then the number of seconds from the first line above (0 or 1800)&lt;/LI&gt;&lt;LI&gt;Format it as YYYY-MM-DD HH:MM:SS.sss&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;so it knows if the time is between xx:00 and xx:29:59 and will do&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;number of seconds from first line is 0&lt;/LI&gt;&lt;LI&gt;relative time calculation is xx:07 + 0 seconds, so resultant time is xx:07&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;if time is between xx:30 and xx:59:59 it will&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;number of seconds from first line is 1800&lt;/LI&gt;&lt;LI&gt;relative time calculation is xx:07 + 1800 seconds, so resultant time is xx:37&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Hope this helps and is useful&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Mar 2021 04:04:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Adding-increments-of-time-to-an-event/m-p/544715#M154264</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2021-03-22T04:04:23Z</dc:date>
    </item>
    <item>
      <title>Re: Adding increments of time to an event</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Adding-increments-of-time-to-an-event/m-p/544717#M154265</link>
      <description>&lt;P&gt;I don't think I totally understood your progression from time A to time B, so this may be wrong when you say you want to go from 13:37 to 14:07. What about 13:59 or 14:11?&lt;/P&gt;</description>
      <pubDate>Mon, 22 Mar 2021 04:06:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Adding-increments-of-time-to-an-event/m-p/544717#M154265</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2021-03-22T04:06:20Z</dc:date>
    </item>
  </channel>
</rss>

