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!

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...

Introducing Splunk Enterprise 9.2

WATCH HERE! Watch this Tech Talk to learn about the latest features and enhancements shipped in the new Splunk ...

Adoption of RUM and APM at Splunk

    Unleash the power of Splunk Observability   Watch Now In this can't miss Tech Talk! The Splunk Growth ...