<?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: Custom Key-Value Delimiter for Arguments in Custom Python Response Handler in All Apps and Add-ons</title>
    <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/REST-API-Modular-Input-Custom-Key-Value-Delimiter-for-Arguments/m-p/200110#M20940</link>
    <description>&lt;P&gt;This worked:&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;That change to dictParameterToStringFormat&lt;/LI&gt;
&lt;LI&gt;Specify global delimiter&lt;/LI&gt;
&lt;LI&gt;Set the delimiter to:   &amp;amp;&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;Now, &amp;amp; becomes the delimiter and the URL arguments look like this:&lt;/P&gt;

&lt;P&gt;login=myuser&amp;amp;pass=sadf73jhdsdf34sdf3&amp;amp;id=754220,100984,766542&amp;amp;t1=1440807720000&amp;amp;t2=1440808020000&lt;/P&gt;</description>
    <pubDate>Tue, 01 Sep 2015 15:10:14 GMT</pubDate>
    <dc:creator>aarontimko</dc:creator>
    <dc:date>2015-09-01T15:10:14Z</dc:date>
    <item>
      <title>REST API Modular Input: Custom Key-Value Delimiter for Arguments in Custom Python Response Handler</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/REST-API-Modular-Input-Custom-Key-Value-Delimiter-for-Arguments/m-p/200103#M20933</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;

&lt;P&gt;I'm trying to pull in data to Splunk from a REST API which requires t1 and t2 arguments defined in epoch time, milliseconds.&lt;BR /&gt;
So, if I poll every 5 minutes &lt;CODE&gt;*/5 * * * *&lt;/CODE&gt; for data, I need t2=CurTime and t1=(CurTime - 5min).&lt;/P&gt;

&lt;P&gt;That way, I get the past 5 minutes of data every poll.&lt;/P&gt;

&lt;P&gt;I set up a custom Response Handler as such, and it seems to be working okay.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;class MyCustomAPI:
    '''Response handler for MyCustomAPI.'''

    def __init__(self,**args):
        pass

    def __call__(self, response_object,raw_response_output,response_type,req_args,endpoint):
        if not "params" in req_args:
            req_args["params"] = {}
        t2 = int(time.time()) * 1000
        t1 = t2 - 300000
        req_args["params"]["t2"] = t2
        req_args["params"]["t1"] = t1
        req_args["params"]["login"] = "myuser"
        req_args["params"]["pass"] = "sadf73jhdsdf34sdf3"
        req_args["params"]["id"] = "754220"
        print_xml_stream(raw_response_output)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;Problem:&lt;/STRONG&gt;&lt;BR /&gt;
I actually need to define multiple comma-separated IDs, e.g.  754220,100984,766542.  If I enter this into the custom Python class parameter, it appears the URI gets malformed and I get "bad request" from the API I'm hitting.  Because the "URL Arguments"  in the REST API data input also get populated with comma-separated key-value pairs, I think perhaps that's the problem.&lt;/P&gt;

&lt;P&gt;Works:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;login=myuser,pass=sadf73jhdsdf34sdf3,id=754220,t1=1440807720000,t2=1440808020000
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Probably won't ever work as-is:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;login=myuser,pass=sadf73jhdsdf34sdf3,id=754220,100984,766542,t1=1440807720000,t2=1440808020000
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I tried putting &lt;CODE&gt;&amp;amp;&lt;/CODE&gt; as the value for "Delimiter" in the REST API data input, but since I'm not actually defining the values there in the web GUI, but in the Python class, that doesn't seem to help.&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Further question for ideal operation&lt;/STRONG&gt;:&lt;BR /&gt;
I would like to only use the MyCustomAPI Python class for defining t1 and t2.&lt;BR /&gt;
For the rest of the values, I would prefer to enter them on-the-fly in the web GUI.&lt;/P&gt;

&lt;P&gt;Response Handler:   (only defines t1 and t2)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;MyCustomAPI
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Response Handler Arguments:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;login=myuser&amp;amp;pass=sadf73jhdsdf34sdf3&amp;amp;id=754220,100984,766542
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Polling Interval:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;*/5 * * * *
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Delimiter:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;amp;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Or as such in the attached screenshot... is this possible?&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/619i0DF4EC7BE82C2B13/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>Sat, 29 Aug 2015 01:07:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/REST-API-Modular-Input-Custom-Key-Value-Delimiter-for-Arguments/m-p/200103#M20933</guid>
      <dc:creator>aarontimko</dc:creator>
      <dc:date>2015-08-29T01:07:29Z</dc:date>
    </item>
    <item>
      <title>Re: REST API Modular Input: Custom Key-Value Delimiter for Arguments in Custom Python Response Handler</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/REST-API-Modular-Input-Custom-Key-Value-Delimiter-for-Arguments/m-p/200104#M20934</link>
      <description>&lt;P&gt;I may have to fix some code.&lt;/P&gt;

