<?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 timerange in python custom command in Splunk Dev</title>
    <link>https://community.splunk.com/t5/Splunk-Dev/timerange-in-python-custom-command/m-p/177333#M2356</link>
    <description>&lt;P&gt;How can i get the earliest and latest time as epoch in a custom command written in python? Either its not possible, i am dense or the docu is not very detailed.&lt;/P&gt;

&lt;P&gt;update:&lt;BR /&gt;
What i need to set it two datetime fields in the format 2015-03-16-17-13-00 and i would like to get the timerange from the timerange picker. Alternative can be a calculated value and provide a form for easy usage. I use these parameters when calling a webservice.&lt;/P&gt;</description>
    <pubDate>Sat, 14 Mar 2015 15:40:00 GMT</pubDate>
    <dc:creator>dominiquevocat</dc:creator>
    <dc:date>2015-03-14T15:40:00Z</dc:date>
    <item>
      <title>timerange in python custom command</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/timerange-in-python-custom-command/m-p/177333#M2356</link>
      <description>&lt;P&gt;How can i get the earliest and latest time as epoch in a custom command written in python? Either its not possible, i am dense or the docu is not very detailed.&lt;/P&gt;

&lt;P&gt;update:&lt;BR /&gt;
What i need to set it two datetime fields in the format 2015-03-16-17-13-00 and i would like to get the timerange from the timerange picker. Alternative can be a calculated value and provide a form for easy usage. I use these parameters when calling a webservice.&lt;/P&gt;</description>
      <pubDate>Sat, 14 Mar 2015 15:40:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/timerange-in-python-custom-command/m-p/177333#M2356</guid>
      <dc:creator>dominiquevocat</dc:creator>
      <dc:date>2015-03-14T15:40:00Z</dc:date>
    </item>
    <item>
      <title>Re: timerange in python custom command</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/timerange-in-python-custom-command/m-p/177334#M2357</link>
      <description>&lt;P&gt;I fear this may not be possible, as I detailed in this answer: &lt;A href="http://answers.splunk.com/answers/116430/earliest-and-latest-information-in-custom-python-search-command.html"&gt;http://answers.splunk.com/answers/116430/earliest-and-latest-information-in-custom-python-search-command.html&lt;/A&gt;&lt;BR /&gt;
Until someone proves me wrong I'd go with the &lt;CODE&gt;addinfo&lt;/CODE&gt; workaround.&lt;/P&gt;</description>
      <pubDate>Sun, 15 Mar 2015 23:38:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/timerange-in-python-custom-command/m-p/177334#M2357</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2015-03-15T23:38:36Z</dc:date>
    </item>
    <item>
      <title>Re: timerange in python custom command</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/timerange-in-python-custom-command/m-p/177335#M2358</link>
      <description>&lt;P&gt;yes, i did see that question and it is rather the same i suppose. I did include&lt;BR /&gt;
    results, dummyresults, settings = splunk.Intersplunk.getOrganizedResults()&lt;BR /&gt;
and i search&lt;BR /&gt;
    |addinfo |mycustomcommand few=params&lt;BR /&gt;
and i get this in settings&lt;BR /&gt;
{   'allowStream': '1'&lt;BR /&gt;
    'sid': '1426523758.18492'&lt;BR /&gt;
    'splunkVersion': '6.2.0'&lt;BR /&gt;&lt;BR /&gt;
    'preview': '0'&lt;BR /&gt;
    'realtime': '0'&lt;BR /&gt;
    'truncated': '0'&lt;BR /&gt;
    'search': '|addinfo |mycustomcommand few=params"'&lt;BR /&gt;
    'keywords': '""'&lt;BR /&gt;
}&lt;/P&gt;

