예제 #1
0
 def get_measurements(self):
     try:
         self.assure_token()
         headers = {
             "Content-Type": "application/json",
             "Authorization": "Bearer %s" % self.token,
             "X-F5aas-Preferred-Account-Id": self.account_id
         }
         url = "https://%s/beacon/%s/metrics" % (self.connection.host,
                                                 self.connection.schema)
         data = {"query": "SHOW MEASUREMENTS"}
         response = requests.post(url,
                                  headers=headers,
                                  data=json.dumps(data))
         if response.status_code < 300:
             return_names = []
             resobj = response.json()['Results'][0]
             if resobj['Series']:
                 values = resobj['Series'][0]['values']
                 for value in values:
                     return_names.append(value[0])
             return return_names
         elif response.status_code == 401:
             self.update_token()
             headers['Authorization'] = "Bearer %s" % self.token
             response = requests.post(url,
                                      headers=headers,
                                      data=json.dumps(data))
             if response.status_code < 300:
                 return_names = []
                 resobj = response.json()['Results'][0]
                 if resobj['Series']:
                     values = resobj['Series'][0]['values']
                     for value in values:
                         return_names.append(value[0])
                 return return_names
             else:
                 http_ex = HTTPError(
                     'error retrieving f5 Beacon measurements: %d: %s' %
                     (response.status_code, response.content))
                 http_ex.status_code = response.status_code
                 raise http_ex
         else:
             http_ex = HTTPError(
                 'error retrieving f5 Beacon measurements: %d: %s' %
                 (response.status_code, response.content))
             http_ex.status_code = response.status_code
             raise http_ex
     except Exception as ex:
         raise AirflowException(
             'exception retrieveing f5 Beacon measurements: %s' % ex)
예제 #2
0
 def get_account_info(self):
     try:
         headers = {
             "Content-Type": "application/json",
             "Authorization": "Bearer %s" % self.token
         }
         url = "https://%s/%s/svc-account/user" % (self.connection.host,
                                                   self.connection.schema)
         response = requests.get(url, headers=headers)
         if response.status_code < 300:
             data = response.json()
             self.account_id = data['primary_account_id']
         else:
             http_ex = HTTPError(
                 'error retrieving f5 Beacon account: %d: %s' %
                 (response.status_code, response.content))
             http_ex.status_code = response.status_code
             raise http_ex
     except Exception as ex:
         raise AirflowException(
             'exception retrieveing f5 Beacon account: %s' % ex)