def _get_entities_from_file(self, file_, path): static_entities = [] config = file_utils.load_yaml_file(path) for entity in config[self.ENTITIES_SECTION]: static_entities.append(entity.copy()) self.cache[file_] = config return static_entities
def __init__(self, conf): try: nagios_config_file = conf.nagios['config_file'] nagios_config = file_utils.load_yaml_file(nagios_config_file) nagios = nagios_config[NAGIOS] # nagios root in the yaml file self.mappings = [self._create_mapping(config) for config in nagios] except Exception as e: LOG.exception('failed in init %s ', e) self.mappings = []
def _configuration_mapping(conf): try: zabbix_config_file = conf.zabbix['config_file'] zabbix_config = file_utils.load_yaml_file(zabbix_config_file) zabbix_config_elements = zabbix_config['zabbix'] mappings = {} for element_config in zabbix_config_elements: mappings[element_config['zabbix_host']] = { ZProps.RESOURCE_TYPE: element_config['type'], ZProps.RESOURCE_NAME: element_config['name'] } return mappings except Exception as e: LOG.exception('failed in init %s ', e) return {}
def _get_changes_entities(self): entities_updates = [] files = file_utils.load_files( self.cfg.static_physical.directory, '.yaml') for file_ in files: full_path = self.cfg.static_physical.directory +\ '/' + file_ config = file_utils.load_yaml_file(full_path) if config: if file_ in self.cache: if str(config) != str(self.cache[file_]): # TODO(alexey_weyl): need also to remove deleted # files from cache old_config = copy.deepcopy(config) self._update_on_existing_entities( self.cache[file_][self.ENTITIES_SECTION], config[self.ENTITIES_SECTION], entities_updates) self._update_on_new_entities( config[self.ENTITIES_SECTION], self.cache[file_][self.ENTITIES_SECTION], entities_updates) self.cache[file_] = old_config else: self.cache[file_] = config entities_updates += \ self._get_entities_from_file(file_, full_path) # iterate over deleted files deleted_files = set(self.cache.keys()) - set(files) for file_ in deleted_files: self._update_on_existing_entities( self.cache[file_][self.ENTITIES_SECTION], {}, entities_updates) del self.cache[file_] return entities_updates
def test_basic_template(self): # Test setup template_path = '%s/templates/general/%s' % (utils.get_resources_dir(), self.BASIC_TEMPLATE) template_definition = file_utils.load_yaml_file(template_path, True) template = Template(template_definition) entities = template.entities relationships = template.relationships scenarios = template.scenarios definitions = template_definition[TFields.DEFINITIONS] # Assertions entities_definition = definitions[TFields.ENTITIES] self._validate_entities(entities, entities_definition) relate_def = definitions[TFields.RELATIONSHIPS] self._validate_relationships(relationships, relate_def, entities) self._validate_scenarios(scenarios, entities)
def _get_changes_entities(self): entities_updates = [] files = file_utils.load_files(self.cfg.static_physical.directory, '.yaml') for file_ in files: full_path = self.cfg.static_physical.directory +\ '/' + file_ config = file_utils.load_yaml_file(full_path) if config: if file_ in self.cache: if str(config) != str(self.cache[file_]): # TODO(alexey_weyl): need also to remove deleted # files from cache old_config = copy.deepcopy(config) self._update_on_existing_entities( self.cache[file_][self.ENTITIES_SECTION], config[self.ENTITIES_SECTION], entities_updates) self._update_on_new_entities( config[self.ENTITIES_SECTION], self.cache[file_][self.ENTITIES_SECTION], entities_updates) self.cache[file_] = old_config else: self.cache[file_] = config entities_updates += \ self._get_entities_from_file(file_, full_path) # iterate over deleted files deleted_files = set(self.cache.keys()) - set(files) for file_ in deleted_files: self._update_on_existing_entities( self.cache[file_][self.ENTITIES_SECTION], {}, entities_updates) del self.cache[file_] return entities_updates
def _retrieve_states_and_priorities_from_file(self, full_path): states = {} priorities = {} config = file_utils.load_yaml_file(full_path, with_exception=True) category = config['category'] for item in config['values']: aggregated_values = item['aggregated values'] priority_value = int(aggregated_values['priority']) # original to operational value for original_state in aggregated_values['original values']: original_value = original_state['name'] operational_value = original_state['operational_value'] states[original_value.upper()] = operational_value priorities[original_value.upper()] = priority_value self._check_validity(category, states, priorities, full_path) self._add_default_states(states, priorities, category) return states, priorities
def _retrieve_states_and_priorities_from_file(self, full_path): states = {} priorities = {} config = file_utils.load_yaml_file(full_path, with_exception=True) category = config['category'] for item in config[self.VALUES]: normalized_state = item['normalized value'] # original to normalized value normalized_state_name = normalized_state['name'] for original_state in normalized_state['original values']: states[original_state['name'].upper()] = normalized_state_name self._add_default_states(states, priorities, category) # normalized value priority priorities[normalized_state_name] = \ int(normalized_state['priority']) self.check_validity(category, priorities, full_path) return states, priorities