Minor fixes for MON Evaluator & Dashboarder 89/8289/4
authorGianpietro Lavado <glavado@whitestack.com>
Mon, 2 Dec 2019 17:41:20 +0000 (17:41 +0000)
committerGianpietro Lavado <glavado@whitestack.com>
Mon, 2 Dec 2019 18:19:30 +0000 (18:19 +0000)
Change-Id: I1f2b1f786809aa84e2ee2cddbf401a03e504ff47
Signed-off-by: Gianpietro Lavado <glavado@whitestack.com>
MANIFEST.in
osm_mon/core/models.py
osm_mon/dashboarder/service.py
osm_mon/evaluator/evaluator.py
osm_mon/tests/unit/core/test_common_db_client.py

index 845273b..d95867d 100644 (file)
@@ -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 *
index 1810c9b..ca25d8b 100644 (file)
@@ -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
index 10dc0f7..74812b5 100644 (file)
@@ -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
index cc9a8ad..7e86743 100644 (file)
@@ -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',
index 7102226..b982bca 100644 (file)
@@ -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")