Splunk Search

Save an 'eval'-based field extraction?

andyspusm
Explorer

I am extracting a field "ipaddr" which is the result of using "eval" to convert a previously extracted field "nwclient_ip_hex" (IP address in hexadecimal, for example "a0b0c0d0") to decimal. The snippet below works fine in the Search app.

How can I save "ipaddr" as a field so that other users of the app will be able to use it without needing all of that logic in the search bar?

... |eval d1 = tonumber(substr(nwclient_ip_hex,1,2),16) |eval d2 = tonumber(substr(nwclient_ip_hex,3,2),16) |eval d3 = tonumber(substr(nwclient_ip_hex,5,2),16) |eval d4 = tonumber(substr(nwclient_ip_hex,7,2),16) |eval ipaddr = d1+"."+d2+"."+d3+"."+d4

Thanks - Andy

0 Karma
1 Solution

gkanapathy
Splunk Employee
Splunk Employee

As of version 4.2.4, there is no way to do this. Search-time field extractions can only be simple substrings of the indexed data. You could encapsulate this logic in a macro, so the user sees less of the logic:

 ... | `convert_to_ip(nwclient_ip_hex)`

Where convert_to_ip() is defined as a macro that does the above. The user will still have to see the invocation of the macro, however.

View solution in original post

0 Karma

gkanapathy
Splunk Employee
Splunk Employee

As of version 4.2.4, there is no way to do this. Search-time field extractions can only be simple substrings of the indexed data. You could encapsulate this logic in a macro, so the user sees less of the logic:

 ... | `convert_to_ip(nwclient_ip_hex)`

Where convert_to_ip() is defined as a macro that does the above. The user will still have to see the invocation of the macro, however.

0 Karma

hulahoop
Splunk Employee
Splunk Employee

gkanapathy, any way to do this in 4.3 or 5.0?

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...