Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add webhook support #75

Open
badsmoke opened this issue Apr 11, 2022 · 1 comment
Open

add webhook support #75

badsmoke opened this issue Apr 11, 2022 · 1 comment

Comments

@badsmoke
Copy link

badsmoke commented Apr 11, 2022

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


@masc3d
Copy link
Owner

masc3d commented Apr 11, 2022

mail as well as this should rather be supported via external scripts. id accept a PR for this if its implemented well, but dont have time to maintain it myself atm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants