def _read_config(self): """ Read configuration from an optional configuration file. """ cfg = NagiosPluginConfig() try: configs = cfg.read() log.debug("Read configuration files:\n%s", pp(configs)) except NoConfigfileFound as e: log.debug("Could not read NagiosPluginConfig: %s", e) return if self.verbose > 2: log.debug("Read configuration:\n%s", pp(cfg.__dict__)) self.read_config(cfg)
def test_read_cfgfile(self): log.info("Testing read temp configfile %r.", self.tmp_cfg) try: cfg = NagiosPluginConfig() configs = cfg.read(self.tmp_cfg) log.debug("Read configuration files:\n%s", pp(configs)) c = {} for section in cfg.sections(): if not section in c: c[section] = {} for option in cfg.options(section): val = cfg.get(section, option) c[section][option] = val log.debug("Found options in config:\n%s", pp(c)) except NoConfigfileFound as e: self.fail("Could not read NagiosPluginConfig by a %s: %s" % ( e.__class__.__name__, str(e)))
def test_config_object(self): log.info("Testing NagiosPluginConfig object.") try: cfg = NagiosPluginConfig() log.debug("NagiosPluginConfig object: %r", cfg) except Exception as e: self.fail("Could not instatiate NagiosPluginConfig by a %s: %s" % (e.__class__.__name__, str(e)))
def test_read_cfgfile(self): log.info("Testing read temp configfile %r.", self.tmp_cfg) try: cfg = NagiosPluginConfig() configs = cfg.read(self.tmp_cfg) log.debug("Read configuration files:\n%s", pp(configs)) c = {} for section in cfg.sections(): if not section in c: c[section] = {} for option in cfg.options(section): val = cfg.get(section, option) c[section][option] = val log.debug("Found options in config:\n%s", pp(c)) except NoConfigfileFound as e: self.fail("Could not read NagiosPluginConfig by a %s: %s" % (e.__class__.__name__, str(e)))
def _load_config_section(self, section, cfg_file=None): """Loads the given section from the given ini-file or from the first found default ini-file.""" if not section: section = self.plugin # log.debug( # "Trying to load extra options from section %r of file %r.", section, cfg_file) cfg = NagiosPluginConfig() configs = [] try: configs = cfg.read(cfg_file) except NoConfigfileFound: return {} configs_str = str(configs) if len(configs): configs_str = ', '.join(["'" + x + "'" for x in configs]) else: configs_str = '<None>' if section not in cfg.sections(): if False: log.debug( "Section %r not found in ini-files %s.", section, configs_str) return {} ini_opts = {} for option in cfg.options(section): val = cfg.get(section, option) ini_opts[option] = val return ini_opts