Splunk Search

How to achieve "Message":"###1234$$$ Invalid" result with rex?

wvsgo215
Engager

splunk data: 2022-01-01T02:06:12.182Z 7c3edf29-c081-4cca-ae9b-0f79ef7d1c8d INFO {"InfoLogInformation":{"MethodName":"index.handler","Message":""Processing completed"","LogType":"Info","Error":"2022-01-01T02:06:12.040Z::400 - {"ResponseStatus":{"ErrorCode":"WorkBookMessageException","Message":"###1234$$$ Invalid." 

query: | rex ",\"Message\":\"\"(?<Message>.*?)\"\""
| rex "\"Exception\":\"400 - {\"ResponseStatus\":{\"ErrorCode\":\"(?<ErrorCode>.*?)\",\"Message\":\"(?<Message>.*?)\""

query result: Message = Processing completed  

I want the result should the Message":"###1234$$$ Invalid.

please help. TIA

Labels (1)
0 Karma

yuanliu
SplunkTrust
SplunkTrust

@wvsgo215 Are you sure the illustrated data is complete and in original format?  I speculate that the original format could be something like

2022-01-01T02:06:12.182Z 7c3edf29-c081-4cca-ae9b-0f79ef7d1c8d INFO {"InfoLogInformation":{"MethodName":"index.handler","Message":"Processing completed","LogType":"Info"},"Error":"2022-01-01T02:06:12.040Z::400 - {'ResponseStatus':{'ErrorCode':'WorkBookMessageException','Message':'###1234$$$ Invalid.'}}"}

If the data is structured, use rex to extract the JSON object, then spath to extract from JSON.  If the log format is like the above, use

 

| rex " INFO (?<info_json>{.+)"
| spath input=info_json path=Error
| eval error_json = replace(Error, "^[^{]*", "")
| eval error_json = replace(error_json, "'", "\"") ``` JSON uses double quote ```
| spath input=error_json

 

You get

ResponseStatus.ErrorCodeResponseStatus.Messageerror_jsonError
WorkBookMessageException###1234$$$ Invalid.{"ResponseStatus":{"ErrorCode":"WorkBookMessageException","Message":"###1234$$$ Invalid."}}2022-01-01T02:06:12.040Z::400 - {'ResponseStatus':{'ErrorCode':'WorkBookMessageException','Message':'###1234$$$ Invalid.'}}

SPL's builtin function is much more robust at handling structured data like JSON.

Tags (1)
0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @wvsgo215,

please try this regex:

| rex "\"Message\":\"(?<message>[^\"]*?)\"\s"

that you can test at https://regex101.com/r/jdWRO8/1

Ciao.

Giuseppe

Get Updates on the Splunk Community!

Detecting Remote Code Executions With the Splunk Threat Research Team

REGISTER NOWRemote code execution (RCE) vulnerabilities pose a significant risk to organizations. If ...

Observability | Use Synthetic Monitoring for Website Metadata Verification

If you are on Splunk Observability Cloud, you may already have Synthetic Monitoringin your observability ...

More Ways To Control Your Costs With Archived Metrics | Register for Tech Talk

Tuesday, May 14, 2024  |  11AM PT / 2PM ET Register to Attend Join us for this Tech Talk and learn how to ...