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
Get Updates on the Splunk Community!

Enterprise Security Content Update (ESCU) | New Releases

In December, the Splunk Threat Research Team had 1 release of new security content via the Enterprise Security ...

Why am I not seeing the finding in Splunk Enterprise Security Analyst Queue?

(This is the first of a series of 2 blogs). Splunk Enterprise Security is a fantastic tool that offers robust ...

Index This | What are the 12 Days of Splunk-mas?

December 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...