Exemple #1
0
    def _load_handlers(self, handler_config_path, **kwargs):
        base_path = os.path.expanduser(handler_config_path)
        conf_files = glob.glob(os.path.join(base_path, '*.conf'))
        logger.debug("Loading handlers from %s", handler_config_path)
        for f in conf_files:
            handler_name = os.path.basename(f)[:-5]
            # We could eventually have the handlers get loaded everytime and
            # update them if their config has changed (via config_version
            # below).  For now lets not get that tricky.
            if handler_name in self._handlers:
                if not kwargs.get('force_load_handlers', False):
                    logger.debug("Handler %s already loaded, skipping.",
                                 handler_name)
                    continue
            conf_version, conf = yaml_config.load_config(f)
            enabled = conf.pop('enabled', False)
            if not enabled:
                logger.debug("Handler %s 'enabled' is not set to true. "
                             "Skipping.", handler_name)
                continue
            cls_string = conf.pop('handler_class')
            logger.debug('Initializing handler %s.', handler_name)
            try:
                handler_cls = load_object_from_string(cls_string)
                self._handlers[handler_name] = handler_cls(conf)
            except Exception as e:
                logutil.log_exception("Skipping handler %s due to "
                    "unhandled exception:" % (handler_name), logger)
                continue

        if not self._handlers:
            logger.error("No handlers loaded.  Exiting.")
            sys.exit(1)
Exemple #2
0
 def get_private_context(self, private_context_file):
     if not private_context_file:
         return None
     try:
         return load_config(private_context_file)[1]
     except (IOError, EmptyConfig):
         logger.exception("Unable to open private context file: %s",
                          private_context_file)
         return None
Exemple #3
0
 def get_private_context(self, private_context_file):
     if not private_context_file:
         return None
     try:
         return load_config(private_context_file)[1]
     except (IOError, EmptyConfig):
         logger.exception("Unable to open private context file: %s",
                          private_context_file)
         return None
Exemple #4
0
def load_nodes(node_file, reset=False):
    """ Loads nodes from a yaml formatted file.

    Nodes are stored in the Node registry.
    """
    logger.info("Loading nodes from %s." % (node_file))
    version, nodes = yaml_config.load_config(node_file)

    items = nodes['nodes']
    load_resource(items, Node, reset=reset)
    return version
Exemple #5
0
def load_nodes(node_file, reset=False):
    """ Loads nodes from a yaml formatted file.

    Nodes are stored in the Node registry.
    """
    logger.info("Loading nodes from %s.", node_file)
    version, nodes = yaml_config.load_config(node_file)

    items = nodes['nodes']
    load_resource(items, Node, reset=reset)
    return version
Exemple #6
0
def load_config(path, force=False):
    global settings, version
    if settings and not force:
        return
    settings = copy.deepcopy(DEFAULTS)
    version, _config_settings = yaml_config.load_config(path)
    if _config_settings:
        deep_update(settings, _config_settings)
    if validator:
        try:
            validator(settings, SCHEMA)
        except ValueError as e:
            raise exceptions.InvalidConfig(path, e.message)
    logger.debug("Config loaded from '%s' with version '%s'.", path, version)
Exemple #7
0
def load_config(path, force=False):
    global settings, version
    if settings and not force:
        return
    settings = copy.deepcopy(DEFAULTS)
    version, _config_settings = yaml_config.load_config(path)
    if _config_settings:
        deep_update(settings, _config_settings)
    if validator:
        try:
            validator(settings, SCHEMA)
        except ValueError as e:
            raise exceptions.InvalidConfig(path, e.message)
    logger.debug("Config loaded from '%s' with version '%s'.", path, version)
Exemple #8
0
def load_resources(resource_file, reset=False):
    """ Loads resources in yaml formatted resource_file in the proper order.

    Returns a sha512 hash of the resources.  The resources themselves are
    stored in their individual registries.
    """
    LOAD_ORDER = [('commands', Command),
                  ('monitoring_groups', MonitoringGroup),
                  ('monitors', Monitor)]

    logger.info("Loading local resources from %s." % (resource_file))
    version, resources = yaml_config.load_config(resource_file)

    for resource_type, resource_class in LOAD_ORDER:
        items = resources[resource_type]
        load_resource(items, resource_class, reset=reset)
    return version
