<?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: accessing starting and ending time of a scheduled search inside the search in Reporting</title>
    <link>https://community.splunk.com/t5/Reporting/accessing-starting-and-ending-time-of-a-scheduled-search-inside/m-p/70456#M1616</link>
    <description>&lt;P&gt;So after messing around a bit, I have found a clunky way to achieve what I wanted, may it helps other!&lt;/P&gt;

&lt;P&gt;First I have created a macro, that takes the last search of the jobs list with the given search name, and return its earliest time (MY_MACRO):&lt;/P&gt;

&lt;P&gt;MY_MACRO(search_name, "hours to subtract before earliest schedule time")&lt;BR /&gt;
    [| rest /services/search/jobs &lt;BR /&gt;
    | search label="$arg1$" &lt;BR /&gt;
    | head 1 &lt;BR /&gt;
    | eval earliest=substr(earliestTime, 1, 19)&lt;BR /&gt;
    | eval earliest=strptime(earliest,"%Y-%m-%dT%H:%M:%S")&lt;BR /&gt;
    | eval earliest=earliest-$arg2$*3600&lt;BR /&gt;
    | eval earliest=round(earliest, 0)&lt;BR /&gt;
    | return earliest]&lt;/P&gt;

&lt;P&gt;Note that you shouldn't return $earliest as in a macro it will not work (maybe interpreted as an argument cause of the $ sign, see &lt;A href="http://splunk-base.splunk.com/answers/80765/debugging-a-search-ran-from-python-script" target="_blank"&gt;here&lt;/A&gt;.&lt;/P&gt;

&lt;P&gt;Then, take the search you want to backfill summary index, let's take index=MY_INDEX as an example (name it MY_SEARCH), and add the MY_MACRO value at the end, so the final search is:&lt;/P&gt;

&lt;P&gt;index=MY_INDEX MY_MACRO(MY_SEARCH, "hours to subtract before earliest schedule time")&lt;/P&gt;

&lt;P&gt;You can then use fill_summary_index.py with this search, the earliest time will be the scheduled time (the UTC+ ... time you can see in the console log), and not the time you run the search.&lt;/P&gt;

&lt;P&gt;Thanks very much to Ayn, Martin and alacercogitatus for the help, I think I'm done with it.&lt;/P&gt;</description>
    <pubDate>Mon, 28 Sep 2020 13:35:51 GMT</pubDate>
    <dc:creator>guilhem</dc:creator>
    <dc:date>2020-09-28T13:35:51Z</dc:date>
    <item>
      <title>accessing starting and ending time of a scheduled search inside the search</title>
      <link>https://community.splunk.com/t5/Reporting/accessing-starting-and-ending-time-of-a-scheduled-search-inside/m-p/70445#M1605</link>
      <description>&lt;P&gt;I would like to access to the starting and ending time of a scheduled search inside the search itself, if I want to run it afterwards with the right parameters.&lt;/P&gt;

&lt;P&gt;If I put the | addinfo command inside the scheduled search it gives me the info_min_time and info_max_time but these contains the time when the search was ran, not the time the search was scheduled to run.&lt;/P&gt;

&lt;P&gt;In fact I want to access this time (when run with the fill_summary_index.py script):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Started job 'XXXX_cHJvZF9zdW1tYXJ5X3JldHVybmluZ19zZWdtZW50X2xhc3RIb3Vy_at_1363205100_2ca7751a68b1bed6' for saved search 'prod_summary_returning_segment_lastHour', UTC = 1363205100 (Wed Mar 13 21:05:00 2013)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks!&lt;/P&gt;

&lt;HR /&gt;

&lt;P&gt;EDIT:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;"For saved search 'saved_search_name'
Executing search to find existing data: 'search splunk_server=local index=my_index source="saved_search_name" | stats count by search_now'
  waiting for job sid = '1363940863.11827'  ... finished
Out of 10 scheduled times, 3 will be skipped because they already exist.

