Skip to content

add webhook support #75

@badsmoke

Description

@badsmoke

hey folks,

in addition to mail support, webhook support would be very nice.

this should be relatively easy to implement, just POST/GET to a url instead of sending the mail.
The url could simply be specified in the config, or as a parameter, the payload should be pretty much identical to the mail.

so e.g. with curl:

gotify GET
curl "https://gotify.domain.tld/message?token=ABASDASDASD" -F "title=btrfs-backup-data" -F "message=some cool text" -F "priority=5"

mattermost POST
curl --silent --output /dev/null -i -X POST -H 'Content-Type: application/json' -d "{\"text\": \"$MESSAGE_TEXT\",\"channel\":\"$CHANNEL\"}" "https://mattermost.domain.tld/hooks/ABASDASDASD"

some little hacky test -> mail.py

import socket
import subprocess
from email.mime.text import MIMEText
import requests


def send(recipient, subject, content):
    if recipient is None:
        return
    #if content is None or len(content) == 0:
    #    return

    # Prepare mail
    msg = MIMEText(content)
    msg['From'] = '%s@%s' % ('btrfs-sxbackup', socket.getfqdn(socket.gethostname()))
    msg['To'] = 'https://gotify.domain.tld/message?token=ABASDASDASD'    #recipient
    msg['Subject'] = subject

    resp = requests.post(msg['To'], json={ "message": content,"priority": 2,"title": msg['From'] })
    retcode = resp.status_code


Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions