<?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 A better way to extract JSON? in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/A-better-way-to-extract-JSON/m-p/667310#M111920</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I want to get Rspamd logs into Splunk with every info available. The best I could do with Rspamd config yields to this:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;2023-11-03 13:02:24 #56502(rspamd_proxy) &amp;lt;7fcfc8&amp;gt;; lua; [string "return function (t...:4: METATEST {"qid":"8BC8C2F741","user":"unknown","ip":"188.68.A.B","header_from":["foo bar via somelist &amp;lt;somelist@baz.org&amp;gt;"],"header_to":["list &amp;lt;somelist@baz.org&amp;gt;"],"header_subject":["proper subject"],"header_date":["Fri, 3 Nov 2023 08:00:43 -0400 (EDT)"],"scan_time":2457,"rcpt":["me@myself.net"],"size":6412,"score":-5.217652,"subject":"proper subject","action":"no action","message_id":"4SMK7v2HQTzJrP1@spike.bar.org","fuzzy":[],"rspamd_server":"rack.myself.net","from":"somelist-bounces@baz.org","symbols":[{"score":-0.500000,"group":"composite","groups":["composite"],"name":"RCVD_DKIM_ARC_DNSWL_MED"},{"score":0,"group":"headers","groups":["headers"],"name":"FROM_HAS_DN"},{"score":0,"group":"headers","options":["somelist@baz.org","somelist-bounces@baz.org"],"groups":["headers"],"name":"FROM_NEQ_ENVFROM"},{"score":-0.010000,"group":"headers","groups":["headers"],"name":"HAS_LIST_UNSUB"},{"score":0,"group":"headers","options":["somelist@baz.org"],"groups":["headers"],"name":"PREVIOUSLY_DELIVERED"},{"score":-1,"group":"abusix","options":["188.68.A.B:from"],"groups":["abusix","rbl"],"name":"RWL_AMI_LASTHOP"},{"score":-0.100000,"group":"mime_types","options":["text/plain"],"groups":["mime_types"],"name":"MIME_GOOD"},{"score":-0.200000,"group":"headers","options":["mailman"],"groups":["headers"],"name":"MAILLIST"},{"score":1,"group":"headers","groups":["headers"],"name":"SUBJECT_ENDS_QUESTION"},{"score":-0.200000,"group":"policies","options":["+ip4:188.68.A.B"],"groups":["policies","spf"],"name":"R_SPF_ALLOW"},{"score":-1,"group":"policies","options":["list.sys4.de:s=2023032101:i=1"],"groups":["policies","arc"],"name":"ARC_ALLOW"},{"score":0,"group":"ungrouped","options":["asn:19xxxx, ipnet:188.68.A.B/20, country:XY"],"groups":[],"name":"ASN"},{"score":0.100000,"group":"headers","groups":["headers"],"name":"RCVD_NO_TLS_LAST"},{"score":0,"group":"headers","groups":["headers","composite"],"name":"FORGED_RECIPIENTS_MAILLIST"},{"score":0,"group":"policies","options":["baz.org:+","bar.org:-"],"groups":["policies","dkim"],"name":"DKIM_TRACE"},{"score":0,"group":"headers","groups":["headers"],"name":"REPLYTO_DOM_NEQ_FROM_DOM"},{"score":0,"group":"policies","options":["bar.org:s=dktest"],"groups":["policies","dkim"],"name":"R_DKIM_REJECT"},{"score":-2.407652,"group":"statistics","options":["97.28%"],"groups":["statistics"],"name":"BAYES_HAM"},{"score":0,"group":"headers","groups":["headers"],"name":"TO_DN_ALL"},{"score":0,"group":"composite","groups":["composite"],"name":"DKIM_MIXED"},{"score":-0.200000,"group":"policies","options":["baz.org:s=20230217-rsa"],"groups":["policies","dkim"],"name":"R_DKIM_ALLOW"},{"score":0,"group":"headers","options":["3"],"groups":["headers"],"name":"RCVD_COUNT_THREE"},{"score":-0.600000,"group":"rbl","options":["188.68.A.B:from","188.68.A.B:received","168.100.A.B:received"],"groups":["rbl","dnswl"],"name":"RCVD_IN_DNSWL_MED"},{"score":-0.100000,"group":"rbl","options":["188.68.A.B:from"],"groups":["rbl","mailspike"],"name":"RWL_MAILSPIKE_GOOD"},{"score":0,"group":"policies","options":["baz.org"],"groups":["policies","dmarc"],"name":"DMARC_NA"},{"score":0,"group":"headers","options":["1"],"groups":["headers"],"name":"RCPT_COUNT_ONE"},{"score":0,"group":"mime_types","options":["0:+"],"groups":["mime_types"],"name":"MIME_TRACE"},{"score":0,"group":"headers","groups":["headers","composite"],"name":"FORGED_SENDER_MAILLIST"},{"score":0,"group":"headers","groups":["headers"],"name":"TO_EQ_FROM"},{"score":0,"group":"headers","options":["foo@bar.org"],"groups":["headers"],"name":"HAS_REPLYTO"}]}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Currently I’m extracting JSON with a props.conf &amp;amp; a transforms.conf:&lt;/P&gt;&lt;P&gt;props.conf&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;[rspamd]
KV_MODE = json
TRANSFORMS-json_extract_rspamd = json_extract_rspamd&lt;/LI-CODE&gt;&lt;P&gt;transforms.conf&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;[json_extract_rspamd]
SOURCE_KEY = _raw
DEST_KEY = _raw
LOOKAHEAD = 10000
#REGEX = ^([^{]+)({.+})$
REGEX = ^(\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d) (#\d+)\(([^)]+)\) ([^;]+); lua[^{]+{(.+})$
FORMAT = {"date":"$1","ida":"$2","process":"$3","idb":"$4",$5
CLONE_SOURCETYPE = _json&lt;/LI-CODE&gt;&lt;P&gt;I end up with this in splunk:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-left" image-alt="Screenshot 2023-11-03 at 13.47.57.png" style="width: 766px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/27932i21A90CD43E31D131/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2023-11-03 at 13.47.57.png" alt="Screenshot 2023-11-03 at 13.47.57.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;From here, I have 2 problems.&lt;/P&gt;&lt;P&gt;1st problem: contrary to native JSON (from my Amavis logs for example), Splunk does not extract nor process basic stats about fields unless I’m explicitly extract them… That’s quite a pain.&lt;BR /&gt;Is there a way / config setting to instruct Splunk to automagically extract every fields?&lt;/P&gt;&lt;P&gt;2nd problem: this JSON is crap. Every object in "symbols[]" looks like this:&lt;span class="lia-inline-image-display-wrapper lia-image-align-left" image-alt="Screenshot 2023-11-03.png" style="width: 257px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/27936iE13742E6EF2135E5/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2023-11-03.png" alt="Screenshot 2023-11-03.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;It’s almost unuseable as it prevent me from linking the name of the symbol to its score and to its options.&lt;/P&gt;&lt;P&gt;Is there a parsing option / function I could use to reliably transform this into something I can work with?&lt;/P&gt;&lt;P&gt;A good result could be&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;turning 
{
   group: abusix
   groups: [
     abusix
     rbl 
   ]
   name: RWL_AMI_LASTHOP
   options: [
    A.B.C.D:from
   ]
   score: -1 
} 

into 

RWL_AMI_LASTHOP: [
   group: abusix
   groups: [
     abusix
     rbl 
   ]
   name: RWL_AMI_LASTHOP
   options: [
    A.B.C.D:from
   ]
   score: -1 
]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I’m open to suggestions, I’ve been working for years with the great JSON logs of Amavis (perfect parsing and usability). This problem is new to me…&lt;/P&gt;</description>
    <pubDate>Fri, 03 Nov 2023 13:33:08 GMT</pubDate>
    <dc:creator>patpro</dc:creator>
    <dc:date>2023-11-03T13:33:08Z</dc:date>
    <item>
      <title>A better way to extract JSON?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/A-better-way-to-extract-JSON/m-p/667310#M111920</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I want to get Rspamd logs into Splunk with every info available. The best I could do with Rspamd config yields to this:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;2023-11-03 13:02:24 #56502(rspamd_proxy) &amp;lt;7fcfc8&amp;gt;; lua; [string "return function (t...:4: METATEST {"qid":"8BC8C2F741","user":"unknown","ip":"188.68.A.B","header_from":["foo bar via somelist &amp;lt;somelist@baz.org&amp;gt;"],"header_to":["list &amp;lt;somelist@baz.org&amp;gt;"],"header_subject":["proper subject"],"header_date":["Fri, 3 Nov 2023 08:00:43 -0400 (EDT)"],"scan_time":2457,"rcpt":["me@myself.net"],"size":6412,"score":-5.217652,"subject":"proper subject","action":"no action","message_id":"4SMK7v2HQTzJrP1@spike.bar.org","fuzzy":[],"rspamd_server":"rack.myself.net","from":"somelist-bounces@baz.org","symbols":[{"score":-0.500000,"group":"composite","groups":["composite"],"name":"RCVD_DKIM_ARC_DNSWL_MED"},{"score":0,"group":"headers","groups":["headers"],"name":"FROM_HAS_DN"},{"score":0,"group":"headers","options":["somelist@baz.org","somelist-bounces@baz.org"],"groups":["headers"],"name":"FROM_NEQ_ENVFROM"},{"score":-0.010000,"group":"headers","groups":["headers"],"name":"HAS_LIST_UNSUB"},{"score":0,"group":"headers","options":["somelist@baz.org"],"groups":["headers"],"name":"PREVIOUSLY_DELIVERED"},{"score":-1,"group":"abusix","options":["188.68.A.B:from"],"groups":["abusix","rbl"],"name":"RWL_AMI_LASTHOP"},{"score":-0.100000,"group":"mime_types","options":["text/plain"],"groups":["mime_types"],"name":"MIME_GOOD"},{"score":-0.200000,"group":"headers","options":["mailman"],"groups":["headers"],"name":"MAILLIST"},{"score":1,"group":"headers","groups":["headers"],"name":"SUBJECT_ENDS_QUESTION"},{"score":-0.200000,"group":"policies","options":["+ip4:188.68.A.B"],"groups":["policies","spf"],"name":"R_SPF_ALLOW"},{"score":-1,"group":"policies","options":["list.sys4.de:s=2023032101:i=1"],"groups":["policies","arc"],"name":"ARC_ALLOW"},{"score":0,"group":"ungrouped","options":["asn:19xxxx, ipnet:188.68.A.B/20, country:XY"],"groups":[],"name":"ASN"},{"score":0.100000,"group":"headers","groups":["headers"],"name":"RCVD_NO_TLS_LAST"},{"score":0,"group":"headers","groups":["headers","composite"],"name":"FORGED_RECIPIENTS_MAILLIST"},{"score":0,"group":"policies","options":["baz.org:+","bar.org:-"],"groups":["policies","dkim"],"name":"DKIM_TRACE"},{"score":0,"group":"headers","groups":["headers"],"name":"REPLYTO_DOM_NEQ_FROM_DOM"},{"score":0,"group":"policies","options":["bar.org:s=dktest"],"groups":["policies","dkim"],"name":"R_DKIM_REJECT"},{"score":-2.407652,"group":"statistics","options":["97.28%"],"groups":["statistics"],"name":"BAYES_HAM"},{"score":0,"group":"headers","groups":["headers"],"name":"TO_DN_ALL"},{"score":0,"group":"composite","groups":["composite"],"name":"DKIM_MIXED"},{"score":-0.200000,"group":"policies","options":["baz.org:s=20230217-rsa"],"groups":["policies","dkim"],"name":"R_DKIM_ALLOW"},{"score":0,"group":"headers","options":["3"],"groups":["headers"],"name":"RCVD_COUNT_THREE"},{"score":-0.600000,"group":"rbl","options":["188.68.A.B:from","188.68.A.B:received","168.100.A.B:received"],"groups":["rbl","dnswl"],"name":"RCVD_IN_DNSWL_MED"},{"score":-0.100000,"group":"rbl","options":["188.68.A.B:from"],"groups":["rbl","mailspike"],"name":"RWL_MAILSPIKE_GOOD"},{"score":0,"group":"policies","options":["baz.org"],"groups":["policies","dmarc"],"name":"DMARC_NA"},{"score":0,"group":"headers","options":["1"],"groups":["headers"],"name":"RCPT_COUNT_ONE"},{"score":0,"group":"mime_types","options":["0:+"],"groups":["mime_types"],"name":"MIME_TRACE"},{"score":0,"group":"headers","groups":["headers","composite"],"name":"FORGED_SENDER_MAILLIST"},{"score":0,"group":"headers","groups":["headers"],"name":"TO_EQ_FROM"},{"score":0,"group":"headers","options":["foo@bar.org"],"groups":["headers"],"name":"HAS_REPLYTO"}]}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Currently I’m extracting JSON with a props.conf &amp;amp; a transforms.conf:&lt;/P&gt;&lt;P&gt;props.conf&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;[rspamd]
KV_MODE = json
TRANSFORMS-json_extract_rspamd = json_extract_rspamd&lt;/LI-CODE&gt;&lt;P&gt;transforms.conf&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;[json_extract_rspamd]
SOURCE_KEY = _raw
DEST_KEY = _raw
LOOKAHEAD = 10000
#REGEX = ^([^{]+)({.+})$
REGEX = ^(\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d) (#\d+)\(([^)]+)\) ([^;]+); lua[^{]+{(.+})$
FORMAT = {"date":"$1","ida":"$2","process":"$3","idb":"$4",$5
CLONE_SOURCETYPE = _json&lt;/LI-CODE&gt;&lt;P&gt;I end up with this in splunk:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-left" image-alt="Screenshot 2023-11-03 at 13.47.57.png" style="width: 766px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/27932i21A90CD43E31D131/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2023-11-03 at 13.47.57.png" alt="Screenshot 2023-11-03 at 13.47.57.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;From here, I have 2 problems.&lt;/P&gt;&lt;P&gt;1st problem: contrary to native JSON (from my Amavis logs for example), Splunk does not extract nor process basic stats about fields unless I’m explicitly extract them… That’s quite a pain.&lt;BR /&gt;Is there a way / config setting to instruct Splunk to automagically extract every fields?&lt;/P&gt;&lt;P&gt;2nd problem: this JSON is crap. Every object in "symbols[]" looks like this:&lt;span class="lia-inline-image-display-wrapper lia-image-align-left" image-alt="Screenshot 2023-11-03.png" style="width: 257px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/27936iE13742E6EF2135E5/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2023-11-03.png" alt="Screenshot 2023-11-03.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;It’s almost unuseable as it prevent me from linking the name of the symbol to its score and to its options.&lt;/P&gt;&lt;P&gt;Is there a parsing option / function I could use to reliably transform this into something I can work with?&lt;/P&gt;&lt;P&gt;A good result could be&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;turning 
{
   group: abusix
   groups: [
     abusix
     rbl 
   ]
   name: RWL_AMI_LASTHOP
   options: [
    A.B.C.D:from
   ]
   score: -1 
} 

into 

RWL_AMI_LASTHOP: [
   group: abusix
   groups: [
     abusix
     rbl 
   ]
   name: RWL_AMI_LASTHOP
   options: [
    A.B.C.D:from
   ]
   score: -1 
]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I’m open to suggestions, I’ve been working for years with the great JSON logs of Amavis (perfect parsing and usability). This problem is new to me…&lt;/P&gt;</description>
      <pubDate>Fri, 03 Nov 2023 13:33:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/A-better-way-to-extract-JSON/m-p/667310#M111920</guid>
      <dc:creator>patpro</dc:creator>
      <dc:date>2023-11-03T13:33:08Z</dc:date>
    </item>
  </channel>
</rss>

