Splunk Search

How can I correlate two fields which exist in separate events but share a common field?

pladamsplunk
Explorer

I have a group of events which has the sourcetype "users"

The events within sourcetype=users contain the format:

username
field2
field3
group_access: "group1, group2, group3, groupX"
field5...

I also have logs within the same index which group together under the sourcetype=hosts

...

The events within sourcetype=hosts contain the format:

hostname
field2
field3
group_access: "group1, group2"
field5...

...

I want to correlate users with access to certain groups to hosts which have common group assignment. For example using the events below

user1
field2
field3
group_access: "group1, group3,"
field5...


host1
field2
field3
group_access: "group2"
field5...

host2
field2
field3
group_access: "group1, group3"
field5...

host3
field2
field3
group_access: "group1, group2"
field5...

I want to show that user 1 has access to host 2 and host 3 by correlation of the group_access. How can i create a query which accomplishes this and expresses it in a table

0 Karma
1 Solution

renjith_nair
Legend

@pladamsplunk,

Can you give this a try ?

 index= "your index" (sourcetype="hosts" OR sourcetype="users")
| rex field=_raw "group_access: \"(?<groups>.+)\""| makemv groups delim=","| mvexpand groups
| eventstats values(user) as user by groups
| where isnotnull(hostname)| mvexpand user  | stats values(hostname) as hostnames by user |nomv hostnames

You may remove | rex field=_raw "group_access: \"(?<groups>.+)\"" if you already have a field groups or adjust the rex to match your original events.

Sample data used :

sourcetype=users

user="user1" ,group_access: "group1, group2, group3, groupX"
user="user2",group_access: "group5, group6"
user="user3",group_access: "group1, group6"

sourcetype=hosts

hostname="host1",group_access: "group2"
hostname="host2",group_access: "group1, group3"
hostname="host3",group_access: "group1, group2"

Result

user    hostnames
user1   host1 host2 host3
user3   host2 host3
---
What goes around comes around. If it helps, hit it with Karma 🙂

View solution in original post

renjith_nair
Legend

@pladamsplunk,

Can you give this a try ?

 index= "your index" (sourcetype="hosts" OR sourcetype="users")
| rex field=_raw "group_access: \"(?<groups>.+)\""| makemv groups delim=","| mvexpand groups
| eventstats values(user) as user by groups
| where isnotnull(hostname)| mvexpand user  | stats values(hostname) as hostnames by user |nomv hostnames

You may remove | rex field=_raw "group_access: \"(?<groups>.+)\"" if you already have a field groups or adjust the rex to match your original events.

Sample data used :

sourcetype=users

user="user1" ,group_access: "group1, group2, group3, groupX"
user="user2",group_access: "group5, group6"
user="user3",group_access: "group1, group6"

sourcetype=hosts

hostname="host1",group_access: "group2"
hostname="host2",group_access: "group1, group3"
hostname="host3",group_access: "group1, group2"

Result

user    hostnames
user1   host1 host2 host3
user3   host2 host3
---
What goes around comes around. If it helps, hit it with Karma 🙂

pladamsplunk
Explorer

This worked!

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