Splunk Enterprise

Looking for a Splunk search to list all indexes that were not used by users for last 30 days

sab007
Engager

Hello Splunkers,

I'm looking for a Splunk search to list all indexes that were not used by users for last 30 days. I've tried the below query from audit logs, but it's not giving me the accurate results. This query is only giving me few indexes but not all the indexes that we used. 

index=_audit sourcetype=audittrail action=search info=granted (NOT TERM(index=_*))
| where match(search, "index\s*(?:=|IN)")
| rex max_match=0 field=search "'search index=(?<used_index>\w+)'"
| stats count by used_index

Appreciate if anyone could share some thoughts on this?

Labels (1)
0 Karma

bowesmana
SplunkTrust
SplunkTrust

In addition to @richgalloway comment, that will give you a list of probable used indexes, but if you then want to compare that to indexes that have received data, you could add the following to his SPL

| eval source="search"
| append [
  | tstats count where index=* by index
  | eval source="data"
  | rename index as used_index
]
| stats values(source) as sources by used_index
| where mvcount(sources)=1 AND sources="data"

This will then show you those indexes that have data in the time period, but have not been seen as being searched.

0 Karma

richgalloway
SplunkTrust
SplunkTrust

I revised the regex a little to better extract index names.

index=_audit sourcetype=audittrail action=search info=granted (NOT TERM(index=_*))
| where match(search, "index\s*(?:=|IN)")
| rex max_match=0 field=search "\bindex\s*=\s*\\\"?(?<used_index>\w+)"
| stats count by used_index

Even with that, however, you won't see all index names.  That's because not all searches specify an index name.  Some may use a macro while others may rely on the role's default indexes.

---
If this reply helps you, Karma would be appreciated.
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Community Content Calendar, September edition

Welcome to another insightful post from our Community Content Calendar! We're thrilled to continue bringing ...

Splunkbase Unveils New App Listing Management Public Preview

Splunkbase Unveils New App Listing Management Public PreviewWe're thrilled to announce the public preview of ...

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Are you leveraging automation to its fullest potential in your threat detection strategy?Our upcoming Security ...