parameters: (path)
docstring: Ship gathered metrics to the Insights API
docstring_summary: Ship gathered metrics to the Insights API
docstring_tokens: Ship gathered metrics to the Insights API
function: def ship(path):
      """
      Ship gathered metrics to the Insights API
      """
      if not path:
          logger.error('Insights for Ansible Automation Platform TAR not found')
          return False
      if not os.path.exists(path):
          logger.error('Insights for Ansible Automation Platform TAR {} not found'.format(path))
          return False
      if "Error:" in str(path):
          return False
  
      logger.debug('shipping analytics file: {}'.format(path))
      url = getattr(settings, 'AUTOMATION_ANALYTICS_URL', None)
      if not url:
          logger.error('AUTOMATION_ANALYTICS_URL is not set')
          return False
      rh_user = getattr(settings, 'REDHAT_USERNAME', None)
      rh_password = getattr(settings, 'REDHAT_PASSWORD', None)
      if not rh_user:
          logger.error('REDHAT_USERNAME is not set')
          return False
      if not rh_password:
          logger.error('REDHAT_PASSWORD is not set')
          return False
      with open(path, 'rb') as f:
          files = {'file': (os.path.basename(path), f, settings.INSIGHTS_AGENT_MIME)}
          s = requests.Session()
          s.headers = get_awx_http_client_headers()
          s.headers.pop('Content-Type')
          with set_environ(**settings.AWX_TASK_ENV):
              response = s.post(
                  url, files=files, verify="/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem", auth=(rh_user, rh_password), headers=s.headers, timeout=(31, 31)
              )
          # Accept 2XX status_codes
          if response.status_code >= 300:
              logger.error('Upload failed with status {}, {}'.format(response.status_code, response.text))
              return False
  
          return True
function_tokens: def ship ( path ) : if not path : logger . error ( 'Insights for Ansible Automation Platform TAR not found' ) return False if not os . path . exists ( path ) : logger . error ( 'Insights for Ansible Automation Platform TAR {} not found' . format ( path ) ) return False if "Error:" in str ( path ) : return False logger . debug ( 'shipping analytics file: {}' . format ( path ) ) url = getattr ( settings , 'AUTOMATION_ANALYTICS_URL' , None ) if not url : logger . error ( 'AUTOMATION_ANALYTICS_URL is not set' ) return False rh_user = getattr ( settings , 'REDHAT_USERNAME' , None ) rh_password = getattr ( settings , 'REDHAT_PASSWORD' , None ) if not rh_user : logger . error ( 'REDHAT_USERNAME is not set' ) return False if not rh_password : logger . error ( 'REDHAT_PASSWORD is not set' ) return False with open ( path , 'rb' ) as f : files = { 'file' : ( os . path . basename ( path ) , f , settings . INSIGHTS_AGENT_MIME ) } s = requests . Session ( ) s . headers = get_awx_http_client_headers ( ) s . headers . pop ( 'Content-Type' ) with set_environ ( * * settings . AWX_TASK_ENV ) : response = s . post ( url , files = files , verify = "/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem" , auth = ( rh_user , rh_password ) , headers = s . headers , timeout = ( 31 , 31 ) ) # Accept 2XX status_codes if response . status_code >= 300 : logger . error ( 'Upload failed with status {}, {}' . format ( response . status_code , response . text ) ) return False return True