Splunk Search

How to extract and create a new field from my sample event?

abovebeyond
Communicator

Hi,

Need some help with Field extraction in the following event:

[{\"email\":\"admin@yourstore.com\",\"smtp-id\":\"\",\"timestamp\":1453954498,\"sv_event_id\":\"SDFJGH543534\",\"sv_message_id\":\"filter1.15rasrsar7\",\"reason\":\"test\",\"event\":\"Delivered\"}]

I want the create a new field - EventType for the value of "event:"

While trying to use the Field Extractor, I tried to mark up:

Delivered
"Delivered\"

and etc... but it's not working right.

Thanks !

Tags (2)
0 Karma
1 Solution

Lowell
Super Champion

If you're event is being parsed a JSON, which normally happens automatically, then you can simply use a fieldalias instead of doing a field extraction.

On second glance, is your JSON data escaped? Or is that just a side effect of posting it here? Pretty sure Splunk doesn't handle escaped JSON automatically. So you could either unescape the data on ingestion, possibly using SEDCMD in props.conf, or if that's not an option, try a field extraction with a regex like this:

"event\\":\\"(?<EventType>[^"\\]+)\\"

View solution in original post

0 Karma

javiergn
Super Champion

That event seems to be in Json format and therefore spath is your friend:

| stats count
| eval myjson = "[{\"email\":\"admin@yourstore.com\",\"smtp-id\":\"\",\"timestamp\":1453954498,\"sv_event_id\":\"SDFJGH543534\",\"sv_message_id\":\"filter1.15rasrsar7\",\"reason\":\"test\",\"event\":\"Delivered\"}]"
| spath input=myjson
| rename "{}.event" as EventType
| table EventType

You can ignore the extra escaping for the double quotes and the first two lines that I needed to test this locally on my machine.

Hope that helps.

0 Karma

Lowell
Super Champion

If you're event is being parsed a JSON, which normally happens automatically, then you can simply use a fieldalias instead of doing a field extraction.

On second glance, is your JSON data escaped? Or is that just a side effect of posting it here? Pretty sure Splunk doesn't handle escaped JSON automatically. So you could either unescape the data on ingestion, possibly using SEDCMD in props.conf, or if that's not an option, try a field extraction with a regex like this:

"event\\":\\"(?<EventType>[^"\\]+)\\"
0 Karma
Get Updates on the Splunk Community!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...