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!

Developer Spotlight with Paul Stout

Welcome to our very first developer spotlight release series where we'll feature some awesome Splunk ...

State of Splunk Careers 2024: Maximizing Career Outcomes and the Continued Value of ...

For the past four years, Splunk has partnered with Enterprise Strategy Group to conduct a survey that gauges ...

Data-Driven Success: Splunk & Financial Services

Splunk streamlines the process of extracting insights from large volumes of data. In this fast-paced world, ...