def get_all_sites()

in jobs/eam-integrations/scripts/api/XMatters/XMatters.py [0:0]


def get_all_sites():
    """Gets all sites from xMatters

  Parameters:
    None

  Returns:
    dict: site name -> xmatters site id
      for all sites with status "ACTIVE"

  Example:
    {
      [...]
      'US Remote (NV)' : '656173de-809d-46c3-82f3-dd718efa6af4',
      'Israel Remote'  : '7ed98c24-c73f-4fa5-b987-a005e80e2d63',
      'US Remote (NM)' : '5224215b-337f-4c6b-bc6a-6211246e2086',
      'US Remote (LA)' : '96c2de74-247d-4bb8-b0ec-592b86768f85',
      [...]
    }
  """
    # https://mozilla-np.xmatters.com/xmatters.com/reapi/2015-04-01/sites
    logger.info("\n")
    logger.info("Gathering all XMatters sites")
    all_sites_url = _config.base_URL_old_api + "sites"
    xm_sites = {}
    xm_sites_inactive = {}
    while True:
        response = requests.get(
            all_sites_url,
            auth=(_config.xm_username, _config.xm_password),
            proxies=_config.proxies,
        )
        if response.status_code == 200:
            rjson = response.json()
            logger.debug(rjson)
        else:
            error = "Could not get sites"
            logger.critical(error)
            raise Exception(error)

        for site in rjson["sites"]:
            logger.debug(site["name"] + " -- " + site["identifier"])
            logger.debug(site)
            if site["status"] == "ACTIVE":
                xm_sites[site["name"]] = site["identifier"]
            else:
                xm_sites_inactive[site["name"]] = site["identifier"]

        if rjson["nextRecordsURL"] == "":
            logger.debug("No nextRecordsURL found. done with fetching")
            break
        else:
            logger.debug("NEXT RECORDS URL FOUND: %s" % rjson["nextRecordsURL"])
            all_sites_url = _config.url + rjson["nextRecordsURL"]

    return xm_sites, xm_sites_inactive