Splunk Search

How to edit my Eval search so that if "field=null", do nothing and if "field=not null", replace value?

ltrand
Contributor

So I'm trying to build an asset table, and update fields based on select criteria. What I'm getting stuck on is I want nothing to happen if there isn't a match, but I want an action if there is a match.

For example, I have a table as follows:
asset_lookup: fields: ip,dns,bunit, category,priority

I have another that is as follows:
hva_asset_lookup: fields: host, system_group

So the asset_lookup, when generated, sets the priority to "medium". I want to override that if there is a match on the hva_asset_lookup, so I do the following search:

| inputlookup asset_lookup 
| lookup hva_assets host AS ip OUTPUT system_group
| eval priority=if(isnull(FISMA_system_name),"medium","critical")

This works, but I'd rather get rid of the "null" action so that I could chain together the logic and continue to change the priority without overriding the prior settings. For example, if I follow that up with this:

| eval priority=case(bunit="hq","high")

Everything that doesn't match is overridden to null. And if I do it prior to the if(isnull()) eval, then the high is overridden. So, how do I override a field only if my eval matches, and to not touch is otherwise?

0 Karma
1 Solution

somesoni2
SplunkTrust
SplunkTrust

How about this. If your condition matches, it'll overwrite the the value of priority to high, in all other cases, will keep the same value (what existed before this command).

 | eval priority=case(bunit="hq","high",true(),priority)

or

 | eval priority=if(bunit="hq","high",priority)

View solution in original post

DalJeanis
SplunkTrust
SplunkTrust

The case statement is the issue. if bunit is not "hq", then the entire statement returns no value.

somesoni2's code snippets are correct (either is equivalent).

0 Karma

somesoni2
SplunkTrust
SplunkTrust

How about this. If your condition matches, it'll overwrite the the value of priority to high, in all other cases, will keep the same value (what existed before this command).

 | eval priority=case(bunit="hq","high",true(),priority)

or

 | eval priority=if(bunit="hq","high",priority)

DalJeanis
SplunkTrust
SplunkTrust

suggestion - somesoni2 - you should move this comment to an answer so that ltrand can accept it.

0 Karma

ltrand
Contributor

Awesome, thanks! I didn't even think about passing the value back in!

0 Karma
Get Updates on the Splunk Community!

Enterprise Security Content Update (ESCU) | New Releases

In the last month, the Splunk Threat Research Team (STRT) has had 2 releases of new security content via the ...

Announcing the 1st Round Champion’s Tribute Winners of the Great Resilience Quest

We are happy to announce the 20 lucky questers who are selected to be the first round of Champion's Tribute ...

We’ve Got Education Validation!

Are you feeling it? All the career-boosting benefits of up-skilling with Splunk? It’s not just a feeling, it's ...