Splunk Search

Using "eventtype" inside "if" function of "eval" command?

woodcock
Esteemed Legend

This is a repost from the forums and includes the question AND THE ANSWER!</p>

QUESTION:

I have an event defined like this in eventtype.conf:

[SOME_EVENT]
search= index=SOME_INDEX (SOME_OTHER_FIELD=A OR SOME_OTHER_FIELD=B OR SOME_OTHER_FIELD=C)

If I search like this, it works:

index=SOME_INDEX | stats sum(eval(if((SOME_OTHER_FIELD==A OR SOME_OTHER_FIELD==B OR SOME_OTHER_FIELD==C),SOME_FIELD,0))) as SOME_TOTAL

But if I search like this, it doesn't:

index=SOME_INDEX | stats sum(eval(if(eventtype==SOME_EVENT,SOME_FIELD,0))) as SOME_TOTAL

For the sake of clarity and supportability (the "OR" clause will continue to grow for this event type), I need to avoid the iteration and use the eventtype.

For reference:
http://www.splunk.com/base/Documentation/latest/SearchReference/CommonEvalFunctions"&gt;http://www.s...

Tags (1)
0 Karma
1 Solution

woodcock
Esteemed Legend

Your fields are numeric, and eventtypes are strings, which means you need to quote them in eval clauses; sure enough, this works:

index=SOME_INDEX | stats sum(eval(if(eventtype=="SOME_EVENT",SOME_FIELD,0))) as SOME_TOTAL

View solution in original post

woodcock
Esteemed Legend

Your fields are numeric, and eventtypes are strings, which means you need to quote them in eval clauses; sure enough, this works:

index=SOME_INDEX | stats sum(eval(if(eventtype=="SOME_EVENT",SOME_FIELD,0))) as SOME_TOTAL

ftk
Motivator

It is fine to answer your own question, but please do so in an actual answer. Please edit your question, remove the answer part, and post an actual answer to the question that can then be accepted. Thanks!

0 Karma

woodcock
Esteemed Legend

Edited/Done.

0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...