task-notify


Nametask-notify JSON
Version 0.8.3 PyPI version JSON
download
home_page
SummaryRun tasks and send notifications if they fail.
upload_time2023-08-14 18:02:00
maintainer
docs_urlNone
authorChristoph Stein
requires_python>=3.9
licenseMIT
keywords tasks email notifications
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Task-notify

Simple 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) failed
```

# Installation

  * Install from pypi: ```pip install task-notify```

# Command line arguments

## -v, --version
Show version

## -h, --help
Show help

## -o, --only_tasks
Only run these tasks, chosen by the "name" property.

Example
```
tasknotify --only_tasks "mytask1" "mytask2"
```

## -t, --only_tags
Only run tasks which have at least one of these tags.

Example
```
tasknotify --only_tags "diskcheck" "informational"
```

## -c, --config,
Path to the configuration file to use

Example
```
tasknotify --config ~/myconfig.json
```

## -p, --pretend
Do not run any tasks, only print what would be run.

## -f, --get_default_config

Place a sample configuration file (```config.json```) in the current working directory

## -s, --show

Show actual output of executed tasks in console log.

## -l, --list

Do not run any tasks, just show a list of available tasks.

# Configuration file

tasknotify 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 ```-f``` command line switch places a default ```config.json``` into your current working directory to serve as a starting point.

## hostname

String 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_methods

The methods of notification can be configured and activated here.

### http_post

HTTP POST message.

  * active: Use this notification method
  * webhook_url: URL to HTTP Post the message to. E.g. the MS Teams webhook url.

### mail

EMail message.

  * active: Use this notification method
  * host:     Mail server
  * port:     Port to use
  * starttls: Use StartTTLS
  * user:     Username
  * password: Password
  * mail_from: Sender Email address
  * mail_to:   Receiver EMail address


## tasks_include_dirs

Optional 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 following ```tasks``` section.

## tasks

Task 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:

*mandatory*

Name of the task. Used in notifications to identify the task, must be unique across all task definitions.
### cmd:

*mandatory*

Actual command to run.
### timeout_s:

*default*: None

Timeout 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*: False

ALWAYS 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_val

*default*: []

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.

# Licensing

Licensed under the MIT license, see also LICENSE.txt

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "task-notify",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": "",
    "keywords": "Tasks,Email,Notifications",
    "author": "Christoph Stein",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/22/72/70ee859cfefae749d06d7ec0a3285003cc65a2b0befe436a7fac5b537e78/task-notify-0.8.3.tar.gz",
    "platform": null,
    "description": "# Task-notify\n\nSimple 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.\n\n\nExample:\n```\n$ tasknotify -c ./config.json --only_tasks \"Free disk space\" \"System uptime\"\n29.01.2023 21:22:41 - INFO: tasknotify 0.8.0\n29.01.2023 21:22:41 - INFO: Queueing worker thread for command: Free disk space\n29.01.2023 21:22:41 - INFO: Queueing worker thread for command: System uptime\n29.01.2023 21:22:41 - WARNING: The command Free disk space failed\n29.01.2023 21:22:41 - INFO: Sending email for task: Free disk space\n29.01.2023 21:22:41 - INFO: 1 command(s) failed\n```\n\n# Installation\n\n  * Install from pypi: ```pip install task-notify```\n\n# Command line arguments\n\n## -v, --version\nShow version\n\n## -h, --help\nShow help\n\n## -o, --only_tasks\nOnly run these tasks, chosen by the \"name\" property.\n\nExample\n```\ntasknotify --only_tasks \"mytask1\" \"mytask2\"\n```\n\n## -t, --only_tags\nOnly run tasks which have at least one of these tags.\n\nExample\n```\ntasknotify --only_tags \"diskcheck\" \"informational\"\n```\n\n## -c, --config,\nPath to the configuration file to use\n\nExample\n```\ntasknotify --config ~/myconfig.json\n```\n\n## -p, --pretend\nDo not run any tasks, only print what would be run.\n\n## -f, --get_default_config\n\nPlace a sample configuration file (```config.json```) in the current working directory\n\n## -s, --show\n\nShow actual output of executed tasks in console log.\n\n## -l, --list\n\nDo not run any tasks, just show a list of available tasks.\n\n# Configuration file\n\ntasknotify 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 ```-f``` command line switch places a default ```config.json``` into your current working directory to serve as a starting point.\n\n## hostname\n\nString 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.\n\n## notify_methods\n\nThe methods of notification can be configured and activated here.\n\n### http_post\n\nHTTP POST message.\n\n  * active: Use this notification method\n  * webhook_url: URL to HTTP Post the message to. E.g. the MS Teams webhook url.\n\n### mail\n\nEMail message.\n\n  * active: Use this notification method\n  * host:     Mail server\n  * port:     Port to use\n  * starttls: Use StartTTLS\n  * user:     Username\n  * password: Password\n  * mail_from: Sender Email address\n  * mail_to:   Receiver EMail address\n\n\n## tasks_include_dirs\n\nOptional list of directories, which will be included. All files in these directories need to be json-files with task definitions, e.g.\n\n```\n{\n    \"tasks\":\n    [\n        {\n            \"name:\"                 \"Get free disk space\",\n            \"cmd\":                  \"df\",\n            \"timeout_s:             10,\n            \"args\":                 [\"-h\", \"--exclude\", \"tmpfs\"],\n            \"cwd\":                  \".\",\n            \"expected_return_val\":  [0],\n            \"notify_on_return_val\": [0],\n            \"force_notify\":         False,\n            \"tags\":                 []\n        },\n        {\n            \"name\":  \"Get host name\",\n            \"cmd\":   \"uname\",\n            \"args\":  [\"-a\"]\n        }\n    ]\n}\n\n```\nNote: Only \"name\" and \"cmd\" are mandatory, all other task attributes will be filled with default values if not supplied.\n\n\nSee also the following ```tasks``` section.\n\n## tasks\n\nTask definitions. Essentially, a task is a command with optional arguments which are run like on a local shell.\n\nEvery task can have the following properties:\n\n### name:\n\n*mandatory*\n\nName of the task. Used in notifications to identify the task, must be unique across all task definitions.\n### cmd:\n\n*mandatory*\n\nActual command to run.\n### timeout_s:\n\n*default*: None\n\nTimeout 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.\n### args:\n\n*default*: []\n\nList of command line arguments.\n### cwd:\n\n*default*: \".\"\n\nWorking directory.\n### expected_return_val:\n\n*default*: [0]\n\nList 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.\n### force_notify:\n\n*default*: False\n\nALWAYS 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).\n### notify_on_return_val\n\n*default*: []\n\nList 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).\n\n### tags:\n\n*default*: []\n\nList of tags for this task.\n\n# Licensing\n\nLicensed under the MIT license, see also LICENSE.txt\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Run tasks and send notifications if they fail.",
    "version": "0.8.3",
    "project_urls": {
        "documentation": "https://gitlab.com/s7one/task-notify",
        "homepage": "https://gitlab.com/s7one/task-notify",
        "repository": "https://gitlab.com/s7one/task-notify"
    },
    "split_keywords": [
        "tasks",
        "email",
        "notifications"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f095633a58be5afa73ab7fd45eed3a12f6bc89ddf71ffd5326b740847155e273",
                "md5": "f708e5805e972ac5227c24b3d3898e50",
                "sha256": "c8fee1a289eeccf60d379cc9864b165ca47086e9d0bf9ad04791acf092ecaf43"
            },
            "downloads": -1,
            "filename": "task_notify-0.8.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f708e5805e972ac5227c24b3d3898e50",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 9255,
            "upload_time": "2023-08-14T18:01:59",
            "upload_time_iso_8601": "2023-08-14T18:01:59.421966Z",
            "url": "https://files.pythonhosted.org/packages/f0/95/633a58be5afa73ab7fd45eed3a12f6bc89ddf71ffd5326b740847155e273/task_notify-0.8.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "227270ee859cfefae749d06d7ec0a3285003cc65a2b0befe436a7fac5b537e78",
                "md5": "b950862d95dd8ed95027436d1bbc6236",
                "sha256": "28ea3662ae3a18a0c6b8262c18214afb6971e51bfee517f37b45e3f677844510"
            },
            "downloads": -1,
            "filename": "task-notify-0.8.3.tar.gz",
            "has_sig": false,
            "md5_digest": "b950862d95dd8ed95027436d1bbc6236",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 8433,
            "upload_time": "2023-08-14T18:02:00",
            "upload_time_iso_8601": "2023-08-14T18:02:00.497130Z",
            "url": "https://files.pythonhosted.org/packages/22/72/70ee859cfefae749d06d7ec0a3285003cc65a2b0befe436a7fac5b537e78/task-notify-0.8.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-08-14 18:02:00",
    "github": false,
    "gitlab": true,
    "bitbucket": false,
    "codeberg": false,
    "gitlab_user": "s7one",
    "gitlab_project": "task-notify",
    "lcname": "task-notify"
}
        
Elapsed time: 0.10262s