Splunk Search

If specified field value does not exist in the current time period do this

splunk3341
Loves-to-Learn Lots

Hi, hoping to get some more insight on my current problem. My problem is the following 

I am using a where clause to capture data for a specific field value. If the specific value does not exist for the current time period I get the following message as a result 'No results found. Try expanding the time range.' Instead of the no results message showing up I would like to display something else. The following is an example.

index=sample_idex sourcetype="smf001"
| fields _time,  FIELD
| lookup sample_lookup.csv system as FIELD output sample_env
| eval e=if(in(sample_env, "env"), 1, 0)
| where e=1
| where FIELD=="value"
| table FIELD

I was thinking of doing something like the following with proper syntax:
| eval where FIELD=="value" else 

 

Labels (3)
Tags (4)
0 Karma

yuanliu
SplunkTrust
SplunkTrust

You are already using if() function.  What is the difference between your pseudo code

| eval where FIELD=="value" else

and

index=sample_idex sourcetype="smf001"
| fields _time,  FIELD
| lookup sample_lookup.csv system as FIELD output sample_env
| eval e=if(in(sample_env, "env"), 1, 0)
| where e=1
| eval FIELD = if(FIELD == "value", FIELD, "display something else")
| table FIELD
0 Karma

richgalloway
SplunkTrust
SplunkTrust

There is no "else" option to the where command.  The trick to solving this problem is to have a query that produces a result even if no events are found.  That's where the appendpipe command comes in handy.

index=sample_idex sourcetype="smf001"
| fields _time,  FIELD
| lookup sample_lookup.csv system as FIELD output sample_env
| eval e=if(in(sample_env, "env"), 1, 0)
| where e=1
| where FIELD=="value"
| appendpipe [ stats count | eval FIELD="something else" | where count=0 | fields - count ]
| table FIELD

 

---
If this reply helps you, Karma would be appreciated.
0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Are you leveraging automation to its fullest potential in your threat detection strategy?Our upcoming Security ...

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...