<?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: Modular Inputs - How can I split the HTTP JSON response into multiple events? in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/Modular-Inputs-How-can-I-split-the-HTTP-JSON-response-into/m-p/320299#M59795</link>
    <description>&lt;P&gt;Each array element should be a separate event.&lt;BR /&gt;
I solved this problem. I overlooked the SCHEMA config.&lt;/P&gt;

&lt;P&gt;It's important to set the streaming mode to xml&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;SCHEME = """&amp;lt;scheme&amp;gt;
    &amp;lt;title&amp;gt;Hello&amp;lt;/title&amp;gt;
    &amp;lt;description&amp;gt;Log Data to Splunk&amp;lt;/description&amp;gt;
    &amp;lt;streaming_mode&amp;gt;xml&amp;lt;/streaming_mode&amp;gt;
&amp;lt;/scheme&amp;gt;
"""

# Empty introspection routine
def do_scheme():
    print SCHEME
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;See Documentation: &lt;BR /&gt;
&lt;A href="https://docs.splunk.com/Documentation/Splunk/6.6.2/AdvancedDev/ModInputsStream"&gt;https://docs.splunk.com/Documentation/Splunk/6.6.2/AdvancedDev/ModInputsStream&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;And than I can post separate events to Splunk by using this code.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;# prints XML stream
def post_data(time, data):
    print "&amp;lt;stream&amp;gt;&amp;lt;event unbroken=\"1\"&amp;gt;&amp;lt;time&amp;gt;%s&amp;lt;/time&amp;gt;&amp;lt;data&amp;gt;%s&amp;lt;/data&amp;gt;&amp;lt;done/&amp;gt;&amp;lt;/event&amp;gt;&amp;lt;/stream&amp;gt;"  % (time,data)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;It's also important to set unbroken attribute and and the  tag. &lt;/P&gt;

&lt;P&gt;See Documentation: &lt;BR /&gt;
&lt;A href="https://docs.splunk.com/Documentation/Splunk/6.6.2/AdvancedDev/ModInputsStream"&gt;https://docs.splunk.com/Documentation/Splunk/6.6.2/AdvancedDev/ModInputsStream&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 08 Sep 2017 10:17:54 GMT</pubDate>
    <dc:creator>manuel2202</dc:creator>
    <dc:date>2017-09-08T10:17:54Z</dc:date>
    <item>
      <title>Modular Inputs - How can I split the HTTP JSON response into multiple events?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Modular-Inputs-How-can-I-split-the-HTTP-JSON-response-into/m-p/320297#M59793</link>
      <description>&lt;P&gt;How can I split the HTTP JSON response into multiple events?&lt;BR /&gt;
My REST API is returning a JSON Array and for each array element I like to create separate event in Splunk.&lt;BR /&gt;
I tried sys.stdout.flush() but without success. How can I set event boundaries?&lt;/P&gt;

&lt;P&gt;This is my json response &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[{"sever1": true}, {"sever2": true}]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This is my run method&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;def run_script():


    try:
        cfg = get_config()
        conn = httplib.HTTPConnection(cfg["url"])
        conn.request("GET", "/")
        r1 = conn.getresponse()
        data1 = json.loads(r1.read())

        for d in data1:
            print d
            sys.stdout.flush()

        conn.close()
    except Exception as e:
        logger.error(e)
    logger.info("RUN HTTP DONE")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 07 Sep 2017 10:25:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Modular-Inputs-How-can-I-split-the-HTTP-JSON-response-into/m-p/320297#M59793</guid>
      <dc:creator>manuel2202</dc:creator>
      <dc:date>2017-09-07T10:25:16Z</dc:date>
    </item>
    <item>
      <title>Re: Modular Inputs - How can I split the HTTP JSON response into multiple events?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Modular-Inputs-How-can-I-split-the-HTTP-JSON-response-into/m-p/320298#M59794</link>
      <description>&lt;P&gt;Is your JSON data actually all on one line that you want to separate into different events? That is, is it like this?:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[{"sever1": true}, {"sever2": true}]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;or this?:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[{"sever1": true}, 
{"sever2": true}]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;What is your purpose in separating the values into different events? This sort of thing &lt;STRONG&gt;can&lt;/STRONG&gt; be done at search time without having to do it at index time.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Sep 2017 15:07:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Modular-Inputs-How-can-I-split-the-HTTP-JSON-response-into/m-p/320298#M59794</guid>
      <dc:creator>cpetterborg</dc:creator>
      <dc:date>2017-09-07T15:07:10Z</dc:date>
    </item>
    <item>
      <title>Re: Modular Inputs - How can I split the HTTP JSON response into multiple events?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Modular-Inputs-How-can-I-split-the-HTTP-JSON-response-into/m-p/320299#M59795</link>
      <description>&lt;P&gt;Each array element should be a separate event.&lt;BR /&gt;
I solved this problem. I overlooked the SCHEMA config.&lt;/P&gt;

&lt;P&gt;It's important to set the streaming mode to xml&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;SCHEME = """&amp;lt;scheme&amp;gt;
    &amp;lt;title&amp;gt;Hello&amp;lt;/title&amp;gt;
    &amp;lt;description&amp;gt;Log Data to Splunk&amp;lt;/description&amp;gt;
    &amp;lt;streaming_mode&amp;gt;xml&amp;lt;/streaming_mode&amp;gt;
