X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osm_mon%2Fcollector%2Fvnf_collectors%2Fvrops%2Fvrops_helper.py;h=775aa1051c00c1437fa2bbd3f6ab9c2c584320b3;hb=refs%2Fchanges%2F41%2F10241%2F2;hp=430cf868a2d34d17dfaa216cdf8a59efa8a921e4;hpb=7233ad262f6c5436c713784a443596c0aa919b04;p=osm%2FMON.git diff --git a/osm_mon/collector/vnf_collectors/vrops/vrops_helper.py b/osm_mon/collector/vnf_collectors/vrops/vrops_helper.py index 430cf86..775aa10 100644 --- a/osm_mon/collector/vnf_collectors/vrops/vrops_helper.py +++ b/osm_mon/collector/vnf_collectors/vrops/vrops_helper.py @@ -53,15 +53,32 @@ class vROPS_Helper(): self.vrops_user = vrops_user self.vrops_password = vrops_password + def get_vrops_token(self): + """Fetches token from vrops + """ + auth_url = '/suite-api/api/auth/token/acquire' + headers = {'Content-Type': 'application/json', 'Accept': 'application/json'} + req_body = {"username": self.vrops_user, "password": self.vrops_password} + resp = requests.post(self.vrops_site + auth_url, + json=req_body, verify=False, + headers=headers) + if resp.status_code != 200: + log.error("Failed to get token from vROPS: {} {}".format(resp.status_code, + resp.content)) + return None + + resp_data = json.loads(resp.content.decode('utf-8')) + return resp_data['token'] + def get_vm_resource_list_from_vrops(self): """ Find all known resource IDs in vROPs """ + auth_token = self.get_vrops_token() api_url = '/suite-api/api/resources?resourceKind=VirtualMachine' - headers = {'Accept': 'application/json'} + headers = {'Accept': 'application/json', 'Authorization': 'vRealizeOpsToken {}'.format(auth_token)} resource_list = [] resp = requests.get(self.vrops_site + api_url, - auth=(self.vrops_user, self.vrops_password), verify=False, headers=headers) if resp.status_code != 200: @@ -82,12 +99,13 @@ class vROPS_Helper(): def get_metrics(self, vdu_mappings={}, monitoring_params={}, - vnfr=None): + vnfr=None, + tags={}): monitoring_keys = {} # Collect the names of all the metrics we need to query for metric_entry in monitoring_params: - metric_name = metric_entry['nfvi-metric'] + metric_name = metric_entry['performance-metric'] if metric_name not in METRIC_MAPPINGS: log.debug("Metric {} not supported, ignoring".format(metric_name)) continue @@ -116,10 +134,12 @@ class vROPS_Helper(): # Now we can make a single call to vROPS to collect all relevant metrics for resources we need to monitor api_url = "/suite-api/api/resources/stats?IntervalType=MINUTES&IntervalCount=1"\ "&rollUpType=MAX¤tOnly=true{}{}".format(stats_key, resource_ids) - headers = {'Accept': 'application/json'} + + auth_token = self.get_vrops_token() + headers = {'Accept': 'application/json', 'Authorization': 'vRealizeOpsToken {}'.format(auth_token)} resp = requests.get(self.vrops_site + api_url, - auth=(self.vrops_user, self.vrops_password), verify=False, headers=headers) + verify=False, headers=headers) if resp.status_code != 200: log.error("Failed to get Metrics data from vROPS for {} {}".format(resp.status_code, @@ -155,7 +175,9 @@ class vROPS_Helper(): vnfr['member-vnf-index-ref'], vdu_name, metric_name, - metric_value) + metric_value, + tags + ) metrics.append(metric)