&lt;P&gt;so i fail to see how this should work? Did no one ever write custom command where you did not have to pass the timerange in preminced parameters?&lt;/P&gt;</description>
      <pubDate>Mon, 16 Mar 2015 16:42:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/timerange-in-python-custom-command/m-p/177335#M2358</guid>
      <dc:creator>dominiquevocat</dc:creator>
      <dc:date>2015-03-16T16:42:48Z</dc:date>
    </item>
    <item>
      <title>Re: timerange in python custom command</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/timerange-in-python-custom-command/m-p/177336#M2359</link>
      <description>&lt;P&gt;Your search fails because you're trying to add the fields returned by &lt;CODE&gt;addinfo&lt;/CODE&gt; to zero results, giving you the fields zero times. Run this instead:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats count | addinfo | mycustomcommand few=params
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The &lt;CODE&gt;stats count&lt;/CODE&gt; will turn zero results into one result with &lt;CODE&gt;count=0&lt;/CODE&gt;, allowing &lt;CODE&gt;addinfo&lt;/CODE&gt; to do its thing. Look for &lt;CODE&gt;info_min_time&lt;/CODE&gt; and &lt;CODE&gt;info_max_time&lt;/CODE&gt; fields.&lt;/P&gt;

&lt;P&gt;As for your other question, I don't know of any. Stuff like &lt;CODE&gt;timechart&lt;/CODE&gt; uses the time range, but is built-in so it doesn't need to rely on this interface.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Mar 2015 20:54:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/timerange-in-python-custom-command/m-p/177336#M2359</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2015-03-16T20:54:06Z</dc:date>
    </item>
    <item>
      <title>Re: timerange in python custom command</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/timerange-in-python-custom-command/m-p/177337#M2360</link>
      <description>&lt;P&gt;Thanks for the heads-up. I did include the " |stats count ", i had previsouly added some fake commands so i have some results &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; but changed to do it as you indicated. However i do not have more in the setting tuple.&lt;/P&gt;

&lt;P&gt;Let me reiterate. I do the search as you said plus in the python i do&lt;BR /&gt;
    results, dummyresults, settings = splunk.Intersplunk.getOrganizedResults()&lt;BR /&gt;
    print settings&lt;BR /&gt;
 so i get it in the results in splunk, i also log it out but that is beside the point. &lt;BR /&gt;
I still only get&lt;BR /&gt;
splunkVersion,keywords,allowStream,preview,sid,truncated,realtime,search in settings&lt;/P&gt;

&lt;P&gt;Whereas if i do&lt;BR /&gt;
    myvariable = settings.get('info_min_time','these are not the droids you are looking for')&lt;BR /&gt;
    print myvariable&lt;BR /&gt;
returns&lt;BR /&gt;
these are not the droids you are looking for&lt;BR /&gt;
so i &lt;EM&gt;think&lt;/EM&gt; is not working very very well?&lt;/P&gt;

&lt;P&gt;any hints?&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 19:10:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/timerange-in-python-custom-command/m-p/177337#M2360</guid>
      <dc:creator>dominiquevocat</dc:creator>
      <dc:date>2020-09-28T19:10:37Z</dc:date>
    </item>
    <item>
      <title>Re: timerange in python custom command</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/timerange-in-python-custom-command/m-p/177338#M2361</link>
      <description>&lt;P&gt;The fields won't end up in the settings tuple, they will end up in the results tuple.&lt;/P&gt;</description>
      <pubDate>Tue, 17 Mar 2015 18:24:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/timerange-in-python-custom-command/m-p/177338#M2361</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2015-03-17T18:24:41Z</dc:date>
    </item>
    <item>
      <title>Re: timerange in python custom command</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/timerange-in-python-custom-command/m-p/177339#M2362</link>
      <description>&lt;P&gt;ok, i see what you mean. The object results is of type list where the value is visible when i print it so i need to transform it. I hope i find a nice example :-). Can splunk please seriously consider passing the timerange pretty please? &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Mar 2015 14:06:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/timerange-in-python-custom-command/m-p/177339#M2362</guid>
      <dc:creator>dominiquevocat</dc:creator>
      <dc:date>2015-03-19T14:06:25Z</dc:date>
    </item>
    <item>
      <title>Re: timerange in python custom command</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/timerange-in-python-custom-command/m-p/177340#M2363</link>
      <description>&lt;P&gt;You can always submit a feature request through the support portal at &lt;A href="https://login.splunk.com/page/sso_redirect?type=portal"&gt;https://login.splunk.com/page/sso_redirect?type=portal&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Mar 2015 22:23:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/timerange-in-python-custom-command/m-p/177340#M2363</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2015-03-19T22:23:45Z</dc:date>
    </item>
    <item>
      <title>Re: timerange in python custom command</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/timerange-in-python-custom-command/m-p/177341#M2364</link>
      <description>&lt;P&gt;I know this is an old thread. But here is my solution:&lt;/P&gt;

