Splunk Search

How do you extract a field value with regex?

sarit_s
Communicator

Hello,

I have an event that looks like :

> <18> 20/02/19 22:23:59 : Maintenance counter "Digital Materials Mode" Value is: 84 hours.

i need to extract the Maintenance counter type (the string between ""), the value and the value type (in the example its hours, can be minutes, days, etc)

The maintenance counter type can be 2 words, 3, 4, etc..

I tried this regex, but it is returning me only events with maintenance counter type that contains 3 words :

index="emea_pj" "Maintenance counter" | rex field=_raw "(?ms)^(?:[^ \\n]* ){6}(?P<MaintenanceCounter>\"\\w+\\s+\\w+\\s+\\w+\")" 

How can I achieve my goal?

thanks

Tags (2)
0 Karma
1 Solution

adonio
Ultra Champion

try this anywhere:

| makeresults count=1 
| eval data = "20/02/19 22:23:59 : Maintenance counter \"Digital Materials Mode\" Value is: 84 hours.;;;20/02/19 22:24:59 : Maintenance counter \"Another Counter\" Value is: 74 seconds.;;;20/02/19 22:25:59 : Maintenance counter \"Counter\" Value is: 64 minutes."
| makemv delim=";;;" data
| mvexpand data
| table data
| rename COMMENT as "above generates fake results, belew is your solution" 
| rex field=data "(?<timestamp>\d{2}\/\d{2}\/\d{2}\s\d{2}:\d{2}:\d{2})\s\:\sMaintenance\scounter\s\"(?<counter>[^\"]+)\"\sValue\sis\:\s(?<value>\d+)\s(?<value_counter>[^\.]+)"

screenshot:
alt text

View solution in original post

0 Karma

adonio
Ultra Champion

try this anywhere:

| makeresults count=1 
| eval data = "20/02/19 22:23:59 : Maintenance counter \"Digital Materials Mode\" Value is: 84 hours.;;;20/02/19 22:24:59 : Maintenance counter \"Another Counter\" Value is: 74 seconds.;;;20/02/19 22:25:59 : Maintenance counter \"Counter\" Value is: 64 minutes."
| makemv delim=";;;" data
| mvexpand data
| table data
| rename COMMENT as "above generates fake results, belew is your solution" 
| rex field=data "(?<timestamp>\d{2}\/\d{2}\/\d{2}\s\d{2}:\d{2}:\d{2})\s\:\sMaintenance\scounter\s\"(?<counter>[^\"]+)\"\sValue\sis\:\s(?<value>\d+)\s(?<value_counter>[^\.]+)"

screenshot:
alt text

0 Karma

sarit_s
Communicator

when running the rex its returning result but if im running it with table it showing no results

index="emea_pj" "Maintenance counter" |SerialNumber| rex field=data "(?\d{2}\/\d{2}\/\d{2}\s\d{2}:\d{2}:\d{2})\s:\sMaintenance\scounter\s\"(?[^\"]+)\"\sValue\sis:\s(?\d+)\s(?[^.]+)" |table data

0 Karma
Get Updates on the Splunk Community!

Updated Team Landing Page in Splunk Observability

We’re making some changes to the team landing page in Splunk Observability, based on your feedback. The ...

New! Splunk Observability Search Enhancements for Splunk APM Services/Traces and ...

Regardless of where you are in Splunk Observability, you can search for relevant APM targets including service ...

Webinar Recap | Revolutionizing IT Operations: The Transformative Power of AI and ML ...

The Transformative Power of AI and ML in Enhancing Observability   In the realm of IT operations, the ...