Splunk Search

REX not being consistent in defining "fields"

MasterOogway
Communicator

I have a set of router and switch syslog events that I am trying to define 'error' Fields for but I don't see the REX statement being consistent. When I run the following search against the listed two syslog events

Search

sourcetype=syslog_info earliest=-1m | rex "(?<error>\%.*-\b([0-4])\-.*):\s"

Syslog data

<DATE Field> %SNMP-3-AUTHFAIL: Authentication failure for SNMP req from host
<DATE Field>  "%ACLLOG-4-ACLLOG_THRESHOLD: Source IP: 10.215.24.52, Destination IP: 167.68.250.45, Source Port: 137, Destination Port: 137, Source Interface: port-channel105, protocol"


I get the following results. Any thoughts to why one works and one doesn't? I am stumped.

1) error="%SNMP-3-AUTHFAIL"
2) error="%ACLLOG-4-ACLLOG_THRESHOLD: Source IP: 10.215.24.52, Destination IP: 167.68.250.45, Source Port: 137, Destination Port: 137, Source Interface: port-channel105, protocol"

Master Oogway

Tags (2)
0 Karma
1 Solution

southeringtonp
Motivator

The difference between your two sample events is that the second one has multiple : characters. The .* performs "greedy" matching, meaning it tries to include as much text as possible in the match.

Adding a question mark -- .*? -- will make it non-greedy:

| rex "(?<error>\%.*-\b([0-4])\-.*?):\s"

Or if you want a more permanent/complete solution, this covers most cases:

props.conf:

[cisco-eventcodes]
REGEX = (%(([\w\-]+)-(\d+)-([\w\_]+)):\s+(.*)$)
FORMAT = message_full::$1 event::$2 facility::$3 severity::$4 mnemonic::$5 message::$6

transforms.conf:

[syslog_info]
REPORT-ciscoevt = cisco-eventcodes

View solution in original post

southeringtonp
Motivator

The difference between your two sample events is that the second one has multiple : characters. The .* performs "greedy" matching, meaning it tries to include as much text as possible in the match.

Adding a question mark -- .*? -- will make it non-greedy:

| rex "(?<error>\%.*-\b([0-4])\-.*?):\s"

Or if you want a more permanent/complete solution, this covers most cases:

props.conf:

[cisco-eventcodes]
REGEX = (%(([\w\-]+)-(\d+)-([\w\_]+)):\s+(.*)$)
FORMAT = message_full::$1 event::$2 facility::$3 severity::$4 mnemonic::$5 message::$6

transforms.conf:

[syslog_info]
REPORT-ciscoevt = cisco-eventcodes

MasterOogway
Communicator

A...ding, ding, ding! This did it. Thank you!
I will try the more permanent solution and see what I get.

0 Karma
Get Updates on the Splunk Community!

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...