-
Notifications
You must be signed in to change notification settings - Fork 0
/
manager.py
79 lines (70 loc) · 4.96 KB
/
manager.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import logging
from config import Config
from .slack import SlackNotification
from .discord import DiscordNotification
from .teams import TeamsNotification
class NotificationManager():
def send_info_notification(victim: Victim):
if "notifications" in Config and Config["notifications"]:
for dest, params in Config["notifications"].items():
if not params["new_victims"]:
continue
if params["type"] == "slack":
if not SlackNotification.send_new_victim_notification(params["url"], victim):
logging.error(f"Failed to send new victim notification to Slack workspace \"{dest}\"")
elif params["type"] == "teams":
if not TeamsNotification.send_new_victim_notification(params["url"], victim):
logging.error(f"Failed to send new victim notification to Teams channel \"{dest}\"")
elif params["type"] == "discord":
if not DiscordNotification.send_new_victim_notification(params["url"], victim):
logging.error(f"Failed to send new victim notification to Discord guild \"{dest}\"")
else:
logging.error(f"Attempted to send a new victim notification to an unsupported notification type: {params['type']}")
def send_victim_removed_notification(victim: Victim):
if "notifications" in Config and Config["notifications"]:
for dest, params in Config["notifications"].items():
if not params["removed_victims"]:
continue
if params["type"] == "slack":
if not SlackNotification.send_victim_removed_notification(params["url"], victim):
logging.error(f"Failed to send removed victim notification to Slack workspace \"{dest}\"")
elif params["type"] == "teams":
if not TeamsNotification.send_victim_removed_notification(params["url"], victim):
logging.error(f"Failed to send removed victim notification to Teams channel \"{dest}\"")
elif params["type"] == "discord":
if not DiscordNotification.send_victim_removed_notification(params["url"], victim):
logging.error(f"Failed to send removed victim notification to Discord guild \"{dest}\"")
else:
logging.error(f"Attempted to send a removed victim notification to an unsupported notification type: {params['type']}")
def send_site_down_notification(site: Site):
if "notifications" in Config and Config["notifications"]:
for dest, params in Config["notifications"].items():
if not params["down_sites"]:
continue
if params["type"] == "slack":
if not SlackNotification.send_site_down_notification(params["url"], site):
logging.error(f"Failed to send site down notification to Slack workspace \"{dest}\"")
elif params["type"] == "teams":
if not TeamsNotification.send_site_down_notification(params["url"], site):
logging.error(f"Failed to send site down notification to Teams channel \"{dest}\"")
elif params["type"] == "discord":
if not DiscordNotification.send_site_down_notification(params["url"], site):
logging.error(f"Failed to send site down notification to Discord guild \"{dest}\"")
else:
logging.error(f"Attempted to send a site down notification to an unsupported notification type: {params['type']}")
def send_error_notification(context: str, error: str, fatal: bool = False):
if "notifications" in Config and Config["notifications"]:
for dest, params in Config["notifications"].items():
if not params["errors"]:
continue
if params["type"] == "slack":
if not SlackNotification.send_error_notification(params["url"], context, error, fatal):
logging.error(f"Failed to send error notification to Slack workspace \"{dest}\"")
elif params["type"] == "teams":
if not TeamsNotification.send_error_notification(params["url"], context, error, fatal):
logging.error(f"Failed to send error notification to Teams channel \"{dest}\"")
elif params["type"] == "discord":
if not DiscordNotification.send_error_notification(params["url"], context, error, fatal):
logging.error(f"Failed to send error notification to Discord guild \"{dest}\"")
else:
logging.error(f"Attempted to send a site down notification to an unsupported notification type: {params['type']}")