Esempio n. 1
0
 def map(self, name, labels):
     mapping = self._mapping.get(name)
     if not mapping:
         raise exceptions.MappingNotFound(key=name)
     kind = mapping['kind']
     properties = {}
     for prop, prop_mapping in mapping['properties'].items():
         value = labels.get(prop_mapping)
         valid = self._validate_value(value, mapping)
         if not valid:
             raise exceptions.InvalidMappedValue(key=name, value=value)
         properties[prop] = value
     return {'kind': kind, 'properties': properties}
Esempio n. 2
0
 def _load_mapping(self):
     mapping_spec = self._load_mapping_spec()
     if not mapping_spec:
         raise exceptions.MappingNotFound(key=self._mapping_key)
     blacklist_values = mapping_spec.get('blacklist_values')
     if not blacklist_values:
         blacklist_values = []
     mappings = mapping_spec['mappings']
     lookup = {}
     for mapping in mappings:
         name = mapping['name']
         lookup[name] = mapping['source_mapping']
         lookup[name].setdefault('blacklist_values', blacklist_values)
     return lookup
Esempio n. 3
0
 def _load_mapping(self):
     # TODO: Read mapping path from config
     mapping_path = "/etc/orca/alerts-mapping.yaml"
     mapping_spec = file_utils.load_yaml(mapping_path).get(
         self._mapping_key)
     if not mapping_spec:
         raise exceptions.MappingNotFound(key=self._mapping_key)
     blacklist_values = mapping_spec.get('blacklist_values')
     if not blacklist_values:
         blacklist_values = []
     mappings = mapping_spec['mappings']
     lookup = {}
     for mapping in mappings:
         name = mapping['name']
         lookup[name] = mapping['source_mapping']
         lookup[name].setdefault('blacklist_values', blacklist_values)
     return lookup