Splunk Search

Using field eval values in if condition.

veerendra_modi
Loves-to-Learn

I have a search as below:

|rex field=Field "^(?.+?)."
| eval Srvr = if(sourcetype="Type_1", Field_1 , if(sourcetype="Type_2", Field_2, "NA"))
| table Id sourcetype Field_1 Srvr

I have two fields
Field_1 that is in sourcetype="Type_1"
Field_2 that is in sourcetype="Type_2"
I want to take the values of these field in one field that is Srvr in the searxh above.

Please suggest as the query is not picking up the values from the fields Field_1 and Filed_2 but the if condition is working with harcoded values.

Tags (1)
0 Karma

somesoni2
Revered Legend

Try this

....| eval Srvr=coalesce(Field_1, Field_2, "NA") | table ....rest of the command
0 Karma
Get Updates on the Splunk Community!

Detecting Remote Code Executions With the Splunk Threat Research Team

REGISTER NOWRemote code execution (RCE) vulnerabilities pose a significant risk to organizations. If ...

Observability | Use Synthetic Monitoring for Website Metadata Verification

If you are on Splunk Observability Cloud, you may already have Synthetic Monitoringin your observability ...

More Ways To Control Your Costs With Archived Metrics | Register for Tech Talk

Tuesday, May 14, 2024  |  11AM PT / 2PM ET Register to Attend Join us for this Tech Talk and learn how to ...