<?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: REST API Modular Input - Tokens in URL (Exit Status 1) in All Apps and Add-ons</title>
    <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/REST-API-Modular-Input-Tokens-in-URL-Exit-Status-1/m-p/129781#M10567</link>
    <description>&lt;P&gt;If you want to token replace url arguments , then encode them into the endpoint url parameter rather than declaring them in the url arguments parameter&lt;/P&gt;

&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/479iEB6071F471427182/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 20 Jul 2015 16:09:24 GMT</pubDate>
    <dc:creator>Damien_Dallimor</dc:creator>
    <dc:date>2015-07-20T16:09:24Z</dc:date>
    <item>
      <title>REST API Modular Input - Tokens in URL (Exit Status 1)</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/REST-API-Modular-Input-Tokens-in-URL-Exit-Status-1/m-p/129773#M10559</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I'm trying to use tokens in the URL Arguments. (I'm hoping I can put the tokens there rather than just the endpoint. I actually tried cutting and pasting my URL arguments with my tokens into the actual URL Endpoint field with a ?, and it still got the same exception. I'm thinking you can put these tokens in the URL Arguments field.)&lt;/P&gt;

&lt;P&gt;Anyway, I'm trying to do a special SQL call to the REST endpoint that includes "$" in the SQL that aren't part of the tokens I'm using. I'm thinking this may be a problem, and they may need to be escaped or something to avoid causing a conflict with the exception handler. &lt;/P&gt;

&lt;P&gt;The REST API setup worked before to pull the bulk of the data in the dataset through this endpoint. So I'm not worried about the endpoint or anything, and I'm not getting far enough now for an error from the REST endpoint itself. &lt;/P&gt;

&lt;P&gt;I'm just now customizing the configuration so that it makes a call using this special SQL with a cron in the "Polling Interval" to keep the dataset up to date.&lt;/P&gt;

&lt;P&gt;I'm on version 1.3.9.&lt;/P&gt;

&lt;P&gt;Here is what my URL arguments look like: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;$order=reported_on DESC^$where=reported_on between $starttime_mten$ and $timenow$^$limit=50000
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Here is the code I added to tokens.py: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;def starttime_mten():
    tenmins = datetime.timedelta(minutes=10)
    now = datetime.data.now()
    timemten = now - tenmins
    return timemten.strftime('%Y-%m-%dT%H:%M:%S')

def timenow()
    now = datetime.data.now()
    return timenow.strftime('%Y-%m-%dT%H:%M:%S')
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Here is the error log:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;07-18-2015 21:39:12.981 +0000 WARN  ModularInputs - Validation for scheme=rest failed: The script returned with exit status 1.
07-18-2015 21:39:12.981 +0000 INFO  ModularInputs - The script returned with exit status 1.
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I also restarted just to make sure there wasn't a problem otherwise, and it failed to load again. Here's that error from the log:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;07-18-2015 22:00:54.157 +0000 ERROR ModularInputs - Introspecting scheme=rest: script running failed (exited with code 1).
07-18-2015 22:00:54.157 +0000 ERROR ModularInputs - Unable to initialize modular input "rest"  defined inside the app "rest_ta": Introspecting scheme=rest: script running failed (exited with code 1).
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Additionally I have a delimeter set of "^"&lt;/P&gt;

&lt;P&gt;And the "Polling Interval" of: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;*/10 * * * * *
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Any thoughts on why I'm getting this error. &lt;/P&gt;

&lt;P&gt;Thanks in advance for the help. &lt;/P&gt;</description>
      <pubDate>Sat, 18 Jul 2015 22:09:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/REST-API-Modular-Input-Tokens-in-URL-Exit-Status-1/m-p/129773#M10559</guid>
      <dc:creator>efullman</dc:creator>
      <dc:date>2015-07-18T22:09:18Z</dc:date>
    </item>
    <item>
      <title>Re: REST API Modular Input - Tokens in URL (Exit Status 1)</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/REST-API-Modular-Input-Tokens-in-URL-Exit-Status-1/m-p/129774#M10560</link>
      <description>&lt;P&gt;Ignore the "5." and "10." in the tokens.py code. That was injected by the editor when I pasted it. &lt;/P&gt;</description>
      <pubDate>Sat, 18 Jul 2015 22:20:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/REST-API-Modular-Input-Tokens-in-URL-Exit-Status-1/m-p/129774#M10560</guid>
      <dc:creator>efullman</dc:creator>
      <dc:date>2015-07-18T22:20:09Z</dc:date>
    </item>
    <item>
      <title>Re: REST API Modular Input - Tokens in URL (Exit Status 1)</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/REST-API-Modular-Input-Tokens-in-URL-Exit-Status-1/m-p/129775#M10561</link>
      <description>&lt;P&gt;One more thing. I cancelled out of the edit of the REST API, and it already had the configuration that didn't work in it. &lt;/P&gt;

