Getting Data In

Setting event time and host metadata from key/value pairs

brent_weaver
Builder

I have this nice JSON event that has all the information I need in it, most namely timestamp and hostname of transaction. How do I rewrite the event to update metadata host and time? This cannot be that hard, the docs show REGEX but I would be able to just use fields.?!?!?!

Any help is much appreciated!

0 Karma
1 Solution

jkat54
SplunkTrust
SplunkTrust

Do this at index time (aka on forwarders & indexers)

Props.conf:

 [yourSourcetype]
TRANSFORMS-datetime=datetimeTransform
TRANSFORMS-hostname=hostnameTransform

Transforms.conf:

[datetimeTransform]
SOURCE_KEY = _raw
REGEX = some regex with a capture group that captures the datetime stamp
DEST_KEY = _time

[hostnameTransform]
SOURCE_KEY = _raw
REGEX = some regex with a capture group that captures host
DEST_KEY = MetaData:Host

See transforms.conf for a list of DEST_KEYs

View solution in original post

0 Karma

jkat54
SplunkTrust
SplunkTrust

Do this at index time (aka on forwarders & indexers)

Props.conf:

 [yourSourcetype]
TRANSFORMS-datetime=datetimeTransform
TRANSFORMS-hostname=hostnameTransform

Transforms.conf:

[datetimeTransform]
SOURCE_KEY = _raw
REGEX = some regex with a capture group that captures the datetime stamp
DEST_KEY = _time

[hostnameTransform]
SOURCE_KEY = _raw
REGEX = some regex with a capture group that captures host
DEST_KEY = MetaData:Host

See transforms.conf for a list of DEST_KEYs

0 Karma

brent_weaver
Builder

Thanks for the response, do I have to use a REGEX to get the value, can't I just use the key from the key value pair?

0 Karma

jkat54
SplunkTrust
SplunkTrust

I suppose you could and if you absolutely have to have regex= to work... Just do (.*) as your regex.

0 Karma

brent_weaver
Builder

Thank for the response. I guesss the question is, do I absolutely need to have REGEX? What I am contending with is a format where I have a time stand followed buy host IP address, the a fully intact JSON string. So In my JSON string I have the true time of the event as a field called timestamp.

My props is as follows:

[bv]
KV_MODE = json
INDEXTED_EXTRACTIONS = json
TRANSFORMS-extract = json_extraction
FIELDALIAS-conn_id = protocol.session_id AS conn_id

transforms.conf:

[json_extraction]
SOURCE_KEY = _raw
DEST_KEY = _raw
REGEX = ^([^{]+)({.+})$
FORMAT = $2

As you see I carve out the first two elements and only keep the JSON string. So this now leaves me with all the metadata I would need to. So how do I use these kv pairs to set this?

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...

Modernize your Splunk Apps – Introducing Python 3.13 in Splunk

We are excited to announce that the upcoming releases of Splunk Enterprise 10.2.x and Splunk Cloud Platform ...

Step into “Hunt the Insider: An Splunk ES Premier Mystery” to catch a cybercriminal ...

After a whole week of being on call, you fell asleep on your keyboard, and you hit a sequence of buttons that ...