class Controller(Thread):
    '''The controller is the link between the transport layer and the
    resources layer. Basically, its job is to load resources modules and
    objects and to call their generic "process" method.
    '''

    def __init__(self, scheduler=None, tq=None, pq=None):

        self.logger.debug("Initializing the controller...")
        Thread.__init__(self, name="CONTROLLER")
        permissions_path = config.controller['permissions_path']

        try:
            self.permissions = permissions.get(permissions_path)
        except (IOError, OSError) as err:
            self.logger.critical(err)
            raise SystemExit

        self.uuid = config.rabbitmq['uuid']
        self.tq = tq
        self.pq = pq
        self.locator = ResourceLocator(scheduler, pq)
        self.logger.debug("Controller successfully initialized.")

    def close(self):
        try:
            self.tq.put("stop")
            for resource in self.locator.get_instance().itervalues():
                resource.close()
        except ResourceException, e:
            self.logger.debug(str(e))
Exemple #2
0
class Controller(Thread):
    '''The controller is the link between the transport layer and the
    resources layer. Basically, its job is to load resources modules and
    objects and to call their generic "process" method.
    '''
    def __init__(self, scheduler=None, tasks_queue=None, publish_queue=None):

        self.logger.debug("Initializing the controller...")
        Thread.__init__(self, name="CONTROLLER")
        permissions_path = config.controller['permissions_path']

        try:
            self.permissions = permissions.get(permissions_path)
        except (IOError, OSError) as err:
            self.logger.critical(err)
            raise SystemExit

        self.uuid = config.rabbitmq['uuid']
        self.tasks_queue = tasks_queue
        self.publish_queue = publish_queue
        self.locator = ResourceLocator(scheduler, publish_queue)
        self.logger.debug("Controller successfully initialized.")

    def close(self):
        try:
            self.tasks_queue.put("stop")
            for resource in self.locator.get_instance().itervalues():
                resource.close()
        except ResourceException, e:
            self.logger.debug(str(e))
Exemple #3
0
class Controller(Thread):
    '''The controller is the link between the transport layer and the
    resources layer. Basically, its job is to load resources modules and
    objects and to call their generic "process" method.
    '''

    def __init__(self, tq=None, pq=None):

        self.logger.debug("Initializing the controller...")
        Thread.__init__(self, name="CONTROLLER")

        self.tq = tq
        self.pq = pq

        self.scheduler = SynSched()
        self.locator = ResourceLocator(pq)
        self.alerter = AlertsController(self.locator, self.scheduler, pq)
        self.logger.debug("Controller successfully initialized.")

    def start_scheduler(self):
        # Start the scheduler thread
        self.scheduler.start()
        self.alerter.start()

        # Prepopulate tasks from config file
        if config.monitor['enable_monitoring']:
            self._enable_monitoring()
        if config.compliance['enable_compliance']:
            self._enable_compliance()

    def _get_monitor_interval(self, resource):
        try:
            default_interval = config.monitor['default_interval']
            return int(config.monitor.get(resource, default_interval))
        except ValueError:
            return default_interval

    def _get_compliance_interval(self, resource):
        try:
            default_interval = config.compliance['default_interval']
            return int(config.compliance.get(resource, default_interval))
        except ValueError:
            return default_interval

    def _enable_monitoring(self):
        resources = self.locator.get_instance()
        for resource in resources.values():
            if not len(resource.states):
                continue
            interval = self._get_monitor_interval(resource.__resource__)
            self.scheduler.add_job(resource.monitor_states, interval)

    def _enable_compliance(self):
        resources = self.locator.get_instance()
        for resource in resources.values():
            if not len(resource.states):
                continue
            interval = self._get_compliance_interval(resource.__resource__)
            self.scheduler.add_job(resource.check_compliance, interval)

    def stop_scheduler(self):
        # Shutdown the scheduler/monitor
        self.logger.debug("Shutting down global scheduler...")
        if self.scheduler.isAlive():
            self.scheduler.shutdown()
            self.scheduler.join()
        self.logger.debug("Scheduler stopped.")

    def close(self):

        # Stop this thread by putting a stop message in the blocking queue get
        self.tq.put("stop")

       # Close properly each resource
        try:
            for resource in self.locator.get_instance().itervalues():
                resource.close()
        except ResourceException, e:
            self.logger.debug(str(e))

        self.stop_scheduler()
Exemple #4
0
class Controller(Thread):
    '''The controller is the link between the transport layer and the
    resources layer. Basically, its job is to load resources modules and
    objects and to call their generic "process" method.
    '''
    def __init__(self, tq=None, pq=None):

        self.logger.debug("Initializing the controller...")
        Thread.__init__(self, name="CONTROLLER")

        self.tq = tq
        self.pq = pq

        self.scheduler = SynSched()
        self.locator = ResourceLocator(pq)
        self.alerter = AlertsController(self.locator, self.scheduler, pq)
        self.logger.debug("Controller successfully initialized.")

    def start_scheduler(self):
        # Start the scheduler thread
        self.scheduler.start()
        self.alerter.start()

        # Prepopulate tasks from config file
        if config.monitor['enable_monitoring']:
            self._enable_monitoring()
        if config.compliance['enable_compliance']:
            self._enable_compliance()

    def _get_monitor_interval(self, resource):
        try:
            default_interval = config.monitor['default_interval']
            return int(config.monitor.get(resource, default_interval))
        except ValueError:
            return default_interval

    def _get_compliance_interval(self, resource):
        try:
            default_interval = config.compliance['default_interval']
            return int(config.compliance.get(resource, default_interval))
        except ValueError:
            return default_interval

    def _enable_monitoring(self):
        resources = self.locator.get_instance()
        for resource in resources.values():
            if not len(resource.states):
                continue
            interval = self._get_monitor_interval(resource.__resource__)
            self.scheduler.add_job(resource.monitor_states, interval)

    def _enable_compliance(self):
        resources = self.locator.get_instance()
        for resource in resources.values():
            if not len(resource.states):
                continue
            interval = self._get_compliance_interval(resource.__resource__)
            self.scheduler.add_job(resource.check_compliance, interval)

    def stop_scheduler(self):
        # Shutdown the scheduler/monitor
        self.logger.debug("Shutting down global scheduler...")
        if self.scheduler.isAlive():
            self.scheduler.shutdown()
            self.scheduler.join()
        self.logger.debug("Scheduler stopped.")

    def close(self):

        # Stop this thread by putting a stop message in the blocking queue get
        self.tq.put("stop")

        # Close properly each resource
        try:
            for resource in self.locator.get_instance().itervalues():
                resource.close()
        except ResourceException, e:
            self.logger.debug(str(e))

        self.stop_scheduler()