Splunk Search

Can someone please give me an explanation as to what the below rex command is doing?

auzark
Path Finder

Can someone please give me an explanation as to what the below rex command is doing.

I do not understand the w+ s+ d+ etc........

| rex field=_raw "(?ms)^\\w+\\s+\\d+\\s+\\d+:\\d+:\\d+\\s+\\w+\\s+\\w+\\s+\\w+:\\s+\\w+:\\s+\\w+\\s+\\w+:\\s+\\w+\\s+\\w+\\s+\\w+:\\s+\\d+\\s+\\w+\\s+\\w+:\\s+\\d+\\-\\d+\\-\\d+\\s+\\d+:\\d+:\\d+\\s+\\w+:\\s+

 

(?P<Time>[^ ]+)\\s+

(?P<Trn_Total>\\d+)\\s+

(?P<Trn_Interval>\\d+)\\s+

(?P<TPS>[^ ]+)\\s+

(?P<SW_Inbound>[^ ]+)\\s+

(?P<SW_Outbound>[^ ]+)\\s+

(?P<SW_Total>[^ ]+)\\s+

(?P<SW_Ext_Pmc>[^ ]+)\\s+

(?P<SW_Int_Pmc>\\d+\\.\\d+)" offset_field=_extracted_fields_bounds

Labels (1)
Tags (1)
0 Karma
1 Solution

gcusello
SplunkTrust
SplunkTrust

Hi @auzark,

the best approach is to read the links that @bowesmana shared.

In few words, the objects in regexes are a way to represent the strings to read, in other words, if you have to read 

2022-12-08 21:25:03 10.10.10.10 user goofy successfully accessed host srvwin001 from 10.10.20.241

and you have to extract a part of the string (e.g. "goofy") you have to identi

2022-12-08 21:25:03 10.10.10.10 user goofy successfully accessed host srvwin001 from 10.10.20.241

fy the part of the string using the objects, from the beginning e.g.

^\d+-\d+-\d+\s+\d+:\d+:\d+\s+\d+\.\d+\.\d+\.\d+\s+user\s+(?<user>\w+)

or from a fixed point

user\s+(?<user>\w+)

the group inside quotes "?<field_name>\w+" is the field to extract, all that is outside quotes is useful to identify the field to extract.

you can find the meaning of each objects in regex101.com.

Ciao.

Giuseppe

View solution in original post

gcusello
SplunkTrust
SplunkTrust

Hi @auzark,

the best approach is to read the links that @bowesmana shared.

In few words, the objects in regexes are a way to represent the strings to read, in other words, if you have to read 

2022-12-08 21:25:03 10.10.10.10 user goofy successfully accessed host srvwin001 from 10.10.20.241

and you have to extract a part of the string (e.g. "goofy") you have to identi

2022-12-08 21:25:03 10.10.10.10 user goofy successfully accessed host srvwin001 from 10.10.20.241

fy the part of the string using the objects, from the beginning e.g.

^\d+-\d+-\d+\s+\d+:\d+:\d+\s+\d+\.\d+\.\d+\.\d+\s+user\s+(?<user>\w+)

or from a fixed point

user\s+(?<user>\w+)

the group inside quotes "?<field_name>\w+" is the field to extract, all that is outside quotes is useful to identify the field to extract.

you can find the meaning of each objects in regex101.com.

Ciao.

Giuseppe

bowesmana
SplunkTrust
SplunkTrust

Good starting point for understanding regex is

https://regex101.com/

and

https://www.regular-expressions.info/

You can see documentation on the shorthand character classes, such as \d, \w and \s here

https://www.regular-expressions.info/shorthand.html

Brackets are using for capturing groups - e.g. (?P<Time>[^ ]+)

https://www.regular-expressions.info/brackets.html

captures the expression matched by all characters up to the subsequent space into the field called Time

Get Updates on the Splunk Community!

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics GA in US-AWS!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...