Splunk Search

Parse a string into multiple fields for my App - Custom Parser

rajim
Path Finder

I have a custom log as below:

1 2017-11-27T09:42:05.449123+00:00 generus0002 Sonahock - - [timeQuality tzKnown="1" isSynced="1" syncAccuracy="235810"] "CTO","23-249691","2017-11-27 09:36:57",13,"Malware","Further investigation required","1.1.2.3",80,"1.2.3.4",64635,"Inbound","Generus IFGW","Eldos Wiper (OPTIONS /)",100.0,"1.1.2.3","","PC-myComputer","","aa:bb:cc:dd:ee:ff","East-West","1.1.2.3","/","DavClnt",""

Now I want to find a regular expression that would parse the log into multiple field-value pairs. The fields will be separated by coma (,) and the first part of the above string i.e.

1 2017-11-27T09:42:05.449123+00:00 generus0002 Sonahock - - [timeQuality tzKnown="1" isSynced="1" syncAccuracy="235810"]
will be skipped.

I have created the below regex. But it's not working.

^(?:[^"\n]"){7}(?P[^"]+)","(?P[^"]+)","(?P[^"]+)[^"\n]",(?P\d+)[^"\n]"(?P[^"]+)[^,\n],"(?P[^"]+)[^,\n],"(?P[^"]+)",(?P[^,]+)[^,\n],"(?P\d+.\d+.\d+.\d+)",(?P[^,]+)[^"\n]"(?P\w+)","(?P\w+\s+\w+)[^,\n],"(?P[^"]+)",(?P\d+.\d+),"(?P[^"]+),"(?P[^"]),"(?P[^"]),"(?P[^"]),"(?P[^"]),"(?P[^"]),"(?P[^"]),"(?P[^"]),"(?P[^"]),"(?P[^"])*

The main problem I'm facing is that there are some fields which might have values like "" (i.e. null value). I think the parser is not working whenever it encounters such fields. Please suggest.

Thanks in advance.

0 Karma

richgalloway
SplunkTrust
SplunkTrust

Try this regex. You'll want to replace each "field*" with something more meaningful. Regular expressions handle empty strings using the * quantifier. BTW, it's not necessary to start your regex at the beginning of the line (unlike what the Splunk regex tool insists on). In this case, the pattern starts with the right bracket that ends the text you want to skip.

] "(?<field1>[^"]*)","(?<field2>[^"]*)","(?<field3>[^"]*)",(?<field4>\d*),"(?<field5>[^"]*)","(?<field6>[^"]*)","(?<field7>[^"]*)",(?<field8>\d*),"(?<field9>[^"]*)",(?<field10>\d*),"(?<field11>[^"]*)","(?<field12>[^"]*)","(?<field13>[^"]*)",(?<field14>[^,]*),"(?<field15>[^"]*)","(?<field16>[^"]*)","(?<field17>[^"]*)","(?<field18>[^"]*)","(?<field19>[^"]*)","(?<field20>[^"]*)","(?<field21>[^"]*)","(?<field22>[^"]*)","(?<field23>[^"]*)","(?<field24>[^"]*)"
---
If this reply helps you, Karma would be appreciated.
0 Karma

richgalloway
SplunkTrust
SplunkTrust

Your regex string was mangled by the system. Please edit your question and put the correct regex as code (highlight the text and click the '101010' button).

---
If this reply helps you, Karma would be appreciated.
0 Karma
Get Updates on the Splunk Community!

Splunk + ThousandEyes: Correlate frontend, app, and network data to troubleshoot ...

 Are you tired of troubleshooting delays caused by siloed frontend, application, and network data? We've got a ...

Splunk Observability for AI

Don’t miss out on an exciting Tech Talk on Splunk Observability for AI!Discover how Splunk’s agentic AI ...

🔐 Trust at Every Hop: How mTLS in Splunk Enterprise 10.0 Makes Security Simpler

From Idea to Implementation: Why Splunk Built mTLS into Splunk Enterprise 10.0  mTLS wasn’t just a checkbox ...