Splunk Search

Join a subsearch with the outer search without a common field

smashedpumpkins
Explorer

I'm having trouble taking the results from a subsearch and joining them with the outer search. My goal is to take a set of logs containing external addresses and match them to the corresponding country which the IP block lives in.

I have a lookup definition named "country_to_ip" which contains "startRange", "endRange", and "country3". For example, one line reads "16777216,16777471,Australia". The startRange variable is the first available IP in decimal format and the endRange is the last available IP in decimal format. My logs contain an external IP in decimal format.

In order to pull the corresponding country from the lookup table I need to join the initial table lookup with a subsearch of the logs where "externalAddress>=startRange AND externalAddress<=endRange".

My problem is that it seems I can only join the results when I have matching fields. But in this case, there are no matching fields, only the calculation that determines if the IP is within the range.

I've stripped my search down for simplicity.

index=XXX sourcetype=XXXX externalAddress
| join where externalAddress>=startRange AND externalAddress<=endRange [| inputlookup country_to_ip | fields startRange,endRange,country3]
| table _time,externalAddress,country3

Tags (1)

somesoni2
Revered Legend

Here is what you need to do:

index=XXX sourcetype=XXXX externalAddress | eval joinfield=1 | join max=0 joinfield [|inputlookup country_to_ip |eval joinfield=1| fields startRange,endRange,country3,joinfield] | where externalAddress>=startRange AND externalAddress<=endRange | table _time,externalAddress,country3

dougmartin
Path Finder

Can you add an explanation of the parts.

0 Karma

jtrucks
Splunk Employee
Splunk Employee

Perhaps you need to use appendcols or just a straight subsearch instead of a join. This allows you to do any search you want and concat them together.

--
Jesse Trucks
Minister of Magic
0 Karma

smashedpumpkins
Explorer

I've tried a million and one solutions including both you've mentioned but have had little success. Would you mind putting together a simple sample for me? I would appreciate it. Thank you.

0 Karma
Get Updates on the Splunk Community!

Database Performance Sidebar Panel Now on APM Database Query Performance & Service ...

We’ve streamlined the troubleshooting experience for database-related service issues by adding a database ...

IM Landing Page Filter - Now Available

We’ve added the capability for you to filter across the summary details on the main Infrastructure Monitoring ...

Dynamic Links from Alerts to IM Navigators - New in Observability Cloud

Splunk continues to improve the troubleshooting experience in Observability Cloud with this latest enhancement ...