Fix 2111: Added config parameter to disable vms status check 91/12691/1 v10.0 v10.1.3 v10.1.4 v10.1.5
authorlimon <alimonj@indra.es>
Tue, 8 Nov 2022 16:36:14 +0000 (17:36 +0100)
committerlimon <alimonj@indra.es>
Tue, 15 Nov 2022 10:19:13 +0000 (11:19 +0100)
Change-Id: I31194532617aa64768c981ab50f3944c8f44598c
Signed-off-by: limon <alimonj@indra.es>
osm_mon/collector/infra_collectors/base_osinfra.py
osm_mon/collector/infra_collectors/vmware.py
osm_mon/core/mon.yaml

index 61e9e42..6d15663 100644 (file)
@@ -57,36 +57,41 @@ class BaseOpenStackInfraCollector(BaseVimInfraCollector):
         vim_status_metric = Metric(vim_tags, "vim_status", vim_status)
         metrics.append(vim_status_metric)
         vnfrs = self.common_db.get_vnfrs(vim_account_id=self.vim_account["_id"])
-        for vnfr in vnfrs:
-            nsr_id = vnfr["nsr-id-ref"]
-            ns_name = self.common_db.get_nsr(nsr_id)["name"]
-            vnf_member_index = vnfr["member-vnf-index-ref"]
-            if vnfr["_admin"]["projects_read"]:
-                vnfr_project_id = vnfr["_admin"]["projects_read"][0]
-            else:
-                vnfr_project_id = ""
-            for vdur in vnfr["vdur"]:
-                if "vim-id" not in vdur:
-                    log.debug("Field vim-id is not present in vdur")
-                    continue
-                resource_uuid = vdur["vim-id"]
-                tags = {
-                    "vim_account_id": self.vim_account["_id"],
-                    "resource_uuid": resource_uuid,
-                    "nsr_id": nsr_id,
-                    "ns_name": ns_name,
-                    "vnf_member_index": vnf_member_index,
-                    "vdur_name": vdur.get("name", ""),
-                    "project_id": vnfr_project_id,
-                }
-                try:
-                    vm = self.nova.servers.get(resource_uuid)
-                    vm_status = 1 if vm.status == "ACTIVE" else 0
-                    vm_status_metric = Metric(tags, "vm_status", vm_status)
-                except Exception as e:
-                    log.warning("VM status is not OK: %s" % e)
-                    vm_status_metric = Metric(tags, "vm_status", 0)
-                metrics.append(vm_status_metric)
+        if self.conf.get("collector", "vm_infra_metrics"):
+            vm_infra_metrics_enabled = str(self.conf.get("collector", "vm_infra_metrics")).lower() in ("yes", "true", "1")
+        else:
+            vm_infra_metrics_enabled = True
+        if vm_infra_metrics_enabled:
+            for vnfr in vnfrs:
+                nsr_id = vnfr["nsr-id-ref"]
+                ns_name = self.common_db.get_nsr(nsr_id)["name"]
+                vnf_member_index = vnfr["member-vnf-index-ref"]
+                if vnfr["_admin"]["projects_read"]:
+                    vnfr_project_id = vnfr["_admin"]["projects_read"][0]
+                else:
+                    vnfr_project_id = ""
+                for vdur in vnfr["vdur"]:
+                    if "vim-id" not in vdur:
+                        log.debug("Field vim-id is not present in vdur")
+                        continue
+                    resource_uuid = vdur["vim-id"]
+                    tags = {
+                        "vim_account_id": self.vim_account["_id"],
+                        "resource_uuid": resource_uuid,
+                        "nsr_id": nsr_id,
+                        "ns_name": ns_name,
+                        "vnf_member_index": vnf_member_index,
+                        "vdur_name": vdur.get("name", ""),
+                        "project_id": vnfr_project_id,
+                    }
+                    try:
+                        vm = self.nova.servers.get(resource_uuid)
+                        vm_status = 1 if vm.status == "ACTIVE" else 0
+                        vm_status_metric = Metric(tags, "vm_status", vm_status)
+                    except Exception as e:
+                        log.warning("VM status is not OK: %s" % e)
+                        vm_status_metric = Metric(tags, "vm_status", 0)
+                    metrics.append(vm_status_metric)
 
         return metrics
 
