Splunk Search

How can I get a text value in my search result to be considered as a numeric value?

abovebeyond
Communicator

Hi,

I have a search result of a JSON file.

"
 { [-]
   number: 58
   result: SUCCESS
} "

How can I consider the "result" as number. for example:
SUCCESS = 1
Failure = 2

Thanks !

0 Karma
1 Solution

somesoni2
SplunkTrust
SplunkTrust

YOu could use eval-if OR eval-case to do that. Another alternative is to use replace

If there are only two possible values

your base search | eval result=if(result="SUCCESS",1,2)

If there are more than two possible values

your base search | eval result=case(result="SUCCESS",1,result="Failure",2,...other cases,1=1,0)

Alternative using replace method

your base search | replace "SUCCESS" with 1 "Failure" with 2 in result

View solution in original post

0 Karma

somesoni2
SplunkTrust
SplunkTrust

YOu could use eval-if OR eval-case to do that. Another alternative is to use replace

If there are only two possible values

your base search | eval result=if(result="SUCCESS",1,2)

If there are more than two possible values

your base search | eval result=case(result="SUCCESS",1,result="Failure",2,...other cases,1=1,0)

Alternative using replace method

your base search | replace "SUCCESS" with 1 "Failure" with 2 in result
0 Karma

abovebeyond
Communicator

Thanks , it will work with JSON format results?

how can i use the "replace" number in rangemap ?

i want to use rangemap as following:
rangemap field=result low=1-2 severe=2-3

Appreciate your help !

0 Karma

somesoni2
SplunkTrust
SplunkTrust

This should work with JSON format results, just ensure that correct field name is used (see the field sidebar on left for field names available).

Just add your rangemap command after any of the above command.
e.g. (updated the ranges)

your base search | eval result=if(result="SUCCESS",1,2) | rangemap field=result low=1-1 severe=2-3
0 Karma

woodcock
Esteemed Legend

Like this:

... | eval result_number = case(result="SUCCESS", 1, result="Failure", 2, true(), -1)

Or, if you need it automatic, you can convert this into a calculated field or a lookup file and then create an automatic lookup.

0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...