Splunk Search

How to lookup match on IP return user value within event?

brdr
Contributor

Hi,

I have a lookup table that consists of 1 column. It contains IP addresses.

I have search against an index that has fields IP addresses and user Ids.

I want to match the IPs in the search to the lookup column IP Address. If I find a match I want to output the user ID in the event only.

How do I do that?

Thx

1 Solution

somesoni2
Revered Legend

Try this version

index=eventlog sourcetype=elog [| inputlookup iptest.csv | table src | rename src as src_ip ] | table user

View solution in original post

chandanghoshCTL
Explorer

if you don't have ip filed in raw data and want use rex to take out IP address ,

plus want know how much data coming from that ip for a day.

index=<YourIDXname>earliest=-1d@d sourcetype =<"if any">
|rex "^[^\t\n]*\t(?P<srcip>[^\t]+)"
| eval size=len(_raw)
| stats sum(size) as bytes by srcip
| eval KB=round(bytes/1024,2)
|lookup iptest.csv local=true ManagementIP as srcip OUTPUT SiteIdentifier HostName DeviceManufactorer DeviceType
| search HostName=*
| dedup srcip
| table SiteIdentifier HostName DeviceManufactorer DeviceType srcip KB
| rename srcip as "Matched IPAddress" |sort by SiteIdentifier DeviceManufactorer

0 Karma

somesoni2
Revered Legend

Try this version

index=eventlog sourcetype=elog [| inputlookup iptest.csv | table src | rename src as src_ip ] | table user

brdr
Contributor

Ah. Thank you! I see where I had it wrong.

0 Karma

somesoni2
Revered Legend

So you only want to see user ID for IP Addresses which are present in the lookup? If yes, try like this (assuming both lookup table and index has field name IP_Address, if they are not same, add a rename command in the subsearch)

your base search e.g. index=foo sourcetype=bar.. [| inputlookup Yourlookup.csv | table IP_Address  ]
| table userID

brdr
Contributor

I may have syntax wrong... (but I tried this below to no avail)

lookup table contains a column named 'src'
the ip address field in the event is named 'src_ip', and user field in the event is 'user'
my search is:

index=eventlog sourcetype=elog | table src_ip user

[| inputlookup iptest.csv | table src | rename src as src_ip ] | table user

0 Karma
Get Updates on the Splunk Community!

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

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