Splunk® Enterprise

Developing Views and Apps for Splunk Web

Acrobat logo Download manual as PDF

Splunk Enterprise version 7.0 is no longer supported as of October 23, 2019. See the Splunk Software Support Policy for details. For information about upgrading to a supported version, see How to upgrade Splunk Enterprise.
Acrobat logo Download topic as PDF

Create a custom alert action script

Alert action script workflow

The script executes the alert action, such as sending an email or connecting to a web resource. To execute the alert action, the script follows a workflow to get information about the triggered alert and run the alert action.

Typically, the script's workflow looks like this:

  • Check the execution mode, based on command line arguments.
  • Read configuration payload from stdin.
  • Run the alert action.
  • Terminate.

Executable files recognized for introspection

There are several types of executable files recognized for introspection.

Recognized file types
*Nix platforms
  • filename.sh
  • filename.py
  • filename.js
  • filename (executable file without an extension)
Windows platforms
  • filename.bat
  • filename.cmd
  • filename.py
  • filename.js
  • filename.exe

About the execution mode

When the alert action is triggered, the script receives one command line argument, which is the string --execute. This argument indicates the execution mode. Your script should check for the --execute argument. Additional execution modes might be added to this interface.

About the script configuration payload

The alert_actions.conf file and savedsearches.conf file define the content of the configuration payload. Upon startup, the script reads the configuration from the payload. Developers typically create the configuration files before writing the script because of this dependency. The configuration file format is usually XML, but can be JSON if specified in alert_actions.conf.

The configuration payload contains:

  • Global information about the system
    * splunkd session key
    * splunkd management URL

  • Information about the triggered alert and search
    * SID
    * Saved search name
    * Path to file containing the search results
    * URL to the search results

  • Alert action configuration
    * This configuration contains the merged parameters of alert_actions.conf and savedsearches.conf.

  • The first search result

Script runtime threshold

The script runs separately for each triggered alert. It should have a brief execution time and terminate once the alert action execution completes. The script is forcefully terminated if the runtime exceeds its runtime threshold. The default runtime threshold is 5 minutes.

Script naming guidelines

The name of the script should be the same as in its alert_actions.conf stanza. You can add an optional file name extension. For example, myapp/bin/myalertaction.py corresponds to [myalertaction] in alert_actions.conf. For more information, see alert_actions.conf.

Where to place the script or executable

Place the script or executable in the following directory:


Override a script with alert.execute.cmd

Developers can use the alert.execute.cmd option to override the filename of the script to execute. You can use a custom binary and executed arguments for more flexibility. Create a stanza and place the path file and arguments in alert_actions.conf.

. . .
alert.execute.cmd = java.path
alert.execute.cmd.arg.0 =  -jar
alert.execute.cmd.arg.1 = $SPLUNK_HOME/etc/apps/myapp/bin/my.jar
alert.execute.cmd.arg.2 = --execute

Script override considerations

  • If you use a custom path file and arguments, make sure that the stanza name in alert_actions.conf is unique.
  • If you use the alert.execute.cmd settings to specify a command to execute, the arguments are also overridden and not appended. --execute is not added unless manually specified,
  • The external process starts with the arguments exactly as specified in the alert_actions.conf stanza.

.path file for a custom binary

As shown in the example above, specify a .path file for alert.execute.cmd in the custom alert action's alert_actions.conf stanza. Absolute paths are not supported for alert.execute.cmd, although they can be used for its arguments. You can also use environment variables, such as $SPLUNK_HOME$ inside the .path file.

Architecture-specific scripts

You can provide an architecture-specific version of a custom alert action script or executable by placing the appropriate version in the corresponding architecture-specific /bin directory for the app. Architecture-specific directories are available for these Intel-based architectures:

  • Linux
  • Apple (darwin)
  • Windows

Only use a platform-specific directory when it is a requirement for that architecture. If you place a script in an architecture-specific directory, the script runs the appropriate version of the script. Otherwise, a platform-neutral version of the script runs in the default /bin directory.





Last modified on 28 August, 2018
Set up custom alert configuration files
Define a custom alert action user interface

This documentation applies to the following versions of Splunk® Enterprise: 6.5.7, 7.0.0, 7.0.1, 7.0.2, 7.0.3, 7.0.4, 7.0.5, 7.0.6, 7.0.7, 7.0.8, 7.0.9, 7.0.10, 7.0.11, 7.0.13, 7.1.0, 7.1.1, 7.1.2, 7.1.3, 7.1.4, 7.1.5, 7.1.6, 7.1.7, 7.1.8, 7.1.9, 7.1.10, 7.2.0, 7.2.1, 7.2.2, 7.2.3, 7.2.4, 7.2.5, 7.2.6, 7.2.7, 7.2.8, 7.2.9, 7.2.10, 7.3.0, 7.3.1, 7.3.2, 7.3.3, 7.3.4, 7.3.5, 7.3.6, 7.3.8, 8.0.0, 8.0.2, 8.0.3, 8.0.4, 8.0.5, 8.0.6, 8.0.7, 8.0.8, 8.0.9, 8.1.0, 8.1.1, 8.1.2, 8.1.3, 8.1.4, 8.1.5, 8.1.6, 8.1.7, 8.1.8, 8.1.9, 8.1.10, 8.1.11, 8.1.12, 8.2.0, 8.2.1, 8.2.2, 8.2.3, 8.2.4, 8.2.5, 8.2.6, 8.2.7, 8.2.8, 8.2.9, 9.0.0, 9.0.1, 9.0.2, 7.3.7, 7.3.9, 8.0.1, 8.0.10

Was this documentation topic helpful?

You must be logged into splunk.com in order to post comments. Log in now.

Please try to keep this discussion focused on the content covered in this documentation topic. If you have a more general question about Splunk functionality or are experiencing a difficulty with Splunk, consider posting a question to Splunkbase Answers.

0 out of 1000 Characters