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!

More Control Over Your Monitoring Costs with Archived Metrics!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...

New in Observability Cloud - Explicit Bucket Histograms

Splunk introduces native support for histograms as a metric data type within Observability Cloud with Explicit ...

Updated Team Landing Page in Splunk Observability

We’re making some changes to the team landing page in Splunk Observability, based on your feedback. The ...