<?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 to get a sourcetype of JSON mixed with text that uses the timestamp within the JSON object and correctly extracts kv and JSON kv pairs? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-a-sourcetype-of-JSON-mixed-with-text-that-uses-the/m-p/141515#M39218</link>
    <description>&lt;P&gt;I downvoted this post because dosnt answer the question&lt;/P&gt;</description>
    <pubDate>Tue, 01 Dec 2015 15:09:58 GMT</pubDate>
    <dc:creator>nmanolak</dc:creator>
    <dc:date>2015-12-01T15:09:58Z</dc:date>
    <item>
      <title>How to get a sourcetype of JSON mixed with text that uses the timestamp within the JSON object and correctly extracts kv and JSON kv pairs?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-a-sourcetype-of-JSON-mixed-with-text-that-uses-the/m-p/141511#M39214</link>
      <description>&lt;P&gt;Hi I'm trying to get JSON data from a message queue into splunk. This works very well but the imported events also contain some message header information&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Tue Dec 02 15:45:56 CET 2014 name="amqp_msg_received" event_id="null" msg_queue="dns-events2splunk-splunk" msg_exchange="dns-events2splunk" msg_body="{"timestamp":"2014-12-02T14:45:56.021Z","src":"192.168.16.56","src_port":"53","dest":"192.168.0.2","dest_port":7521,"dns_meta":{"status":"NOERROR","id":42347,"flags":["qr","rd","ra"],"queries":"1","answers":"1"},"dns_query":{"domain":"lopq.ch.","class":"IN","type":"A"},"dns_response":{"domain":"lopq.ch.","ttl":8477,"class":"IN","type":"A","IP":"10.14.183.106"}}"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;How can i now get a sourcetype that&lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;using the timestamp within the json object&lt;/LI&gt;
&lt;LI&gt;correctly extracts the kv pairs as well as the json kv pairs&lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;Alternatively only taking the msg_body and correctly extract the json object&lt;/P&gt;</description>
      <pubDate>Tue, 02 Dec 2014 15:04:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-a-sourcetype-of-JSON-mixed-with-text-that-uses-the/m-p/141511#M39214</guid>
      <dc:creator>mathiask</dc:creator>
      <dc:date>2014-12-02T15:04:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to get a sourcetype of JSON mixed with text that uses the timestamp within the JSON object and correctly extracts kv and JSON kv pairs?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-a-sourcetype-of-JSON-mixed-with-text-that-uses-the/m-p/141512#M39215</link>
      <description>&lt;P&gt;btw im using Splunk Enterprise and not Splunk Cloud, and there i cannot find the sourcetype json_predefined_timestamp&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 18:18:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-a-sourcetype-of-JSON-mixed-with-text-that-uses-the/m-p/141512#M39215</guid>
      <dc:creator>mathiask</dc:creator>
      <dc:date>2020-09-28T18:18:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to get a sourcetype of JSON mixed with text that uses the timestamp within the JSON object and correctly extracts kv and JSON kv pairs?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-a-sourcetype-of-JSON-mixed-with-text-that-uses-the/m-p/141513#M39216</link>
      <description>&lt;P&gt;I also use Websphere, and the jms connector...&lt;/P&gt;

&lt;P&gt;There are a lot of possible actions, but nothing that covers your needs at 100%...&lt;BR /&gt;
I don't use json, but xml, but problems and solutions are the same...&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;I'm happy about the header, because
we put a lot of good informations in
it, we can search at, because there
are automatically converted to fields
by splunk&lt;/LI&gt;
&lt;LI&gt;To handle the body, I've made a
field-extraction with a regex like&lt;BR /&gt;
"body=(?P.*). After that I can user spath :
spath input=xml ...&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;There two other options :&lt;BR /&gt;
 - make a custom message handler, for the jms connector, there you could put all your json data into key-value, to have splunk extract it automatically&lt;BR /&gt;
 - or with a custom message handler or changes in the jms connector, but everything in json, and use kvmode=json (I'm not sure it works, for xml you can make it... you have to check).&lt;/P&gt;

&lt;P&gt;.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Dec 2014 17:43:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-a-sourcetype-of-JSON-mixed-with-text-that-uses-the/m-p/141513#M39216</guid>
      <dc:creator>sbsbb</dc:creator>
      <dc:date>2014-12-02T17:43:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to get a sourcetype of JSON mixed with text that uses the timestamp within the JSON object and correctly extracts kv and JSON kv pairs?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-a-sourcetype-of-JSON-mixed-with-text-that-uses-the/m-p/141514#M39217</link>
      <description>&lt;P&gt;I you don't mind loosing the data that doesn't fall within the msg_body, then you can use SEDCMD to eliminate all the the JSON string, something like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;SEDCMD-stripnonjson1 = s/^.*msg_body="//
SEDCMD-stripnonjson2 = s/}"$/}/
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This will leave only the JSON string for it index, which can then be used to get the timestamp and be parsed into the kv pairs:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;KV_MODE = json
TIME_PREFIX = "timestamp":"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;These would go in the props.conf file for the data coming in to the indexers. You may also want to define the linebreak to do it on each JSON string at the beginning of a line if they cross lines:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;BREAK_ONLY_BEFORE = ^{
NO_BINARY_CHECK = 1
SHOULD_LINEMERGE = true
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I have tried this on your data, and it appears to have worked.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Dec 2014 20:44:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-a-sourcetype-of-JSON-mixed-with-text-that-uses-the/m-p/141514#M39217</guid>
      <dc:creator>cpetterborg</dc:creator>
      <dc:date>2014-12-02T20:44:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to get a sourcetype of JSON mixed with text that uses the timestamp within the JSON object and correctly extracts kv and JSON kv pairs?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-a-sourcetype-of-JSON-mixed-with-text-that-uses-the/m-p/141515#M39218</link>
      <description>&lt;P&gt;I downvoted this post because dosnt answer the question&lt;/P&gt;</description>
      <pubDate>Tue, 01 Dec 2015 15:09:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-a-sourcetype-of-JSON-mixed-with-text-that-uses-the/m-p/141515#M39218</guid>
      <dc:creator>nmanolak</dc:creator>
      <dc:date>2015-12-01T15:09:58Z</dc:date>
    </item>
  </channel>
</rss>

