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!

Enterprise Security Content Update (ESCU) | New Releases

In November, the Splunk Threat Research Team had one release of new security content via the Enterprise ...

Index This | Divide 100 by half. What do you get?

November 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with this ...

Stay Connected: Your Guide to December Tech Talks, Office Hours, and Webinars!

❄️ Celebrate the season with our December lineup of Community Office Hours, Tech Talks, and Webinars! ...