def main(): """Parse args and run main daemon function :return: None """ parser = optparse.OptionParser( "%prog [options]", version="%prog " + VERSION) parser.add_option('-c', '--config', dest="config_file", metavar="INI-CONFIG-FILE", help='Config file') parser.add_option('-d', '--daemon', action='store_true', dest="is_daemon", help="Run in daemon mode") parser.add_option('-r', '--replace', action='store_true', dest="do_replace", help="Replace previous running scheduler") parser.add_option('--debugfile', dest='debug_file', help=("Debug file. Default: not used " "(why debug a bug free program? :) )")) parser.add_option("-p", "--profile", dest="profile", help="Dump a profile file. Need the python cProfile librairy") opts, args = parser.parse_args() if args: parser.error("Does not accept any argument.") daemon = Alignak(debug=opts.debug_file is not None, **opts.__dict__) if not opts.profile: daemon.main() else: # For perf running: import cProfile cProfile.run('''daemon.main()''', opts.profile)
def main(): """Parse args and run main daemon function :return: None """ args = parse_daemon_args() daemon = Alignak(debug=args.debug_file is not None, **args.__dict__) daemon.main()
def main(): """Parse args and run main daemon function :return: None """ try: args = parse_daemon_args() daemon = Alignak(**args.__dict__) daemon.main() except Exception as exp: # pylint: disable=broad-except sys.stderr.write("*** Daemon exited because: %s" % str(exp)) traceback.print_exc() exit(1)
def setup_with_file(self, paths, add_default=True): self.time_hacker.set_my_time() self.print_header() # i am arbiter-like self.broks = {} self.me = None self.log = logger self.log.load_obj(self) if not isinstance(paths, list): paths = [paths] # Fix for modules tests add_default = False # Don't mix config if add_default: paths.insert(0, 'etc/alignak_1r_1h_1s.cfg') self.config_files = paths self.conf = Config() buf = self.conf.read_config(self.config_files) raw_objects = self.conf.read_config_buf(buf) self.conf.create_objects_for_type(raw_objects, 'arbiter') self.conf.create_objects_for_type(raw_objects, 'module') self.conf.early_arbiter_linking() # If we got one arbiter defined here (before default) we should be in a case where # the tester want to load/test a module, so we simulate an arbiter daemon # and the modules loading phase. As it has its own modulesmanager, should # not impact scheduler modules ones, especially we are asking for arbiter type :) if len(self.conf.arbiters) == 1: arbdaemon = Arbiter([''],[''], False, False, None, None) # only load if the module_dir is reallyexisting, so was set explicitly # in the test configuration if os.path.exists(getattr(self.conf, 'modules_dir', '')): arbdaemon.modules_dir = self.conf.modules_dir arbdaemon.load_modules_manager() # we request the instances without them being *started* # (for those that are concerned ("external" modules): # we will *start* these instances after we have been daemonized (if requested) me = None for arb in self.conf.arbiters: me = arb arbdaemon.modules_manager.set_modules(arb.modules) arbdaemon.do_load_modules() arbdaemon.load_modules_configuration_objects(raw_objects) self.conf.create_objects(raw_objects) self.conf.instance_id = 0 self.conf.instance_name = 'test' # Hack push_flavor, that is set by the dispatcher self.conf.push_flavor = 0 self.conf.load_triggers() #import pdb;pdb.set_trace() self.conf.linkify_templates() #import pdb;pdb.set_trace() self.conf.apply_inheritance() #import pdb;pdb.set_trace() self.conf.explode() #print "Aconf.services has %d elements" % len(self.conf.services) self.conf.apply_implicit_inheritance() self.conf.fill_default() self.conf.remove_templates() #print "conf.services has %d elements" % len(self.conf.services) self.conf.override_properties() self.conf.linkify() self.conf.apply_dependencies() self.conf.explode_global_conf() self.conf.propagate_timezone_option() self.conf.create_business_rules() self.conf.create_business_rules_dependencies() self.conf.is_correct() if not self.conf.conf_is_correct: print "The conf is not correct, I stop here" self.conf.dump() return self.conf.clean() self.confs = self.conf.cut_into_parts() self.conf.prepare_for_sending() self.conf.show_errors() self.dispatcher = Dispatcher(self.conf, self.me) scheddaemon = Alignak(None, False, False, False, None, None) self.scheddaemon = scheddaemon self.sched = scheddaemon.sched scheddaemon.modules_dir = modules_dir scheddaemon.load_modules_manager() # Remember to clean the logs we just created before launching tests self.clear_logs() m = MacroResolver() m.init(self.conf) self.sched.load_conf(self.conf) e = ExternalCommandManager(self.conf, 'applyer') self.sched.external_command = e e.load_scheduler(self.sched) e2 = ExternalCommandManager(self.conf, 'dispatcher') e2.load_arbiter(self) self.external_command_dispatcher = e2 self.sched.conf.accept_passive_unknown_check_results = False self.sched.schedule()
def setup_with_file(self, configuration_file): """ Load alignak with defined configuration file If the configuration loading fails, a SystemExit exception is raised to the caller. The conf_is_correct property indicates if the configuration loading succeeded or failed. The configuration errors property contains a list of the error message that are normally logged as ERROR by the arbiter. @verified :param configuration_file: path + file name of the main configuration file :type configuration_file: str :return: None """ self.broks = {} self.schedulers = {} self.brokers = {} self.pollers = {} self.receivers = {} self.reactionners = {} self.arbiter = None self.conf_is_correct = False self.configuration_warnings = [] self.configuration_errors = [] # Add collector for test purpose. self.setup_logger() # Initialize the Arbiter with no daemon configuration file self.arbiter = Arbiter(None, [configuration_file], False, False, False, False, '/tmp/arbiter.log', 'arbiter-master') try: # The following is copy paste from setup_alignak_logger # The only difference is that keep logger at INFO level to gather messages # This is needed to assert later on logs we received. self.logger.setLevel(logging.INFO) # Force the debug level if the daemon is said to start with such level if self.arbiter.debug: self.logger.setLevel(logging.DEBUG) # Log will be broks for line in self.arbiter.get_header(): self.logger.info(line) self.arbiter.load_monitoring_config_file() # If this assertion does not match, then there is a bug in the arbiter :) self.assertTrue(self.arbiter.conf.conf_is_correct) self.conf_is_correct = True self.configuration_warnings = self.arbiter.conf.configuration_warnings self.configuration_errors = self.arbiter.conf.configuration_errors except SystemExit: self.configuration_warnings = self.arbiter.conf.configuration_warnings print("Configuration warnings:") for msg in self.configuration_warnings: print(" - %s" % msg) self.configuration_errors = self.arbiter.conf.configuration_errors print("Configuration errors:") for msg in self.configuration_errors: print(" - %s" % msg) raise for arb in self.arbiter.conf.arbiters: if arb.get_name() == self.arbiter.arbiter_name: self.arbiter.myself = arb self.arbiter.dispatcher = Dispatcher(self.arbiter.conf, self.arbiter.myself) self.arbiter.dispatcher.prepare_dispatch() # Build schedulers dictionary with the schedulers involved in the configuration for scheduler in self.arbiter.dispatcher.schedulers: sched = Alignak([], False, False, True, '/tmp/scheduler.log') sched.load_modules_manager(scheduler.name) sched.new_conf = scheduler.conf_package if sched.new_conf: sched.setup_new_conf() self.schedulers[scheduler.scheduler_name] = sched # Build pollers dictionary with the pollers involved in the configuration for poller in self.arbiter.dispatcher.pollers: self.pollers[poller.poller_name] = poller # Build receivers dictionary with the receivers involved in the configuration for receiver in self.arbiter.dispatcher.receivers: self.receivers[receiver.receiver_name] = receiver # Build reactionners dictionary with the reactionners involved in the configuration for reactionner in self.arbiter.dispatcher.reactionners: self.reactionners[reactionner.reactionner_name] = reactionner # Build brokers dictionary with the brokers involved in the configuration for broker in self.arbiter.dispatcher.brokers: self.brokers[broker.broker_name] = broker
def setup_with_file(self, paths, add_default=True): self.time_hacker.set_my_time() self.print_header() # i am arbiter-like self.broks = {} self.me = None self.log = logger self.log.load_obj(self) if not isinstance(paths, list): paths = [paths] # Fix for modules tests add_default = False # Don't mix config if add_default: paths.insert(0, 'etc/alignak_1r_1h_1s.cfg') self.config_files = paths self.conf = Config() buf = self.conf.read_config(self.config_files) raw_objects = self.conf.read_config_buf(buf) self.conf.create_objects_for_type(raw_objects, 'arbiter') self.conf.create_objects_for_type(raw_objects, 'module') self.conf.early_arbiter_linking() # If we got one arbiter defined here (before default) we should be in a case where # the tester want to load/test a module, so we simulate an arbiter daemon # and the modules loading phase. As it has its own modulesmanager, should # not impact scheduler modules ones, especially we are asking for arbiter type :) if len(self.conf.arbiters) == 1: arbdaemon = Arbiter([''], [''], False, False, None, None) arbdaemon.load_modules_manager() # we request the instances without them being *started* # (for those that are concerned ("external" modules): # we will *start* these instances after we have been daemonized (if requested) me = None for arb in self.conf.arbiters: me = arb arbdaemon.do_load_modules(arb.modules) arbdaemon.load_modules_configuration_objects(raw_objects) self.conf.create_objects(raw_objects) self.conf.instance_id = 0 self.conf.instance_name = 'test' # Hack push_flavor, that is set by the dispatcher self.conf.push_flavor = 0 self.conf.load_triggers() #import pdb;pdb.set_trace() self.conf.linkify_templates() #import pdb;pdb.set_trace() self.conf.apply_inheritance() #import pdb;pdb.set_trace() self.conf.explode() #print "Aconf.services has %d elements" % len(self.conf.services) self.conf.apply_implicit_inheritance() self.conf.fill_default() self.conf.remove_templates() #print "conf.services has %d elements" % len(self.conf.services) self.conf.override_properties() self.conf.linkify() self.conf.apply_dependencies() self.conf.explode_global_conf() self.conf.propagate_timezone_option() self.conf.create_business_rules() self.conf.create_business_rules_dependencies() self.conf.is_correct() if not self.conf.conf_is_correct: print "The conf is not correct, I stop here" self.conf.dump() return self.conf.clean() self.confs = self.conf.cut_into_parts() self.conf.prepare_for_sending() self.conf.show_errors() self.dispatcher = Dispatcher(self.conf, self.me) scheddaemon = Alignak(None, False, False, False, None, None) self.scheddaemon = scheddaemon self.sched = scheddaemon.sched scheddaemon.load_modules_manager() # Remember to clean the logs we just created before launching tests self.clear_logs() m = MacroResolver() m.init(self.conf) self.sched.load_conf(self.conf) e = ExternalCommandManager(self.conf, 'applyer') self.sched.external_command = e e.load_scheduler(self.sched) e2 = ExternalCommandManager(self.conf, 'dispatcher') e2.load_arbiter(self) self.external_command_dispatcher = e2 self.sched.conf.accept_passive_unknown_check_results = False self.sched.schedule()