splunksplunk-querysplunk-formula

Extracting fields from logs using rex


I am trying to extract few fields from an event log using rex command and display the fields in a tabular format.

This is my log: LOG_LEVEL="INFO" MESSAGE="Type_of_Call = Sample Call LOB = F Date/Time_Stamp = 2022-10-10T21:10:53.900129 Policy_Number = 12-AB-1234-5 Requester_Id = A1231301 Last_Name = SAMPLE State = IL City = Chicago Zip 12345" APPLICATION_VERSION="appVersion_IS_UNDEFINED"

Fields that I want to extract are: Type_of_Call, LOB, Date/Time_Stamp, Policy_Number, Requester_Id, Last_Name, State, City, Zip

This is my splunk rex command:

rex field=_raw "Type_of_Call\s*=\s*(?<Type_Of_Call>\w+)\s+Call\s+LOB\s*=\s*(?<LOB>\w+)\s+Date/Time_Stamp\s*=\s*(?<Date_Time_Stamp>[0-9TZ.:-]+)\s+Policy_Number\s*=\s*(?<Policy_Number>[\w-]+)\s+Requestor_Id\s*=\s*(?<Requestor_Id>\w+)\s+Last_Name\s*=\s*(\w+)\s+State\s*=\s*(?<State>\w+)"
| table msg "Type of Call" "LOB" "Date/Time Stamp" "Policy Number" "Requester Id" "LastName" "State" 

The issue that I am having is that Only LOB field and State field come back with values, State field for some reason is adding an escape character and pulling the last "

This is what the results look like: enter image description here

Can someone please help

If changing the logs itself could be a fix then i can do that as well


Solution

  • In addition to what @Mads Hansen offered, the slash in "Date/Time_Stamp" must be escaped. Try this regex:

    Type_of_Call\s*=\s*(?<Type_Of_Call>\w+)\s+Call\s+LOB\s*=\s*(?<LOB>\w+)\s+Date\/Time_Stamp\s*=\s*(?<Date_Time_Stamp>[0-9TZ.:-]+)\s+Policy_Number\s*=\s*(?<Policy_Number>[\w-]+)\s+Requester_Id\s*=\s*(?<Requestor_Id>\w+)\s+Last_Name\s*=\s*(\w+)\s+State\s*=\s*(?<State>\w+)