From: lavado Date: Fri, 29 Nov 2019 17:40:30 +0000 (-0500) Subject: Minor fixes to additional metric labels X-Git-Tag: v7.0.0rc1~11 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=refs%2Fchanges%2F70%2F8270%2F1;p=osm%2FMON.git Minor fixes to additional metric labels Change-Id: Ia2ad1b28c7c1fd61effaf46d04f97e004a93be15 Signed-off-by: lavado --- diff --git a/osm_mon/collector/infra_collectors/base_osinfra.py b/osm_mon/collector/infra_collectors/base_osinfra.py index 9c8447c..37b9293 100644 --- a/osm_mon/collector/infra_collectors/base_osinfra.py +++ b/osm_mon/collector/infra_collectors/base_osinfra.py @@ -46,7 +46,10 @@ class BaseOpenStackInfraCollector(BaseVimInfraCollector): def collect(self) -> List[Metric]: metrics = [] vim_status = self.is_vim_ok() - vim_project_id = self.vim_account['_admin']['projects_read'][0] + if self.vim_account['_admin']['projects_read']: + vim_project_id = self.vim_account['_admin']['projects_read'][0] + else: + vim_project_id = None vim_tags = { 'vim_account_id': self.vim_account['_id'], 'project_id': vim_project_id @@ -58,7 +61,10 @@ class BaseOpenStackInfraCollector(BaseVimInfraCollector): nsr_id = vnfr['nsr-id-ref'] ns_name = self.common_db.get_nsr(nsr_id)['name'] vnf_member_index = vnfr['member-vnf-index-ref'] - vnfr_project_id = vnfr['_admin']['projects_read'][0] + if vnfr['_admin']['projects_read']: + vnfr_project_id = vnfr['_admin']['projects_read'][0] + else: + vnfr_project_id = None for vdur in vnfr['vdur']: if 'vim-id' not in vdur: log.debug("Field vim-id is not present in vdur") diff --git a/osm_mon/collector/infra_collectors/onos.py b/osm_mon/collector/infra_collectors/onos.py index 21ef85d..1ad2f4f 100644 --- a/osm_mon/collector/infra_collectors/onos.py +++ b/osm_mon/collector/infra_collectors/onos.py @@ -42,7 +42,10 @@ class OnosInfraCollector(BaseSdncInfraCollector): def collect(self) -> List[Metric]: metrics = [] sdnc_status = self.is_sdnc_ok() - sdnc_project_id = self.sdnc['_admin']['projects_read'][0] + if self.sdnc['_admin']['projects_read']: + sdnc_project_id = self.sdnc['_admin']['projects_read'][0] + else: + sdnc_project_id = None sdnc_tags = { 'sdnc_id': self.sdnc['_id'], 'project_id': sdnc_project_id diff --git a/osm_mon/collector/vnf_collectors/juju.py b/osm_mon/collector/vnf_collectors/juju.py index 8be9e28..a73f1bb 100644 --- a/osm_mon/collector/vnf_collectors/juju.py +++ b/osm_mon/collector/vnf_collectors/juju.py @@ -51,7 +51,10 @@ class VCACollector(BaseCollector): # Populate extra tags for metrics tags = {} tags['ns_name'] = self.common_db.get_nsr(nsr_id)['name'] - tags['project_id'] = vnfr['_admin']['projects_read'][0] + if vnfr['_admin']['projects_read']: + tags['project_id'] = vnfr['_admin']['projects_read'][0] + else: + tags['project_id'] = None metrics = [] for vdur in vnfr['vdur']: diff --git a/osm_mon/collector/vnf_collectors/openstack.py b/osm_mon/collector/vnf_collectors/openstack.py index a13380a..d1cd2a1 100644 --- a/osm_mon/collector/vnf_collectors/openstack.py +++ b/osm_mon/collector/vnf_collectors/openstack.py @@ -85,7 +85,10 @@ class OpenstackCollector(BaseVimCollector): # Populate extra tags for metrics tags = {} tags['ns_name'] = self.common_db.get_nsr(nsr_id)['name'] - tags['project_id'] = vnfr['_admin']['projects_read'][0] + if vnfr['_admin']['projects_read']: + tags['project_id'] = vnfr['_admin']['projects_read'][0] + else: + tags['project_id'] = None metrics = [] for vdur in vnfr['vdur']: diff --git a/osm_mon/collector/vnf_collectors/vio.py b/osm_mon/collector/vnf_collectors/vio.py index 77129e1..b59f02d 100644 --- a/osm_mon/collector/vnf_collectors/vio.py +++ b/osm_mon/collector/vnf_collectors/vio.py @@ -52,7 +52,10 @@ class VIOCollector(BaseVimCollector): nsr_id = vnfr['nsr-id-ref'] tags = {} tags['ns_name'] = self.common_db.get_nsr(nsr_id)['name'] - tags['project_id'] = vnfr['_admin']['projects_read'][0] + if vnfr['_admin']['projects_read']: + tags['project_id'] = vnfr['_admin']['projects_read'][0] + else: + tags['project_id'] = None # Fetch the list of all known resources from vROPS. resource_list = self.vrops.get_vm_resource_list_from_vrops() diff --git a/osm_mon/collector/vnf_collectors/vmware.py b/osm_mon/collector/vnf_collectors/vmware.py index 0e76bfd..626a402 100644 --- a/osm_mon/collector/vnf_collectors/vmware.py +++ b/osm_mon/collector/vnf_collectors/vmware.py @@ -188,7 +188,10 @@ class VMwareCollector(BaseVimCollector): nsr_id = vnfr['nsr-id-ref'] tags = {} tags['ns_name'] = self.common_db.get_nsr(nsr_id)['name'] - tags['project_id'] = vnfr['_admin']['projects_read'][0] + if vnfr['_admin']['projects_read']: + tags['project_id'] = vnfr['_admin']['projects_read'][0] + else: + tags['project_id'] = None # Fetch the list of all known resources from vROPS. resource_list = self.vrops.get_vm_resource_list_from_vrops() diff --git a/osm_mon/core/common_db.py b/osm_mon/core/common_db.py index 7bd2491..8f2f552 100644 --- a/osm_mon/core/common_db.py +++ b/osm_mon/core/common_db.py @@ -61,9 +61,11 @@ class CommonDbClient: def get_vnfd_by_name(self, vnfd_name: str): # TODO: optimize way of getting single VNFD in shared enviroments (RBAC) - vnfd = self.common_db.get_list("vnfds", - {"name": vnfd_name})[0] - return vnfd + if self.common_db.get_list("vnfds", {"name": vnfd_name}): + vnfd = self.common_db.get_list("vnfds", {"name": vnfd_name})[0] + return vnfd + else: + return None def get_nsrs(self): return self.common_db.get_list('nsrs') diff --git a/osm_mon/core/mon.yaml b/osm_mon/core/mon.yaml index bfdda5a..ef31ebc 100644 --- a/osm_mon/core/mon.yaml +++ b/osm_mon/core/mon.yaml @@ -52,7 +52,6 @@ dashboarder: grafana: url: http://grafana:3000 - token: "Basic YWRtaW46YWRtaW4=" prometheus: url: http://prometheus:9090 diff --git a/osm_mon/dashboarder/backends/grafana.py b/osm_mon/dashboarder/backends/grafana.py index 123f9e9..491cd52 100644 --- a/osm_mon/dashboarder/backends/grafana.py +++ b/osm_mon/dashboarder/backends/grafana.py @@ -25,7 +25,7 @@ import requests log = logging.getLogger(__name__) -# TODO (lavado): migrate to Class, import config variables +# TODO (lavado): migrate to Class, import config variables to get token url = "http://grafana:3000/api/" headers = { 'content-type': "application/json", @@ -38,7 +38,6 @@ def get_all_dashboard_uids(): dashboards = response.json() dashboard_uids = [] for dashboard in dashboards: - print(dashboard['uid']) dashboard_uids.append(dashboard['uid']) log.debug("Searching for all dashboard uids: %s", dashboard_uids) return dashboard_uids