Splunk Search

Host Metrics with associated indexes

WebNerdNick
Engager

We're using this query to retrieve metrics on our hosts:

 

index=_internal source=*metrics.log group=tcpin_connections 
| eval sourceHost=if(isnull(hostname), sourceHost,hostname) 
| rename connectionType as connectType
| eval connectType=case(fwdType=="uf","univ fwder", fwdType=="lwf", "lightwt fwder",fwdType=="full", "heavy fwder", connectType=="cooked" or connectType=="cookedSSL","Splunk fwder", connectType=="raw" or connectType=="rawSSL","legacy fwder")
| eval version=if(isnull(version),"pre 4.2",version)
| rename version as Ver
| dedup sourceIp
| table connectType, sourceIp, sourceHost, Ver

 

This gives us everything we need, except for what indexes these hosts are sending data to.

I'm aware of this query to retrieve the indexes and the hosts that are sending data to them:

 

|tstats values(host) where index=* by index

 

 

How can I combine the two, either with a join or a sub search where in the table output, we have a column for index, which would give us a list of indexes the hosts are sending to?  

 

Labels (2)
0 Karma
1 Solution

richgalloway
SplunkTrust
SplunkTrust

This should do it.  It just runs both queries and uses the stats command to regroup the results.

index=_internal source=*metrics.log group=tcpin_connections 
| eval sourceHost=if(isnull(hostname), sourceHost,hostname) 
| rename connectionType as connectType
| eval connectType=case(fwdType=="uf","univ fwder", fwdType=="lwf", "lightwt fwder",fwdType=="full", "heavy fwder", connectType=="cooked" or connectType=="cookedSSL","Splunk fwder", connectType=="raw" or connectType=="rawSSL","legacy fwder")
| eval version=if(isnull(version),"pre 4.2",version)
| rename version as Ver
| dedup sourceIp
| append [ | tstats values(host) as sourceHost where index=* by index | mvexpand sourceHost ]
| stats values(*) as * by sourceHost
| table connectType, sourceIp, sourceHost, Ver, index


 

---
If this reply helps you, Karma would be appreciated.

View solution in original post

0 Karma

richgalloway
SplunkTrust
SplunkTrust

This should do it.  It just runs both queries and uses the stats command to regroup the results.

index=_internal source=*metrics.log group=tcpin_connections 
| eval sourceHost=if(isnull(hostname), sourceHost,hostname) 
| rename connectionType as connectType
| eval connectType=case(fwdType=="uf","univ fwder", fwdType=="lwf", "lightwt fwder",fwdType=="full", "heavy fwder", connectType=="cooked" or connectType=="cookedSSL","Splunk fwder", connectType=="raw" or connectType=="rawSSL","legacy fwder")
| eval version=if(isnull(version),"pre 4.2",version)
| rename version as Ver
| dedup sourceIp
| append [ | tstats values(host) as sourceHost where index=* by index | mvexpand sourceHost ]
| stats values(*) as * by sourceHost
| table connectType, sourceIp, sourceHost, Ver, index


 

---
If this reply helps you, Karma would be appreciated.
0 Karma

WebNerdNick
Engager

I selected this answer as the solution. After coming back to this a few days later, it seems to be reporting what I was looking for. Not sure if there was some odd caching going on when I was testing over and over, but this at least gets me close to what I was looking for.

0 Karma

WebNerdNick
Engager

In my results under the index column, all I get is "_internal".

0 Karma

richgalloway
SplunkTrust
SplunkTrust

Interesting.  I see _internal and non-internal indexes when I run it on one of my sandboxes.

What do you see when you run the tstats query alone?

---
If this reply helps you, Karma would be appreciated.
0 Karma

WebNerdNick
Engager

tstats alone gives me an index column with proper index names (not _index), and then I have a values(host) column that has large listings of the hostnames that send to the related index.

0 Karma

richgalloway
SplunkTrust
SplunkTrust

That sounds about right, although I would expect each index to be on a separate line with the corresponding index name.  Do you have a screenshot?

---
If this reply helps you, Karma would be appreciated.
0 Karma
Get Updates on the Splunk Community!

Continuing Innovation & New Integrations Unlock Full Stack Observability For Your ...

You’ve probably heard the latest about AppDynamics joining the Splunk Observability portfolio, deepening our ...

Monitoring Amazon Elastic Kubernetes Service (EKS)

As we’ve seen, integrating Kubernetes environments with Splunk Observability Cloud is a quick and easy way to ...

Cloud Platform & Enterprise: Classic Dashboard Export Feature Deprecation

As of Splunk Cloud Platform 9.3.2408 and Splunk Enterprise 9.4, classic dashboard export features are now ...