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!

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

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...