*** Spawning a total of 7 searches (max 8 concurrent) ***
Started job 'XXXXcHJvZF9zdW1tYXJ5X3JldHVybmluZ19zZWdtZW50X2xhc3RIb3Vy_at_1363259100_86ab6683906837c8' for saved search 'prod_summary_returning_segment_lastHour', UTC = 1363259100 (Thu Mar 14 12:05:00 2013)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This is the time (UTC = ...) that I want to access, even if I run the search in an unscheduled manner, the real scheduled time is still computed by the python script somehow. I want to know if I can access this value inside the search itself?&lt;/P&gt;

&lt;P&gt;Thanks for the answers!&lt;/P&gt;

&lt;P&gt;Guilhem&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 13:34:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/accessing-starting-and-ending-time-of-a-scheduled-search-inside/m-p/70445#M1605</guid>
      <dc:creator>guilhem</dc:creator>
      <dc:date>2020-09-28T13:34:25Z</dc:date>
    </item>
    <item>
      <title>Re: accessing starting and ending time of a scheduled search inside the search</title>
      <link>https://community.splunk.com/t5/Reporting/accessing-starting-and-ending-time-of-a-scheduled-search-inside/m-p/70446#M1606</link>
      <description>&lt;P&gt;Wouldn't this be what now() returns?&lt;/P&gt;</description>
      <pubDate>Thu, 21 Mar 2013 20:51:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/accessing-starting-and-ending-time-of-a-scheduled-search-inside/m-p/70446#M1606</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2013-03-21T20:51:09Z</dc:date>
    </item>
    <item>
      <title>Re: accessing starting and ending time of a scheduled search inside the search</title>
      <link>https://community.splunk.com/t5/Reporting/accessing-starting-and-ending-time-of-a-scheduled-search-inside/m-p/70447#M1607</link>
      <description>&lt;P&gt;The now() description is:&lt;/P&gt;

&lt;P&gt;now(): This function takes no arguments and returns the time that the search was started. The time is represented in Unix time or seconds since epoch.&lt;/P&gt;