&lt;P&gt;When you set the url args in your response handler using the params dict , they get auto persisted back to inputs.conf for you , and it seems this part of the code is hard coded to use a "," delimiter vs the custom delimiter you have declared to use (&amp;amp;). Give me  a day or 2.&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/616i50CFBD91C55B5146/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>Sat, 29 Aug 2015 10:57:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/REST-API-Modular-Input-Custom-Key-Value-Delimiter-for-Arguments/m-p/200104#M20934</guid>
      <dc:creator>Damien_Dallimor</dc:creator>
      <dc:date>2015-08-29T10:57:07Z</dc:date>
    </item>
    <item>
      <title>Re: REST API Modular Input: Custom Key-Value Delimiter for Arguments in Custom Python Response Handler</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/REST-API-Modular-Input-Custom-Key-Value-Delimiter-for-Arguments/m-p/200105#M20935</link>
      <description>&lt;P&gt;In &lt;STRONG&gt;rest_ta/bin/rest.py&lt;/STRONG&gt; , try changing the dictParameterToStringFormat function to be like :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;def dictParameterToStringFormat(parameter):

    if parameter:
        return ''.join(('{}={}'+delimiter).format(key, val) for key, val in parameter.items())[:-1] 
    else:
        return None
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 30 Aug 2015 10:14:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/REST-API-Modular-Input-Custom-Key-Value-Delimiter-for-Arguments/m-p/200105#M20935</guid>
      <dc:creator>Damien_Dallimor</dc:creator>
      <dc:date>2015-08-30T10:14:48Z</dc:date>
    </item>
    <item>
      <title>Re: REST API Modular Input: Custom Key-Value Delimiter for Arguments in Custom Python Response Handler</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/REST-API-Modular-Input-Custom-Key-Value-Delimiter-for-Arguments/m-p/200106#M20936</link>
      <description>&lt;P&gt;Thanks Damien!&lt;/P&gt;

&lt;P&gt;For testing, I temporarily disabled my other REST inputs and changed the dictParameterToStringFormat function to the new code above.&lt;/P&gt;

&lt;P&gt;The REST input I left enabled had the comma-separated values in the MyCustomAPI Response Handler and &amp;amp; as the delimiter in the REST API input.&lt;/P&gt;

&lt;P&gt;Error below from splunkd.log, I'm running 1.3.9 rest_ta version.&lt;BR /&gt;
def dictParameterToStringFormat(parameter):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; if parameter:
      return ''.join(('{}={}'+delimiter).format(key, val) for key, val in parameter.items())[:-1]
 else:
      return None

ERROR ExecProcessor - message from "python /opt/splunk/etc/apps/rest_ta/bin/rest.py" NameError: global name 'delimiter' is not defined
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 31 Aug 2015 07:27:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/REST-API-Modular-Input-Custom-Key-Value-Delimiter-for-Arguments/m-p/200106#M20936</guid>
      <dc:creator>aarontimko</dc:creator>
      <dc:date>2015-08-31T07:27:33Z</dc:date>
    </item>
    <item>
      <title>Re: REST API Modular Input: Custom Key-Value Delimiter for Arguments in Custom Python Response Handler</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/REST-API-Modular-Input-Custom-Key-Value-Delimiter-for-Arguments/m-p/200107#M20937</link>
      <description>&lt;P&gt;I'm just giving quick reference examples here.Untested.&lt;BR /&gt;
Make the delimiter var global then.&lt;/P&gt;</description>
      <pubDate>Mon, 31 Aug 2015 07:36:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/REST-API-Modular-Input-Custom-Key-Value-Delimiter-for-Arguments/m-p/200107#M20937</guid>
      <dc:creator>Damien_Dallimor</dc:creator>
      <dc:date>2015-08-31T07:36:37Z</dc:date>
    </item>
    <item>
      <title>Re: REST API Modular Input: Custom Key-Value Delimiter for Arguments in Custom Python Response Handler</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/REST-API-Modular-Input-Custom-Key-Value-Delimiter-for-Arguments/m-p/200108#M20938</link>
      <description>&lt;P&gt;As per previous comment , "Make the delimiter var global then".&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/618iA060633180F42F66/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;Wait for me to release a new tested version when I get some bandwidth.&lt;/P&gt;</description>
      <pubDate>Mon, 31 Aug 2015 12:49:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/REST-API-Modular-Input-Custom-Key-Value-Delimiter-for-Arguments/m-p/200108#M20938</guid>
      <dc:creator>Damien_Dallimor</dc:creator>
      <dc:date>2015-08-31T12:49:55Z</dc:date>
    </item>
    <item>
      <title>Re: REST API Modular Input: Custom Key-Value Delimiter for Arguments in Custom Python Response Handler</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/REST-API-Modular-Input-Custom-Key-Value-Delimiter-for-Arguments/m-p/200109#M20939</link>
      <description>&lt;P&gt;Thanks!&lt;BR /&gt;
I thought my comment didn't go through so that's why it got submitted twice.&lt;/P&gt;</description>
      <pubDate>Mon, 31 Aug 2015 18:18:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/REST-API-Modular-Input-Custom-Key-Value-Delimiter-for-Arguments/m-p/200109#M20939</guid>
      <dc:creator>aarontimko</dc:creator>
      <dc:date>2015-08-31T18:18:36Z</dc:date>
    </item>
    <item>
      <title>Re: REST API Modular Input: Custom Key-Value Delimiter for Arguments in Custom Python Response Handler</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/REST-API-Modular-Input-Custom-Key-Value-Delimiter-for-Arguments/m-p/200110#M20940</link>
      <description>&lt;P&gt;This worked:&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;That change to dictParameterToStringFormat&lt;/LI&gt;
&lt;LI&gt;Specify global delimiter&lt;/LI&gt;
&lt;LI&gt;Set the delimiter to:   &amp;amp;&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;Now, &amp;amp; becomes the delimiter and the URL arguments look like this:&lt;/P&gt;

&lt;P&gt;login=myuser&amp;amp;pass=sadf73jhdsdf34sdf3&amp;amp;id=754220,100984,766542&amp;amp;t1=1440807720000&amp;amp;t2=1440808020000&lt;/P&gt;</description>
      <pubDate>Tue, 01 Sep 2015 15:10:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/REST-API-Modular-Input-Custom-Key-Value-Delimiter-for-Arguments/m-p/200110#M20940</guid>
      <dc:creator>aarontimko</dc:creator>
      <dc:date>2015-09-01T15:10:14Z</dc:date>
    </item>
  </channel>
</rss>

