2023-05-17 23:05:59 +00:00
|
|
|
import json
|
|
|
|
import logging
|
|
|
|
import requests
|
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
class WebhookHandler:
|
2023-06-03 16:19:05 +00:00
|
|
|
@staticmethod
|
|
|
|
def get_providers():
|
|
|
|
return [
|
|
|
|
"Discord",
|
|
|
|
"Home Assistant",
|
|
|
|
"Mattermost",
|
|
|
|
"Opsgenie",
|
|
|
|
"Signal",
|
|
|
|
"Slack",
|
|
|
|
"SMTP",
|
|
|
|
"Splunk",
|
|
|
|
"Teams",
|
|
|
|
"Telegram",
|
|
|
|
"Custom",
|
|
|
|
]
|
|
|
|
|
2023-06-03 19:05:21 +00:00
|
|
|
@staticmethod
|
|
|
|
def get_monitored_actions():
|
|
|
|
return ["server_start", "server_stop", "server_crash", "server_backup"]
|
|
|
|
|
2023-05-17 23:05:59 +00:00
|
|
|
@staticmethod
|
2023-06-03 22:11:29 +00:00
|
|
|
def send_discord_webhook(title, url, message, color):
|
2023-05-17 23:05:59 +00:00
|
|
|
dataset = {
|
|
|
|
"username": "Crafty Webhooks",
|
|
|
|
"avatar_url": "https://docs.craftycontrol.com/img/favicon.ico",
|
|
|
|
"embeds": [
|
|
|
|
{
|
|
|
|
"title": title,
|
|
|
|
"description": message,
|
|
|
|
"color": color,
|
|
|
|
}
|
|
|
|
],
|
|
|
|
}
|
2023-06-03 22:11:29 +00:00
|
|
|
requests.post(
|
|
|
|
url,
|
|
|
|
data=json.dumps(dataset),
|
|
|
|
headers={"Content-type": "application/json"},
|
2023-05-17 23:05:59 +00:00
|
|
|
)
|