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!

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer at Splunk .conf24 ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...

Share Your Ideas & Meet the Lantern team at .Conf! Plus All of This Month’s New ...

Splunk Lantern is Splunk’s customer success center that provides advice from Splunk experts on valuable data ...