From fdb88a550d2bc5a4152ca3bc2ed87e79e0794c24 Mon Sep 17 00:00:00 2001 From: Eyal Date: Sun, 29 Jan 2017 11:23:45 +0200 Subject: [PATCH] fix mapping to create an alarm on a resource other then host e.g a network interface attached to a host Implements: blueprint collectd-datasource Change-Id: Ib9133fb4b9738daeb49fd86085d63a76a26b0b65 --- .../datasources_values/network.interface.yaml | 22 +++++++++++++++++++ vitrage/api_handler/apis/template.py | 2 +- .../collectd_vitrage/vitrageplugin.py | 2 +- vitrage/datasources/collectd/driver.py | 8 +++++-- vitrage/datasources/collectd/properties.py | 3 +++ vitrage/datasources/collectd/transformer.py | 8 +++++++ 6 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 etc/vitrage/datasources_values/network.interface.yaml diff --git a/etc/vitrage/datasources_values/network.interface.yaml b/etc/vitrage/datasources_values/network.interface.yaml new file mode 100644 index 000000000..358c6c2d2 --- /dev/null +++ b/etc/vitrage/datasources_values/network.interface.yaml @@ -0,0 +1,22 @@ +category: RESOURCE +values: + - aggregated values: + priority: 40 + original values: + - name: DELETED + operational_value: DELETED + - aggregated values: + priority: 30 + original values: + - name: ERROR + operational_value: ERROR + - aggregated values: + priority: 20 + original values: + - name: SUBOPTIMAL + operational_value: SUBOPTIMAL + - aggregated values: + priority: 10 + original values: + - name: available + operational_value: OK diff --git a/vitrage/api_handler/apis/template.py b/vitrage/api_handler/apis/template.py index cbffaf1f8..00105a2db 100644 --- a/vitrage/api_handler/apis/template.py +++ b/vitrage/api_handler/apis/template.py @@ -53,7 +53,7 @@ class TemplateApis(object): def show_template(self, ctx, template_uuid): - LOG.debug("Show template with uuid: $s", str(template_uuid)) + LOG.debug("Show template with uuid: %s", str(template_uuid)) template = self.templates[template_uuid] diff --git a/vitrage/datasources/collectd/collectd_vitrage/vitrageplugin.py b/vitrage/datasources/collectd/collectd_vitrage/vitrageplugin.py index 3c0e88526..44ff3cc54 100644 --- a/vitrage/datasources/collectd/collectd_vitrage/vitrageplugin.py +++ b/vitrage/datasources/collectd/collectd_vitrage/vitrageplugin.py @@ -85,7 +85,7 @@ class VitrageNotifier(CollectDPlugin): payload = { 'host': notification.host, 'plugin': notification.plugin, - 'type': notification.type, + 'collectd_type': notification.type, 'message': notification.message, 'severity': severity, 'time': notification.time, diff --git a/vitrage/datasources/collectd/driver.py b/vitrage/datasources/collectd/driver.py index 70f14f7f5..78c21cf90 100644 --- a/vitrage/datasources/collectd/driver.py +++ b/vitrage/datasources/collectd/driver.py @@ -79,8 +79,12 @@ class CollectdDriver(AlarmDriverBase): event[DSProps.EVENT_TYPE] = event_type if CollectdDriver.conf_map: - collectd_host = event[CProps.HOST] - v_resource = CollectdDriver.conf_map[collectd_host] + # PLUGIN_INSTANCE is optional + resources = [event[CProps.HOST], event[CProps.PLUGIN], + event.get(CProps.PLUGIN_INSTANCE)] + resource = '/'.join([resource for resource in resources if + resource]) + v_resource = CollectdDriver.conf_map[resource] event[CProps.RESOURCE_NAME] = v_resource[CProps.RESOURCE_NAME] event[CProps.RESOURCE_TYPE] = v_resource[CProps.RESOURCE_TYPE] diff --git a/vitrage/datasources/collectd/properties.py b/vitrage/datasources/collectd/properties.py index 9b282d369..2c0a6a729 100644 --- a/vitrage/datasources/collectd/properties.py +++ b/vitrage/datasources/collectd/properties.py @@ -20,4 +20,7 @@ class CollectdProperties(object): TIME = 'time' MESSAGE = 'message' HOST = 'host' + PLUGIN = 'plugin' + PLUGIN_INSTANCE = 'plugin_instance' + TYPE_INSTANCE = 'type_instance' ID = 'id' diff --git a/vitrage/datasources/collectd/transformer.py b/vitrage/datasources/collectd/transformer.py index 79a13516a..43cae4e2b 100644 --- a/vitrage/datasources/collectd/transformer.py +++ b/vitrage/datasources/collectd/transformer.py @@ -57,6 +57,7 @@ class CollectdTransformer(AlarmTransformerBase): metadata = { VProps.NAME: entity_event[CProps.MESSAGE], VProps.SEVERITY: entity_event[CProps.SEVERITY], + VProps.RAWTEXT: self.generate_raw_text(entity_event) } return graph_utils.create_vertex( @@ -101,3 +102,10 @@ class CollectdTransformer(AlarmTransformerBase): def get_type(self): return COLLECTD_DATASOURCE + + @staticmethod + def generate_raw_text(entity_event): + resources = [entity_event.get(CProps.TYPE_INSTANCE), + entity_event[CProps.PLUGIN], + entity_event.get(CProps.PLUGIN_INSTANCE)] + return '-'.join([resource for resource in resources if resource])