Splunk Search

How do you include index/sourcetype in table data? (e.g. | table ..., ..., index)

ktrumpol
Path Finder

Hey guys, having a little trouble with this one.

How does one include the index in a table. This doesn't work:

(index=cwdswindows OR index=cwds) earliest_time="-7d"| stats max(_time) AS last_seen by host | sort host | convert timeformat="%m/%d/%Y %H:%M:%S" ctime(last_seen) | table host, last_seen, index

I know it is pretty obvious by which index I search that is obviously the resulting index, but it would be nice if when I am sent the alert I can visibly see the source of the host and time last seen in my data table. I'm guessing since index is not a field, but rather a source full of fields, that is the issue. What is the way around this?

Thanks for any help at all!

0 Karma
1 Solution

grijhwani
Motivator

You need to include index in your "stats" clause, otherwise it will not be present for the table clause.

Initially I thought it was because you had "convert" before rather than after "table", but that works either way.

View solution in original post

gkanapathy
Splunk Employee
Splunk Employee

index is an ordinary field like any other. The reason it does not appear for you is that your stats command removes it. It will remove any field except those specified. If you really only have a single index, you modify your stats command by adding either first(index) as index, adding index to the split-by clause.

grijhwani
Motivator

You need to include index in your "stats" clause, otherwise it will not be present for the table clause.

Initially I thought it was because you had "convert" before rather than after "table", but that works either way.

ktrumpol
Path Finder

Ahah! Including index in my stats clause definitely fixed the issue. Thank you thank you.

0 Karma

ktrumpol
Path Finder

Awesome! Thank you for trying to replicate my search to accurately diagnose the issue. I'll be sure to try this and vote your answer if it works.

0 Karma

asimagu
Builder

it should work like that, you can try without the commas

table host last_seen index
0 Karma

asimagu
Builder

No, I did not use convert, he may be right then

0 Karma

ktrumpol
Path Finder

Did you try using convert in your search? The guy below said that when using convert, it has to come after table.

0 Karma

asimagu
Builder

I tried showing the index field in a table and it worked for me with and without the commas... it's worth trying 😉

0 Karma

ktrumpol
Path Finder

Hm I can't imagine without commas would make the difference, but I will try when I get back to my machine tomorrow! I'll let you know. Thanks.

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!

Catalog Is Now Generally Available on Splunk Cloud Platform

A Unified View of Your Data  Security logs, application events, business data, and historical telemetry often ...

Developer Spotlight with Eduard Lekanne

From Network Engineer to Building Agentic AI for Splunk Eduard Lekanne has been architecting technology ...

From Data Landing to Insight

Search Across More of Your Data Ecosystem The data you need may live in Splunk, high-volume machine data, ...