Splunk Search

Search in eval if

pranaynanda
Path Finder

I want to do something like

...base search | eval Mod=if(Module=Excel OR Module=Word, [search extension=xls OR extension=xslx OR extension=doc OR extension=docx|stats count by extension],"It is not an MS Office document")...

I always keep running into an error that says the search encountered an unexpected character. Please help.

Tags (2)
0 Karma

alemarzu
Motivator

Hi there, please try addin single quotes ' before and after the brackets, like this.

...base search | eval Mod=if(Module=Excel OR Module=Word, '[search extension=xls OR extension=xslx OR extension=doc OR extension=docx|stats count by extension]',"It is not an MS Office document")...

Hope it helps.

0 Karma

pranaynanda
Path Finder

How will I get the output out of it? How will I get results of Mod?

0 Karma

dhivyamu
Explorer

where you able to solve this issue?

0 Karma

DalJeanis
Legend

Try something like...

...base search 
| eval myExt=if(extension="xls" OR extension="xlsx" OR extension="doc" OR extension="docx",extension,"Not MS Office")
| stats count by myExt
0 Karma

pranaynanda
Path Finder

That doesn't work for me. in the base search it's like if Module=$field2$. So if the module matches some value x, I want to search something and display a chart. Otherwise I want to search something else and display a different chart.

0 Karma

dineshraj9
Builder

Can you explain what is the output you are expecting?

Mod is variable and the if condition if first case returns a table and not a single value, and in second case is set with a text message.

0 Karma

pranaynanda
Path Finder

would something like this be valid?

... Module=Excel| eval Modx=if(Module="Excel" , "extension=xls OR extension=xlsx","extension=doc OR extension=docx") | search Modx

0 Karma

pranaynanda
Path Finder

Well basically, in the base search it's something like Module=$field2$ that is guided by a drop down box. I wish to check if the module is A or if module is B then run this search otherwise run a regex.

0 Karma

pranaynanda
Path Finder

I basically want to search different if the condition matches or fails.

0 Karma

niketn
Legend

You will have to give more details of what you are trying to do in else condition and what is the query you might run.

Also sample mock fields for Office and Not-office documents.

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma

pranaynanda
Path Finder

Basically, If the condition happens to be true, I want it to search by extension and return with stats. Otherwise, in the else part, I wish to run a regex.

0 Karma
Get Updates on the Splunk Community!

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...