Dashboards & Visualizations

unexpected close tag with regex

puneetgupz
New Member

I want to extract error code from the below text but getting unexpected closing tag. The name of the column in the Database is SERVICE_RESPONSE

Text:

Service execution forgetGCPPauseAndResumeCall Failed. Error -> Status Code - > 404, Status Text -> Not Found, Response Body ->{"message":"HTTP 404 Not Found","code":"not found","status":404,"contextId":"c496bcae-115b-456c-a557-3d5e2daae0b8","details":[],"errors":[]}. Check Business audit for more details

Solution1:

| rex field=SERVICE_RESPONSE "\"status\"\s*:\s*(?P<ERROR_CODE>\d+)"
//above expression is giving unexpected close tag

 

Solution2: 
| rex field=SERVICE_RESPONSE "&lt;dqt&gt;status&lt;dqt&gt;\:(?P<ERROR_CODE>.\w+)"

Tags (1)
0 Karma

richgalloway
SplunkTrust
SplunkTrust

The regex used in the rex command goes through multiple layers of parsing so it needs multiple escape characters for embedded quotation marks.

Solution 1:

| rex field=SERVICE_RESPONSE "\\\"status\\\"\s*:\s*(?P<ERROR_CODE>\d+)"

 Solution 2 won't work because regular expressions don't honor URL encoding.

---
If this reply helps you, Karma would be appreciated.
0 Karma

PickleRick
SplunkTrust
SplunkTrust

I suspect the HTML entities were due to some copy-pasting magic, not as part of the regexes themselves.

As for the regex - I don't understand what @puneetgupz means by "unexpected close tag"

When unescaped, the regex works perfectly well in regex101 - https://regex101.com/r/mR5JiJ/1

(you don't need to escape the quotes in regex; just in a string in Splunk).

EDIT: OK. Escaping is needed but in another place

| rex field=SERVICE_RESPONSE "\"status\"\\s*:\\s*(?P<ERROR_CODE>\\d+)"
0 Karma

puneetgupz
New Member

Still getting the same error

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Beyond Detection: How Splunk and Cisco Integrated Security Platforms Transform ...

Financial services organizations face an impossible equation: maintain 99.9% uptime for mission-critical ...

Customer success is front and center at .conf25

Hi Splunkers, If you are not able to be at .conf25 in person, you can still learn about all the latest news ...

.conf25 Global Broadcast: Don’t Miss a Moment

Hello Splunkers, .conf25 is only a click away.  Not able to make it to .conf25 in person? No worries, you can ...