def _create_vertex(self, entity_event): metadata = { VProps.NAME: get_label(entity_event, PAlertLabels.ALERT_NAME), VProps.SEVERITY: get_label(entity_event, PAlertLabels.SEVERITY), PProps.STATUS: entity_event.get(PProps.STATUS), } return graph_utils.create_vertex( self._create_entity_key(entity_event), vitrage_category=ECategory.ALARM, vitrage_type=entity_event[DSProps.ENTITY_TYPE], vitrage_sample_timestamp=entity_event[DSProps.SAMPLE_DATE], entity_state=self._get_alarm_state(entity_event), update_timestamp=get_alarm_update_time(entity_event), metadata=metadata)
def _enrich_alert(self, alert, event_type): """Enrich prometheus alert. Adding fields to prometheus alert in order to map it to vitrage entity. :param alert: Prometheus alert :param event_type: The type of the event. Always 'prometheus.alert'. :return: Enriched prometheus alert """ alert[DSProps.EVENT_TYPE] = event_type vitrage_entity_unique_props = \ self._calculate_vitrage_entity_unique_props(alert) alert[PDProps.ENTITY_UNIQUE_PROPS] = \ vitrage_entity_unique_props old_alarm = self._old_alarm(alert) alert = self._filter_and_cache_alarm(alert, old_alarm, self._filter_get_erroneous, get_alarm_update_time(alert)) return alert
def enrich_event(self, event, event_type): """Get an event from Prometheus and create a list of alarm events :param event: dictionary of this form: { "status": "firing", "groupLabels": { "alertname": "HighInodeUsage" }, "groupKey": "{}:{alertname=\"HighInodeUsage\"}", "commonAnnotations": { "mount_point": "/%", "description": "\"Consider ssh\"ing into the instance \"\n", "title": "High number of inode usage", "value": "96.81%", "device": "/dev/vda1%", "runbook": "troubleshooting/filesystem_alerts_inodes.md" }, "alerts": [ { "status": "firing", "labels": { "severity": "critical", "fstype": "ext4", "instance": "localhost:9100", "job": "node", "alertname": "HighInodeUsage", "device": "/dev/vda1", "mountpoint": "/" }, "endsAt": "0001-01-01T00:00:00Z", "generatorURL": "http://devstack-rocky-4:9090/graph?g0.htm1", "startsAt": "2018-05-03T12:25:38.231388525Z", "annotations": { "mount_point": "/%", "description": "\"Consider ssh\"ing into the instance\"\n", "title": "High number of inode usage", "value": "96.81%", "device": "/dev/vda1%", "runbook": "troubleshooting/filesystem_alerts_inodes.md" } } ], "version": "4", "receiver": "vitrage", "externalURL": "http://devstack-rocky-4:9093", "commonLabels": { "severity": "critical", "fstype": "ext4", "instance": "localhost:9100", "job": "node", "alertname": "HighInodeUsage", "device": "/dev/vda1", "mountpoint": "/" } } :param event_type: The type of the event. Always 'prometheus.alarm'. :return: a list of events, one per Prometheus alert """ LOG.debug('Going to enrich event: %s', str(event)) alarms = [] for alarm in event.get(PProps.ALERTS, []): alarm[DSProps.EVENT_TYPE] = event_type alarm[PProps.STATUS] = event[PProps.STATUS] old_alarm = self._old_alarm(alarm) alarm = self._filter_and_cache_alarm(alarm, old_alarm, self._filter_get_erroneous, get_alarm_update_time(alarm)) if alarm: alarms.append(alarm) LOG.debug('Enriched event. Created alarm events: %s', str(alarms)) return self.make_pickleable(alarms, PROMETHEUS_DATASOURCE, DatasourceAction.UPDATE)
def enrich_event(self, event, event_type): """Get an event from Prometheus and create a list of alarm events :param event: dictionary of this form: { "details": { "status": "firing", "groupLabels": { "alertname": "HighInodeUsage" }, "groupKey": "{}:{alertname=\"HighInodeUsage\"}", "commonAnnotations": { "mount_point": "/%", "description": "\"Consider ssh\"ing into instance \"\n", "title": "High number of inode usage", "value": "96.81%", "device": "/dev/vda1%", "runbook": "troubleshooting/filesystem_alerts_inodes.md" }, "alerts": [ { "status": "firing", "labels": { "severity": "critical", "fstype": "ext4", "instance": "localhost:9100", "job": "node", "alertname": "HighInodeUsage", "device": "/dev/vda1", "mountpoint": "/" }, "endsAt": "0001-01-01T00:00:00Z", "generatorURL": "http://devstack-4:9090/graph?g0.htm1", "startsAt": "2018-05-03T12:25:38.231388525Z", "annotations": { "mount_point": "/%", "description": "\"Consider ssh\"ing into instance\"\n", "title": "High number of inode usage", "value": "96.81%", "device": "/dev/vda1%", "runbook": "filesystem_alerts_inodes.md" } } ], "version": "4", "receiver": "vitrage", "externalURL": "http://devstack-rocky-4:9093", "commonLabels": { "severity": "critical", "fstype": "ext4", "instance": "localhost:9100", "job": "node", "alertname": "HighInodeUsage", "device": "/dev/vda1", "mountpoint": "/" } } } :param event_type: The type of the event. Always 'prometheus.alarm'. :return: a list of events, one per Prometheus alert """ LOG.debug('Going to enrich event: %s', str(event)) alarms = [] details = event.get(EProps.DETAILS) if details: for alarm in details.get(PProps.ALERTS, []): alarm[DSProps.EVENT_TYPE] = event_type alarm[PProps.STATUS] = details[PProps.STATUS] instance_id = get_label(alarm, PLabels.INSTANCE) if ':' in instance_id: instance_id = instance_id[:instance_id.index(':')] # The 'instance' label can be instance ip or hostname. # we try to fetch the instance id from nova by its ip, # and if not found we leave it as it is. nova_instance = self.nova_client.servers.list( search_opts={'all_tenants': 1, 'ip': instance_id}) if nova_instance: instance_id = nova_instance[0].id alarm[PLabels.INSTANCE_ID] = instance_id old_alarm = self._old_alarm(alarm) alarm = self._filter_and_cache_alarm( alarm, old_alarm, self._filter_get_erroneous, get_alarm_update_time(alarm)) if alarm: alarms.append(alarm) LOG.debug('Enriched event. Created alarm events: %s', str(alarms)) return self.make_pickleable(alarms, PROMETHEUS_DATASOURCE, DatasourceAction.UPDATE)