Exemple #9
0
def load_resources(resource_file, reset=False):
    """ Loads resources in yaml formatted resource_file in the proper order.

    Returns a sha512 hash of the resources.  The resources themselves are
    stored in their individual registries.
    """
    LOAD_ORDER = [('commands', Command),
                  ('monitoring_groups', MonitoringGroup),
                  ('monitors', Monitor)]

    logger.info("Loading local resources from %s.", resource_file)
    version, resources = yaml_config.load_config(resource_file)

    for resource_type, resource_class in LOAD_ORDER:
        items = resources[resource_type]
        load_resource(items, resource_class, reset=reset)
    return version
Exemple #10
0
    def load_handlers(self, handler_config_path, **kwargs):
        conf_files = self.list_handler_configs(handler_config_path)
        logger.info("Loading handlers from %s", handler_config_path)
        for f in conf_files:
            handler_name = self.get_handler_name(f)
            # We could eventually have the handlers get loaded everytime and
            # update them if their config has changed (via config_version
            # below).  For now lets not get that tricky.
            if handler_name in self.handlers:
                if not kwargs.get('force_load_handlers', False):
                    logger.debug("Handler %s already loaded, skipping.",
                                 handler_name)
                    continue
            _, config = yaml_config.load_config(f)
            handler = self.load_handler(handler_name, config, **kwargs)
            if handler:
                self.handlers[handler_name] = handler

        if not self.handlers:
            logger.error("No handlers loaded.  Exiting.")
            sys.exit(1)
Exemple #11
0
    def _load_handlers(self, handler_config_path, **kwargs):
        conf_files = self._list_handler_configs(handler_config_path)
        logger.debug("Loading handlers from %s", handler_config_path)
        for f in conf_files:
            handler_name = self._get_handler_name(f)
            # We could eventually have the handlers get loaded everytime and
            # update them if their config has changed (via config_version
            # below).  For now lets not get that tricky.
            if handler_name in self._handlers:
                if not kwargs.get('force_load_handlers', False):
                    logger.debug("Handler %s already loaded, skipping.",
                                 handler_name)
                    continue
            conf_version, config = yaml_config.load_config(f)
            handler = self._load_handler(handler_name, config, **kwargs)
            if handler:
                self._handlers[handler_name] = handler

        if not self._handlers:
            logger.error("No handlers loaded.  Exiting.")
            sys.exit(1)
 def test_indent_include(self):
     full_path = os.path.join(self.root, 'config.yaml')
     version, relative_config = yaml_config.load_config(full_path)
     self.assertEqual(relative_config['included']['a'], 1)
Exemple #13
0
 def test_relative_include(self):
     full_path = os.path.join(self.root, 'config.yaml')
     version, relative_config = yaml_config.load_config(full_path)
     self.assertEqual(relative_config['foo'], 'bar')
     self.assertEqual(relative_config['file1'], 1)
Exemple #14
0
 def test_missing_config(self):
     with self.assertRaises(IOError):
         yaml_config.load_config('nonexistant.yaml')
Exemple #15
0
 def test_indent_include(self):
     full_path = os.path.join(self.root, 'config.yaml')
     version, relative_config = yaml_config.load_config(full_path)
     self.assertEqual(relative_config['included']['a'], 1)
Exemple #16
0
 def test_empty_config(self):
     full_path = os.path.join(self.root, 'empty.yaml')
     with self.assertRaises(yaml_config.EmptyConfig) as ee:
         yaml_config.load_config(full_path)
     self.assertEqual(ee.exception.filename, full_path)
 def load_nodes(self):
     version, nodes = yaml_config.load_config(self.path)
     logger.debug("Loaded node config (%s) from %s.", version, self.path)
     return nodes
 def test_relative_include(self):
     full_path = os.path.join(self.root, 'config.yaml')
     version, relative_config = yaml_config.load_config(full_path)
     self.assertEqual(relative_config['foo'], 'bar')
     self.assertEqual(relative_config['file1'], 1)
 def test_missing_config(self):
     with self.assertRaises(IOError):
         yaml_config.load_config('nonexistant.yaml')