Handles sending notifications via the configured notifiers
| 14 | from notifiers.stdout_client import StdoutNotifier |
| 15 | |
| 16 | class Notifier(): |
| 17 | """Handles sending notifications via the configured notifiers |
| 18 | """ |
| 19 | |
| 20 | def __init__(self, notifier_config): |
| 21 | """Initializes Notifier class |
| 22 | |
| 23 | Args: |
| 24 | notifier_config (dict): A dictionary containing configuration for the notifications. |
| 25 | """ |
| 26 | |
| 27 | self.logger = structlog.get_logger() |
| 28 | self.notifier_config = notifier_config |
| 29 | self.last_analysis = dict() |
| 30 | |
| 31 | enabled_notifiers = list() |
| 32 | self.logger = structlog.get_logger() |
| 33 | self.twilio_configured = self._validate_required_config('twilio', notifier_config) |
| 34 | if self.twilio_configured: |
| 35 | self.twilio_client = TwilioNotifier( |
| 36 | twilio_key=notifier_config['twilio']['required']['key'], |
| 37 | twilio_secret=notifier_config['twilio']['required']['secret'], |
| 38 | twilio_sender_number=notifier_config['twilio']['required']['sender_number'], |
| 39 | twilio_receiver_number=notifier_config['twilio']['required']['receiver_number'] |
| 40 | ) |
| 41 | enabled_notifiers.append('twilio') |
| 42 | |
| 43 | self.discord_configured = self._validate_required_config('discord', notifier_config) |
| 44 | if self.discord_configured: |
| 45 | self.discord_client = DiscordNotifier( |
| 46 | webhook=notifier_config['discord']['required']['webhook'], |
| 47 | username=notifier_config['discord']['required']['username'], |
| 48 | avatar=notifier_config['discord']['optional']['avatar'] |
| 49 | ) |
| 50 | enabled_notifiers.append('discord') |
| 51 | |
| 52 | self.slack_configured = self._validate_required_config('slack', notifier_config) |
| 53 | if self.slack_configured: |
| 54 | self.slack_client = SlackNotifier( |
| 55 | slack_webhook=notifier_config['slack']['required']['webhook'] |
| 56 | ) |
| 57 | enabled_notifiers.append('slack') |
| 58 | |
| 59 | self.gmail_configured = self._validate_required_config('gmail', notifier_config) |
| 60 | if self.gmail_configured: |
| 61 | self.gmail_client = GmailNotifier( |
| 62 | username=notifier_config['gmail']['required']['username'], |
| 63 | password=notifier_config['gmail']['required']['password'], |
| 64 | destination_addresses=notifier_config['gmail']['required']['destination_emails'] |
| 65 | ) |
| 66 | enabled_notifiers.append('gmail') |
| 67 | |
| 68 | self.telegram_configured = self._validate_required_config('telegram', notifier_config) |
| 69 | if self.telegram_configured: |
| 70 | self.telegram_client = TelegramNotifier( |
| 71 | token=notifier_config['telegram']['required']['token'], |
| 72 | chat_id=notifier_config['telegram']['required']['chat_id'], |
| 73 | parse_mode=notifier_config['telegram']['optional']['parse_mode'] |