From d7d4188d061bd0889c8fdb347844ced89ee402ac Mon Sep 17 00:00:00 2001 From: Kien Nguyen Date: Mon, 24 Dec 2018 16:06:01 +0700 Subject: [PATCH] Check if instance_id is not None get_label returns instance_id that can be None [1]. It could lead to the exception [2]. The patch will resolve it. [1] https://github.com/openstack/vitrage/blob/master/vitrage/datasources/prometheus/properties.py#L56 [2] http://paste.openstack.org/show/738265/ Change-Id: Ic914832fde53cd904bfc0e3313348d3025c69ca0 --- vitrage/datasources/prometheus/driver.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/vitrage/datasources/prometheus/driver.py b/vitrage/datasources/prometheus/driver.py index 8be65e986..40309507a 100644 --- a/vitrage/datasources/prometheus/driver.py +++ b/vitrage/datasources/prometheus/driver.py @@ -148,17 +148,18 @@ class PrometheusDriver(AlarmDriverBase): 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(':')] + if instance_id is not None: + 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 + # 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(