Alerts in Splunk are equivalent to cron or batch jobs. An alert is comprised of: saved search terms, a schedule to run it, rules to trigger it and actions to perform. Alerts can be sent via email or RSS, or used to trigger a shell script. Any saved search can be turned into an alert.
via SplunkWebYou can set up alerts either through the Saved Search tab of the Admin link. By clicking on any saved search, you can set up an alert:

Or you can configure an alert through the saved search link in the drop down menu next to the search box. Click on the Schedule & Alerts tab:

Schedule
Alert Rules
Alert Actions
Alert History
When you receive alerts, any fields included in your search will also be displayed. You can edit the saved search to change which fields are displayed in your alert.
To eliminate a field, pipe your search to fields - $FIELDNAME. To add a field, pipe your search to fields + $FIELDNAME. You can add or subtract any number of fields -- just separate them with a comma: fields - $FIELD1, $FIELD2 + $FIELD3, $FIELD4.
For example:
This search will keep the sourcetype field from appearing in your alerts.
via configuration filesYou can configure the above aspects through savedsearches.conf. Copy savedsearches.conf from $SPLUNK_HOME/etc/bundles/default/ into $SPLUNK_HOME/etc/bundles/local/. Open $SPLUNK_HOME/etc/bundles/local/savedsearches.conf file. You can edit all of the fields below:
[<Splunk name>]
* Name of the saved Splunk (header)
query = <string>
* Actual query terms of this saved Splunk (eg. index::sampledata http NOT 500)
isglobal = <integer>
* If isglobal is set to 1, everyone can see/use this Splunk
Possible values: 1/0.
counttype = <string>
* Which count to compare the quantity against relation
Possible values: "number of events", "number of hosts",
"number of sources", "number of sourcetypes"
relation = <string>
* How to compare against count
Possible values: "greater than", "less than", "equal to",
"drops by", "rises by"
quantity = <integer>
* Number to compare against the number returned for the given counttype
schedule = <string>
* Cron style schedule (i.e. */12 * * * *)
action_script = <string>
* Name of shell script to run
action_rss = <integer>
* Whether or not to create an rss link
Possible values: 1/0
action_email = <string>
* Comma delimited list of email addresses to send to
sendresults = <integer>
* Whether or not to send the results along with the email/shell script
Possible values: 1/0For example:
[sudoalert] action_rss = 1 counttype = number of events disabled = false enableSched = 1 isGlobal = 0 quantity = 0 query = sudo relation = greater than schedule = */12 * * * * sendresults = 0 userid = 1
Your alert can trigger a shell script.
Specify the name of the script file to run when a saved search triggers an alert. You don't need to provide the path to the script if the script is located under $SPLUNK_HOME/bin/scripts/.
Command line arguments passed to the script are:
$1 - number of events returned when search run $2 - searched terms saved at the time saved search was created $3 - fully qualified query string, the way query is run internally $4 - saved search name $5 - trigger reason for the alert $6 - encoded http link to the saved search results $7 - tags that have been saved against this saved search, if there are any.
For examples on how scripts can be configured to work with alerts, please see send SNMP traps and send syslog events.
Comments
If you want fairly quick alerts when something new happens:
- create the search
- schedule the search, say for 5 minutes
- limit the search to "startminutesago=5"
- set the "If" "number of events" "greater than" "0"
As one might imagine, overlapping the schedule and startminutes will get you more alerts than you want. Setting "if" to "always" will alert even when no new events occur.
Posted by mgh4 on Dec 12 2007, 1:34pm