Splunk Search

count condition

subachu
New Member

I'm having trouble writing a search statement that sets the count to 0 when the service is normally.

This is my data example.

name status
A failed
B failed
C failed
A normally
B normally
C normally

Counting with name will also count normally.
I want to count status failed only.

In this case, everything is normally, I want to display 0.

I know this is not correct, but I want to do like this.

|eval A =if((status=failed),count,null)
|stats count as A

I can't think of a conditional statement that counts when the status is failed.

Tags (1)
0 Karma
1 Solution

mayurr98
Super Champion

Try this ?

 <your search> | stats count(eval(status="failed")) as failed_count by name

View solution in original post

mayurr98
Super Champion

Try this ?

 <your search> | stats count(eval(status="failed")) as failed_count by name

Sukisen1981
Champion

instead of if , use a case
|eval A=case(status=failed,1)
so A has counts only for failed status

0 Karma

subachu
New Member

Thank you for helping.
what do it mean (status=failed,1)?
I thought (status=failed,0).

0 Karma

Sukisen1981
Champion

hi you said 'I want to count status failed only.' hence I made status=failed as 0.
You can assign any value based on your need

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