Splunk Search

Eval Ranges combined with specific values

bfong
Engager

Hi,

I'm looking to grab numbers of http responses (status) as "Good" or "Bad" and am successful with the following query in which I can get Total number of Responses, number of Good/Bad Responses, and what the percentages of Good/Bad Responses out of Total:

    (index="A" OR index="B") (host="A")
   | stats count as Total, count(eval(tonumber(status)>=400)) as "Bad_Request" , count(eval(tonumber(status)<=399)) as "Good_Request" 
   | eval Bad_Request_Perc=((Bad_Request/Total)*100) 
   | eval Good_Request_Perc=((Good_Request/Total)*100)

However, when trying to exclude specific values to one range and adding values, I am able to retrieve "Bad_Requests" and respective percentage, but unable to retrieve any values for "Good_Requests" (and consequently percentage), using the following:

 (index="A" OR index="B") (host="A")
| stats count as Total, count(eval(status>=400 AND status!=404 AND status!=410)) as "Bad_Request", count(eval(status<=399 AND status=404 AND status=410)) as "Good_Request"
| eval Good_Request_Percentage=((Good_Request/Total)*100) | eval Bad_Request_Percentage=((Bad_Request/Total)*100)

Does anyone know why I can get results excluding from a range, but can't get results specifying a range and specific values?

Thanks.

Tags (1)
0 Karma
1 Solution

DalJeanis
Legend

Logically, no status is ever going to be <=399 AND =404 at the same time. Change that to OR.

 (index="A" OR index="B") (host="A")
 | stats count as Total, 
count(eval(status>=400 AND status!=404 AND status!=410)) as "Bad_Request", 
count(eval(status<=399 OR status=404 OR status=410)) as "Good_Request"
 | eval Good_Request_Percentage=((Good_Request/Total)*100) | eval Bad_Request_Percentage=((Bad_Request/Total)*100)

View solution in original post

DalJeanis
Legend

Logically, no status is ever going to be <=399 AND =404 at the same time. Change that to OR.

 (index="A" OR index="B") (host="A")
 | stats count as Total, 
count(eval(status>=400 AND status!=404 AND status!=410)) as "Bad_Request", 
count(eval(status<=399 OR status=404 OR status=410)) as "Good_Request"
 | eval Good_Request_Percentage=((Good_Request/Total)*100) | eval Bad_Request_Percentage=((Bad_Request/Total)*100)
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Observability Simplified: Combining User Experience, Application Performance & ...

Tech Talk Observability Simplified: Combining User Experience, Application Performance & Network ...

Event Series May & June: From Network Visibility to Service Intelligence

Unifying the Network: Moving from Alert Noise to Service Intelligence with Splunk ITSI In today’s hybrid ...

Global Splunk User Group Events: May + June 2026

Your Splunk Community Awaits: Discover Upcoming User Group Events Worldwide    Staying ahead in the fast-paced ...