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
Get Updates on the Splunk Community!

Introducing Splunk Enterprise 9.2

WATCH HERE! Watch this Tech Talk to learn about the latest features and enhancements shipped in the new Splunk ...

Adoption of RUM and APM at Splunk

    Unleash the power of Splunk Observability   Watch Now In this can't miss Tech Talk! The Splunk Growth ...

Routing logs with Splunk OTel Collector for Kubernetes

The Splunk Distribution of the OpenTelemetry (OTel) Collector is a product that provides a way to ingest ...