<?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 Add _time field to macro results in Splunk Dev</title>
    <link>https://community.splunk.com/t5/Splunk-Dev/Add-time-field-to-macro-results/m-p/353103#M5634</link>
    <description>&lt;P&gt;Hi, I'm trying to work out a way of adding the existing time to results produced by running the following macro;&lt;/P&gt;

&lt;P&gt;| &lt;CODE&gt;suppression_eventtypes&lt;/CODE&gt; &lt;/P&gt;

&lt;P&gt;I'm currently pulling back the following fields;&lt;/P&gt;

&lt;P&gt;| fields suppression, start_time, end_time &lt;/P&gt;

&lt;P&gt;With the intention being to create some logic which will return any suppression's with an end_time 7 days from the current time. I can work out the logic needed, but am struggling to pull the current time back within the results as it's not produced as a field from the macro.&lt;/P&gt;

&lt;P&gt;any ideas? Thanks.&lt;/P&gt;</description>
    <pubDate>Tue, 29 Sep 2020 18:29:39 GMT</pubDate>
    <dc:creator>jacqu3sy</dc:creator>
    <dc:date>2020-09-29T18:29:39Z</dc:date>
    <item>
      <title>Add _time field to macro results</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Add-time-field-to-macro-results/m-p/353103#M5634</link>
      <description>&lt;P&gt;Hi, I'm trying to work out a way of adding the existing time to results produced by running the following macro;&lt;/P&gt;

&lt;P&gt;| &lt;CODE&gt;suppression_eventtypes&lt;/CODE&gt; &lt;/P&gt;

&lt;P&gt;I'm currently pulling back the following fields;&lt;/P&gt;

&lt;P&gt;| fields suppression, start_time, end_time &lt;/P&gt;

&lt;P&gt;With the intention being to create some logic which will return any suppression's with an end_time 7 days from the current time. I can work out the logic needed, but am struggling to pull the current time back within the results as it's not produced as a field from the macro.&lt;/P&gt;

&lt;P&gt;any ideas? Thanks.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 18:29:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Add-time-field-to-macro-results/m-p/353103#M5634</guid>
      <dc:creator>jacqu3sy</dc:creator>
      <dc:date>2020-09-29T18:29:39Z</dc:date>
    </item>
    <item>
      <title>Re: Add _time field to macro results</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Add-time-field-to-macro-results/m-p/353104#M5635</link>
      <description>&lt;P&gt;The current time is available from the &lt;CODE&gt;now&lt;/CODE&gt; function.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | eval current_time=now() | ...
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 14 Mar 2018 18:26:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Add-time-field-to-macro-results/m-p/353104#M5635</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2018-03-14T18:26:49Z</dc:date>
    </item>
    <item>
      <title>Re: Add _time field to macro results</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Add-time-field-to-macro-results/m-p/353105#M5636</link>
      <description>&lt;P&gt;@jacqu3sy, Based on the description seems like you need is &lt;CODE&gt;relative_time()&lt;/CODE&gt; function to give you the epoch time 7 days from current time i.e. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval EndTimeThreshold=relative_time(now(),"+7d@d")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Following is a run anywhere search to test your &lt;CODE&gt;end_time&lt;/CODE&gt; values (if it is string time the same needs to be converted to epoch time using &lt;CODE&gt;strptime()&lt;/CODE&gt;. If it is already epoch timem, then &lt;CODE&gt;strptime()&lt;/CODE&gt; is not required)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval end_time="2018/03/15"
| eval end_time=strptime(end_time,"%Y/%m/%d")
| eval EndTimeThreshold=relative_time(now(),"+7d@d")
| eval duration=EndTimeThreshold-end_time
| fieldformat EndTimeThreshold=strftime(EndTimeThreshold,"%Y/%m/%d %H:%M:%S")
| eval suppression=if(duration&amp;lt;=604800,"Within 7 Days","Outside 7 Days")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Please try out and confirm.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Mar 2018 20:00:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Add-time-field-to-macro-results/m-p/353105#M5636</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2018-03-14T20:00:52Z</dc:date>
    </item>
    <item>
      <title>Re: Add _time field to macro results</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Add-time-field-to-macro-results/m-p/353106#M5637</link>
      <description>&lt;P&gt;great, thanks.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Mar 2018 10:12:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Add-time-field-to-macro-results/m-p/353106#M5637</guid>
      <dc:creator>jacqu3sy</dc:creator>
      <dc:date>2018-03-15T10:12:21Z</dc:date>
    </item>
    <item>
      <title>Re: Add _time field to macro results</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Add-time-field-to-macro-results/m-p/353107#M5638</link>
      <description>&lt;P&gt;Thats perfect. Many thanks.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Mar 2018 10:12:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Add-time-field-to-macro-results/m-p/353107#M5638</guid>
      <dc:creator>jacqu3sy</dc:creator>
      <dc:date>2018-03-15T10:12:36Z</dc:date>
    </item>
    <item>
      <title>Re: Add _time field to macro results</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Add-time-field-to-macro-results/m-p/353108#M5639</link>
      <description>&lt;P&gt;@jacqu3sy, if your problem is resolved, please accept the answer to help future readers.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Mar 2018 12:46:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Add-time-field-to-macro-results/m-p/353108#M5639</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2018-03-15T12:46:10Z</dc:date>
    </item>
  </channel>
</rss>

