Splunk Search

How to compare two difference sources and return events that have the same hostname in both sources?

chaseto
Explorer

Hello Experts,

I have 2 different sources

source 1 has hostname, ip address
source 2 has hostname, os, os version

I want to do a comparison on both the sources and get the events which have hostname common in both the sources. How this can be done?...Thanks in advance.

0 Karma

somesoni2
Revered Legend

If you just want common host name, try this

(index=foo source=source1) OR (index=bar source=source1) | fields source hostname | stats values(source) as source by hostname | where mvcount(source)=2

OR

(your base search for source1) | stats count by source hostname | append [ search (your base search for source2) |stats count by source hostname] | stats values(source) as source by hostname | where mvcount(source)=2

If you want to merge both the sources to show fields for common hostnames, try this

(index=foo source=source1) OR (index=bar source=source1) | fields source hostname ip_address os os_version | stats values(*) as source by hostname | where mvcount(source)=2

chaseto
Explorer

source1

hostname ip_address

abcq123 123.1.5.22

fwef123 109.1.1.101

source 2
hostname os os_version
abcq123 windows 10
jnknkn122 ubuntu 5

result:

hostname ip_address os os_version

abcq123 123.1.5.22 windows 10

fwef123 109.1.1.101

jnknkn122 ubuntu 5

0 Karma

somesoni2
Revered Legend

Ok.. What are your queries to get data from both the sources?

0 Karma

chaseto
Explorer

ya need the records from both sources

0 Karma

somesoni2
Revered Legend

No, what is the query that you write to get result from the source?

0 Karma

chaseto
Explorer

index=abc source=source1 |join hostname [index=abc source=source2]|table hostname,ipaddress,os,os_version

0 Karma

chaseto
Explorer

Thanks somesh,will try this but In the below query of yours

(index=foo source=source1) OR (index=bar source=source1) | fields source hostname ip_address os os_version | stats values(*) as source by hostname | where mvcount(source)=2

what should I replace source and source1 in mine and in mvcount(source) ...its kinda confusing source,source1.....my sources are source1 and source2

0 Karma

bmacias84
Champion

... | join hostname | table hostname ipaddress, osversion

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

[Puzzles] Solve, Learn, Repeat: Matching cron expressions

This puzzle (first published here) is based on matching timestamps to cron expressions.All the timestamps ...

Design, Compete, Win: Submit Your Best Splunk Dashboards for a .conf26 Pass

Hello Splunkers,  We’re excited to kick off a Splunk Dashboard contest! We know that dashboards are a primary ...

May 2026 Splunk Expert Sessions: Security & Observability

Level Up Your Operations: May 2026 Splunk Expert Sessions Whether you are refining your security posture or ...