&lt;P&gt;create an regular time picker input field, and use earliest and latest as command parameter. The python can get the them as normal parameters. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  &amp;lt;input type="time" token="my_time" searchWhenChanged="false"&amp;gt;
          &amp;lt;label&amp;gt;Time Range&amp;lt;/label&amp;gt;
          &amp;lt;default&amp;gt;
            &amp;lt;earliest&amp;gt;-7d@h&amp;lt;/earliest&amp;gt;
            &amp;lt;latest&amp;gt;now&amp;lt;/latest&amp;gt;
          &amp;lt;/default&amp;gt;

....

 &amp;lt;search&amp;gt;
          &amp;lt;query&amp;gt;|mycommand myparameters  earliest=$my_time.earliest$ latest=$my_time.latest$
          &amp;lt;/query&amp;gt;
        &amp;lt;/search&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;It does not seem to have a built-in validator for time range. this brings a new question: is there a way to get the parsed time values? Hate to redo it as Splunk has already done it.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Aug 2016 17:10:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/timerange-in-python-custom-command/m-p/177341#M2364</guid>
      <dc:creator>Dev999</dc:creator>
      <dc:date>2016-08-15T17:10:55Z</dc:date>
    </item>
    <item>
      <title>Re: timerange in python custom command</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/timerange-in-python-custom-command/m-p/177342#M2365</link>
      <description>&lt;P&gt;I'm surprised the $my_time$ calls don't work. You're on a recent release of Splunk, right?&lt;/P&gt;

&lt;P&gt;The usual behavior is to refer to those tokens within similar &lt;CODE&gt;&amp;lt;earliest&amp;gt;&lt;/CODE&gt; and &lt;CODE&gt;&amp;lt;latest&amp;gt;&lt;/CODE&gt; tags as part of the search definition. You should be able to set that up in the UI without reverting to the source editor.&lt;/P&gt;

