Splunk Search

Can you help me with an eval that has conditions?

jip31
Motivator

hello,

I use the code below in order to test if a filename exists.

It works, but only when I put the token time on "all time".

When I put a short token time like "last hour", there is no "Yes" or "No" but "Any results" message

When there is "Any results", I want to display "No".

Could you help me please??

index="ai-wkst-windows-fr" sourcetype="tools:flags" filename="ACV-TOUPDATE.$w$*" 
| dedup host 
| eval filename=if(filename=="ACV-TOUPDATE.$w$", "YES", "NO") 
| table filename
Tags (1)
0 Karma
1 Solution

sdchakraborty
Contributor

Hi,

Can you try the below search.

 index="ai-wkst-windows-fr" sourcetype="tools:flags" filename="ACV-TOUPDATE.$w$*" 
 | dedup host 
 | append [|makeresults | eval filename = "Not Defined" | table filename]
 | eval filename=if(filename=="ACV-TOUPDATE.$w$", "YES", "NO") 
| head 1
 | table filename

View solution in original post

0 Karma

sdchakraborty
Contributor

Hi,

Can you try the below search.

 index="ai-wkst-windows-fr" sourcetype="tools:flags" filename="ACV-TOUPDATE.$w$*" 
 | dedup host 
 | append [|makeresults | eval filename = "Not Defined" | table filename]
 | eval filename=if(filename=="ACV-TOUPDATE.$w$", "YES", "NO") 
| head 1
 | table filename
0 Karma

jip31
Motivator

hi
with your code when In change the token time i have two lines with Yes and No.....

0 Karma

sdchakraborty
Contributor

Sorry missed one code, please try the below one,
index="ai-wkst-windows-fr" sourcetype="tools:flags" filename="ACV-TOUPDATE.$w$*"
| dedup host
| append [|makeresults | eval filename = "Not Defined" | table filename]
| eval filename=if(filename=="ACV-TOUPDATE.$w$", "YES", "NO")
| head 1
| table filename

0 Karma

jip31
Motivator

Perfect thanks

0 Karma

sdchakraborty
Contributor

Cool....I edited my main answer as well

0 Karma

harishalipaka
Motivator

hi @jip31

can u try like this

   index="ai-wkst-windows-fr" sourcetype="tools:flags" filename="ACV-TOUPDATE.$w$*" 
     | dedup host 
    |eval token="ACV-TOUPDATE.$w$"
     | eval filename=if(filename==token, "YES", "NO") 
     | table filename
Thanks
Harish
0 Karma

nagarjuna280
Communicator

what is "any results", do you mean "no results found try expanding time range"

Try this

index="ai-wkst-windows-fr" sourcetype="tools:flags" filename=*
| dedup host
| eval filename=if(filename=="ACV-TOUPDATE.$w$", "YES", "NO")
| table filename

0 Karma

jip31
Motivator

Yes i mean "no results found try expanding time range"
you code dont works because with it I have always "No"

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 ...