&amp;lt;/scheme&amp;gt;
"""

# Empty introspection routine
def do_scheme():
    print SCHEME
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;See Documentation: &lt;BR /&gt;
&lt;A href="https://docs.splunk.com/Documentation/Splunk/6.6.2/AdvancedDev/ModInputsStream"&gt;https://docs.splunk.com/Documentation/Splunk/6.6.2/AdvancedDev/ModInputsStream&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;And than I can post separate events to Splunk by using this code.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;# prints XML stream
def post_data(time, data):
    print "&amp;lt;stream&amp;gt;&amp;lt;event unbroken=\"1\"&amp;gt;&amp;lt;time&amp;gt;%s&amp;lt;/time&amp;gt;&amp;lt;data&amp;gt;%s&amp;lt;/data&amp;gt;&amp;lt;done/&amp;gt;&amp;lt;/event&amp;gt;&amp;lt;/stream&amp;gt;"  % (time,data)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;It's also important to set unbroken attribute and and the  tag. &lt;/P&gt;

&lt;P&gt;See Documentation: &lt;BR /&gt;
&lt;A href="https://docs.splunk.com/Documentation/Splunk/6.6.2/AdvancedDev/ModInputsStream"&gt;https://docs.splunk.com/Documentation/Splunk/6.6.2/AdvancedDev/ModInputsStream&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Sep 2017 10:17:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Modular-Inputs-How-can-I-split-the-HTTP-JSON-response-into/m-p/320299#M59795</guid>
      <dc:creator>manuel2202</dc:creator>
      <dc:date>2017-09-08T10:17:54Z</dc:date>
    </item>
    <item>
      <title>Re: Modular Inputs - How can I split the HTTP JSON response into multiple events?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Modular-Inputs-How-can-I-split-the-HTTP-JSON-response-into/m-p/320300#M59796</link>
      <description>&lt;P&gt;I've moved your comment to an answer. Please accept your own answer here so that it will be flagged as having an accepted answer. - Thanks!&lt;/P&gt;</description>
      <pubDate>Fri, 08 Sep 2017 15:30:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Modular-Inputs-How-can-I-split-the-HTTP-JSON-response-into/m-p/320300#M59796</guid>
      <dc:creator>cpetterborg</dc:creator>
      <dc:date>2017-09-08T15:30:00Z</dc:date>
    </item>
  </channel>
</rss>

