From 1d71df519a27b90cf88c11b1b14227928db2db1f Mon Sep 17 00:00:00 2001 From: Gianpietro Lavado Date: Mon, 2 Dec 2019 17:41:20 +0000 Subject: [PATCH] Minor fixes for MON Evaluator & Dashboarder Change-Id: I1f2b1f786809aa84e2ee2cddbf401a03e504ff47 Signed-off-by: Gianpietro Lavado --- MANIFEST.in | 2 +- osm_mon/core/models.py | 6 ++++-- osm_mon/dashboarder/service.py | 5 +++-- osm_mon/evaluator/evaluator.py | 4 ++-- osm_mon/tests/unit/core/test_common_db_client.py | 5 +++-- 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/MANIFEST.in b/MANIFEST.in index 845273b..d95867d 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -22,5 +22,5 @@ include requirements.txt include test-requirements.txt include README.rst -recursive-include osm_mon *.py *.xml *.sh *.yaml +recursive-include osm_mon *.py *.xml *.sh *.yaml *.json recursive-include devops-stages * diff --git a/osm_mon/core/models.py b/osm_mon/core/models.py index 1810c9b..ca25d8b 100644 --- a/osm_mon/core/models.py +++ b/osm_mon/core/models.py @@ -44,7 +44,8 @@ class Alarm: 'threshold': self.threshold, 'statistic': self.statistic, 'metric': self.metric, - 'tags': self.tags + 'tags': self.tags, + 'operation': self.operation } return alarm @@ -54,8 +55,9 @@ class Alarm: alarm.uuid = data.get('uuid', str(uuid.uuid4())) alarm.name = data.get('name') alarm.severity = data.get('severity') - alarm.threshold = data.get('threshold') + alarm.threshold = float(data.get('threshold')) alarm.statistic = data.get('statistic') alarm.metric = data.get('metric') alarm.tags = data.get('tags') + alarm.operation = data.get('operation') return alarm diff --git a/osm_mon/dashboarder/service.py b/osm_mon/dashboarder/service.py index 10dc0f7..74812b5 100644 --- a/osm_mon/dashboarder/service.py +++ b/osm_mon/dashboarder/service.py @@ -25,6 +25,7 @@ import logging from osm_mon.core.common_db import CommonDbClient from osm_mon.core.config import Config import osm_mon.dashboarder.backends.grafana as grafana +from osm_mon import __path__ as mon_path log = logging.getLogger(__name__) @@ -46,7 +47,7 @@ class DashboarderService: project_id = project['_id'] # Collect Project IDs for periodical dashboard clean-up osm_resource_uids.append(project_id) - dashboard_path = '/mon/osm_mon/dashboarder/templates/project_scoped.json' + dashboard_path = '{}/dashboarder/templates/project_scoped.json'.format(mon_path) if project_id not in dashboard_uids: project_name = project['name'] grafana.create_dashboard(project_id, project_name, @@ -60,7 +61,7 @@ class DashboarderService: nsrs = self.common_db.get_nsrs() for nsr in nsrs: nsr_id = nsr['_id'] - dashboard_path = '/mon/osm_mon/dashboarder/templates/ns_scoped.json' + dashboard_path = '{}/dashboarder/templates/ns_scoped.json'.format(mon_path) # Collect NS IDs for periodical dashboard clean-up osm_resource_uids.append(nsr_id) # Check if the NSR's VNFDs contain metrics diff --git a/osm_mon/evaluator/evaluator.py b/osm_mon/evaluator/evaluator.py index cc9a8ad..7e86743 100644 --- a/osm_mon/evaluator/evaluator.py +++ b/osm_mon/evaluator/evaluator.py @@ -79,8 +79,8 @@ class Evaluator: def _build_alarm_response(self, alarm: Alarm, status: AlarmStatus): response = ResponseBuilder() tags = {} - for tag in alarm.tags: - tags[tag.name] = tag.value + for name, value in alarm.tags.items(): + tags[name] = value now = time.strftime("%d-%m-%Y") + " " + time.strftime("%X") return response.generate_response( 'notify_alarm', diff --git a/osm_mon/tests/unit/core/test_common_db_client.py b/osm_mon/tests/unit/core/test_common_db_client.py index 7102226..b982bca 100644 --- a/osm_mon/tests/unit/core/test_common_db_client.py +++ b/osm_mon/tests/unit/core/test_common_db_client.py @@ -172,8 +172,9 @@ class CommonDbClientTest(unittest.TestCase): alarm.uuid = '1' common_db_client = CommonDbClient(self.config) common_db_client.create_alarm(alarm) - create.assert_called_with('alarms', {'tags': {}, 'threshold': 50.0, 'metric': 'metric', 'severity': 'severity', - 'statistic': 'statistic', 'name': 'name', 'uuid': '1'}) + create.assert_called_with('alarms', {'tags': {}, 'threshold': 50.0, 'metric': 'metric', + 'severity': 'severity', 'statistic': 'statistic', + 'name': 'name', 'operation': 'operation', 'uuid': '1'}) @mock.patch.object(dbmongo.DbMongo, "db_connect", mock.Mock()) @mock.patch.object(dbmongo.DbMongo, "del_one") -- 2.25.1