Splunk Search

lookup Compare value for 2 different Columns

raomu
Explorer

This is my search -

| metadata type=hosts 
| table host 
| lookup Device.csv Hostname as host OUTPUT Status
| where (Status="Active")
| table host 

What I want is to compare either Hostname OR Ip -- lookup Device.csv Hostname OR ip as host OUTPUT status

Tags (2)
0 Karma
1 Solution

pradeepkumarg
Influencer

What you can do is, use the lookup command twice, one for host and one for ip and store it in different values. Then combine and take the non null value from these two fields into a new field


| metadata type=hosts
| table host
| lookup Device.csv Hostname as host OUTPUT Status_host | lookup Device.csv ip as host OUTPUT Status_ip | eval Status=coalesce(Status_host,Status_ip)
| where (Status="Active")
| table host

View solution in original post

pradeepkumarg
Influencer

What you can do is, use the lookup command twice, one for host and one for ip and store it in different values. Then combine and take the non null value from these two fields into a new field


| metadata type=hosts
| table host
| lookup Device.csv Hostname as host OUTPUT Status_host | lookup Device.csv ip as host OUTPUT Status_ip | eval Status=coalesce(Status_host,Status_ip)
| where (Status="Active")
| table host

somesoni2
Revered Legend

Another variation of this could be this

| metadata type=hosts 
| table host 
| lookup Device.csv Hostname as host OUTPUT Status | lookup Device.csv ip as host OUTPUTNEW Status 
| where (Status="Active")
| table host

The OUTPUTNEW in the lookup command will ensure that lookup is done only if first lookup based on Hostname returns no Status.

Get Updates on the Splunk Community!

Webinar Recap | Revolutionizing IT Operations: The Transformative Power of AI and ML ...

The Transformative Power of AI and ML in Enhancing Observability   In the realm of IT operations, the ...

.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 ...