&lt;P&gt;If that makes no sense, I can be more specific.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Aug 2016 21:18:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/timerange-in-python-custom-command/m-p/177342#M2365</guid>
      <dc:creator>sloshburch</dc:creator>
      <dc:date>2016-08-15T21:18:21Z</dc:date>
    </item>
    <item>
      <title>Re: timerange in python custom command</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/timerange-in-python-custom-command/m-p/177343#M2366</link>
      <description>&lt;P&gt;looks like a fairly nice workaround, i will try it &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; but would really like to have it directly in one of the tuples&lt;/P&gt;</description>
      <pubDate>Tue, 16 Aug 2016 08:57:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/timerange-in-python-custom-command/m-p/177343#M2366</guid>
      <dc:creator>dominiquevocat</dc:creator>
      <dc:date>2016-08-16T08:57:06Z</dc:date>
    </item>
    <item>
      <title>Re: timerange in python custom command</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/timerange-in-python-custom-command/m-p/177344#M2367</link>
      <description>&lt;P&gt;What exactly do you mean by "directly in one of the tuples"? I may have misunderstood originally.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Aug 2016 13:17:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/timerange-in-python-custom-command/m-p/177344#M2367</guid>
      <dc:creator>sloshburch</dc:creator>
      <dc:date>2016-08-16T13:17:11Z</dc:date>
    </item>
    <item>
      <title>Re: timerange in python custom command</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/timerange-in-python-custom-command/m-p/177345#M2368</link>
      <description>&lt;P&gt;this is for custom command, not regular Splunk search. the time range is used as parameters for a custom command that is consumed by python code on the Splunk server, not within dashboard page.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Aug 2016 13:41:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/timerange-in-python-custom-command/m-p/177345#M2368</guid>
      <dc:creator>Dev999</dc:creator>
      <dc:date>2016-08-16T13:41:58Z</dc:date>
    </item>
    <item>
      <title>Re: timerange in python custom command</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/timerange-in-python-custom-command/m-p/177346#M2369</link>
      <description>&lt;P&gt;Hi SloshBurch, my question was regarding writing a custom command and take the search earliest and searchlatest for passing the timerange to filter a request to a api.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Aug 2016 07:12:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/timerange-in-python-custom-command/m-p/177346#M2369</guid>
      <dc:creator>dominiquevocat</dc:creator>
      <dc:date>2016-08-17T07:12:40Z</dc:date>
    </item>
    <item>
      <title>Re: timerange in python custom command</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/timerange-in-python-custom-command/m-p/177347#M2370</link>
      <description>&lt;P&gt;Ok, so you were not asking in response to what I posted. Just wanted to make sure.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Aug 2016 12:20:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/timerange-in-python-custom-command/m-p/177347#M2370</guid>
      <dc:creator>sloshburch</dc:creator>
      <dc:date>2016-08-17T12:20:15Z</dc:date>
    </item>
    <item>
      <title>Re: timerange in python custom command</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/timerange-in-python-custom-command/m-p/177348#M2371</link>
      <description>&lt;P&gt;If you are using GeneratingCommand in python sdk, here is the answer, tested both at Search command and in a dashboard:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;def generate(self):
   ....
   search_results = self.search_results_info
   logger.debug('search time: %s %s' % (str(search_results.search_et), str(search_results.search_lt)) )
   ....
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Result:&lt;BR /&gt;
search time: 1470837600.0 1471443921.0&lt;/P&gt;</description>
      <pubDate>Wed, 17 Aug 2016 14:51:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/timerange-in-python-custom-command/m-p/177348#M2371</guid>
      <dc:creator>Dev999</dc:creator>
      <dc:date>2016-08-17T14:51:25Z</dc:date>
    </item>
    <item>
      <title>Re: timerange in python custom command</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/timerange-in-python-custom-command/m-p/177349#M2372</link>
      <description>&lt;P&gt;please ignore this answer. See the new one above.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Aug 2016 14:52:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/timerange-in-python-custom-command/m-p/177349#M2372</guid>
      <dc:creator>Dev999</dc:creator>
      <dc:date>2016-08-17T14:52:33Z</dc:date>
    </item>
    <item>
      <title>Re: timerange in python custom command</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/timerange-in-python-custom-command/m-p/177350#M2373</link>
      <description>&lt;P&gt;Works nicely. I just might polish this half-assed PRTG custom command finally &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Aug 2016 08:25:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/timerange-in-python-custom-command/m-p/177350#M2373</guid>
      <dc:creator>dominiquevocat</dc:creator>
      <dc:date>2016-08-19T08:25:05Z</dc:date>
    </item>
    <item>
      <title>Re: timerange in python custom command</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/timerange-in-python-custom-command/m-p/177351#M2374</link>
      <description>&lt;P&gt;Thank you for your good answer!!!!&lt;/P&gt;</description>
      <pubDate>Tue, 01 Jan 2019 10:51:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/timerange-in-python-custom-command/m-p/177351#M2374</guid>
      <dc:creator>jason96</dc:creator>
      <dc:date>2019-01-01T10:51:01Z</dc:date>
    </item>
    <item>
      <title>Re: timerange in python custom command</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/timerange-in-python-custom-command/m-p/177352#M2375</link>
      <description>&lt;P&gt;This works well for me until I selected the all time option, then an error telling me it can't read the property. Any ideas how to work around this issue?&lt;/P&gt;</description>
      <pubDate>Wed, 30 Jan 2019 20:26:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/timerange-in-python-custom-command/m-p/177352#M2375</guid>
      <dc:creator>NathanielHunter</dc:creator>
      <dc:date>2019-01-30T20:26:02Z</dc:date>
    </item>
  </channel>
</rss>

