<?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: How do I go about the parsing of Splunk modular input with JSON data? in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/How-do-I-go-about-the-parsing-of-Splunk-modular-input-with-JSON/m-p/431846#M75578</link>
    <description>&lt;P&gt;It looks like you're using simple mode for modular input rather than xml:&lt;/P&gt;

&lt;P&gt;&lt;A href="http://docs.splunk.com/Documentation/Splunk/7.2.0/AdvancedDev/ModInputsStream"&gt;http://docs.splunk.com/Documentation/Splunk/7.2.0/AdvancedDev/ModInputsStream&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;This is setup in your introspection in the  tag: &lt;/P&gt;

&lt;P&gt;&lt;A href="http://docs.splunk.com/Documentation/Splunk/7.2.0/AdvancedDev/ModInputsScripts"&gt;http://docs.splunk.com/Documentation/Splunk/7.2.0/AdvancedDev/ModInputsScripts&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 22 Oct 2018 16:16:43 GMT</pubDate>
    <dc:creator>coccyx</dc:creator>
    <dc:date>2018-10-22T16:16:43Z</dc:date>
    <item>
      <title>How do I go about the parsing of Splunk modular input with JSON data?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-do-I-go-about-the-parsing-of-Splunk-modular-input-with-JSON/m-p/431842#M75574</link>
      <description>&lt;P&gt;Hi Splunk community,&lt;/P&gt;

&lt;P&gt;I am facing some issue in using the Splunk modular input. &lt;/P&gt;

&lt;P&gt;The modular input is built around events and event writers that are constructing an xml event. But, when i search the events in Splunk, i would like to see the included JSON event; see attached event.&lt;BR /&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/5943i90F9300C7B6F9D2F/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;Below you see a code snippet of the code that generates the event.&lt;BR /&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/5944i83A261D450307504/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;for refence to splunk modular input&lt;BR /&gt;
&lt;A href="https://github.com/splunk/splunk-sdk-python/tree/master/splunklib"&gt;https://github.com/splunk/splunk-sdk-python/tree/master/splunklib&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Is there anybody who knows how this is suppose to work ?&lt;/P&gt;</description>
      <pubDate>Mon, 22 Oct 2018 08:49:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-do-I-go-about-the-parsing-of-Splunk-modular-input-with-JSON/m-p/431842#M75574</guid>
      <dc:creator>AndersNierhoff</dc:creator>
      <dc:date>2018-10-22T08:49:23Z</dc:date>
    </item>
    <item>
      <title>Re: How do I go about the parsing of Splunk modular input with JSON data?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-do-I-go-about-the-parsing-of-Splunk-modular-input-with-JSON/m-p/431843#M75575</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;
