Splunk Enterprise

lookup with if statement through eval.

rahul_mckc_splu
Loves-to-Learn

Here is my search 

index=abc Status=FAILED | eval exception =if(bucket_name=s3-abc, "yes","no") | stats count by bucket_name exception

now if my bucket name is s3-abc, it would print bucket_name=s3-abc and exception=yes, rest all buckets will fall under exception=no.

Now i need to do this task through a lookup, i have a lookup which is buckets.csv and fields is there bucket_name, so I need to see that lookup if the bucket is there then it should print exception=yes rest it should print exception=no. i am doing like this but not getting anything

index=abc Status=FAILED | eval exception =if(|search [|inputlookup bucket.csv |fields bucket_name], "yes","no") | stats count by bucket_name exception

 

Labels (1)
0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

If you csv has bucket_name and exception (always set to "yes") you could try this

index=abc Status=FAILED 
| lookup bucket.csv
| fillnull value="no" exception
| stats count by bucket_name exception
0 Karma

rahul_mckc_splu
Loves-to-Learn

no, it does not seems to be the solution. if you can read what I want.

i need to match my lookup then print "yes" or "no" depends upon if that field value exist.

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

You said you need to find out if bucket name exists in your bucket.csv - this is what lookup does, however, you need a field to look up from the csv, so why not make it exception so the lookup will return exception as yes if it exists in the csv. If this isn't returned, exception will be null, so fillnull can set the nulls to no. Doesn't this get you to the position you wanted i.e. all buckets in the csv will have exception set to yes and all those not in the csv will have exception set to no. If this is not what you are after, please explain your request more clearly.

0 Karma

rahul_mckc_splu
Loves-to-Learn

Here is my search 

index=abc Status=FAILED | eval exception =if(bucket_name=s3-abc, "yes","no") | stats count by bucket_name exception

now if my bucket name is s3-abc, it would print bucket_name=s3-abc and exception=yes, rest all buckets will fall under exception=no.

 

Now i have lookup like this

bucket_name

bucket_name
s3-abc
s3-bcd
 s3-bcw

 so I need to see that lookup, if the bucket is there then it should print exception=yes rest it should print exception=no. i am doing like this but not getting anything

iindex=abc Status=FAILED  | lookup bucket.csv bucket_name| fillnull value="no" exception | stats count by bucket_name exception

then it is not matching and also printing the "yes" it should print if raw logs has any of the buckets in buckets.csv 

0 Karma

rahul_mckc_splu
Loves-to-Learn

worked..thanks alot

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Can you change your lookup so it is like this?

bucket_nameexception
s3-abcyes
s3-bcdyes
 s3-bcwyes
0 Karma

rahul_mckc_splu
Loves-to-Learn

i have 10000 records in raw logs, and i can't maintain all field names in lookup, so i have almost 20-25 exceptions which i am handling in a lookup, and trying to match those in raw logs to have exception printed as "yes" or "no".

0 Karma

rahul_mckc_splu
Loves-to-Learn

My lookup does not have any exception field, and it would not have it. The reason of printing yes and no is to have match field name in lookup.

0 Karma

rahul_mckc_splu
Loves-to-Learn

then it is not matching and also not printing the "yes" , it should print "yes" if raw logs has any of the buckets in buckets.csv it is only printing "no"

 
 
0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Try this:

index=abc Status=FAILED
| join type=left bucket_name [| inputlookup bucket.csv | eval exception="yes"]
| fillnull value="no" exception
| stats count by bucket_name exception
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 ...