Beispiel #1
0
    def __init__(self, conf):
        super(KapacitorDriver, self).__init__()
        self.cfg = conf

        if not KapacitorDriver.conf_map:
            self.conf_map = KapacitorConfig(conf)
        self._client = None
Beispiel #2
0
    def test_get_vitrage_resource(self):
        """Test the resource returned after processing a list of mappings

        :return:
        """
        # Action
        kapacitor_conf = KapacitorConfig(self.conf)

        # Test assertions
        mapped_resource = kapacitor_conf.get_vitrage_resource(None)
        self.assertIsNone(mapped_resource, 'expected None')

        mapped_resource = kapacitor_conf.get_vitrage_resource('')
        self.assertIsNone(mapped_resource, 'expected None')

        mapped_resource = kapacitor_conf.get_vitrage_resource('cloud.compute1')
        self.assertIsNotNone(mapped_resource, 'expected Not None')
        self.assertEqual(NOVA_HOST_DATASOURCE, mapped_resource[0])
        self.assertEqual('compute-1', mapped_resource[1])

        mapped_resource = kapacitor_conf.get_vitrage_resource('compute-2')
        self.assertIsNotNone(mapped_resource, 'expected Not None')
        self.assertEqual(NOVA_HOST_DATASOURCE, mapped_resource[0])
        self.assertEqual('compute-2', mapped_resource[1])

        mapped_resource = kapacitor_conf.get_vitrage_resource('instance-1')
        self.assertIsNotNone(mapped_resource, 'expected Not None')
        self.assertEqual(NOVA_INSTANCE_DATASOURCE, mapped_resource[0])
        self.assertEqual('instance-1', mapped_resource[1])
Beispiel #3
0
class KapacitorDriver(AlarmDriverBase):
    ServiceKey = namedtuple('ServiceKey', ['hostname', 'alarmid'])
    conf_map = None

    def __init__(self):
        super(KapacitorDriver, self).__init__()

        if not KapacitorDriver.conf_map:
            self.conf_map = KapacitorConfig()
        self._client = None

    @staticmethod
    def get_event_types():
        return [
            'kapacitor.alarm.ok', 'kapacitor.alarm.info',
            'kapacitor.alarm.warning', 'kapacitor.alarm.critical'
        ]

    def _vitrage_type(self):
        return KAPACITOR_DATASOURCE

    def _alarm_key(self, alarm):
        return self.ServiceKey(hostname=alarm[KProps.RESOURCE_NAME],
                               alarmid=alarm[KProps.ID])

    def _enrich_alarms(self, alarms):
        """Enrich kapacitor alarm using kapacitor configuration file

        Converting Kapacitor host name to Vitrage resource type and name
        It is function of get_all for pulling method
        Not implement yet
        """
        pass

    def enrich_event(self, event, event_type):
        event[DSProps.EVENT_TYPE] = event_type

        kapacitor_host = event[KProps.HOST]
        vitrage_resource = self.conf_map.get_vitrage_resource(kapacitor_host)
        event[KProps.RESOURCE_TYPE] = \
            vitrage_resource[0] if vitrage_resource else None
        event[KProps.RESOURCE_NAME] = \
            vitrage_resource[1] if vitrage_resource else None
        return KapacitorDriver.make_pickleable([event], KAPACITOR_DATASOURCE,
                                               DatasourceAction.UPDATE)[0]

    def _is_erroneous(self, alarm):
        return alarm and alarm[KProps.PRIORITY] != KapacitorState.OK

    def _status_changed(self, new_alarm, old_alarm):
        return new_alarm and old_alarm and \
            not new_alarm[KProps.PRIORITY] == old_alarm[KProps.PRIORITY]

    def _is_valid(self, alarm):
        return alarm[KProps.RESOURCE_TYPE] is not None and \
            alarm[KProps.RESOURCE_NAME] is not None

    def _get_alarms(self):
        """Query all alarm and send to vitrage

        Not implement yet
        """
        return []

    @staticmethod
    def should_delete_outdated_entities():
        return True