I am using the following Splunk query to get all the response content and their corresponding response status code.
index=main env=nonprod sourcetype="*sample-service*" "response"
Sample response log from the above Splunk query looks like:
||INFO||||Response:{"requestId:"369018b6-0fd4-11ee-be56-0242ac120002","headers":{"Content-Type":["application/json"]},"url":"https://sample-service.abcCompany.com","statusCode":200,"method":"POST","timeTaken":98,"body":{"..":"..","...":"..."}}
I am trying to extract the statusCode
as a field so that I can see the number of occurrences of each http statusCode from the service response.
Here is the regular expression I tried to extract statusCode:
"statusCode":([\d]*)
I tried using above regular expression in the Splunk query:
index=main env=nonprod sourcetype="*sample-service*" "response" | rex "statusCode":([\d]*)
But got Error in the search parser:
Error in 'SearchParser': Missing a search command before '\'.
Not sure how to implement this to extract the statusCode field so that I can visualize the number of occurrences of each statusCode.
My expected result sample is:
statusCode | count |
---|---|
200 | 5000 |
404 | 4 |