Splunk Search

How can I find all scheduled searches that have a timeframe of 'All time'?

cwhelan
Explorer

I am looking to find all scheduled searches within the environment that are using a timeframe of 'All time' e.g. if a search is scheduled to run every hour and is using timeframe of 'All time', I would like to change that search to use 'Last 60 minutes' instead.

Any helpful searches would be appreciated!

Labels (2)
0 Karma
1 Solution

richgalloway
SplunkTrust
SplunkTrust

Here is a search I use to help me find all-time searches.  It's not perfect, but definitely helps.

| rest splunk_server=local /servicesNS/-/-/saved/searches 
| search is_scheduled=1 disabled=0 
| fields dispatch.earliest_time dispatch.latest_time eai:acl.owner eai:acl.sharing search cron_schedule title eai:acl.app schedule_window
| where NOT like(title, "_ScheduledView_%")
| rex field=search "(?<base>^\|+)"
| rex field=base "earliest\s*=\s*(?<earliest>[^\|\s]+)"
| rename dispatch.earliest_time as earliest_time, dispatch.latest_time as latest_time, eai:acl.owner as Owner, eai:acl.sharing as Sharing, eai:acl.app as App
| where (earliest_time<100 AND isnull(earliest) and NOT match(base,"^\|"))
---
If this reply helps you, Karma would be appreciated.

View solution in original post

cwhelan
Explorer

Thanks a lot guys.

Taruchit
Contributor

Hi @cwhelan,

Please share if the below code helps you get the results: -

 

index=_audit search_et="N/A" search_lt="N/A" user!="splunk-system-user"
|rex "\s+savedsearch\_name=\"(?<searchName>[\w\d\_\-]*[^\"])"
|stats count BY searchName

 

Thank you

richgalloway
SplunkTrust
SplunkTrust

This query will detect ad-hoc as well as scheduled searches, but only finds those that actually ran during the search window.  It won't report on those that are scheduled to run at another time.

---
If this reply helps you, Karma would be appreciated.

Taruchit
Contributor

Hi @richgalloway,

Thank you for sharing.

If I modify the rex to avoid capturing empty string for field "savedsearch_name", in your opinion does that help to solve the problem of avoiding ad-hoc searches in the result?

Thank you

0 Karma

richgalloway
SplunkTrust
SplunkTrust

Yes, that would help.  However, because the audit log only contains searches that have run in the time range, the query will not detect searches that are scheduled but have not yet run.

---
If this reply helps you, Karma would be appreciated.

Taruchit
Contributor

Thank you for sharing your inputs.

0 Karma

Taruchit
Contributor

Hi @richgalloway,

It would be very helpful if you could share your inputs/feedback on the SPL that I posted.

Thank you

0 Karma

richgalloway
SplunkTrust
SplunkTrust

Here is a search I use to help me find all-time searches.  It's not perfect, but definitely helps.

| rest splunk_server=local /servicesNS/-/-/saved/searches 
| search is_scheduled=1 disabled=0 
| fields dispatch.earliest_time dispatch.latest_time eai:acl.owner eai:acl.sharing search cron_schedule title eai:acl.app schedule_window
| where NOT like(title, "_ScheduledView_%")
| rex field=search "(?<base>^\|+)"
| rex field=base "earliest\s*=\s*(?<earliest>[^\|\s]+)"
| rename dispatch.earliest_time as earliest_time, dispatch.latest_time as latest_time, eai:acl.owner as Owner, eai:acl.sharing as Sharing, eai:acl.app as App
| where (earliest_time<100 AND isnull(earliest) and NOT match(base,"^\|"))
---
If this reply helps you, Karma would be appreciated.

cwhelan
Explorer

@richgalloway By any chance, is it possible to find how much space on disk a search used? e.g. some users are running ad-hoc searches that frequently exceed 10GB in disk size.

I tried editing Taruchit's search but couldn't find any fields in _audit relating to search size on disk.

0 Karma

richgalloway
SplunkTrust
SplunkTrust

The only place I've found disk usage information is in the Job Inspector.

---
If this reply helps you, Karma would be appreciated.
Get Updates on the Splunk Community!

Introducing the Splunk Community Dashboard Challenge!

Welcome to Splunk Community Dashboard Challenge! This is your chance to showcase your skills in creating ...

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 Certification at ...

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