A little bit more details, regarding conf files:&lt;BR /&gt;
inputs.conf&lt;BR /&gt;
[myModularInput://firsttest]&lt;BR /&gt;
sourcetype = myModularInput:json&lt;/P&gt;

&lt;P&gt;props.conf&lt;BR /&gt;
[myModularInput:json]&lt;BR /&gt;
TRUNCATE = 0&lt;BR /&gt;
INDEXED_EXTRACTIONS = json&lt;BR /&gt;
KV_MODE=none&lt;/P&gt;

&lt;P&gt;no transform&lt;/P&gt;

&lt;P&gt;this current setup fails as the data can not be parsed as json ( it is a xml document).&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 21:40:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-do-I-go-about-the-parsing-of-Splunk-modular-input-with-JSON/m-p/431843#M75575</guid>
      <dc:creator>AndersNierhoff</dc:creator>
      <dc:date>2020-09-29T21:40:06Z</dc:date>
    </item>
    <item>
      <title>Re: How do I go about the parsing of Splunk modular input with JSON data?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-do-I-go-about-the-parsing-of-Splunk-modular-input-with-JSON/m-p/431844#M75576</link>
      <description>&lt;P&gt;To clarify my question, how do i get rid of the XML part of the event. It is fine that the values in the xml event is used to modify the time, index, sourcetype, source .... but in Splunk when i do a search i want the data available as json.&lt;/P&gt;

&lt;P&gt;script output:&lt;/P&gt;

&lt;P&gt;2018-10-22T14:39:24.915000+0200&lt;BR /&gt;
{'time': '2018-10-22T14:39:24.915000+0200', 'test': 'Issue'}&lt;/P&gt;

&lt;P&gt;index event:&lt;/P&gt;

&lt;P&gt;2018-10-22T14:39:24.915000+0200&lt;BR /&gt;
{'time': '2018-10-22T14:39:24.915000+0200', 'test': 'Issue'}&lt;/P&gt;

&lt;P&gt;expected event:&lt;BR /&gt;
{'time': '2018-10-22T14:39:24.915000+0200', 'test': 'Issue'}&lt;/P&gt;</description>
      <pubDate>Mon, 22 Oct 2018 12:42:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-do-I-go-about-the-parsing-of-Splunk-modular-input-with-JSON/m-p/431844#M75576</guid>
      <dc:creator>AndersNierhoff</dc:creator>
      <dc:date>2018-10-22T12:42:52Z</dc:date>
    </item>
    <item>
      <title>Re: How do I go about the parsing of Splunk modular input with JSON data?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-do-I-go-about-the-parsing-of-Splunk-modular-input-with-JSON/m-p/431845#M75577</link>
      <description>&lt;P&gt;Hi, It looks like the text viewer is interpreting the xml data.&lt;/P&gt;

&lt;P&gt;To clarify my question, how do i get rid of the XML part of the event. It is fine that the values in the xml event is used to modify the time, index, sourcetype, source .... but in Splunk when i do a search i want the data available as json.&lt;/P&gt;

&lt;P&gt;script output:&lt;BR /&gt;
stream&lt;BR /&gt;
event stanza="myModularInput://issuedebug" unbroken="1"&lt;BR /&gt;
time&amp;gt;2018-10-22T14:55:12.821000+0200OrderedDict([('time', '2018-10-22T14:55:12.821000+0200'), ('test', 'Issue')])2018-10-22T14:55:12.821000+0200OrderedDict([('time', '2018-10-22T14:55:12.821000+0200'), ('test', 'Issue')])&lt;/P&gt;</description>
      <pubDate>Mon, 22 Oct 2018 13:16:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-do-I-go-about-the-parsing-of-Splunk-modular-input-with-JSON/m-p/431845#M75577</guid>
      <dc:creator>AndersNierhoff</dc:creator>
      <dc:date>2018-10-22T13:16:22Z</dc:date>
    </item>
    <item>
      <title>Re: How do I go about the parsing of Splunk modular input with JSON data?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-do-I-go-about-the-parsing-of-Splunk-modular-input-with-JSON/m-p/431846#M75578</link>
      <description>&lt;P&gt;It looks like you're using simple mode for modular input rather than xml:&lt;/P&gt;

&lt;P&gt;&lt;A href="http://docs.splunk.com/Documentation/Splunk/7.2.0/AdvancedDev/ModInputsStream"&gt;http://docs.splunk.com/Documentation/Splunk/7.2.0/AdvancedDev/ModInputsStream&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;This is setup in your introspection in the  tag: &lt;/P&gt;

&lt;P&gt;&lt;A href="http://docs.splunk.com/Documentation/Splunk/7.2.0/AdvancedDev/ModInputsScripts"&gt;http://docs.splunk.com/Documentation/Splunk/7.2.0/AdvancedDev/ModInputsScripts&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Oct 2018 16:16:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-do-I-go-about-the-parsing-of-Splunk-modular-input-with-JSON/m-p/431846#M75578</guid>
      <dc:creator>coccyx</dc:creator>
      <dc:date>2018-10-22T16:16:43Z</dc:date>
    </item>
    <item>
      <title>Re: How do I go about the parsing of Splunk modular input with JSON data?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-do-I-go-about-the-parsing-of-Splunk-modular-input-with-JSON/m-p/431847#M75579</link>
      <description>&lt;P&gt;Hi, And thanks for you reply. This was one of the parameters that i have been testing out, but to no luck.&lt;BR /&gt;
I tried to make my test case more simple.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;import sys
import os
import six

import json
import time
import datetime

#import splunklib.client as client
# import splunklib
from splunklib.modularinput import Script, Scheme, Argument, EventWriter, Event
FUNCTION_NAME = "testModularInput"


class testModularInput(Script):
    """ Class for importing jira data
    """
    def get_scheme(self):
        scheme = Scheme(self.__class__.__name__)
        scheme.description = self.__class__.__name__
        scheme.use_external_validation = False
        scheme.use_single_instance = True
        scheme.streaming_mode = Scheme.streaming_mode_xml
        username_arg = Argument(
            name="username",
            title="User name",
            data_type=Argument.data_type_string,
            required_on_create=True,
            required_on_edit=True
        )
        scheme.add_argument(username_arg)
        return scheme

    def validate_input(self, validation_definition):
        return None

    def stream_events(self, inputs, ew):
        for input_name, input_item in inputs.inputs.items():
            event = Event()
            event.stanza = input_name
            event.time = datetime.datetime.now().isoformat()+"+0200"
            event.data = "test input of date"
            event.index = "main"
            ew.write_event(event)
        return None

if __name__ == "__main__":
    instance = testModularInput()
    if len(sys.argv) &amp;gt; 1:
        if sys.argv[1] == "--scheme":
            instance.get_scheme()
        elif sys.argv[1] == "--validate-arguments":
            instance.validate_input()
        else:
            instance.usage()
            pass
    else:
        instance.run(sys.argv)
    sys.exit(0)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;result in Splunk ( i have added dash to ensure that the xml is not hidden.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;stream&amp;gt;
  &amp;lt;event stanza="testModularInput://testDebug" unbroken="1"&amp;gt;
    &amp;lt;time&amp;gt;2018-10-23T08:30:03.869000+0200&amp;lt;/time&amp;gt;
    &amp;lt;index&amp;gt;main&amp;lt;/index&amp;gt;
    &amp;lt;data&amp;gt;test input of date&amp;lt;/data&amp;gt;
    &amp;lt;done /&amp;gt;
  &amp;lt;/event&amp;gt;
&amp;lt;/stream&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 23 Oct 2018 05:01:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-do-I-go-about-the-parsing-of-Splunk-modular-input-with-JSON/m-p/431847#M75579</guid>
      <dc:creator>AndersNierhoff</dc:creator>
      <dc:date>2018-10-23T05:01:18Z</dc:date>
    </item>
    <item>
      <title>Re: How do I go about the parsing of Splunk modular input with JSON data?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-do-I-go-about-the-parsing-of-Splunk-modular-input-with-JSON/m-p/431848#M75580</link>
      <description>&lt;P&gt;You can try passing all the details while initializing the object for Event class.&lt;BR /&gt;
Ex. event = Event(data="{}", stanza="", time="%.3f" % time.time())&lt;/P&gt;

&lt;P&gt;And than use ew.write_event(event)&lt;/P&gt;

&lt;P&gt;Note: You'll require to import time module. (import time)&lt;/P&gt;</description>
      <pubDate>Wed, 06 Feb 2019 12:08:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-do-I-go-about-the-parsing-of-Splunk-modular-input-with-JSON/m-p/431848#M75580</guid>
      <dc:creator>rshah_splunk</dc:creator>
      <dc:date>2019-02-06T12:08:24Z</dc:date>
    </item>
    <item>
      <title>Re: How do I go about the parsing of Splunk modular input with JSON data?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-do-I-go-about-the-parsing-of-Splunk-modular-input-with-JSON/m-p/431849#M75581</link>
      <description>&lt;P&gt;Just for info, I newer got this to work. I found a work around of using print(evemt.data) instead. &lt;/P&gt;</description>
      <pubDate>Tue, 05 Mar 2019 09:13:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-do-I-go-about-the-parsing-of-Splunk-modular-input-with-JSON/m-p/431849#M75581</guid>
      <dc:creator>AndersNierhoff</dc:creator>
      <dc:date>2019-03-05T09:13:17Z</dc:date>
    </item>
  </channel>
</rss>

