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!

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...

Observability Simplified: Combining User Experience, Application Performance & ...

Tech Talk Observability Simplified: Combining User Experience, Application Performance & Network ...

Event Series May & June: From Network Visibility to Service Intelligence

Unifying the Network: Moving from Alert Noise to Service Intelligence with Splunk ITSI In today’s hybrid ...