&lt;P&gt;When I restarted it got the introspection error. &lt;/P&gt;

&lt;P&gt;Now the app doesn't seem to be loaded. &lt;/P&gt;

&lt;P&gt;The Data Input window doesn't come up with REST as one of the choices. I'll need some help to identify where to edit that configuration file so that the REST can load. I assume I'll have to fix that first and restart before we can fix this. &lt;/P&gt;</description>
      <pubDate>Sat, 18 Jul 2015 22:28:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/REST-API-Modular-Input-Tokens-in-URL-Exit-Status-1/m-p/129775#M10561</guid>
      <dc:creator>efullman</dc:creator>
      <dc:date>2015-07-18T22:28:07Z</dc:date>
    </item>
    <item>
      <title>Re: REST API Modular Input - Tokens in URL (Exit Status 1)</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/REST-API-Modular-Input-Tokens-in-URL-Exit-Status-1/m-p/129776#M10562</link>
      <description>&lt;P&gt;Answered my own question. &lt;/P&gt;

&lt;P&gt;Turns out this exit status was because I had serious errors in my python code. &lt;/P&gt;

&lt;P&gt;The final python that at least passed exception handling (we'll see if it works in the SQL), was:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;def starttime_mten():
     tenmins = datetime.timedelta(minutes=10)
     now = datetime.date.now()
     timemten = now - tenmins
     return timemten.strftime('%Y-%m-%dT%H:%M:%S')

def timenow():
     now = datetime.date.now()
     return now.strftime('%Y-%m-%dT%H:%M:%S')
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;In order to fix the load error that caused the rest_ta not to load, I had to delete my Python changes. Then it loaded okay. Then I went back in and essentially debugged my buggy python. &lt;/P&gt;</description>
      <pubDate>Sat, 18 Jul 2015 23:10:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/REST-API-Modular-Input-Tokens-in-URL-Exit-Status-1/m-p/129776#M10562</guid>
      <dc:creator>efullman</dc:creator>
      <dc:date>2015-07-18T23:10:48Z</dc:date>
    </item>
    <item>
      <title>Re: REST API Modular Input - Tokens in URL (Exit Status 1)</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/REST-API-Modular-Input-Tokens-in-URL-Exit-Status-1/m-p/129777#M10563</link>
      <description>&lt;P&gt;More refinement. Needed datatime  not date.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;def starttime_mten():
     tenmins = datetime.timedelta(minutes=10)
     now = datetime.datetime.now()
     timemten = now - tenmins
     return timemten.strftime('%Y-%m-%dT%H:%M:%S')

def timenow():
     now = datetime.datetime.now()
     return now.strftime('%Y-%m-%dT%H:%M:%S')
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 19 Jul 2015 00:44:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/REST-API-Modular-Input-Tokens-in-URL-Exit-Status-1/m-p/129777#M10563</guid>
      <dc:creator>efullman</dc:creator>
      <dc:date>2015-07-19T00:44:25Z</dc:date>
    </item>
    <item>
      <title>Re: REST API Modular Input - Tokens in URL (Exit Status 1)</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/REST-API-Modular-Input-Tokens-in-URL-Exit-Status-1/m-p/129778#M10564</link>
      <description>&lt;P&gt;Your cron pattern has 1 too many "*".&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;*/10 * * * *&lt;/CODE&gt;   not  &lt;CODE&gt;*/10 * * * * *&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Token replacement only applys to the endpoint field , not the url_args field. &lt;/P&gt;</description>
      <pubDate>Sun, 19 Jul 2015 02:46:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/REST-API-Modular-Input-Tokens-in-URL-Exit-Status-1/m-p/129778#M10564</guid>
      <dc:creator>Damien_Dallimor</dc:creator>
      <dc:date>2015-07-19T02:46:32Z</dc:date>
    </item>
    <item>
      <title>Re: REST API Modular Input - Tokens in URL (Exit Status 1)</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/REST-API-Modular-Input-Tokens-in-URL-Exit-Status-1/m-p/129779#M10565</link>
      <description>&lt;P&gt;Thanks for your input, I did see the error in the cron. I've since realized I can't poll the database this frequently I need to build a more extensive parser that saves the data and time of the last event, and then starts the search with that value. &lt;/P&gt;

&lt;P&gt;Before I do that I need to implement something brute force that will execute with the cron: &lt;CODE&gt;0 0 * * *&lt;/CODE&gt; (e.g. every midnight).&lt;/P&gt;

&lt;P&gt;My new python is simpler, just figuring out yesterday's date. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;def start_day():
     one_day = datetime.timedelta(days=1)
     today = datetime.date.today()
     startday = today - one_day
     return startday.strftime('%Y-%m-%d')
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I'm actually doing a call with URL arguments that include:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;$where=applieddate between $start_day$ and $datetoday$
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;However, I'm getting an error, and I think its because the tokens aren't replacing. I'm getting a 400, but the return as error is logged into the index and it reads: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;http_error_code = 400 error_message = {"message":"query.soql.no-such-column","errorCode":"query.soql.no-such-column","data":{"data":{"column":"$start_day$","dataset":"alpha.34796","position":{"row":1,"column":38,"line":"SELECT * WHERE `applieddate` BETWEEN `$start_day$` AND `$datetoday$` ORDER BY `applieddate` DESC NULL FIRST\n      
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I would have expected the two tokens to be replaced with the date, since this is coming back from the endpoint into the index. Any ideas why the python wouldn't have executed?&lt;/P&gt;

&lt;P&gt;I saved it into the tokens.py file, and then I restarted Splunk for good measure in case it needed to be loaded in an include or something. &lt;/P&gt;

&lt;P&gt;Your ideas are appreciated. &lt;/P&gt;</description>
      <pubDate>Mon, 20 Jul 2015 05:11:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/REST-API-Modular-Input-Tokens-in-URL-Exit-Status-1/m-p/129779#M10565</guid>
      <dc:creator>efullman</dc:creator>
      <dc:date>2015-07-20T05:11:35Z</dc:date>
    </item>
    <item>
      <title>Re: REST API Modular Input - Tokens in URL (Exit Status 1)</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/REST-API-Modular-Input-Tokens-in-URL-Exit-Status-1/m-p/129780#M10566</link>
      <description>&lt;P&gt;I just noticed your comment that the tokens don't work in the URL arguments. &lt;/P&gt;

&lt;P&gt;I was looking through the rest.py code. It seems like we could call the replaceTokens function for the url_args. As you know this "else" is near the end of the code. &lt;/P&gt;

&lt;P&gt;I tried to hack a mod in here, but my python skills are weak. This didn't work, as a second "do_run", how would you suggest I could hack this in?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;    else:
    config = get_input_config()
        original_endpoint=config.get("endpoint")
        #token replacement
        endpoint_list = replaceTokens(original_endpoint)
        #token replacement url args
        original_url_args=config.get("url_args")
        url_arg_list = replaceTokens(original_url_args)

        sequential_mode=int(config.get("sequential_mode",0))

        if bool(sequential_mode):
            do_run(config,endpoint_list)
         #token for url args
            do_run(config,url_arg_list)
        else:  #parallel mode
            for endpoint in endpoint_list:
                requester = threading.Thread(target=do_run, args=(config,[endpo$
                requester.start()
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 20 Jul 2015 15:27:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/REST-API-Modular-Input-Tokens-in-URL-Exit-Status-1/m-p/129780#M10566</guid>
      <dc:creator>efullman</dc:creator>
      <dc:date>2015-07-20T15:27:39Z</dc:date>
    </item>
    <item>
      <title>Re: REST API Modular Input - Tokens in URL (Exit Status 1)</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/REST-API-Modular-Input-Tokens-in-URL-Exit-Status-1/m-p/129781#M10567</link>
      <description>&lt;P&gt;If you want to token replace url arguments , then encode them into the endpoint url parameter rather than declaring them in the url arguments parameter&lt;/P&gt;

&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/479iEB6071F471427182/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jul 2015 16:09:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/REST-API-Modular-Input-Tokens-in-URL-Exit-Status-1/m-p/129781#M10567</guid>
      <dc:creator>Damien_Dallimor</dc:creator>
      <dc:date>2015-07-20T16:09:24Z</dc:date>
    </item>
    <item>
      <title>Re: REST API Modular Input - Tokens in URL (Exit Status 1)</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/REST-API-Modular-Input-Tokens-in-URL-Exit-Status-1/m-p/129782#M10568</link>
      <description>&lt;P&gt;Thanks I'll give it a try&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jul 2015 16:14:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/REST-API-Modular-Input-Tokens-in-URL-Exit-Status-1/m-p/129782#M10568</guid>
      <dc:creator>efullman</dc:creator>
      <dc:date>2015-07-20T16:14:12Z</dc:date>
    </item>
    <item>
      <title>Re: REST API Modular Input - Tokens in URL (Exit Status 1)</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/REST-API-Modular-Input-Tokens-in-URL-Exit-Status-1/m-p/129783#M10569</link>
      <description>&lt;P&gt;Thanks that worked as expected. I think adding token replacement in the other terms besides the endpoint would be a good improvement for the future. &lt;/P&gt;</description>
      <pubDate>Mon, 20 Jul 2015 16:40:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/REST-API-Modular-Input-Tokens-in-URL-Exit-Status-1/m-p/129783#M10569</guid>
      <dc:creator>efullman</dc:creator>
      <dc:date>2015-07-20T16:40:22Z</dc:date>
    </item>
    <item>
      <title>Re: REST API Modular Input - Tokens in URL (Exit Status 1)</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/REST-API-Modular-Input-Tokens-in-URL-Exit-Status-1/m-p/129784#M10570</link>
      <description>&lt;P&gt;Hi Damien/efullman, Can you guys please drop a hint about where to declare these variable tokens specified inside &lt;EM&gt;Endpoint URL&lt;/EM&gt;. I have a few tokens inserted into the &lt;EM&gt;endpoint URL&lt;/EM&gt; which I want to be fetched from some python class. But I can't seem to figure out where to put/insert that python code in the /rest_ta/bin directory?&lt;/P&gt;</description>
      <pubDate>Wed, 09 Sep 2015 05:14:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/REST-API-Modular-Input-Tokens-in-URL-Exit-Status-1/m-p/129784#M10570</guid>
      <dc:creator>upmangaurav</dc:creator>
      <dc:date>2015-09-09T05:14:41Z</dc:date>
    </item>
    <item>
      <title>Re: REST API Modular Input - Tokens in URL (Exit Status 1)</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/REST-API-Modular-Input-Tokens-in-URL-Exit-Status-1/m-p/129785#M10571</link>
      <description>&lt;P&gt;Have a look at the token substitution section in &lt;A href="https://splunkbase.splunk.com/app/1546/#/documentation"&gt;the documentation&lt;/A&gt;.&lt;/P&gt;

&lt;P&gt;rest_ta/bin/tokens.py&lt;/P&gt;</description>
      <pubDate>Wed, 09 Sep 2015 07:42:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/REST-API-Modular-Input-Tokens-in-URL-Exit-Status-1/m-p/129785#M10571</guid>
      <dc:creator>Damien_Dallimor</dc:creator>
      <dc:date>2015-09-09T07:42:45Z</dc:date>
    </item>
    <item>
      <title>Re: REST API Modular Input - Tokens in URL (Exit Status 1)</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/REST-API-Modular-Input-Tokens-in-URL-Exit-Status-1/m-p/129786#M10572</link>
      <description>&lt;P&gt;Thanks Damien, That did it!&lt;/P&gt;</description>
      <pubDate>Thu, 10 Sep 2015 11:53:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/REST-API-Modular-Input-Tokens-in-URL-Exit-Status-1/m-p/129786#M10572</guid>
      <dc:creator>upmangaurav</dc:creator>
      <dc:date>2015-09-10T11:53:57Z</dc:date>
    </item>
  </channel>
</rss>

