Minor fixes to additional metric labels 70/8270/1
authorlavado <glavado@whitestack.com>
Fri, 29 Nov 2019 17:40:30 +0000 (12:40 -0500)
committerlavado <glavado@whitestack.com>
Fri, 29 Nov 2019 17:40:57 +0000 (12:40 -0500)
Change-Id: Ia2ad1b28c7c1fd61effaf46d04f97e004a93be15
Signed-off-by: lavado <glavado@whitestack.com>
osm_mon/collector/infra_collectors/base_osinfra.py
osm_mon/collector/infra_collectors/onos.py
osm_mon/collector/vnf_collectors/juju.py
osm_mon/collector/vnf_collectors/openstack.py
osm_mon/collector/vnf_collectors/vio.py
osm_mon/collector/vnf_collectors/vmware.py
osm_mon/core/common_db.py
osm_mon/core/mon.yaml
osm_mon/dashboarder/backends/grafana.py

index 9c8447c..37b9293 100644 (file)
@@ -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")
index 21ef85d..1ad2f4f 100644 (file)
@@ -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
index 8be9e28..a73f1bb 100644 (file)
@@ -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']:
index a13380a..d1cd2a1 100644 (file)
@@ -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']:
index 77129e1..b59f02d 100644 (file)
@@ -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()
index 0e76bfd..626a402 100644 (file)
@@ -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()
index 7bd2491..8f2f552 100644 (file)
@@ -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')
index bfdda5a..ef31ebc 100644 (file)
@@ -52,7 +52,6 @@ dashboarder:
 
 grafana:
   url: http://grafana:3000
-  token: "Basic YWRtaW46YWRtaW4="
 
 prometheus:
   url: http://prometheus:9090
index 123f9e9..491cd52 100644 (file)
@@ -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