&lt;P&gt;The 'search was started' is a bit confusing. Let's say this search was scheduled to run the 01/01/2013 and I run it the 03/01/2013, what will now() return: 01/01/2013 or 03/01/2013?&lt;/P&gt;</description>
      <pubDate>Fri, 22 Mar 2013 08:19:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/accessing-starting-and-ending-time-of-a-scheduled-search-inside/m-p/70447#M1607</guid>
      <dc:creator>guilhem</dc:creator>
      <dc:date>2013-03-22T08:19:19Z</dc:date>
    </item>
    <item>
      <title>Re: accessing starting and ending time of a scheduled search inside the search</title>
      <link>https://community.splunk.com/t5/Reporting/accessing-starting-and-ending-time-of-a-scheduled-search-inside/m-p/70448#M1608</link>
      <description>&lt;P&gt;I don't really get how you mean by scheduled here - if you run it manually on 3/1/2013 it's obviously not scheduled, so there's no way of accessing a scheduled time that you're not using anyway.&lt;/P&gt;</description>
      <pubDate>Fri, 22 Mar 2013 08:34:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/accessing-starting-and-ending-time-of-a-scheduled-search-inside/m-p/70448#M1608</guid>
      <dc:creator>Ayn</dc:creator>
      <dc:date>2013-03-22T08:34:21Z</dc:date>
    </item>
    <item>
      <title>Re: accessing starting and ending time of a scheduled search inside the search</title>
      <link>https://community.splunk.com/t5/Reporting/accessing-starting-and-ending-time-of-a-scheduled-search-inside/m-p/70449#M1609</link>
      <description>&lt;P&gt;Yes, I see where is the confusion. But when you use the script fill_summary_index.py, in the console log, you can see (see edited post, not enough room here)&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 13:34:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/accessing-starting-and-ending-time-of-a-scheduled-search-inside/m-p/70449#M1609</guid>
      <dc:creator>guilhem</dc:creator>
      <dc:date>2020-09-28T13:34:58Z</dc:date>
    </item>
    <item>
      <title>Re: accessing starting and ending time of a scheduled search inside the search</title>
      <link>https://community.splunk.com/t5/Reporting/accessing-starting-and-ending-time-of-a-scheduled-search-inside/m-p/70450#M1610</link>
      <description>&lt;P&gt;You could get this from the REST endpoint /saved/searches, see more here: &lt;A href="http://docs.splunk.com/Documentation/Splunk/5.0.2/RESTAPI/RESTsearch#saved.2Fsearches.2F.7Bname.7D"&gt;http://docs.splunk.com/Documentation/Splunk/5.0.2/RESTAPI/RESTsearch#saved.2Fsearches.2F.7Bname.7D&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Specifically the &lt;CODE&gt;next_scheduled_time&lt;/CODE&gt; value should be what you want.&lt;/P&gt;</description>
      <pubDate>Fri, 22 Mar 2013 13:47:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/accessing-starting-and-ending-time-of-a-scheduled-search-inside/m-p/70450#M1610</guid>
      <dc:creator>Ayn</dc:creator>
      <dc:date>2013-03-22T13:47:23Z</dc:date>
    </item>
    <item>
      <title>Re: accessing starting and ending time of a scheduled search inside the search</title>
      <link>https://community.splunk.com/t5/Reporting/accessing-starting-and-ending-time-of-a-scheduled-search-inside/m-p/70451#M1611</link>
      <description>&lt;P&gt;I have never used this before (the REST API). Gonna need some time to test if I can make it work. Thanks for the answer.&lt;/P&gt;</description>
      <pubDate>Fri, 22 Mar 2013 15:30:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/accessing-starting-and-ending-time-of-a-scheduled-search-inside/m-p/70451#M1611</guid>
      <dc:creator>guilhem</dc:creator>
      <dc:date>2013-03-22T15:30:04Z</dc:date>
    </item>
    <item>
      <title>Re: accessing starting and ending time of a scheduled search inside the search</title>
      <link>https://community.splunk.com/t5/Reporting/accessing-starting-and-ending-time-of-a-scheduled-search-inside/m-p/70452#M1612</link>
      <description>&lt;P&gt;Note that you can access it using the &lt;CODE&gt;rest&lt;/CODE&gt; command in the search language.&lt;/P&gt;</description>
      <pubDate>Fri, 22 Mar 2013 15:32:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/accessing-starting-and-ending-time-of-a-scheduled-search-inside/m-p/70452#M1612</guid>
      <dc:creator>Ayn</dc:creator>
      <dc:date>2013-03-22T15:32:14Z</dc:date>
    </item>
    <item>
      <title>Re: accessing starting and ending time of a scheduled search inside the search</title>
      <link>https://community.splunk.com/t5/Reporting/accessing-starting-and-ending-time-of-a-scheduled-search-inside/m-p/70453#M1613</link>
      <description>&lt;P&gt;Thank you very much. I have tested the rest keyword and it works very weel. I was able to (almost) solve the problem. I still have a parsing error but it may be due to the macro I use (following topic here: &lt;BR /&gt;
&lt;A href="http://splunk-base.splunk.com/answers/80765/debugging-a-search-ran-from-python-script"&gt;http://splunk-base.splunk.com/answers/80765/debugging-a-search-ran-from-python-script&lt;/A&gt;)&lt;/P&gt;

&lt;P&gt;Also it looks like the endpoint you give ( saved/searches) doesn't exists in my system. I only have inputs in the /services/search.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Mar 2013 13:38:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/accessing-starting-and-ending-time-of-a-scheduled-search-inside/m-p/70453#M1613</guid>
      <dc:creator>guilhem</dc:creator>
      <dc:date>2013-03-25T13:38:08Z</dc:date>
    </item>
    <item>
      <title>Re: accessing starting and ending time of a scheduled search inside the search</title>
      <link>https://community.splunk.com/t5/Reporting/accessing-starting-and-ending-time-of-a-scheduled-search-inside/m-p/70454#M1614</link>
      <description>&lt;P&gt;You should have /services/saved/searches/ though.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Mar 2013 14:52:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/accessing-starting-and-ending-time-of-a-scheduled-search-inside/m-p/70454#M1614</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2013-03-25T14:52:09Z</dc:date>
    </item>
    <item>
      <title>Re: accessing starting and ending time of a scheduled search inside the search</title>
      <link>https://community.splunk.com/t5/Reporting/accessing-starting-and-ending-time-of-a-scheduled-search-inside/m-p/70455#M1615</link>
      <description>&lt;P&gt;Yes I do, but I don't see all of my saved search inside. Only a very small portion of them,  can't tell what is their common factor?&lt;/P&gt;

&lt;P&gt;Same in the  /services/scheduled/, I don't have any of my search here, just an empty view folder.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Mar 2013 15:08:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/accessing-starting-and-ending-time-of-a-scheduled-search-inside/m-p/70455#M1615</guid>
      <dc:creator>guilhem</dc:creator>
      <dc:date>2013-03-25T15:08:17Z</dc:date>
    </item>
    <item>
      <title>Re: accessing starting and ending time of a scheduled search inside the search</title>
      <link>https://community.splunk.com/t5/Reporting/accessing-starting-and-ending-time-of-a-scheduled-search-inside/m-p/70456#M1616</link>
      <description>&lt;P&gt;So after messing around a bit, I have found a clunky way to achieve what I wanted, may it helps other!&lt;/P&gt;

&lt;P&gt;First I have created a macro, that takes the last search of the jobs list with the given search name, and return its earliest time (MY_MACRO):&lt;/P&gt;

&lt;P&gt;MY_MACRO(search_name, "hours to subtract before earliest schedule time")&lt;BR /&gt;
    [| rest /services/search/jobs &lt;BR /&gt;
    | search label="$arg1$" &lt;BR /&gt;
    | head 1 &lt;BR /&gt;
    | eval earliest=substr(earliestTime, 1, 19)&lt;BR /&gt;
    | eval earliest=strptime(earliest,"%Y-%m-%dT%H:%M:%S")&lt;BR /&gt;
    | eval earliest=earliest-$arg2$*3600&lt;BR /&gt;
    | eval earliest=round(earliest, 0)&lt;BR /&gt;
    | return earliest]&lt;/P&gt;

&lt;P&gt;Note that you shouldn't return $earliest as in a macro it will not work (maybe interpreted as an argument cause of the $ sign, see &lt;A href="http://splunk-base.splunk.com/answers/80765/debugging-a-search-ran-from-python-script" target="_blank"&gt;here&lt;/A&gt;.&lt;/P&gt;

&lt;P&gt;Then, take the search you want to backfill summary index, let's take index=MY_INDEX as an example (name it MY_SEARCH), and add the MY_MACRO value at the end, so the final search is:&lt;/P&gt;

&lt;P&gt;index=MY_INDEX MY_MACRO(MY_SEARCH, "hours to subtract before earliest schedule time")&lt;/P&gt;

&lt;P&gt;You can then use fill_summary_index.py with this search, the earliest time will be the scheduled time (the UTC+ ... time you can see in the console log), and not the time you run the search.&lt;/P&gt;

&lt;P&gt;Thanks very much to Ayn, Martin and alacercogitatus for the help, I think I'm done with it.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 13:35:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/accessing-starting-and-ending-time-of-a-scheduled-search-inside/m-p/70456#M1616</guid>
      <dc:creator>guilhem</dc:creator>
      <dc:date>2020-09-28T13:35:51Z</dc:date>
    </item>
  </channel>
</rss>

