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!

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics GA in US-AWS!

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