X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=osm_policy_module%2Fcommon%2Fmon_client.py;h=e4f75336aaf02ace3a5463e36b876bfc965b25a4;hb=bfe6988e8ec5ad9283200f46134529cac10e006c;hp=d5e8dfc3da089f8d1f64ef1a9a06871ef6523293;hpb=d37c54c64eec65c9a3c490a31eef3a02a76cb474;p=osm%2FPOL.git diff --git a/osm_policy_module/common/mon_client.py b/osm_policy_module/common/mon_client.py index d5e8dfc..e4f7533 100644 --- a/osm_policy_module/common/mon_client.py +++ b/osm_policy_module/common/mon_client.py @@ -23,7 +23,7 @@ ## import json import logging -import random +from random import SystemRandom from json import JSONDecodeError import yaml @@ -50,8 +50,10 @@ class MonClient: operation: str, statistic: str = "AVERAGE", action: str = "", + vnfr: object = None, + vnfd: object = None, ): - cor_id = random.randint(1, 10e7) + cor_id = SystemRandom().randint(1, 10e7) msg = self._build_create_alarm_payload( cor_id, metric_name, @@ -62,6 +64,8 @@ class MonClient: statistic, operation, action, + vnfr, + vnfd, ) log.debug("Sending create_alarm_request %s", msg) producer = AIOKafkaProducer( @@ -107,7 +111,7 @@ class MonClient: async def delete_alarm( self, ns_id: str, vnf_member_index: str, vdu_name: str, alarm_uuid: str ): - cor_id = random.randint(1, 10e7) + cor_id = SystemRandom().randint(1, 10e7) msg = self._build_delete_alarm_payload( cor_id, ns_id, vdu_name, vnf_member_index, alarm_uuid ) @@ -165,7 +169,27 @@ 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] + metric_port = 9100 + 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 +201,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,