Splunk Search

Grouping (Range?) HTTP Status codes

dbcase
Motivator

Hi,

I have queries that I'd like to group HTTP Status codes together... (i.e. anything 200-299, or 300-399, or 400-499, or 500-599) . I have a dropdown that prompts the user to select

 <input type="dropdown" token="http_code" searchWhenChanged="true">
        <label>Select Http Status Code Range:</label>
        <default>200</default>
        <choice value="200">200 - 299</choice>
        <choice value="300">300 - 399</choice>
        <choice value="400">400 - 499</choice>
        <choice value="500">500 - 599</choice>

      </input>

but I'm not sure how to get the query working. This is what I have it it kinda works but it still returns other codes even thought the value is zero

index=itscom source=*access* |rex "HTTP\S+ (?<status>\d+)"|stats count(eval(searchmatch("status=2*"))) as "200-299" by status

alt text

Tags (1)
0 Karma
1 Solution

somesoni2
SplunkTrust
SplunkTrust

Try this

index=itscom source=*access* |rex "HTTP\S+ (?<status>\d+)" 
| bucket status span=100 | eval status=mvindex(split(status,"-"),0)."-".(tonumber(mvindex(split(status,"-"),1))-1)
| stats count by status

View solution in original post

somesoni2
SplunkTrust
SplunkTrust

Try this

index=itscom source=*access* |rex "HTTP\S+ (?<status>\d+)" 
| bucket status span=100 | eval status=mvindex(split(status,"-"),0)."-".(tonumber(mvindex(split(status,"-"),1))-1)
| stats count by status

dbcase
Motivator

Wow, tat is pretty good! It doesn't seem to get the 500-599 ones though.

0 Karma

dbcase
Motivator

nevermind, my fat fingers can't type so well 🙂

0 Karma

somesoni2
SplunkTrust
SplunkTrust

Lets try this than

index=itscom source=*access* |rex "HTTP\S+ (?\d+)" 
 | bucket status span=100 | eval status=mvindex(split(status,"-"),0)."-".(tonumber(mvindex(split(status,"-"),0))+99)
 | stats count by status
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 ...