<?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 REST API Modular input - creating class in responsehandler.py in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/REST-API-Modular-input-creating-class-in-responsehandler-py/m-p/392048#M70024</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;I'm trying to get data in Splunk using REST API (data are in json format).&lt;BR /&gt;
I understand I have to create my own class in responsehandler.py, but I don't know anything about python...&lt;/P&gt;

&lt;P&gt;I tried a lot of things based on exemples but unsuccessfully... &lt;/P&gt;

&lt;P&gt;Below a sample of my data...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;{"infos":
    [
    {"component":
        {"measures":
        [
            {"metric":"ncloc","periods":[{"index":1,"value":"245"}],"value":"4082"},
            {"metric":"sqale_index","periods":[{"index":1,"value":"0"}],"value":"3564"},
            .....
            {"metric":"blocker_violations","periods":[{"index":1,"value":"0"}],"value":"0"}
        ]
        }
    }
    ]
}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Any help would be very appreciated !&lt;BR /&gt;
Thanks,&lt;BR /&gt;
David&lt;/P&gt;</description>
    <pubDate>Fri, 03 Aug 2018 12:11:33 GMT</pubDate>
    <dc:creator>DavidCaputo</dc:creator>
    <dc:date>2018-08-03T12:11:33Z</dc:date>
    <item>
      <title>REST API Modular input - creating class in responsehandler.py</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/REST-API-Modular-input-creating-class-in-responsehandler-py/m-p/392048#M70024</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;I'm trying to get data in Splunk using REST API (data are in json format).&lt;BR /&gt;
I understand I have to create my own class in responsehandler.py, but I don't know anything about python...&lt;/P&gt;

&lt;P&gt;I tried a lot of things based on exemples but unsuccessfully... &lt;/P&gt;

&lt;P&gt;Below a sample of my data...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;{"infos":
    [
    {"component":
        {"measures":
        [
            {"metric":"ncloc","periods":[{"index":1,"value":"245"}],"value":"4082"},
            {"metric":"sqale_index","periods":[{"index":1,"value":"0"}],"value":"3564"},
            .....
            {"metric":"blocker_violations","periods":[{"index":1,"value":"0"}],"value":"0"}
        ]
        }
    }
    ]
}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Any help would be very appreciated !&lt;BR /&gt;
Thanks,&lt;BR /&gt;
David&lt;/P&gt;</description>
      <pubDate>Fri, 03 Aug 2018 12:11:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/REST-API-Modular-input-creating-class-in-responsehandler-py/m-p/392048#M70024</guid>
      <dc:creator>DavidCaputo</dc:creator>
      <dc:date>2018-08-03T12:11:33Z</dc:date>
    </item>
    <item>
      <title>Re: REST API Modular input - creating class in responsehandler.py</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/REST-API-Modular-input-creating-class-in-responsehandler-py/m-p/392049#M70025</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;class infosJSONArrayHandler:

            def __init__(self,**args):
                    pass

            def __call__(self, response_object,raw_response_output,response_type,req_args,endpoint):
                    if response_type == "json":
                            output = json.loads(raw_response_output)
                            for info in output["infos"]:
                                    print_xml_stream(json.dumps(info))
                    else:
                            print_xml_stream(raw_response_output)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;NOTE: Python doesn't like inconsitently mixed tabs and spaces for indentation.&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Aug 2018 05:41:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/REST-API-Modular-input-creating-class-in-responsehandler-py/m-p/392049#M70025</guid>
      <dc:creator>ansif</dc:creator>
      <dc:date>2018-08-06T05:41:26Z</dc:date>
    </item>
    <item>
      <title>Re: REST API Modular input - creating class in responsehandler.py</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/REST-API-Modular-input-creating-class-in-responsehandler-py/m-p/392050#M70026</link>
      <description>&lt;P&gt;Thanks ansif,&lt;BR /&gt;
I tried to use this class (I used only tabs for indentation) but it doesn't work eather...&lt;/P&gt;

&lt;P&gt;I looked to the internal index and found this : &lt;BR /&gt;
 "08-27-2018 11:00:06.975 +0200 ERROR ExecProcessor - message from "python /data/splunk/etc/apps/rest_ta/bin/rest.py" HTTP Request error: 401 Client Error: Not Authorized"&lt;/P&gt;

&lt;P&gt;I guess the python code you provide is correct but the problem is somewhere else...&lt;BR /&gt;
David&lt;/P&gt;</description>
      <pubDate>Mon, 27 Aug 2018 09:21:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/REST-API-Modular-input-creating-class-in-responsehandler-py/m-p/392050#M70026</guid>
      <dc:creator>DavidCaputo</dc:creator>
      <dc:date>2018-08-27T09:21:09Z</dc:date>
    </item>
  </channel>
</rss>

