def get_full_channel_set(channel_name: str, logger_general: logging.Logger, redis: Optional[RedisApi], alerts_log_file: str, internal_conf: InternalConfig = InternalConf, user_conf: UserConfig = UserConf) -> ChannelSet: # Initialise list of channels with default channels channels = [ _get_console_channel(channel_name, logger_general), _get_log_channel(alerts_log_file, channel_name, logger_general, internal_conf) ] # Initialise backup channel sets with default channels backup_channels_for_telegram = ChannelSet(channels) backup_channels_for_twilio = ChannelSet(channels) # Add telegram alerts to channel set if they are enabled from config file if user_conf.telegram_alerts_enabled: telegram_channel = _get_telegram_channel(channel_name, logger_general, redis, backup_channels_for_telegram, user_conf) channels.append(telegram_channel) else: telegram_channel = None # Add email alerts to channel set if they are enabled from config file if user_conf.email_alerts_enabled: email_channel = _get_email_channel(channel_name, logger_general, redis, user_conf) channels.append(email_channel) else: email_channel = None # Add twilio alerts to channel set if they are enabled from config file if user_conf.twilio_alerts_enabled: twilio_channel = _get_twilio_channel(channel_name, logger_general, redis, backup_channels_for_twilio, internal_conf, user_conf) channels.append(twilio_channel) else: # noinspection PyUnusedLocal twilio_channel = None # Set up email channel as backup channel for telegram and twilio if email_channel is not None: backup_channels_for_telegram.add_channel(email_channel) backup_channels_for_twilio.add_channel(email_channel) # Set up telegram channel as backup channel for twilio if telegram_channel is not None: backup_channels_for_twilio.add_channel(telegram_channel) return ChannelSet(channels)
def setUp(self) -> None: self.logger = logging.getLogger('dummy') self.monitor_name = 'testmonitor' self.counter_channel = CounterChannel(self.logger) self.channel_set = ChannelSet([self.counter_channel]) self.repo_name = 'dummy/repository/' self.releases_page = 'dummy.releases.page' self.redis_prefix = TestInternalConf.redis_github_releases_key_prefix self.db = TestInternalConf.redis_test_database self.host = TestUserConf.redis_host self.port = TestUserConf.redis_port self.password = TestUserConf.redis_password self.redis = RedisApi(self.logger, self.db, self.host, self.port, self.password) self.redis.delete_all_unsafe() try: self.redis.ping_unsafe() except RedisConnectionError: self.fail('Redis is not online.') self.monitor = GitHubMonitor(self.monitor_name, self.channel_set, self.logger, self.redis, self.repo_name, self.releases_page, self.redis_prefix) self.monitor._internal_conf = TestInternalConf
def setUp(self) -> None: self.node_name = 'testnode' self.logger = logging.getLogger('dummy') self.downtime_alert_time_interval = \ TestInternalConf.downtime_alert_time_interval self.downtime_alert_time_interval_with_error_margin = \ self.downtime_alert_time_interval + timedelta(seconds=0.5) self.max_missed_blocks_time_interval = \ TestInternalConf.max_missed_blocks_time_interval self.max_missed_blocks_time_interval_with_error_margin = \ self.max_missed_blocks_time_interval + timedelta(seconds=0.5) self.max_missed_blocks_in_time_interval = \ TestInternalConf.max_missed_blocks_in_time_interval self.full_node = Node(name=self.node_name, rpc_url=None, node_type=NodeType.NON_VALIDATOR_FULL_NODE, pubkey=None, network='', redis=None, internal_conf=TestInternalConf) self.validator = Node(name=self.node_name, rpc_url=None, node_type=NodeType.VALIDATOR_FULL_NODE, pubkey=None, network='', redis=None, internal_conf=TestInternalConf) self.counter_channel = CounterChannel(self.logger) self.channel_set = ChannelSet([self.counter_channel]) self.dummy_exception = DummyException() self.dummy_block_height = -1 self.dummy_block_time = datetime.min + timedelta(days=123) self.dummy_block_time_after_time_interval = \ self.dummy_block_time + \ self.max_missed_blocks_time_interval_with_error_margin self.dummy_missing_validators = -1 self.dummy_voting_power = 1000 self.dummy_no_of_peers = 1000 self.peers_validator_danger_boundary = \ TestInternalConf.validator_peer_danger_boundary self.peers_less_than_validator_danger_boundary = \ self.peers_validator_danger_boundary - 2 self.peers_more_than_validator_danger_boundary = \ self.peers_validator_danger_boundary + 2 self.peers_validator_safe_boundary = \ TestInternalConf.validator_peer_safe_boundary self.peers_less_than_validator_safe_boundary = \ self.peers_validator_safe_boundary - 2 self.peers_more_than_validator_safe_boundary = \ self.peers_validator_safe_boundary + 2 self.peers_full_node_danger_boundary = \ TestInternalConf.full_node_peer_danger_boundary self.peers_less_than_full_node_danger_boundary = \ self.peers_full_node_danger_boundary - 2 self.peers_more_than_full_node_danger_boundary = \ self.peers_full_node_danger_boundary + 2
def setUp(self) -> None: self.alerter_name = 'testalerter' self.logger = logging.getLogger('dummy') self.counter_channel = CounterChannel(self.logger) self.channel_set = ChannelSet([self.counter_channel]) self.mute_key = TestInternalConf.redis_periodic_alive_reminder_mute_key self.par = PeriodicAliveReminder( timedelta(), self.channel_set, self.mute_key, None)
def setUp(self) -> None: self.logger = logging.getLogger('dummy') self.monitor_name = 'testmonitor' self.counter_channel = CounterChannel(self.logger) self.channel_set = ChannelSet([self.counter_channel]) self.repo_name = 'dummy/repository/' self.releases_page = 'dummy.releases.page' self.redis_prefix = TestInternalConf.redis_github_releases_key_prefix self.db = TestInternalConf.redis_test_database self.host = TestUserConf.redis_host self.port = TestUserConf.redis_port self.password = TestUserConf.redis_password self.monitor = GitHubMonitor(self.monitor_name, self.channel_set, self.logger, None, self.repo_name, self.releases_page, self.redis_prefix, TestInternalConf)
def setUp(self) -> None: self.alerter_name = 'testalerter' self.logger = logging.getLogger('dummy') self.counter_channel = CounterChannel(self.logger) self.channel_set = ChannelSet([self.counter_channel]) self.db = TestInternalConf.redis_test_database self.host = TestUserConf.redis_host self.port = TestUserConf.redis_port self.password = TestUserConf.redis_password self.redis = RedisApi(self.logger, self.db, self.host, self.port, self.password) self.redis.delete_all_unsafe() try: self.redis.ping_unsafe() except RedisConnectionError: self.fail('Redis is not online.') self.mute_key = TestInternalConf.redis_periodic_alive_reminder_mute_key self.par = PeriodicAliveReminder( timedelta(), self.channel_set, self.mute_key, self.redis)
def get_full_channel_set(channel_name: str, logger_general: logging.Logger, redis: Optional[RedisApi], alerts_log_file: str, internal_conf: InternalConfig = InternalConf, user_conf: UserConfig = UserConf) -> ChannelSet: # Logger initialisation logger_alerts = create_logger(alerts_log_file, 'alerts', internal_conf.logging_level) # Initialise list of channels with default channels channels = [ ConsoleChannel(channel_name, logger_general), LogChannel(channel_name, logger_general, logger_alerts) ] # Initialise backup channel sets with default channels backup_channels_for_telegram = ChannelSet(channels) backup_channels_for_twilio = ChannelSet(channels) # Add telegram alerts to channel set if user_conf.telegram_alerts_enabled: telegram_bot = TelegramBotApi(user_conf.telegram_alerts_bot_token, user_conf.telegram_alerts_bot_chat_id) telegram_channel = TelegramChannel(channel_name, logger_general, redis, telegram_bot, backup_channels_for_telegram) channels.append(telegram_channel) else: telegram_channel = None # Add email alerts to channel set if user_conf.email_alerts_enabled: email = EmailSender(user_conf.email_smtp, user_conf.email_from) email_channel = EmailChannel(channel_name, logger_general, redis, email, user_conf.email_to) channels.append(email_channel) else: email_channel = None # Add twilio alerts to channel set if user_conf.twilio_alerts_enabled: twilio = TwilioApi(user_conf.twilio_account_sid, user_conf.twilio_auth_token) twilio_channel = TwilioChannel(channel_name, logger_general, redis, twilio, user_conf.twilio_phone_number, user_conf.twilio_dial_numbers, internal_conf.twiml_instructions_url, internal_conf.redis_twilio_snooze_key, backup_channels_for_twilio) channels.append(twilio_channel) else: # noinspection PyUnusedLocal twilio_channel = None # Set up email channel as backup channel for telegram and twilio if email_channel is not None: backup_channels_for_telegram.add_channel(email_channel) backup_channels_for_twilio.add_channel(email_channel) # Set up telegram channel as backup channel for twilio if telegram_channel is not None: backup_channels_for_twilio.add_channel(telegram_channel) return ChannelSet(channels)