Feature 10339 - Enhanced Alarm Mgmt. (SOL005 FM Interface) 16/10516/4
authorAtul Agarwal <atul.agarwal@altran.com>
Fri, 19 Mar 2021 10:11:38 +0000 (10:11 +0000)
committerAtul Agarwal <atul.agarwal@altran.com>
Fri, 21 May 2021 10:11:26 +0000 (10:11 +0000)
Change-Id: I917a09ebc4c3b262b5dea8056cae775615a654d6
Signed-off-by: Atul Agarwal <atul.agarwal@altran.com>
osm_policy_module/alarming/service.py
osm_policy_module/autoscaling/service.py
osm_policy_module/common/mon_client.py
osm_policy_module/tests/integration/test_policy_agent.py

index 37fa6a1..b93dba7 100644 (file)
@@ -101,6 +101,14 @@ class AlarmingService:
                                 metric_name = self._get_metric_name(
                                     vnf_monitoring_param
                                 )
+                                alarm_action = dict()
+                                for action_type in ["ok", "insufficient-data", "alarm"]:
+                                    if "actions" in alarm_descriptor and action_type in alarm_descriptor["actions"]:
+                                        for url in alarm_descriptor["actions"][action_type]:
+                                            if "webhook" in alarm_action:
+                                                alarm_action["webhook"].append(url["url"])
+                                            else:
+                                                alarm_action["webhook"] = [url["url"]]
                                 alarm_uuid = await self.mon_client.create_alarm(
                                     metric_name=metric_name,
                                     ns_id=nsr_id,
@@ -108,6 +116,7 @@ class AlarmingService:
                                     vnf_member_index=vnfr["member-vnf-index-ref"],
                                     threshold=alarm_descriptor["value"],
                                     operation=alarm_descriptor["operation"],
+                                    action=str(alarm_action),
                                 )
                                 alarm = VnfAlarmRepository.create(
                                     alarm_id=alarm_descriptor["alarm-id"],
index 2709f64..a8c36e0 100644 (file)
@@ -190,6 +190,7 @@ class AutoscalingService:
                                                     operation=scaling_criteria[
                                                         "scale-in-relational-operation"
                                                     ],
+                                                    action="scale_in"
                                                 )
                                             )
                                             alarm = ScalingAlarmRepository.create(
@@ -215,6 +216,7 @@ class AutoscalingService:
                                             operation=scaling_criteria[
                                                 "scale-out-relational-operation"
                                             ],
+                                            action="scale_out",
                                         )
                                         alarm = ScalingAlarmRepository.create(
                                             alarm_uuid=alarm_uuid,
index ff8339f..b8c3779 100644 (file)
@@ -53,6 +53,7 @@ class MonClient:
         threshold: int,
         operation: str,
         statistic: str = "AVERAGE",
+        action: str = '',
     ):
         cor_id = random.randint(1, 10e7)
         msg = self._build_create_alarm_payload(
@@ -64,6 +65,7 @@ class MonClient:
             threshold,
             statistic,
             operation,
+            action,
         )
         log.debug("Sending create_alarm_request %s", msg)
         producer = AIOKafkaProducer(
@@ -170,6 +172,7 @@ class MonClient:
         threshold: int,
         statistic: str,
         operation: str,
+        action: str,
     ):
 
         alarm_create_request = {
@@ -182,6 +185,7 @@ class MonClient:
             "severity": "critical",
             "threshold_value": threshold,
             "statistic": statistic,
+            "action": action,
             "tags": {
                 "ns_id": ns_id,
                 "vdu_name": vdu_name,
index 2c86b12..6b1dc64 100644 (file)
@@ -505,6 +505,7 @@ class PolicyModuleAgentTest(unittest.TestCase):
             threshold=80,
             vdu_name="cirros_ns-1-cirros_vnfd-VM-1",
             vnf_member_index="1",
+            action="scale_out",
         )
         create_alarm.assert_not_called_with(
             metric_name="average_memory_utilization",
@@ -513,6 +514,7 @@ class PolicyModuleAgentTest(unittest.TestCase):
             threshold=20,
             vdu_name="cirros_ns-1-cirros_vnfd-VM-1",
             vnf_member_index="1",
+            action="scale_out",
         )
         create_alarm.assert_any_call(
             metric_name="average_memory_utilization",
@@ -521,6 +523,7 @@ class PolicyModuleAgentTest(unittest.TestCase):
             threshold=80,
             vdu_name="cirros_ns-2-cirros_vnfd-VM-1",
             vnf_member_index="2",
+            action="scale_out",
         )
         create_alarm.assert_not_called_with(
             metric_name="average_memory_utilization",
@@ -529,6 +532,7 @@ class PolicyModuleAgentTest(unittest.TestCase):
             threshold=20,
             vdu_name="cirros_ns-2-cirros_vnfd-VM-1",
             vnf_member_index="2",
+            action="scale_out",
         )
         scaling_record = ScalingGroup.get()
         self.assertEqual(scaling_record.name, "scale_cirros_vnfd-VM")
@@ -569,6 +573,7 @@ class PolicyModuleAgentTest(unittest.TestCase):
             vnf_member_index="1",
             threshold=20.0,
             operation="LT",
+            action="{'webhook': ['localhost:9090', 'localhost:9090', 'localhost:9090']}"
         )
         create_alarm.assert_any_call(
             metric_name="average_memory_utilization",
@@ -577,6 +582,7 @@ class PolicyModuleAgentTest(unittest.TestCase):
             vnf_member_index="2",
             threshold=20.0,
             operation="LT",
+            action="{'webhook': ['localhost:9090', 'localhost:9090', 'localhost:9090']}"
         )