Class for handling webhook notifications
| 7 | from notifiers.utils import NotifierUtils |
| 8 | |
| 9 | class WebhookNotifier(NotifierUtils): |
| 10 | """Class for handling webhook notifications |
| 11 | """ |
| 12 | |
| 13 | def __init__(self, url, username, password): |
| 14 | self.logger = structlog.get_logger() |
| 15 | self.url = url |
| 16 | self.username = username |
| 17 | self.password = password |
| 18 | |
| 19 | |
| 20 | def notify(self, message): |
| 21 | """Sends the message. |
| 22 | |
| 23 | Args: |
| 24 | message (str): The message to send. |
| 25 | """ |
| 26 | |
| 27 | if self.username and self.password: |
| 28 | request = requests.post(self.url, json=message, auth=(self.username, self.password)) |
| 29 | else: |
| 30 | request = requests.post(self.url, json=message) |
| 31 | |
| 32 | if not request.status_code == requests.codes.ok: |
| 33 | self.logger.error("Request failed: %s - %s", request.status_code, request.content) |