Splunk Search

how can I use a string value to compare number?

pramit46
Contributor

I have a field with values > = != etc., and another field that determines threshold
Now I want to Compare the value of third field against the threshold field using the value of that (String) operator. How to achieve this?

for example:

Threshold (Num)|Value(Num)|Operator(String)
10|12|">"
10|7|"!="
10|4|"<"

I need to compare the values using respective operator values and determine if the threshold is breached.
Any clue?

0 Karma
1 Solution

somesoni2
SplunkTrust
SplunkTrust

How about a big case statement which writes an expression for every possible operator (should be a finite list), like this

your current search with fields Threshold, Value, Operator 
| eval isBreached=case(Operator=">" AND Value>Threshold, "Yes", Operator="!=" AND Value!=Threshold,"Yes", Operator="<" AND Value<Threshold,"Yes", true(),"No") | rest of the search

View solution in original post

0 Karma

somesoni2
SplunkTrust
SplunkTrust

How about a big case statement which writes an expression for every possible operator (should be a finite list), like this

your current search with fields Threshold, Value, Operator 
| eval isBreached=case(Operator=">" AND Value>Threshold, "Yes", Operator="!=" AND Value!=Threshold,"Yes", Operator="<" AND Value<Threshold,"Yes", true(),"No") | rest of the search
0 Karma

pramit46
Contributor

Awesome. Thanks a million @somesoni2. This helps a lot 🙂
Really Appreciate this.

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 ...