Bug Fix - 2305: Automated scaling of Vnf is not happening through metrics collected...
[osm/POL.git] / osm_policy_module / common / mon_client.py
index d5e8dfc..e9216aa 100644 (file)
@@ -50,6 +50,8 @@ class MonClient:
         operation: str,
         statistic: str = "AVERAGE",
         action: str = "",
+        vnfr: object = None,
+        vnfd: object = None,
     ):
         cor_id = random.randint(1, 10e7)
         msg = self._build_create_alarm_payload(
@@ -62,6 +64,8 @@ class MonClient:
             statistic,
             operation,
             action,
+            vnfr,
+            vnfd,
         )
         log.debug("Sending create_alarm_request %s", msg)
         producer = AIOKafkaProducer(
@@ -165,7 +169,26 @@ class MonClient:
         statistic: str,
         operation: str,
         action: str,
+        vnfr=None,
+        vnfd=None,
     ):
+        tags = {
+            "ns_id": ns_id,
+            "vdu_name": vdu_name,
+            "vnf_member_index": vnf_member_index,
+        }
+        if vnfr and vnfd:
+            # TODO: Change for multiple DF support
+            df = vnfd.get("df", [{}])[0]
+            if "exporters-endpoints" in df:
+                metric_port = df["exporters-endpoints"].get("metric-port", 9100)
+            if metric_name.startswith("kpi_"):
+                metric_name = metric_name.replace("kpi_", "")
+                metric_name.strip()
+                for vdu in vnfr["vdur"]:
+                    if vdu["name"] == vdu_name:
+                        vdu_ip = vdu["ip-address"]
+                        tags = {"instance": vdu_ip + ":" + str(metric_port)}
         alarm_create_request = {
             "correlation_id": cor_id,
             "alarm_name": "osm_alarm_{}_{}_{}_{}".format(
@@ -177,11 +200,7 @@ class MonClient:
             "threshold_value": threshold,
             "statistic": statistic,
             "action": action,
-            "tags": {
-                "ns_id": ns_id,
-                "vdu_name": vdu_name,
-                "vnf_member_index": vnf_member_index,
-            },
+            "tags": tags,
         }
         msg = {
             "alarm_create_request": alarm_create_request,