Splunk Search

If/then in lookup table match

wweiland
Contributor

I'm trying to use a lookup table in my search. In the nmap event, I'm given a host and port. I have a lookup table that has host, port, and service. For services such as 22 (SSH) that are a given across all systems, I want to use a * as the host so I don't have to enter all the systems into the lookup table. For more rare known services I want to use the actual hostname in the lookup table.

Is it possible to tell the search to match in the lookup table for the host first and if it doesn't find it then try to match the * value? Is there a better way of doing this?

Thanks,
Todd

Tags (2)
0 Karma
1 Solution

kaufmanm
Communicator

You can leave the host value blank to signify a generic or common service, and then use two lookups to get what you want.

services.csv
host,port,service
,22,ssh
splunk01,8089,splunk_management

  • | lookup services port OUTPUT service | lookup services host port OUTPUT service

You might have to output to a different field and then merge them to get it to work, but I imagine the second lookup will overwrite in cases where this host has a special port 22 defined and leave the original value otherwise. The key is you can use your lookup file without specifying a host.

View solution in original post

0 Karma

kaufmanm
Communicator

You can leave the host value blank to signify a generic or common service, and then use two lookups to get what you want.

services.csv
host,port,service
,22,ssh
splunk01,8089,splunk_management

  • | lookup services port OUTPUT service | lookup services host port OUTPUT service

You might have to output to a different field and then merge them to get it to work, but I imagine the second lookup will overwrite in cases where this host has a special port 22 defined and leave the original value otherwise. The key is you can use your lookup file without specifying a host.

0 Karma

wweiland
Contributor

the 2nd lookup did overwrite the 1st lookup so I did have to separate out.

| lookup asset_service_list host as default port as dest_port OUTPUT service as service1 | lookup asset_service_list host as dest_host port as dest_port OUTPUT service as service2 | eval service=if(isnull(service2),service1,service2)

Thanks again for the help!!

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