Splunk Search

How to compare hosts in Splunk to CMDB export?

DennisVT
Engager

I just came to the realization that this query shows "missing" when it's either missing in Splunk or exists in Splunk but not in the export:

index=_internal

| fields host

| dedup host

| eval host=lower(host)

| append [ | inputlookup Export.csv | rename Hostname as host | eval host=lower(host)]

| stats count by host

| eval count=count-1

| eval Status=if(count=0,"Missing","OK")

| sort Status

| table host Status

What I would like is to change the query to show where it's missing.

Labels (1)
0 Karma
1 Solution

PaulPanther
Motivator

One way could be:

 

index=_internal
| dedup host
| eval host=lower(host)
| append
[| inputlookup Export.csv
| rename hostname as host
| eval source="Export.csv"
| eval host=lower(host)]
| chart count over host by source

 

Faster is the following search with metadata command:

| metadata type=hosts index=_internal 
| eval source="metadata" 
| eval host=lower(host) 
| append 
    [| inputlookup Export.csv 
    | rename hostname as host 
    | eval source="Export.csv" 
    | eval host=lower(host)] 
| chart count over host by source

 

View solution in original post

DennisVT
Engager

The second gives excellent results, thanks for your help

0 Karma

bowesmana
SplunkTrust
SplunkTrust

An addition to the other comments - if you ever use dedup, it probably makes sense to lower before the dedup

 

PickleRick
SplunkTrust
SplunkTrust
| tstats count by host where index=_internal
| fields host
| eval where=1
| append [ | inputlookup Export.csv
    | rename Hostname as host
    | eval host=lower(host)
    | stats count by host
    | fields host
    | eval where=2 ]
| stats sum(where) by host
| where where!=3
| eval status=case(where=1,"index only",where=2,"lookup only",1=1,"error")

 

0 Karma

PaulPanther
Motivator

One way could be:

 

index=_internal
| dedup host
| eval host=lower(host)
| append
[| inputlookup Export.csv
| rename hostname as host
| eval source="Export.csv"
| eval host=lower(host)]
| chart count over host by source

 

Faster is the following search with metadata command:

| metadata type=hosts index=_internal 
| eval source="metadata" 
| eval host=lower(host) 
| append 
    [| inputlookup Export.csv 
    | rename hostname as host 
    | eval source="Export.csv" 
    | eval host=lower(host)] 
| chart count over host by source

 

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!

Why Splunk Customers Should Attend Cisco Live 2026 Las Vegas

Why Splunk Customers Should Attend Cisco Live 2026 Las Vegas     Cisco Live 2026 is almost here, and this ...

What Is the Name of the USB Key Inserted by Bob Smith? (BOTS Hint, Not the Answer)

Hello Splunkers,   So you searched, “what is the name of the usb key inserted by bob smith?”  Not gonna lie… ...

Automating Threat Operations and Threat Hunting with Recorded Future

    Automating Threat Operations and Threat Hunting with Recorded Future June 29, 2026 | Register   Is your ...