Splunk Search

How to remove json key value pairs from events log data

ayushram
Observer

Splunk search events returns json format log data. I want to remove a particular key:value pair since the value of this key is huge (in terms of length) and unnecessary. How can I do so.

sample log data:

{
"abcd1": "asd",
"abcd2": [],
"abcd3": true,
"toBeRemoved": [{
"abcd8": 234,
"abcd9": [{
"abcd10": "asd234"
}],
"abcd11": "asdasd"
}],
"abcd4": 324.234,
"abcd5": "dfsad dfsdf",
"abcd6": 0,
"abcd7": "asfsdf"
}

The key:value pair to be removed has been marked in bold.

! NOTE THIS IS FORMATTED DATA, FIELDS CAN HAVE STRINGS, NUMBERS, BOTH, LISTS, ETC !

 

 

Labels (3)
0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Try something like this - this assumes "toBeRemove" is not the first element i.e. is is preceded by a comma (which needs to be removed).

| rex mode=sed "s/(?ms),\s*\"toBeRemoved\":\s*\[([^\[\]]+|\[[^\]]*\])*\]//g"
0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @ayushram,

if you want to remove the highlighted data from the logs before indexing you have to add to your props.conf:

[your_sourcetype]
SEDCMD = s/(?ms)\"toBeRemoved\":.*\}\],//g

remember that this props.conf must be added on your Indexers or (if present) on your Heavy Forwarders.

Ciao.

Giuseppe

0 Karma

ayushram
Observer

I do not have access to pros.conf

Is there any way to do this from search itself?
I want my final data in " | table ", but it's not loading wherever this highlighted field appears (since it has too many characters)

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @ayushram,

you can avoid to display a part of your logs in your searches, but accessing the raw log it's all visible:

 

| rex mode=sed "s/(?ms)\"toBeRemoved\":.*\}\],//g"

 

Ciao.

Giuseppe

 

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Community Content Calendar, September edition

Welcome to another insightful post from our Community Content Calendar! We're thrilled to continue bringing ...

Splunkbase Unveils New App Listing Management Public Preview

Splunkbase Unveils New App Listing Management Public PreviewWe're thrilled to announce the public preview of ...

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Are you leveraging automation to its fullest potential in your threat detection strategy?Our upcoming Security ...