Splunk Search

How do I compare lookup field to search and print another field in lookup file?

cyrus_thesplunk
Engager

Currently in my logs I am getting the hostname of the users but not their usernames. I created a lookup table that contains hostnames and usernames. I am trying to match the hostname from search to the hostname in the lookup file and then print their correlated username in a table format in the search visualization. 

Lookup file:

hostnameusername
host1user1
host2user2
host3user3
host4user4

 

search:
index=windows sourcetype:eventlogs 
[|inputlookup users.csv | fields hostname username | rename hostname as users]
~~~print username correlated to "users" in the above string.~~~

Labels (1)
0 Karma
1 Solution

woodcock
Esteemed Legend

index="windows" AND sourcetype="eventlogs"
| lookup users.csv hostname AS host OUTPUT username AS users
| table _time Time Hostname Username Src IP

View solution in original post

0 Karma

woodcock
Esteemed Legend

index="windows" AND sourcetype="eventlogs"
| lookup users.csv hostname AS host OUTPUT username AS users
| table _time Time Hostname Username Src IP

0 Karma

cyrus_thesplunk
Engager

Thank you! This worked perfectly

0 Karma

somesoni2
Revered Legend

You would need to use "lookup" command to enrich your data from lookup table fields, like this

index=windows sourcetype:eventlogs 
| lookup users.csv hostname as host OUTPUT username as users
0 Karma

cyrus_thesplunk
Engager

Got it. I understand this part but where are you comparing the hostname in the search to hostname in the lookup file and then printing the username correlated to that hostname in the table.

This is what the search visualization results should look like.

TimeHostnameUsernameSrc IP
5:01 amhost1user1192.xxx.xxx.xxx
5:07 amhost2user2192.xxx.xxx.xxx
5:09 amhost3user3192.xxx.xxx.xxx


Username information is the only thing thats coming from the lookup file. Rest of it comes from the search. 

0 Karma
Get Updates on the Splunk Community!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...