Splunk Search

How to extract a JSON part from an incoming stream from journald to output only one value with /opt/splunk/etc/slave-apps/_cluster/local/transforms.conf

mlange2007
New Member

The JSON part to extract is MESSAGES. We created a REGEX which works in the search, but it should be also added permanently to this "transforms.conf" file.

Our solution, which didn't work, is:

[journald_clean_index_k8s]
REGEX=MESSAGE\":\"(?.*)\"
DEST_KEY = MetaData:Message
FORMAT= message:$1
0 Karma

DalJeanis
Legend

First, us there a particular reason you are wanting message to be a metadata field? I believe it can be as simple as this...

 [journald_clean_index_k8s]
 REGEX=^.*MESSAGE\":\"(?[^\"]*)\"
 FORMAT= Message::$1

...or even...

 [journald_clean_index_k8s]
 REGEX=^.*MESSAGE\":\"(?<Message>[^\"]*)\"

Updated to add a simpler version, and to use [^\"]* instead of .* to avoid backtracking.


Refer to this one for a little more instruction, including more steps if you want it indexed: https://answers.splunk.com/answers/171148/how-to-write-regex-to-extract-and-index-a-field-en.html

Second, do you want index time or search time extraction?

Here's some discussion about those considerations:

https://answers.splunk.com/answers/396276/should-i-use-an-index-time-field-extraction.html
https://answers.splunk.com/answers/234011/index-time-field-extraction-regexp-issue.html

0 Karma
Get Updates on the Splunk Community!

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer Certification at ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...

Share Your Ideas & Meet the Lantern team at .Conf! Plus All of This Month’s New ...

Splunk Lantern is Splunk’s customer success center that provides advice from Splunk experts on valuable data ...