All Apps and Add-ons

how can I get the value of a user embedded field named "index"?

juniormint
Communicator

I have log events that contain an user embedded field named "index". Out of the box Splunk seems to effectively ignore user's index when auto extracting field.

My goal is to find a good way to get the value for user's index field. I'm not really sure of the right way to deal with this situation, so please feel free to suggest anything (I'm already working on getting rid of the poorly named field).

My initial thought was to use rex, but I'm having a bit of a time getting the right regex. Suggestions for a correct rex expression?

rex field=_raw ".*index=\"(<app>.*)\""

_raw is something like:

data="xxxx",index="allgoodman",session="12345"

Thanks for any help.
-J

0 Karma
1 Solution

yannK
Splunk Employee
Splunk Employee

You have the right approach,
the splunk index will overwrite your automatic field extraction.

if you data is like data="xxxx",index="allgoodman",session="12345"

you can define a new field and use a rex.

<mysearch> | rex "index=\"<?index_app>\w+\"" | table index index_app _raw

and if you create an automatic field extraction, you can drop the escaped double quotes.

View solution in original post

yannK
Splunk Employee
Splunk Employee

You have the right approach,
the splunk index will overwrite your automatic field extraction.

if you data is like data="xxxx",index="allgoodman",session="12345"

you can define a new field and use a rex.

<mysearch> | rex "index=\"<?index_app>\w+\"" | table index index_app _raw

and if you create an automatic field extraction, you can drop the escaped double quotes.

yannK
Splunk Employee
Splunk Employee

The field is optional, by default is applied to _raw.
You need to specify it if you already have the text in a field to narrow the extraction.

0 Karma

juniormint
Communicator

This seems to work. Thanks so much!

<mysearch> | rex field=_raw "index=\"(?<index_app>\w+)\"" | table index, index_app, _raw
0 Karma

juniormint
Communicator

does that rex expression really work? do you need a field or sed in there and probably an _raw?

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 ...