Bug Fix - 2305: Automated scaling of Vnf is not happening through metrics collected by feature Service KPI of VNF using exporter endpoint

Change-Id: I5cbb13919539d8727aba2519a50be47f618f24c2
Signed-off-by: Rahul Kumar <rahul.k4@tataelxsi.co.in>
diff --git a/osm_policy_module/common/mon_client.py b/osm_policy_module/common/mon_client.py
index d5e8dfc..e9216aa 100644
--- a/osm_policy_module/common/mon_client.py
+++ b/osm_policy_module/common/mon_client.py
@@ -50,6 +50,8 @@
         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 @@
             statistic,
             operation,
             action,
+            vnfr,
+            vnfd,
         )
         log.debug("Sending create_alarm_request %s", msg)
         producer = AIOKafkaProducer(
@@ -165,7 +169,26 @@
         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 @@
             "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,