def _initialise_monitor_logger(monitor_display_name: str, monitor_module_name: str) -> logging.Logger: # Try initialising the logger until successful. This had to be done # separately to avoid instances when the logger creation failed and we # attempt to use it. while True: try: monitor_logger = create_logger( env.MONITORS_LOG_FILE_TEMPLATE.format(monitor_display_name), monitor_module_name, env.LOGGING_LEVEL, True) break except Exception as e: msg = get_initialisation_error_message(monitor_display_name, e) # Use a dummy logger in this case because we cannot create the # monitor's logger. log_and_print(msg, logging.getLogger('DUMMY_LOGGER')) # sleep before trying again time.sleep(RE_INITIALISE_SLEEPING_PERIOD) return monitor_logger
def _initialise_transformer_redis( transformer_name: str, transformer_logger: logging.Logger) -> RedisApi: # Try initialising the Redis API until successful. This had to be done # separately to avoid instances when Redis creation failed and we # attempt to use it. while True: try: redis = RedisApi(logger=transformer_logger.getChild( RedisApi.__name__), db=env.REDIS_DB, host=env.REDIS_IP, port=env.REDIS_PORT, namespace=env.UNIQUE_ALERTER_IDENTIFIER) break except Exception as e: msg = get_initialisation_error_message(transformer_name, e) log_and_print(msg, transformer_logger) # sleep before trying again time.sleep(RE_INITIALISE_SLEEPING_PERIOD) return redis
def _initialise_store(store_type: Type[T], store_display_name: str) -> T: store_logger = _initialise_store_logger(store_display_name, store_type.__name__) # Try initialising the store until successful while True: try: rabbitmq = RabbitMQApi( logger=store_logger.getChild(RabbitMQApi.__name__), host=env.RABBIT_IP) store = store_type(store_display_name, store_logger, rabbitmq) log_and_print("Successfully initialised {}".format( store_display_name), store_logger) break except Exception as e: msg = get_initialisation_error_message(store_display_name, e) log_and_print(msg, store_logger) # sleep before trying again time.sleep(RE_INITIALISE_SLEEPING_PERIOD) return store
def _initialise_logger(component_display_name: str, component_module_name: str, log_file_template: str) -> logging.Logger: # Try initialising the logger until successful. This had to be done # separately to avoid instances when the logger creation failed and we # attempt to use it. while True: try: new_logger = create_logger( log_file_template.format(component_display_name), component_module_name, env.LOGGING_LEVEL, rotating=True) break except Exception as e: msg = get_initialisation_error_message(component_display_name, e) # Use a dummy logger in this case because we cannot create the # manager's logger. log_and_print(msg, dummy_logger) log_and_print(get_reattempting_message(component_display_name), dummy_logger) # sleep before trying again time.sleep(RE_INITIALISE_SLEEPING_PERIOD) return new_logger
def _initialise_health_checker_manager() -> HealthCheckerManager: manager_display_name = HEALTH_CHECKER_MANAGER_NAME health_checker_manager_logger = _initialise_logger( manager_display_name, HealthCheckerManager.__name__, env.MANAGERS_LOG_FILE_TEMPLATE) # Attempt to initialise the health checker manager while True: try: health_checker_manager = HealthCheckerManager( health_checker_manager_logger, manager_display_name) break except Exception as e: msg = get_initialisation_error_message(manager_display_name, e) log_and_print(msg, health_checker_manager_logger) log_and_print(get_reattempting_message(manager_display_name), health_checker_manager_logger) # sleep before trying again time.sleep(RE_INITIALISE_SLEEPING_PERIOD) return health_checker_manager
def _initialise_config_manager() -> Tuple[ConfigsManager, logging.Logger]: display_name = CONFIGS_MANAGER_NAME config_manager_logger = _initialise_logger(display_name, ConfigsManager.__name__, env.CONFIG_MANAGER_LOG_FILE) rabbit_ip = env.RABBIT_IP while True: try: config_manager = ConfigsManager(display_name, config_manager_logger, '../config', rabbit_ip) return config_manager, config_manager_logger except Exception as e: # This is already logged, we need to try again. This exception # should not happen, but if it does the program can't fully start # up log_and_print(get_initialisation_error_message(display_name, e), config_manager_logger) log_and_print(get_reattempting_message(display_name), config_manager_logger) # sleep before trying again time.sleep(RE_INITIALISE_SLEEPING_PERIOD)
def start(self) -> None: log_and_print("{} started.".format(self), self._logger) self._initialise_rabbitmq() while True: try: # Before listening for new data send the data waiting to be sent # in the publishing queue. If the message is not routed, start # consuming and perform sending later. try: self._send_data() except MessageWasNotDeliveredException as e: self._logger.exception(e) self._listen_for_data() except (pika.exceptions.AMQPConnectionError, pika.exceptions.AMQPChannelError) as e: # If we have either a channel error or connection error, the # channel is reset, therefore we need to re-initialise the # connection or channel settings raise e except Exception as e: self._logger.exception(e) raise e
def _initialise_heartbeat_handler() -> HeartbeatHandler: component_display_name = HEARTBEAT_HANDLER_NAME logger = _initialise_health_checker_logger(component_display_name, HeartbeatHandler.__name__) redis = _initialise_component_redis(component_display_name, logger) # Try initialising the heartbeat handler until successful while True: try: heartbeat_handler = HeartbeatHandler(logger, redis, component_display_name) log_and_print( "Successfully initialised {}".format(component_display_name), logger) break except Exception as e: msg = get_initialisation_error_message(component_display_name, e) log_and_print(msg, logger) # sleep before trying again time.sleep(RE_INITIALISE_SLEEPING_PERIOD) return heartbeat_handler
def _initialise_ping_publisher() -> PingPublisher: component_display_name = PING_PUBLISHER_NAME logger = _initialise_health_checker_logger(component_display_name, PingPublisher.__name__) redis = _initialise_component_redis(component_display_name, logger) # Try initialising the ping publisher until successful while True: try: ping_publisher = PingPublisher(30, logger, redis, component_display_name) log_and_print( "Successfully initialised {}".format(component_display_name), logger) break except Exception as e: msg = get_initialisation_error_message(component_display_name, e) log_and_print(msg, logger) # sleep before trying again time.sleep(RE_INITIALISE_SLEEPING_PERIOD) return ping_publisher
def _initialise_twilio_alerts_handler( account_sid: str, auth_token: str, channel_id: str, channel_name: str, call_from: str, call_to: List[str], twiml: str, twiml_is_url: bool) \ -> TwilioAlertsHandler: # Handler display name based on channel name handler_display_name = TWILIO_ALERTS_HANDLER_NAME_TEMPLATE.format( channel_name) handler_logger = _initialise_channel_handler_logger( handler_display_name, TwilioAlertsHandler.__name__) # Try initialising handler until successful while True: try: twilio_api = TwilioApi(account_sid, auth_token) twilio_channel = TwilioChannel( channel_name, channel_id, handler_logger.getChild(TwilioChannel.__name__), twilio_api) rabbitmq = RabbitMQApi(logger=handler_logger.getChild( RabbitMQApi.__name__), host=env.RABBIT_IP) twilio_alerts_handler = TwilioAlertsHandler( handler_display_name, handler_logger, rabbitmq, twilio_channel, call_from, call_to, twiml, twiml_is_url) log_and_print( "Successfully initialised {}".format(handler_display_name), handler_logger) break except Exception as e: msg = get_initialisation_error_message(handler_display_name, e) log_and_print(msg, handler_logger) # sleep before trying again time.sleep(RE_INITIALISE_SLEEPING_PERIOD) return twilio_alerts_handler
def _initialise_pagerduty_alerts_handler( integration_key: str, channel_id: str, channel_name: str) -> PagerDutyAlertsHandler: # Handler display name based on channel name handler_display_name = PAGERDUTY_ALERTS_HANDLER_NAME_TEMPLATE.format( channel_name) handler_logger = _initialise_channel_handler_logger( handler_display_name, PagerDutyAlertsHandler.__name__) # Try initialising handler until successful while True: try: pagerduty_api = PagerDutyApi(integration_key) pagerduty_channel = PagerDutyChannel( channel_name, channel_id, handler_logger.getChild(PagerDutyChannel.__name__), pagerduty_api) rabbitmq = RabbitMQApi(logger=handler_logger.getChild( RabbitMQApi.__name__), host=env.RABBIT_IP) pagerduty_alerts_handler = PagerDutyAlertsHandler( handler_display_name, handler_logger, rabbitmq, pagerduty_channel, env.CHANNELS_MANAGER_PUBLISHING_QUEUE_SIZE) log_and_print( "Successfully initialised {}".format(handler_display_name), handler_logger) break except Exception as e: msg = get_initialisation_error_message(handler_display_name, e) log_and_print(msg, handler_logger) # sleep before trying again time.sleep(RE_INITIALISE_SLEEPING_PERIOD) return pagerduty_alerts_handler
def _initialise_opsgenie_alerts_handler( api_key: str, eu_host: bool, channel_id: str, channel_name: str) -> OpsgenieAlertsHandler: # Handler display name based on channel name handler_display_name = OPSGENIE_ALERTS_HANDLER_NAME_TEMPLATE.format( channel_name) handler_logger = _initialise_channel_handler_logger( handler_display_name, OpsgenieAlertsHandler.__name__) # Try initialising handler until successful while True: try: opsgenie_api = OpsgenieApi(api_key, eu_host) opsgenie_channel = OpsgenieChannel( channel_name, channel_id, handler_logger.getChild(OpsgenieChannel.__name__), opsgenie_api) rabbitmq = RabbitMQApi(logger=handler_logger.getChild( RabbitMQApi.__name__), host=env.RABBIT_IP) opsgenie_alerts_handler = OpsgenieAlertsHandler( handler_display_name, handler_logger, rabbitmq, opsgenie_channel, env.CHANNELS_MANAGER_PUBLISHING_QUEUE_SIZE) log_and_print( "Successfully initialised {}".format(handler_display_name), handler_logger) break except Exception as e: msg = get_initialisation_error_message(handler_display_name, e) log_and_print(msg, handler_logger) # sleep before trying again time.sleep(RE_INITIALISE_SLEEPING_PERIOD) return opsgenie_alerts_handler
def _initialise_telegram_alerts_handler( bot_token: str, bot_chat_id: str, channel_id: str, channel_name: str) -> TelegramAlertsHandler: # Handler display name based on channel name handler_display_name = TELEGRAM_ALERTS_HANDLER_NAME_TEMPLATE.format( channel_name) handler_logger = _initialise_channel_handler_logger( handler_display_name, TelegramAlertsHandler.__name__) # Try initialising handler until successful while True: try: telegram_bot = TelegramBotApi(bot_token, bot_chat_id) telegram_channel = TelegramChannel( channel_name, channel_id, handler_logger.getChild(TelegramChannel.__name__), telegram_bot) rabbitmq = RabbitMQApi(logger=handler_logger.getChild( RabbitMQApi.__name__), host=env.RABBIT_IP) telegram_alerts_handler = TelegramAlertsHandler( handler_display_name, handler_logger, rabbitmq, telegram_channel, env.CHANNELS_MANAGER_PUBLISHING_QUEUE_SIZE) log_and_print( "Successfully initialised {}".format(handler_display_name), handler_logger) break except Exception as e: msg = get_initialisation_error_message(handler_display_name, e) log_and_print(msg, handler_logger) # sleep before trying again time.sleep(RE_INITIALISE_SLEEPING_PERIOD) return telegram_alerts_handler
def _initialise_health_checker_logger( component_display_name: str, component_module_name: str) \ -> logging.Logger: # Try initialising the logger until successful. This had to be done # separately to avoid instances when the logger creation failed and we # attempt to use it. while True: try: component_logger = create_logger( env.HEALTH_CHECKER_LOG_FILE_TEMPLATE.format( component_display_name), component_module_name, env.LOGGING_LEVEL, rotating=True) break except Exception as e: msg = get_initialisation_error_message(component_display_name, e) # Use a dummy logger in this case because we cannot create the # transformer's logger. log_and_print(msg, logging.getLogger('DUMMY_LOGGER')) # sleep before trying again time.sleep(RE_INITIALISE_SLEEPING_PERIOD) return component_logger
def on_terminate(signum: int, stack: FrameType) -> None: log_and_print("The Health Checker is terminating. All components will be " "stopped gracefully.", dummy_logger) log_and_print("Terminating the {}.".format(HEALTH_CHECKER_MANAGER_NAME), dummy_logger) health_checker_manager_process.terminate() health_checker_manager_process.join() log_and_print("The Health Checker process has ended.", dummy_logger) sys.exit()
def _initialise_alert_router() -> Tuple[AlertRouter, logging.Logger]: display_name = ALERT_ROUTER_NAME # Try initialising the logger until successful. This had to be done # separately to avoid instances when the logger creation failed and we # attempt to use it. while True: try: alert_router_logger = create_logger(env.ALERT_ROUTER_LOG_FILE, AlertRouter.__name__, env.LOGGING_LEVEL, rotating=True) break except Exception as e: # Use a dummy logger in this case because we cannot create the # manager's logger. dummy_logger = logging.getLogger('DUMMY_LOGGER') log_and_print(get_initialisation_error_message(display_name, e), dummy_logger) log_and_print(get_reattempting_message(display_name), dummy_logger) # sleep before trying again time.sleep(RE_INITIALISE_SLEEPING_PERIOD) rabbit_ip = env.RABBIT_IP redis_ip = env.REDIS_IP redis_db = env.REDIS_DB redis_port = env.REDIS_PORT unique_alerter_identifier = env.UNIQUE_ALERTER_IDENTIFIER while True: try: alert_router = AlertRouter(display_name, alert_router_logger, rabbit_ip, redis_ip, redis_db, redis_port, unique_alerter_identifier, env.ENABLE_CONSOLE_ALERTS, env.ENABLE_LOG_ALERTS) return alert_router, alert_router_logger except Exception as e: log_and_print(get_initialisation_error_message(display_name, e), alert_router_logger) log_and_print(get_reattempting_message(display_name), alert_router_logger) # sleep before trying again time.sleep(RE_INITIALISE_SLEEPING_PERIOD)
def start_monitor(monitor: Monitor) -> None: while True: try: log_and_print("{} started.".format(monitor), monitor.logger) monitor.start() except (pika.exceptions.AMQPConnectionError, pika.exceptions.AMQPChannelError): # Error would have already been logged by RabbitMQ logger. log_and_print(get_stopped_message(monitor), monitor.logger) except Exception: # Close the connection with RabbitMQ if we have an unexpected # exception, and start again monitor.disconnect_from_rabbit() log_and_print(get_stopped_message(monitor), monitor.logger) log_and_print( "Restarting {} in {} seconds.".format(monitor, RESTART_SLEEPING_PERIOD), monitor.logger) time.sleep(RESTART_SLEEPING_PERIOD)
def start_health_checker_component(component: HealthCheckerComponentType) \ -> None: while True: try: log_and_print("{} started.".format(component), component.logger) component.start() except (pika.exceptions.AMQPConnectionError, pika.exceptions.AMQPChannelError): # Error would have already been logged by RabbitMQ logger. log_and_print(get_stopped_message(component), component.logger) except Exception: # Close the connection with RabbitMQ if we have an unexpected # exception, and start again component.disconnect_from_rabbit() log_and_print(get_stopped_message(component), component.logger) log_and_print( "Restarting {} in {} seconds.".format(component, RESTART_SLEEPING_PERIOD), component.logger) time.sleep(RESTART_SLEEPING_PERIOD)
def on_terminate(self, signum: int, stack: FrameType) -> None: log_and_print( "{} is terminating. All sub-processes will be stopped " "gracefully and then the {} process will " "exit.".format(self, self), self.logger) for component, process in self.component_process_dict.items(): log_and_print("Terminating the process of {}".format(component), self.logger) process.terminate() process.join() log_and_print("{} terminated.".format(self), self.logger) sys.exit()
def _on_terminate(self, signum: int, stack: FrameType) -> None: log_and_print( "{} is terminating. Connections with RabbitMQ will be closed, and " "any running stores will be stopped gracefully. Afterwards the {} " "process will exit.".format(self, self), self.logger) self.disconnect_from_rabbit() for store, process in self._store_process_dict.items(): log_and_print("Terminating the process of {}".format(store), self.logger) process.terminate() process.join() log_and_print("{} terminated.".format(self), self.logger) sys.exit()
def _on_terminate(self, signum: int, stack: FrameType) -> None: log_and_print("{} is terminating. Connections with RabbitMQ will be " "closed, and any running data transformers will be " "stopped gracefully. Afterwards the {} process will " "exit.".format(self, self), self.logger) self.disconnect_from_rabbit() for transformer, process in self.transformer_process_dict.items(): log_and_print("Terminating the process of {}".format(transformer), self.logger) process.terminate() process.join() log_and_print("{} terminated.".format(self), self.logger) sys.exit()
def _start_stores_processes(self) -> None: # Start each store in a separate process if it is not yet started or it # is not alive. This must be done in case of a restart of the manager. if SYSTEM_STORE_NAME not in self._store_process_dict or \ not self._store_process_dict[SYSTEM_STORE_NAME].is_alive(): log_and_print("Attempting to start the {}.".format( SYSTEM_STORE_NAME), self.logger) system_store_process = Process(target=start_system_store, args=()) system_store_process.daemon = True system_store_process.start() self._store_process_dict[SYSTEM_STORE_NAME] = system_store_process if GITHUB_STORE_NAME not in self._store_process_dict or \ not self._store_process_dict[GITHUB_STORE_NAME].is_alive(): log_and_print("Attempting to start the {}.".format( GITHUB_STORE_NAME), self.logger) github_store_process = Process(target=start_github_store, args=()) github_store_process.daemon = True github_store_process.start() self._store_process_dict[GITHUB_STORE_NAME] = github_store_process if ALERT_STORE_NAME not in self._store_process_dict or \ not self._store_process_dict[ALERT_STORE_NAME].is_alive(): log_and_print("Attempting to start the {}.".format( ALERT_STORE_NAME), self.logger) alert_store_process = Process(target=start_alert_store, args=()) alert_store_process.daemon = True alert_store_process.start() self._store_process_dict[ALERT_STORE_NAME] = alert_store_process if CONFIG_STORE_NAME not in self._store_process_dict or \ not self._store_process_dict[CONFIG_STORE_NAME].is_alive(): log_and_print("Attempting to start the {}.".format( CONFIG_STORE_NAME), self.logger) config_store_process = Process(target=start_config_store, args=()) config_store_process.daemon = True config_store_process.start() self._store_process_dict[CONFIG_STORE_NAME] = config_store_process
def run_health_checker_manager() -> None: health_checker_manager = _initialise_health_checker_manager() while True: try: log_and_print("{} started.".format(health_checker_manager), health_checker_manager.logger) health_checker_manager.start() except Exception as e: health_checker_manager.logger.exception(e) log_and_print(get_stopped_message(health_checker_manager), health_checker_manager.logger) log_and_print("Restarting {} in {} seconds.".format( health_checker_manager, RESTART_SLEEPING_PERIOD), health_checker_manager.logger) time.sleep(RESTART_SLEEPING_PERIOD)
def _on_terminate(self, signum: int, stack: FrameType) -> None: log_and_print( "{} is terminating. Connections with RabbitMQ will be " "closed, and any running monitors will be stopped " "gracefully. Afterwards the {} process will exit.".format( self, self), self.logger) self.disconnect_from_rabbit() for config_id, process_details in self.config_process_dict.items(): log_and_print("Terminating the process of {}".format(config_id), self.logger) process = process_details['process'] process.terminate() process.join() log_and_print("{} terminated.".format(self), self.logger) sys.exit()
def _on_terminate(self, signum: int, stack: FrameType) -> None: log_and_print( "{} is terminating. Connections with RabbitMQ will be closed, and " "any running system alerters will be stopped gracefully. " "Afterwards the {} process will exit.".format(self, self), self.logger) self.disconnect_from_rabbit() for _, process_details in self.parent_id_process_dict.items(): log_and_print( "Terminating the alerter process of {}".format( process_details['chain']), self.logger) process = process_details['process'] process.terminate() process.join() log_and_print("{} terminated.".format(self), self.logger) sys.exit()
def run_alerters_manager(manager: AlertersManager) -> None: while True: try: manager.start() except (pika.exceptions.AMQPConnectionError, pika.exceptions.AMQPChannelError): # Error would have already been logged by RabbitMQ logger. # Since we have to re-initialise just break the loop. log_and_print(get_stopped_message(manager), manager.logger) except Exception: # Close the connection with RabbitMQ if we have an unexpected # exception, and start again manager.disconnect_from_rabbit() log_and_print(get_stopped_message(manager), manager.logger) log_and_print( "Restarting {} in {} seconds.".format(manager, RESTART_SLEEPING_PERIOD), manager.logger) time.sleep(RESTART_SLEEPING_PERIOD)
def on_terminate(signum: int, stack: FrameType) -> None: def terminate_and_join_process(process: multiprocessing.Process, name: str): log_and_print("Terminating the {}".format(name), dummy_logger) process.terminate() process.join() dummy_logger = logging.getLogger('Dummy') log_and_print( "The alerter is terminating. All components will be stopped " "gracefully.", dummy_logger) terminate_and_join_process(config_manager_runner_process, CONFIGS_MANAGER_NAME) terminate_and_join_process(system_monitors_manager_process, SYSTEM_MONITORS_MANAGER_NAME) terminate_and_join_process(github_monitors_manager_process, GITHUB_MONITORS_MANAGER_NAME) terminate_and_join_process(data_transformers_manager_process, DATA_TRANSFORMERS_MANAGER_NAME) terminate_and_join_process(system_alerters_manager_process, SYSTEM_ALERTERS_MANAGER_NAME) terminate_and_join_process(github_alerter_manager_process, GITHUB_ALERTER_MANAGER_NAME) terminate_and_join_process(data_store_process, DATA_STORE_MANAGER_NAME) terminate_and_join_process(alert_router_process, ALERT_ROUTER_NAME) terminate_and_join_process(channels_manager_process, CHANNELS_MANAGER_NAME) log_and_print("PANIC process terminated.", dummy_logger) log_and_print("The alerting and monitoring process has ended.", dummy_logger) sys.exit()
def run_config_manager() -> None: config_manager, config_manager_logger = _initialise_config_manager() while True: try: config_manager.start() except (pika.exceptions.AMQPConnectionError, pika.exceptions.AMQPChannelError): # Error would have already been logged by RabbitMQ logger. # Since we have to re-initialise just break the loop. log_and_print(get_stopped_message(config_manager), config_manager_logger) except Exception: config_manager.disconnect_from_rabbit() log_and_print(get_stopped_message(config_manager), config_manager_logger) log_and_print( "Restarting {} in {} seconds.".format(config_manager, RESTART_SLEEPING_PERIOD), config_manager_logger) time.sleep(RESTART_SLEEPING_PERIOD)
def terminate_and_join_process(process: multiprocessing.Process, name: str): log_and_print("Terminating the {}".format(name), dummy_logger) process.terminate() process.join()
def _initialise_and_declare_config_queues() -> None: # TODO: This can be refactored by storing the queue configurations in # : constant.py so that it is easier to maintain. dummy_logger = logging.getLogger('Dummy') while True: try: rabbitmq = RabbitMQApi(dummy_logger, env.RABBIT_IP) log_and_print( "Connecting with RabbitMQ to create and bind " "configuration queues.", dummy_logger) ret = rabbitmq.connect() if ret == -1: log_and_print( "RabbitMQ is temporarily unavailable. Re-trying in {} " "seconds.".format(RE_INITIALISE_SLEEPING_PERIOD), dummy_logger) time.sleep(RE_INITIALISE_SLEEPING_PERIOD) continue # Config exchange declaration log_and_print("Creating {} exchange.".format(CONFIG_EXCHANGE), dummy_logger) rabbitmq.exchange_declare(CONFIG_EXCHANGE, 'topic', False, True, False, False) # Alert router queues log_and_print( "Creating queue '{}'".format(ALERT_ROUTER_CONFIGS_QUEUE_NAME), dummy_logger) rabbitmq.queue_declare(ALERT_ROUTER_CONFIGS_QUEUE_NAME, False, True, False, False) log_and_print( "Binding queue '{}' to '{}' exchange with routing " "key {}.".format(ALERT_ROUTER_CONFIGS_QUEUE_NAME, CONFIG_EXCHANGE, 'channels.*'), dummy_logger) rabbitmq.queue_bind(ALERT_ROUTER_CONFIGS_QUEUE_NAME, CONFIG_EXCHANGE, 'channels.*') # System Alerters Manager queues log_and_print( "Creating queue '{}'".format( SYSTEM_ALERTERS_MANAGER_CONFIGS_QUEUE_NAME), dummy_logger) rabbitmq.queue_declare(SYSTEM_ALERTERS_MANAGER_CONFIGS_QUEUE_NAME, False, True, False, False) log_and_print( "Binding queue '{}' to '{}' exchange with routing " "key {}.".format(SYSTEM_ALERTERS_MANAGER_CONFIGS_QUEUE_NAME, CONFIG_EXCHANGE, 'chains.*.*.alerts_config'), dummy_logger) rabbitmq.queue_bind(SYSTEM_ALERTERS_MANAGER_CONFIGS_QUEUE_NAME, CONFIG_EXCHANGE, 'chains.*.*.alerts_config') log_and_print( "Binding queue '{}' to '{}' exchange with routing " "key {}.".format(SYSTEM_ALERTERS_MANAGER_CONFIGS_QUEUE_NAME, CONFIG_EXCHANGE, 'general.alerts_config'), dummy_logger) rabbitmq.queue_bind(SYSTEM_ALERTERS_MANAGER_CONFIGS_QUEUE_NAME, CONFIG_EXCHANGE, 'general.alerts_config') # Channels manager queues log_and_print( "Creating queue '{}'".format( CHANNELS_MANAGER_CONFIGS_QUEUE_NAME), dummy_logger) rabbitmq.queue_declare(CHANNELS_MANAGER_CONFIGS_QUEUE_NAME, False, True, False, False) log_and_print( "Binding queue '{}' to '{}' exchange with routing " "key {}.".format(CHANNELS_MANAGER_CONFIGS_QUEUE_NAME, CONFIG_EXCHANGE, 'channels.*'), dummy_logger) rabbitmq.queue_bind(CHANNELS_MANAGER_CONFIGS_QUEUE_NAME, CONFIG_EXCHANGE, 'channels.*') # GitHub Monitors Manager queues log_and_print( "Creating queue '{}'".format( GITHUB_MONITORS_MANAGER_CONFIGS_QUEUE_NAME), dummy_logger) rabbitmq.queue_declare(GITHUB_MONITORS_MANAGER_CONFIGS_QUEUE_NAME, False, True, False, False) log_and_print( "Binding queue '{}' to '{}' exchange with routing " "key {}.".format(GITHUB_MONITORS_MANAGER_CONFIGS_QUEUE_NAME, CONFIG_EXCHANGE, 'chains.*.*.repos_config'), dummy_logger) rabbitmq.queue_bind(GITHUB_MONITORS_MANAGER_CONFIGS_QUEUE_NAME, CONFIG_EXCHANGE, 'chains.*.*.repos_config') log_and_print( "Binding queue '{}' to '{}' exchange with routing " "key {}.".format(GITHUB_MONITORS_MANAGER_CONFIGS_QUEUE_NAME, CONFIG_EXCHANGE, 'general.repos_config'), dummy_logger) rabbitmq.queue_bind(GITHUB_MONITORS_MANAGER_CONFIGS_QUEUE_NAME, CONFIG_EXCHANGE, 'general.repos_config') # System Monitors Manager queues log_and_print( "Creating queue '{}'".format( SYSTEM_MONITORS_MANAGER_CONFIGS_QUEUE_NAME), dummy_logger) rabbitmq.queue_declare(SYSTEM_MONITORS_MANAGER_CONFIGS_QUEUE_NAME, False, True, False, False) log_and_print( "Binding queue '{}' to '{}' exchange with routing " "key {}.".format(SYSTEM_MONITORS_MANAGER_CONFIGS_QUEUE_NAME, CONFIG_EXCHANGE, 'chains.*.*.nodes_config'), dummy_logger) rabbitmq.queue_bind(SYSTEM_MONITORS_MANAGER_CONFIGS_QUEUE_NAME, CONFIG_EXCHANGE, 'chains.*.*.nodes_config') log_and_print( "Binding queue '{}' to '{}' exchange with routing " "key {}.".format(SYSTEM_MONITORS_MANAGER_CONFIGS_QUEUE_NAME, CONFIG_EXCHANGE, 'general.systems_config'), dummy_logger) rabbitmq.queue_bind(SYSTEM_MONITORS_MANAGER_CONFIGS_QUEUE_NAME, CONFIG_EXCHANGE, 'general.systems_config') # Config Store queues log_and_print( "Creating queue '{}'".format(STORE_CONFIGS_QUEUE_NAME), dummy_logger) rabbitmq.queue_declare(STORE_CONFIGS_QUEUE_NAME, False, True, False, False) log_and_print( "Binding queue '{}' to '{}' exchange with routing " "key {}.".format(STORE_CONFIGS_QUEUE_NAME, CONFIG_EXCHANGE, '#'), dummy_logger) rabbitmq.queue_bind(STORE_CONFIGS_QUEUE_NAME, CONFIG_EXCHANGE, '#') ret = rabbitmq.disconnect() if ret == -1: log_and_print( "RabbitMQ is temporarily unavailable. Re-trying in {} " "seconds.".format(RE_INITIALISE_SLEEPING_PERIOD), dummy_logger) time.sleep(RE_INITIALISE_SLEEPING_PERIOD) continue log_and_print( "Configuration queues initialisation procedure has " "completed successfully. Disconnecting with " "RabbitMQ.", dummy_logger) break except pika.exceptions.AMQPChannelError as e: log_and_print( "Channel error while initialising the configuration " "queues: {}. Re-trying in {} " "seconds.".format(repr(e), RE_INITIALISE_SLEEPING_PERIOD), dummy_logger) time.sleep(RE_INITIALISE_SLEEPING_PERIOD) except pika.exceptions.AMQPConnectionError as e: log_and_print( "RabbitMQ connection error while initialising the " "configuration queues: {}. Re-trying in {} " "seconds.".format(repr(e), RE_INITIALISE_SLEEPING_PERIOD), dummy_logger) time.sleep(RE_INITIALISE_SLEEPING_PERIOD) except Exception as e: log_and_print( "Unexpected exception while initialising the " "configuration queues: {}. Re-trying in {} " "seconds.".format(repr(e), RE_INITIALISE_SLEEPING_PERIOD), dummy_logger) time.sleep(RE_INITIALISE_SLEEPING_PERIOD)