Splunk Search

capture error 4xx/5xx

nithys
Communicator

Hi

Using below query to capture 4xx,5xx error ,but getting as no result found 

index=*    source IN ("/aws/lambda/*")  msg="**"
(error.status=4* OR error.status=5*)
| eval status=case(like(error.status, "4%"), "4xx", like(error.status, "5%"), "5xx") | stats count by error.status

Screenshot 2025-03-13 at 3.49.38 PM.pngScreenshot 2025-03-13 at 3.51.18 PM.pngScreenshot 2025-03-13 at 3.48.27 PM.png

{"name":"","","pid":8,"level":50,"error":{"message":"Request failed with status code 500","name":"AxiosError","stack":"AxiosError: Request failed with status code 500\n    )","config":{"transitional":{"silentJSONParsing":true,"forcedJSONParsing":true,"clarifyTimeoutError":false},"adapter":["xhr","http"],"transformRequest":[null],"transformResponse":[null],"timeout":0,"xsrfCookieName":"X","xsrfHeaderName":"X-","maxContentLength":-1,"maxBodyLength":-1,"env":{},"headers":{"Accept":"application/json, text/plain, */*","Content-Type":"application/json","Authorization":"","User-Agent":"","Accept-Encoding":"gzip, compress, deflate, br"},"method":"get",""},"code":"ERR_BAD_RESPONSE","status":500},"eventAttributes":{"Identifier":2025732,"VersionNumber":"A.43"},"msg":"msg:data:error","time":":48:38.213Z","v":0}

this is my raw event format mostly looks like 

Labels (3)
0 Karma

yuanliu
SplunkTrust
SplunkTrust

Is it possible that your raw event is noncompliant?  This is what your illustrated event format suggests.  If that format is exact, Splunk cannot extract anything other than "name" field.  There are two elements that violates JSON syntax.  The mock event contains two bare strings that are not key-value pairs, as pointed out as "MISSING-KEY1" and "MISSING-KEY2" in the following pretty-print of a "corrected" conformant JSON object:

{
    "name": "",
    "MISSING-KEY1": "",
    "pid": 8,
    "level": 50,
    "error": {
        "message": "Request failed with status code 500",
        "name": "AxiosError",
        "stack": "AxiosError: Request failed with status code 500\n    )",
        "config": {
            "transitional": {
                "silentJSONParsing": true,
                "forcedJSONParsing": true,
                "clarifyTimeoutError": false
            },
            "adapter": [
                "xhr",
                "http"
            ],
            "transformRequest": [
                null
            ],
            "transformResponse": [
                null
            ],
            "timeout": 0,
            "xsrfCookieName": "X",
            "xsrfHeaderName": "X-",
            "maxContentLength": -1,
            "maxBodyLength": -1,
            "env": {},
            "headers": {
                "Accept": "application/json, text/plain, */*",
                "Content-Type": "application/json",
                "Authorization": "",
                "User-Agent": "",
                "Accept-Encoding": "gzip, compress, deflate, br"
            },
            "method": "get",
            "MISSING-KEY2": ""
        },
        "code": "ERR_BAD_RESPONSE",
        "status": 500
    },
    "eventAttributes": {
        "Identifier": 2025732,
        "VersionNumber": "A.43"
    },
    "msg": "msg:data:error",
    "time": ":48:38.213Z",
    "v": 0
}

If your actual events are non-compliant, Splunk will not have a value for error.status.

By the way,  the command "eval status=case(like(error.status, "4%"), "4xx", like(error.status, "5%"), "5xx")" is wasted as your stats command does not use the field status.

0 Karma

bowesmana
SplunkTrust
SplunkTrust

Are your fields auto extracted, i.e. if you just do

index=*    source IN ("/aws/lambda/*")  msg="**"

in verbose search mode, do you see error.status in the left hand panel? If so, can you see values of 4xx and 5xx?

It may be that if your JSON objects are longer than 5k, the status field may not be auto extracted, so you could try

index=* source IN ("/aws/lambda/*")  msg="**"
| spath error.status
| search (error.status=4* OR error.status=5*)
| eval status=case(like(error.status, "4%"), "4xx", like(error.status, "5%"), "5xx") 
| stats count by error.status

which will tell you if it's a JSON object limit

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!

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...