Splunk Search

How do I extract a numerical field and rename the value?


this is the raw data from my search index=myindex sourceype=mysourcetype

2016-11-10 07:41:29 Local7.Debug    community=PUBLIC, enterprise=, uptime=25949301, agent_ip=, version=Ver2,,,,,,,,,,,,,,,,,,,,,,,,,,,,

i need to break these values into two fields

first field* the last decimal will be 1-28 i also want to replace this with the description of the code
so would be Version would be Box would be Port etc.

second field =2 i need the part after =. this will be numerical value or a name so it could be a 1,2,3etc or it could read something like Preroll


Re: How do I extract a numerical field and rename the value?

Path Finder

If you can get ahold of the MIB you might be able to create a lookup table and match up those values with the text of the MIB.

Something like this:

OID,name, Version, Box, Port

Although looking at the data is splunk extracting each OID as a separate field?

0 Karma

Re: How do I extract a numerical field and rename the value?


Firstly, to match each of the *.1 as Version, *.2 as Box and *.3 as Port you will require a lookup table which in this case I will call as idLookup.csv and its lookup definition I will call as idLookup_def. See here on how to create a lookup table and lookup definition.


Once the lookup table and lookup definition is done, we will need the search part which will extract the data from your events and will lookup the data against the description.

Your data has key value pairs where there are no corresponding values for a particular key after =, for example,

To handle such values first I have rexed/sed a value NA to make them,. After that you can take the values out in three fields called stringPrefix, stringSuffix and stringValue. such that for the kv pairs in your data like or will end up with string fields as follows:

stringPrefix with value
stringSuffix with value 23 or 25...
stringValue with value LABCAPMP4 or NA...and so on.

Once you have these three strings for each of the 28 key value pair from your data then we can match the stringSuffix with your suffix field in the lookup definition using | lookup command and get the description saved in idLookup.csv.

Below is then the complete query that should achieve the result you seek:

your query to get the events
| rex field=_raw mode=sed "s/=,/=NA,/g"
| rex field=_raw max_match=0 "(?<sP>(\d+\.)+)(?<sS>\d+)=(?<sV>[^,]+)"
| eval tempString=mvzip(sP, (mvzip (sS, sV, "~")), "~")
| mvexpand tempString
| rex field=tempString "(?<stringPrefix>[^~]+)~(?<stringSuffix>[^~]+)~(?<stringValue>(.*))"
| eval myString=stringPrefix."".stringSuffix
| lookup idLookup_def suffix as stringSuffix OUTPUT description as description
| table stringPrefix, stringSuffix, myString, description, stringValue

Hope it helps.

View solution in original post


Re: How do I extract a numerical field and rename the value?


worked perfectly. i had the lookup but i wasn't sure how to break it down correctly. much thanks!!

0 Karma