Dashboards & Visualizations

Using Eval field in regular expression

codywsj
Loves-to-Learn

Hi,

I was wondering if we can use the field in eval inside the regular expression in rex?

 

my search query


| eval IP=if(("$spec_IP$"=="*"),"(?<file_ip>\d+.\d+.\d+.\d+)","$spec_IP$")
| rex field=_raw "\d{1,2}-\S{3}\s\d{2}:\d{2}:\d{2}.\d{3}\s\S{3}\s\[IP\]\s%NICWIN-4-Security_560_Security[\S\s]+?(?<log_time>(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s\d{2}\s\d{2}:\d{2}:\d{2})[\S\s]+?\S*Object\sName:\s(?<object_name>[\S\s]+?)New\sHandle\sID[\S\s]+?Primary\sUser\sName:\s(?<username>[\S\s]+?)\s+"

I am trying to use the eval field IP (bold & italic) in the regular expression in the rex command.

Labels (2)
Tags (1)
0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @codywsj ,

did you tried to divide the eval statement in two rows?

| rex "(?<file_ip>\d+.\d+.\d+.\d+)"
| eval IP=if(("$spec_IP$"=="*"),file_ip,"$spec_IP$")
| rex "\d{1,2}-\S{3}\s\d{2}:\d{2}:\d{2}.\d{3}\s\S{3}\s\[IP\]\s%NICWIN-4-Security_560_Security[\S\s]+?(?<log_time>(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s\d{2}\s\d{2}:\d{2}:\d{2})[\S\s]+?\S*Object\sName:\s(?<object_name>[\S\s]+?)New\sHandle\sID[\S\s]+?Primary\sUser\sName:\s(?<username>[\S\s]+?)\s+"

Ciao.

Giuseppe

0 Karma

codywsj
Loves-to-Learn

Hi @gcusello ,

what i meant was in the 

eval IP=if(("$spec_IP$"=="*"),file_ip,"$spec_IP$")

 the field "IP", i would like to use it in the regular expression of the rex field:

| rex "\d{1,2}-\S{3}\s\d{2}:\d{2}:\d{2}.\d{3}\s\S{3}\s\[IP\]\s%NICWIN-4-Security_560_Security[\S\s]+?(?<log_time>(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s\d{2}\s\d{2}:\d{2}:\d{2})[\S\s]+?\S*Object\sName:\s(?<object_name>[\S\s]+?)New\sHandle\sID[\S\s]+?Primary\sUser\sName:\s(?<username>[\S\s]+?)\s+"

 By just typing the eval field into the regular expression, it does not work as SPLUNK does not process the "IP" as the field in the eval command rather it just takes it as a word "IP" literally.

\[IP\]

 This is the output i got:

 

BIJ.PNG

 
 
 
Tags (1)
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 ...