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!

CX Day is Coming!

Customer Experience (CX) Day is on October 7th!! We're so excited to bring back another day full of wonderful ...

Strengthen Your Future: A Look Back at Splunk 10 Innovations and .conf25 Highlights!

The Big One: Splunk 10 is Here!  The moment many of you have been waiting for has arrived! We are thrilled to ...

Now Offering the AI Assistant Usage Dashboard in Cloud Monitoring Console

Today, we’re excited to announce the release of a brand new AI assistant usage dashboard in Cloud Monitoring ...