Splunk Search

How can we make a null value as a success?

vrmandadi
Builder

Hello all,

I ran the below query

...|stats count by message_type

I got the below result

message_type count
a_req 2
a_res 1
b_req 4
b_res 2

I ran a query to combine the a_req and a_res total

  | rex field=EWS_MESSAGE_QUALIFIER "(?<MESSAGE_TYPE>\w+)_"      |chart  count by MESSAGE_TYPE  

.Which combines both the a_req and a_res

message_type count
a 3
b 6

Now i am trying to categorize into success and failure based on some codes , below is the query i ran

| rex field=EWS_MESSAGE_QUALIFIER "(?<MESSAGE_TYPE>\w+)_" 
|eval category=if((CODE="0" OR CODE="null")   AND (CODE1="000" OR CODE1="null")  AND (CODE2="000" OR CODE2="null") ,"Success","Failure") 
|chart  count by MESSAGE_TYPE,category | addcoltotals labelfield=total 
|fillnull value=TOTAL |fields- total

but The above search is not considering the null values of the responses codes as success.How can this be done ?

thanks in advance

Tags (3)
0 Karma

somesoni2
Revered Legend

Use the isnull function to compare a field against null.

your base search | rex field=EWS_MESSAGE_QUALIFIER "(?<MESSAGE_TYPE>\w+)_" 
 |eval category=if((CODE="0" OR isnull(CODE))   AND (CODE1="000" OR isnull(CODE))  AND (CODE2="000" OR isnull(CODE)) ,"Success","Failure") 
 |chart  count by MESSAGE_TYPE,category | addcoltotals labelfield=total 
 |fillnull value=TOTAL |fields- total

Also, check if the conditions are correct, I think the order of conditios. IMO, it should be like this

your base search | rex field=EWS_MESSAGE_QUALIFIER "(?<MESSAGE_TYPE>\w+)_" 
 |eval category=if(CODE="0" OR isnull(CODE) OR CODE1="000" OR CODE2="000" ,"Success","Failure") 
 |chart  count by MESSAGE_TYPE,category | addcoltotals labelfield=total 
 |fillnull value=TOTAL |fields- total

vrmandadi
Builder

Thanks for the reply somesh...I tried in another way I first gave a table command and then filled the null with zero and just gave the rest of the query

0 Karma

MuS
Legend

Hi vrmandadi,

take a look at this answer https://answers.splunk.com/answers/176466/how-to-use-eval-if-there-is-no-result-from-the-bas-1.html to get an idea how you can use eval if there is no result in the base search.

Hope this helps ...

cheers, MuS

0 Karma

vrmandadi
Builder

Well mine is a different scenario ,I got the result and done in another way ,I first gave a table command and then filled the null with zero and just gave the rest of the query

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!

Community Content Calendar, September edition

Welcome to another insightful post from our Community Content Calendar! We're thrilled to continue bringing ...

Splunkbase Unveils New App Listing Management Public Preview

Splunkbase Unveils New App Listing Management Public PreviewWe're thrilled to announce the public preview of ...

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Are you leveraging automation to its fullest potential in your threat detection strategy?Our upcoming Security ...