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
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Tech Talk Recap | Mastering Threat Hunting

Mastering Threat HuntingDive into the world of threat hunting, exploring the key differences between ...

Observability for AI Applications: Troubleshooting Latency

If you’re working with proprietary company data, you’re probably going to have a locally hosted LLM or many ...

Splunk AI Assistant for SPL vs. ChatGPT: Which One is Better?

In the age of AI, every tool promises to make our lives easier. From summarizing content to writing code, ...