Package: task-notify
Task-notifySimple solution to run scripts/commands and send notifications via email or webhook (e.g. MS Teams) if it fails. Works great with cron to automate tasks.Example:$ tasknotify -c ./config.json --only_tasks "Free disk space" "System uptime"
29.01.2023 21:22:41 - INFO: tasknotify 0.8.0
29.01.2023 21:22:41 - INFO: Queueing worker thread for command: Free disk space
29.01.2023 21:22:41 - INFO: Queueing worker thread for command: System uptime
29.01.2023 21:22:41 - WARNING: The command Free disk space failed
29.01.2023 21:22:41 - INFO: Sending email for task: Free disk space
29.01.2023 21:22:41 - INFO: 1 command(s) failedInstallationInstall from pypi:pip install task-notifyCommand line arguments-v, --versionShow version-h, --helpShow help-o, --only_tasksOnly run these tasks, chosen by the "name" property.Exampletasknotify --only_tasks "mytask1" "mytask2"-t, --only_tagsOnly run tasks which have at least one of these tags.Exampletasknotify --only_tags "diskcheck" "informational"-c, --config,Path to the configuration file to useExampletasknotify --config ~/myconfig.json-p, --pretendDo not run any tasks, only print what would be run.-f, --get_default_configPlace a sample configuration file (config.json) in the current working directory-s, --showShow actual output of executed tasks in console log.-l, --listDo not run any tasks, just show a list of available tasks.Configuration filetasknotify uses one configuration file to keep all needed information. Optionally, task definitions can also be split into several files and included. Running task-notify with the-fcommand line switch places a defaultconfig.jsoninto your current working directory to serve as a starting point.hostnameString describing the host where tasknotify runs. This gets included into notification messages to distinguish the messages origin if you run the script on more than one host.notify_methodsThe methods of notification can be configured and activated here.http_postHTTP POST message.active: Use this notification methodwebhook_url: URL to HTTP Post the message to. E.g. the MS Teams webhook url.mailEMail message.active: Use this notification methodhost:     Mail serverport:     Port to usestarttls: Use StartTTLSuser:     Usernamepassword: Passwordmail_from: Sender Email addressmail_to:   Receiver EMail addresstasks_include_dirsOptional list of directories, which will be included. All files in these directories need to be json-files with task definitions, e.g.{
    "tasks":
    [
        {
            "name:"                 "Get free disk space",
            "cmd":                  "df",
            "timeout_s:             10,
            "args":                 ["-h", "--exclude", "tmpfs"],
            "cwd":                  ".",
            "expected_return_val":  [0],
            "notify_on_return_val": [0],
            "force_notify":         False,
            "tags":                 []
        },
        {
            "name":  "Get host name",
            "cmd":   "uname",
            "args":  ["-a"]
        }
    ]
}Note: Only "name" and "cmd" are mandatory, all other task attributes will be filled with default values if not supplied.See also the followingtaskssection.tasksTask definitions. Essentially, a task is a command with optional arguments which are run like on a local shell.Every task can have the following properties:name:mandatoryName of the task. Used in notifications to identify the task, must be unique across all task definitions.cmd:mandatoryActual command to run.timeout_s:default: NoneTimeout in seconds. If the command does not finish/return within this time, the process will be killed and the task will be considered to have failed.args:default: []List of command line arguments.cwd:default: "."Working directory.expected_return_val:default: [0]List of expected return value(s) for this task. If the actual return value does not match one of these values, then the task will be considered failed and a notification will be send.force_notify:default: FalseALWAYS send a notification about this task, regardless of the return value. The return value will still be used to check if the task has failed (thus resulting in another notification message).notify_on_return_valdefault: []List of return values which will lead to sending a notification about this task. The return value will still be used to check if the task has failed (thus resulting in another notification message).tags:default: []List of tags for this task.LicensingLicensed under the MIT license, see also LICENSE.txt