def __init__(self, as_child=False, *args, **kw): if as_child: signal.signal(signal.SIGTERM, self.terminate) for _class in handlers.list_classes(): __class = _class() __class.register(callback=self.register_handler) self.handler_modules[_class] = __class for _class in inputs.list_classes(): __class = _class() __class.register(callback=self.register_input) self.input_modules[_class] = __class output_modules = [x.strip() for x in conf.get('worker', 'output_modules', '').split(',')] for _class in outputs.list_classes(): _output = _class() if _output.name() in output_modules: _output.register(callback=self.register_output) self.output_modules[_class] = _output storage_modules = [x.strip() for x in conf.get('worker', 'storage_modules', '').split(',')] for _class in storage.list_classes(): _storage = _class() if _storage.name() in storage_modules: _storage.register(callback=self.register_storage) self.storage_modules[_class] = _storage self.storage = _storage output_exclude_events = conf.get('worker', 'output_exclude_events', '') self.output_exclude_events = [x.strip() for x in output_exclude_events.split(',')]
def async_execute_handlers(commands, notification, job_uuid): """ Routine to execute handlers for the given commands and notification To be run an an asynchronous child process. """ log.info("COLLECT %r for %s by %s" % (commands, job_uuid, multiprocessing.current_process().name)) # register handlers with the interrests again in this subprocess handler_interests = {} def register_handler(interests={}): for interest,how in interests.iteritems(): if not handler_interests.has_key(interest): handler_interests[interest] = [] handler_interests[interest].append(how) for _class in handlers.list_classes(): handler = _class() handler.register(callback=register_handler) log.debug("async_execute_handlers %r for job %r" % (commands, job_uuid), level=8) for command in commands: if handler_interests.has_key(command): for interest in handler_interests[command]: notification = interest['callback'](notification=notification) return (notification, job_uuid)
def run(self): for _class in inputs.list_classes(): module = _class() module.register(callback=self.register_input) self.input_modules[_class] = module for _class in handlers.list_classes(): handler = _class() handler.register(callback=self.register_handler) input_modules = conf.get('collector', 'input_modules') if input_modules == None: input_modules = "" input_modules = [x.strip() for x in input_modules.split(',')] for _input in self.input_modules.values(): if _input.name() in input_modules: _input.run(callback=self.execute, interests=self.handler_interests.keys())