Incorrect or missing information? Notification Scripts
SABnzbd can run a user-provided script to be executed when a notification needs to be sent. In Config->Notifications you can specify for which type of notifications the script should be executed.
Scripts may use any scripting language available on your system; common choices are Python, Unix shell, and Windows batch scripts. All scripts must be located in the scripts-directory, that can be specified in Config->Folders. Furthermore, the script must be executable. On Linux this means the x-bit must be on. On Windows, the requirement is that the script's extension is listed in your system's PATHEXT environment variable.
If everything went well, SABnzbd expects the script to exit with status code 0. If the returned exit status is non-zero, the output will be shown to the user as an error.
Parameters
The script will receive the parameters described below.
Use %1 in Windows scripts and $1 in Unix scripts. Note that on Windows the input parameters are surrounded by quotes (e.g. "job name").
NOTE Much more information is available to scripts via environment variables, see below!
| Position | Description |
|---|---|
| 1 | Type of notification
|
| 2 | The title of the notification in the user's language |
| 3 | The notification message |
Environment variable: SAB_NOTIFICATION_PARAMETERS |
Parameters (can be specified in Config->Notifications) |
Environment variables
Notification scripts receive a limited amount of extra information via environment variables, in addition to any notification script parameters set in the config:
| Variable | Description |
|---|---|
SAB_VERSION |
The version of SABnzbd |
SAB_PROGRAM_DIR |
The directory where the current SABnzbd instance is located |
SAB_API_KEY |
The API-key that can be used to communicate with SABnzbd via its API. |
SAB_API_URL |
The URL to the SABnzbd API, for example http://127.0.0.1:8080/api.It does not include the required apikey parameter, which is supplied via SAB_API_KEY.
|
SAB_PAR2_COMMAND |
The path to the par2 command on the system running SABnzbd |
SAB_RAR_COMMAND |
The path to the unrar command on the system running SABnzbd |
SAB_7ZIP_COMMAND |
The path to the 7z command on the system running SABnzbd. Not all systems have 7zip installed (it's optional for SABnzbd), so this can also be empty |
Example Python script
To get the parameters in Python, you can do this:
import os
import sys
try:
(scriptname, notification_type, notification_title, notification_text) = sys.argv
except:
print("No commandline parameters found")
sys.exit(1)
parameters = os.environ.get("SAB_NOTIFICATION_PARAMETERS")
# continue script
# Your code goes here
# Success code
sys.exit(0)