index 65e739d..6547ab8 100644 (file)
@@ -194,35 +194,40 @@ class VMwareInfraCollector(BaseVimInfraCollector):
         vim_status_metric = Metric(vim_tags, "vim_status", vim_status)
         metrics.append(vim_status_metric)
         vnfrs = self.common_db.get_vnfrs(vim_account_id=vim_account_id)
-        for vnfr in vnfrs:
-            nsr_id = vnfr["nsr-id-ref"]
-            ns_name = self.common_db.get_nsr(nsr_id)["name"]
-            vnf_member_index = vnfr["member-vnf-index-ref"]
-            if vnfr["_admin"]["projects_read"]:
-                vnfr_project_id = vnfr["_admin"]["projects_read"][0]
-            else:
-                vnfr_project_id = ""
-            for vdur in vnfr["vdur"]:
-                resource_uuid = vdur["vim-id"]
-                tags = {
-                    "vim_account_id": self.vim_account_id,
-                    "resource_uuid": resource_uuid,
-                    "nsr_id": nsr_id,
-                    "ns_name": ns_name,
-                    "vnf_member_index": vnf_member_index,
-                    "vdur_name": vdur["name"],
-                    "project_id": vnfr_project_id,
-                }
-                try:
-                    vm_list = self.check_vm_status(resource_uuid)
-                    for vm in vm_list:
-                        if vm["status"] == "4" and vm["deployed"] == "true":
-                            vm_status = 1
-                        else:
-                            vm_status = 0
-                        vm_status_metric = Metric(tags, "vm_status", vm_status)
-                except Exception:
-                    log.exception("VM status is not OK!")
-                    vm_status_metric = Metric(tags, "vm_status", 0)
-                metrics.append(vm_status_metric)
+        if self.conf.get("collector", "vm_infra_metrics"):
+            vm_infra_metrics_enabled = str(self.conf.get("collector", "vm_infra_metrics")).lower() in ("yes", "true", "1")
+        else:
+            vm_infra_metrics_enabled = True
+        if vm_infra_metrics_enabled:
+            for vnfr in vnfrs:
+                nsr_id = vnfr["nsr-id-ref"]
+                ns_name = self.common_db.get_nsr(nsr_id)["name"]
+                vnf_member_index = vnfr["member-vnf-index-ref"]
+                if vnfr["_admin"]["projects_read"]:
+                    vnfr_project_id = vnfr["_admin"]["projects_read"][0]
+                else:
+                    vnfr_project_id = ""
+                for vdur in vnfr["vdur"]:
+                    resource_uuid = vdur["vim-id"]
+                    tags = {
+                        "vim_account_id": self.vim_account_id,
+                        "resource_uuid": resource_uuid,
+                        "nsr_id": nsr_id,
+                        "ns_name": ns_name,
+                        "vnf_member_index": vnf_member_index,
+                        "vdur_name": vdur["name"],
+                        "project_id": vnfr_project_id,
+                    }
+                    try:
+                        vm_list = self.check_vm_status(resource_uuid)
+                        for vm in vm_list:
+                            if vm["status"] == "4" and vm["deployed"] == "true":
+                                vm_status = 1
+                            else:
+                                vm_status = 0
+                            vm_status_metric = Metric(tags, "vm_status", vm_status)
+                    except Exception:
+                        log.exception("VM status is not OK!")
+                        vm_status_metric = Metric(tags, "vm_status", 0)
+                    metrics.append(vm_status_metric)
         return metrics
index 85d21e3..90c342a 100644 (file)
@@ -43,6 +43,7 @@ collector:
   interval: 30
   process_pool_size: 10
   process_execution_timeout: 50
+  vm_infra_metrics: true
 
 evaluator:
   interval: 30