Splunk Search

using EVAL

mikefoti
Communicator

I have a form that prompts user for a 4 digit number representing a location. I want to insert that location number into a formula that calculates the location's IP address. I then want to use that IP as the basis for a search.

My formula with a location number of 0191 looks like this:

10.(INT(0191/256+170)).(MOD(0191,256)).48)

The resulting IP address is 10.170.191.48

I then hope to use the IP is the following search:

index="winradius" nps_nasIP=10.170.191.48

So I think I would use EVAL as follows:

index="winradius" (eval nps_nasIP=10.(INT(0191/256+170)).(MOD(0191,256)).48)

But this doesn't work.
No error message... just no results are returned.
Not sure how to fix or even troubleshoot this.

Tags (1)
0 Karma

ziegfried
Influencer

You could do this using a subsearch:

index="winradius" [ | stats count | eval nps_nasIP="10." . tostring(floor(tonumber("0191")/256+170)) . "." . tostring(tonumber("0191")%256) . ".48" | return nps_nasIP ]

ziegfried
Influencer

Yes, it's possible. You should take a look at the SideviewUtils app and try to do that using customBahavior on form elements.

http://splunk-base.splunk.com/apps/36405/sideview-utils

0 Karma

mikefoti
Communicator

Thanks.
Can you tell me if, rather they trying to evaluate the formula within the search string, I can insert some code into the form... so that when the user enters 0191, the form calls a script to apply the formula and then inserts he result to the search?

0 Karma

ziegfried
Influencer

it should work, at least on 4.3. The subsearch creates an additional condition for the outer search nps_nasIP="10.170.191.48".

The dot characeter . is used for string concatenation.

There's no INT and MOD function for Splunk's eval command so I changed them to INT ==> floor(tonumber(X)) and MOD ==> X%Y

Here's a list of functions you can use with the eval command: http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/CommonEvalFunctions

0 Karma

landen99
Motivator

or just round(x)

0 Karma

mikefoti
Communicator

A couple of things....
1 - thanks for the very quick reply!
2 - unfortunately it doesn't work
3 - what does this string do . "." .
4 - in my formula INT and MOD are mathematical functions so I would not expect replacing the function names with "tonumber" to return the expected result

INT means "round the result to nearest whole number"
MOD(191/256) means "tell me the remainder if 191 is devided by 265"

0 Karma
Get Updates on the Splunk Community!

App Platform's 2025 Year in Review: A Year of Innovation, Growth, and Community

As we step into 2026, it’s the perfect moment to reflect on what an extraordinary year 2025 was for the Splunk ...

Operationalizing Entity Risk Score with Enterprise Security 8.3+

Overview Enterprise Security 8.3 introduces a powerful new feature called “Entity Risk Scoring” (ERS) for ...

Unlock Database Monitoring with Splunk Observability Cloud

  In today’s fast-paced digital landscape, even minor database slowdowns can disrupt user experiences and ...