Alerting

How to get scheduled searches and its results

takuyaikeda
Explorer

We operate by using scheduled searches to periodically search through logs collected by Splunk, and trigger actions when log entries matching certain conditions are found.

You can create a list of actions triggered recently (for example, within the past week) by searching for alert_fired="alert_fired" in the _audit index.

At this time, is it possible to join the log entries that matched in each search execution to the list? (I want to know the result of "| loadjob <sid>" for each search.)

The expected output is a table with the search execution time (_time), the search name (ss_name), and the log entries.

Labels (1)
Tags (1)
0 Karma
1 Solution

gcusello
SplunkTrust
SplunkTrust

Hi @takuyaikeda ,

please try this:

index=_audit action=search info=granted search=* NOT "search_id='scheduler" NOT "search='
| history" NOT "user=splunk-system-user" NOT "search='typeahead" NOT "search='
| metadata type=* 
| search totalCount>0" 
| stats count by user search _time 
| sort _time 
| convert ctime(_time) 
| stats list(_time) as time list(search) as search by user

Ciao.

Giuseppe

View solution in original post

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @takuyaikeda ,

please try this:

index=_audit action=search info=granted search=* NOT "search_id='scheduler" NOT "search='
| history" NOT "user=splunk-system-user" NOT "search='typeahead" NOT "search='
| metadata type=* 
| search totalCount>0" 
| stats count by user search _time 
| sort _time 
| convert ctime(_time) 
| stats list(_time) as time list(search) as search by user

Ciao.

Giuseppe

0 Karma

takuyaikeda
Explorer

Thank you for providing valuable information.
While we were able to gather information related to the schedule search execution results using the query you provided, we were unable to obtain the logs detected by the search execution.
However, using the query you provided as a reference, we were able to achieve our desired outcome via the server's CLI, so I would like to report that the issue has been resolved.

The commands we are executing on the server are as follows:

curl -sS -k -u '<ID:PW>' https://localhost:8089/services/search/jobs/export -d search='search index=_audit "user=splunk-system-user" "info=completed" NOT "result_count=0" NOT "savedsearch_name=\"\"" earliest=-2h | stats count by timestamp savedsearch_name search_id' -d output_mode=csv | while read line ; do echo "${line}" | cut -d ',' -f 1 ; echo "${line}" | cut -d ',' -f 2 ; sid=`echo ${line} | cut -d ',' -f 3 | sed "s/'//g"` ; curl -sS -k -u '<ID:PW>' https://localhost:8089/services/search/jobs/export -d search="|loadjob ${sid}" | grep "<field k='_raw'>" | sed -e 's/<\/*field[^>]*>//g' -e 's/<\/*v[^>]*>//g' ; done

(I understand that this is not the optimal solution, but at least I was able to obtain the necessary information with this one-liner.)

Giuseppe, grazie mille

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @takuyaikeda ,

good for you, see next time!

Ciao and happy splunking

Giuseppe

P.S.: Karma Points are appreciated 😉

0 Karma
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!

Take Action Automatically on Splunk Alerts with Red Hat Ansible Automation Platform

 Are you ready to revolutionize your IT operations? As digital transformation accelerates, the demand for ...

Calling All Security Pros: Ready to Race Through Boston?

Hey Splunkers, .conf25 is heading to Boston and we’re kicking things off with something bold, competitive, and ...

Beyond Detection: How Splunk and Cisco Integrated Security Platforms Transform ...

Financial services organizations face an impossible equation: maintain 99.9% uptime for mission-critical ...