Splunk Search

Problems Evaluating Field After Rex Extraction

mwollenweber
Engager

I'm trying to evaluate a field after it is extracted at search time using rex. Unfortunately it is failing. An example query:

sslvpn* "Session started" | dedup _raw | rex field=_raw "\[(?<ip>\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b)\]\ (?<netid>.*)\(" | ip != 10.*

Results in an error message:

Search operation 'ip' is unknown. You
might not have permission to run this
operation.

I know IP field is being discovered as the following query works:

sslvpn* "Session started" | dedup _raw | rex field=_raw "\[(?<ip>\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b)\]\ (?<netid>.*)\(" | stats values(netid), dc(netid), values(host) by ip | RENAME dc(netid) as netid_count | WHERE netid_count > 1

What I'm hoping to do is filter based on IP addresses. I've also tried adding a WHERE clause but that didn't work either. Help would be appreciated.

Tags (2)
0 Karma
1 Solution

dwaddle
SplunkTrust
SplunkTrust

The first thing after a pipe should be a command, and ip is not a command. Without seeing your search I would say that where should have worked. But we'll try something else instead.

sslvpn* "Session started" 
| dedup _raw 
| rex field=_raw "\[(?<ip>\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b)\]\ (?<netid>.*)\(" 
| search ip != 10.*

Alternately, this is a good place for the cidrmatch function which is part of the where command. So, something like:

sslvpn* "Session started" 
| dedup _raw 
| rex field=_raw "\[(?<ip>\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b)\]\ (?<netid>.*)\(" 
| where cidrmatch("10.0.0.0/8",ip)

View solution in original post

mwollenweber
Engager

Excellent, your where cidrmatch solution works. Oddly enough

sslvpn* "Session started" 
| dedup _raw 
| rex field=_raw "\[(?<ip>\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b)\]\ (?<netid>.*)\(" 
| where ip != "10.*"

evaluates correctly but doesn't appropriately filter but

sslvpn* "Session started" 
| dedup _raw 
| rex field=_raw "\[(?<ip>\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b)\]\ (?<netid>.*)\(" 
| where ip != 10.*

is malformed with error:

Error in 'where' command: The expression is malformed. The factor is missing.

ip has a string as a type, so I'm not sure why the two options above fail, but your approach works. Thanks again!

0 Karma

dwaddle
SplunkTrust
SplunkTrust

The first thing after a pipe should be a command, and ip is not a command. Without seeing your search I would say that where should have worked. But we'll try something else instead.

sslvpn* "Session started" 
| dedup _raw 
| rex field=_raw "\[(?<ip>\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b)\]\ (?<netid>.*)\(" 
| search ip != 10.*

Alternately, this is a good place for the cidrmatch function which is part of the where command. So, something like:

sslvpn* "Session started" 
| dedup _raw 
| rex field=_raw "\[(?<ip>\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b)\]\ (?<netid>.*)\(" 
| where cidrmatch("10.0.0.0/8",ip)
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...

Modernize your Splunk Apps – Introducing Python 3.13 in Splunk

We are excited to announce that the upcoming releases of Splunk Enterprise 10.2.x and Splunk Cloud Platform ...

Step into “Hunt the Insider: An Splunk ES Premier Mystery” to catch a cybercriminal ...

After a whole week of being on call, you fell asleep on your keyboard, and you hit a sequence of buttons that ...