Splunk Search

eval if command with returned value = all from dropdown list

krusovice
Path Finder

Hello all,

I'm forming the eval query based on the value extracted from dropdown token.

| eval city=if((_raw LIKE "%$city$%"),"$city$","0" )

Issue here is that the dropdown is having All=* configured. If user chosen "All" from the dropdown list, the "city" token will be equal to 0, which is not correct.

How can I pass all the "city" value to the next query if All is selected?

Tags (1)
0 Karma
1 Solution

mayurr98
Super Champion

why do not you just try city="$city$" to pass the city value?

View solution in original post

0 Karma

mayurr98
Super Champion

why do not you just try city="$city$" to pass the city value?

0 Karma

krusovice
Path Finder

No it is not working. city token is from dropdown list. There is no such field "city=" in the log. My simplified query as below:

index=* "Country: $clicked_country$ - CITY: $city$" 
| eval country=if((_raw LIKE "%$clicked_country$%"),"$clicked_country$","0")
| eval city=if((_raw LIKE "%$city$%"),"$city$","0")
| stats values(date_hour) as "Hour" by country city
0 Karma

mayurr98
Super Champion

why do not you extract city and country to make your job easier I see from the events they are in standard format.

| rex field=_raw "Country\:\s(?<country>[^\s]+)\s\-\sCity\:\s(?<city>[^\s]+)" | search city="$city$"

and then use * as a wildcard for ALL.

From your current search query you need to substitute * for the main search and % for the eval statement.

let me know if this helps!

0 Karma

krusovice
Path Finder

Yes it is working fine now after several tests. Thanks to @mayurr98 and @493669.

0 Karma

deepashri_123
Motivator

Hey krusovice,

Is your city field already extracted?
If yes, then rather than writing eval you can try something like this:

index=* | search city=$city$ 

In this case, if you select all, city will be selected as city=* and that should help!!

Let me know if this worked!!

0 Karma

krusovice
Path Finder

hi @493669 and @deepashri,

Both solution not working. There is no "city=" to be matched in the log. the $city$ field is from dropdown list (e.g. All, London, Mancester....etc).

Solution provided by @493669 still returning as "*".

0 Karma

493669
Super Champion

In what scenario you are using $city$ token? if you could share what output you are expecting...

0 Karma

krusovice
Path Finder

Desired output in table format as explained in:

https://answers.splunk.com/answers/624710/formatting-output-in-table.html

0 Karma

493669
Super Champion

try this:

index=*|  rex field=_raw "Country\:\s(?<country>[^\s]+).*City\:\s(?<city>[^\s]+)"
| search city="$city$" AND country="$clicked_country$"
 | stats values(date_hour) as "Hour" by country city
0 Karma

mayurr98
Super Champion

how are you getting events from the dropdown list? is it coming from lookup? or you are extracting it at search time ?
it would be great if you share sample events and xml for your current dashboard.

0 Karma

krusovice
Path Finder

city token from dropdown list is extracted using regex to catch the "city" in the log.

Sample log:
Request_A - Country: GERMANY - City: BER

0 Karma

493669
Super Champion

why you wont try simply

 | eval city="$city$"
0 Karma
Get Updates on the Splunk Community!

More Ways To Control Your Costs With Archived Metrics | Register for Tech Talk

Tuesday, May 14, 2024  |  11AM PT / 2PM ET Register to Attend Join us for this Tech Talk and learn how to ...

.conf24 | Personalize your .conf experience with Learning Paths!

Personalize your .conf24 Experience Learning paths allow you to level up your skill sets and dive deeper ...

Threat Hunting Unlocked: How to Uplevel Your Threat Hunting With the PEAK Framework ...

WATCH NOWAs AI starts tackling low level alerts, it's more critical than ever to uplevel your threat hunting ...