Ejemplo n.º 1
0
    def run(self):
        """Lunch checks and triggers updates on BIRD configuration."""
        # Lunch a thread for each configuration
        if not self.services:
            self.log.warning("no service checks are configured")
        else:
            self.log.info("going to lunch %s threads", len(self.services))
            for service in self.services:
                self.log.debug("lunching thread for %s", service)
                _config = {}
                for option, getter in SERVICE_OPTIONS_TYPE.items():
                    _config[option] = getattr(self.config, getter)(service,
                                                                   option)
                _thread = ServiceCheck(service, _config, self.action)
                _thread.start()

        # Stay running until we are stopped
        while True:
            # Fetch items from action queue
            operation = self.action.get(block=True)
            self.log.info(
                "returned an item from the queue for %s with IP "
                "prefix %s and action to %s Bird configuration",
                operation.name, operation.ip_prefix, operation)
            bird_updated = self._update_bird_conf_file(operation)
            self.action.task_done()
            if bird_updated:
                ip_version = operation.ip_version
                cmd = self.bird_configuration[ip_version]['reconfigure_cmd']
                reconfigure_bird(cmd)
Ejemplo n.º 2
0
    def run(self):
        """Lunches checks and triggers updates on BIRD configuration."""
        self.log.info("Lunching checks")

        # Lunch a thread for each configuration
        self.log.info("Going to lunch {} threads".format(len(self.services)))
        for service in self.services:
            self.log.debug("Lunching thread for {}".format(service))
            _config = {}
            for option, getter in OPTIONS_TYPE.items():
                _config[option] = getattr(self.config, getter)(service, option)
            _thread = ServiceCheck(
                service,
                _config,
                self.action,
                self.log)
            _thread.start()

        # Stay running until we are stopped
        while True:
            # Fetch items from action queue
            operation = self.action.get(block=True)
            self.log.info(("Returned an item from the queue for {n} with "
                           "IP prefix {i} and action to {o} Bird "
                           "configuration").format(n=operation.name,
                                                   i=operation.ip_prefix,
                                                   o=operation))

            bird_updated = self._update_bird_prefix_conf(operation)
            self.action.task_done()
            if bird_updated:
                self._reload_bird()
Ejemplo n.º 3
0
    def run(self):
        """Lunch checks and triggers updates on BIRD configuration."""
        # Lunch a thread for each configuration
        if not self.services:
            self.log.warning("no service checks are configured")
        else:
            self.log.info("going to lunch %s threads", len(self.services))
            if self.config.has_option('daemon', 'splay_startup'):
                splay_startup = self.config.getfloat('daemon', 'splay_startup')
            else:
                splay_startup = None

            for service in self.services:
                self.log.debug("lunching thread for %s", service)
                _config = {}
                for option, getter in SERVICE_OPTIONS_TYPE.items():
                    try:
                        _config[option] = getattr(self.config, getter)(service,
                                                                       option)
                    except NoOptionError:
                        pass  # for optional settings

                _thread = ServiceCheck(service, _config, self.action,
                                       splay_startup)
                _thread.start()

        # Stay running until we are stopped
        while True:
            # Fetch items from action queue
            operation = self.action.get(block=True)

            if isinstance(operation, ServiceCheckDiedError):
                self.log.critical(operation)
                self.log.critical("This is a fatal error and the only way to "
                                  "recover is to restart, thus exiting with a "
                                  "non-zero code and let systemd act by "
                                  "triggering a restart")
                sys.exit(1)

            self.log.info(
                "returned an item from the queue for %s with IP "
                "prefix %s and action to %s Bird configuration",
                operation.name, operation.ip_prefix, operation)
            bird_updated = self._update_bird_conf_file(operation)
            self.action.task_done()
            if bird_updated:
                ip_version = operation.ip_version
                if operation.bird_reconfigure_cmd is None:
                    reconfigure_bird(
                        self.bird_configuration[ip_version]['reconfigure_cmd'])
                else:
                    run_custom_bird_reconfigure(operation)
Ejemplo n.º 4
0
    def run(self):
        """Lunches checks and triggers updates on BIRD configuration."""
        self.log.info("Lunching checks")
        _workers = []

        # Lunch a thread for each configuration
        self.log.info("Going to lunch {} threads".format(len(self.services)))
        for service in self.services:
            self.log.debug("Lunching thread for {}".format(service))
            _config = {}
            for option, getter in OPTIONS_TYPE.items():
                _config[option] = getattr(self.config, getter)(service, option)
            _thread = ServiceCheck(
                service,
                _config,
                self.action,
                self.log)
            _thread.start()
            _workers.append(_thread)

        # Stay running until we are stopped
        while True:
            try:
                # Fetch items from action queue
                health_action = self.action.get(1)
                self.log.info(("Returned an item from the queue for {} with "
                               "IP prefix {} and action to {} from Bird "
                               "configuration").format(health_action[0],
                                                       health_action[1],
                                                       health_action[2]))

                bird_updated = self._update_bird_prefix_conf(health_action)
                self.action.task_done()
                if bird_updated:
                    self._reload_bird()
            except Empty:
                # Just keep trying to fetch items
                continue

        for _thread in _workers:
            _thread.join()
Ejemplo n.º 5
0
    def run(self):
        """Lunches checks and triggers updates on BIRD configuration."""

        # Lunch a thread for each configuration
        if not self.services:
            self.log.warning("no service checks are configured")
        else:
            msg = "going to lunch {n} threads".format(n=len(self.services))
            self.log.info(msg)
            for service in self.services:
                msg = "lunching thread for {n}".format(n=service)
                self.log.debug(msg, json_blob=False)
                _config = {}
                for option, getter in SERVICE_OPTIONS_TYPE.items():
                    _config[option] = getattr(self.config, getter)(service,
                                                                   option)
                _thread = ServiceCheck(
                    service,
                    _config,
                    self.action,
                    self.log)
                _thread.start()

        # Stay running until we are stopped
        while True:
            # Fetch items from action queue
            operation = self.action.get(block=True)
            msg = ("returned an item from the queue for {n} with IP prefix {i}"
                   " and action to {o} Bird configuration"
                   .format(n=operation.name,
                           i=operation.ip_prefix,
                           o=operation))
            self.log.info(msg)
            bird_updated = self._update_bird_conf_file(operation)
            self.action.task_done()
            if bird_updated:
                reconfigure_bird(
                    self.log,
                    self.config.get('daemon', 'bird_reconfigure_cmd')
                )