def main(): restclient = RestClient(API_ENDPOINT, credentials_file='api_credentials.json', verify=False) file_path = '/your-path-to-file/download.csv' root_app_scope_name = 'your-root-scope' restclient.download(file_path, '/assets/cmdb/download/' + root_app_scope_name) # Basic Error handling if resp.status_code != 200: print("Unsuccessful request returned code: {} , response: {}".format(resp.status_code, resp.text)) exit(-1) results = resp.json() # check if results were returned, if so print them out, # sometimes the list is inside the json as result other times raw return. if hasattr(results, 'results'): print(json.dumps(results["results"], indent=2)) else: print(json.dumps(results, indent=2)) return
def download_agent(agent_options): # Ordered metadata used to construct the filename agent_metadata = [{ "option": None, "prefix": None, "suffix": None, "arch": None, "extension": None, "platform": None }, { "option": 1, "prefix": "tet-win-sensor-", "suffix": ".win64", "arch": "x86_64", "extension": ".zip", "platform": "MSWindows10Pro" }, { "option": 2, "prefix": "tet-sensor-", "suffix": ".el5", "arch": "x86_64", "extension": ".rpm", "platform": "CentOS-5.11" }, { "option": 3, "prefix": "tet-sensor-", "suffix": ".el6", "arch": "x86_64", "extension": ".rpm", "platform": "CentOS-6.10" }, { "option": 4, "prefix": "tet-sensor-", "suffix": ".el7", "arch": "x86_64", "extension": ".rpm", "platform": "CentOS-7.8" }, { "option": 5, "prefix": "tet-sensor-", "suffix": ".el8", "arch": "x86_64", "extension": ".rpm", "platform": "CentOS-8.1" }, { "option": 6, "prefix": "tet-sensor-", "suffix": ".sles11", "arch": "x86_64", "extension": ".rpm", "platform": "SUSELinuxEnterpriseServer-11.4" }, { "option": 7, "prefix": "tet-sensor-", "suffix": ".sles11", "arch": "s390x", "extension": ".rpm", "platform": "SUSELinuxEnterpriseServer-11.4" }, { "option": 8, "prefix": "tet-sensor-", "suffix": ".sles12", "arch": "s390x", "extension": ".rpm", "platform": "SUSELinuxEnterpriseServer-12.5" }, { "option": 9, "prefix": "tet-sensor-lw-", "suffix": ".lw-linux-amd64", "arch": "amd64", "extension": ".zip", "platform": "linux-amd64" }, { "option": 10, "prefix": "tet-sensor-lw-", "suffix": ".lw-linux-386", "arch": "386", "extension": ".zip", "platform": "linux-amd64" }, { "option": 11, "prefix": "tet-sensor-lw-", "suffix": ".lw-aix-ppc", "arch": "ppc", "extension": ".zip", "platform": "AIX-7.2" }, { "option": 12, "prefix": "tet-sensor-lw-", "suffix": ".lw-solaris-amd64", "arch": "amd64", "extension": ".zip", "platform": "AIX-7.2" }] platform_opt = agent_options["agent_platform"] agent_type = agent_options["agent_type"] agent_platform = agent_metadata[platform_opt]['platform'] agent_arch = agent_metadata[platform_opt]['arch'] #agent_pkg_type = 'sensor_w_cfg' agent_pkg_type = 'sensor_bin_pkg' host = env.TET_HOST.get("host") api_key = env.TET_API_KEY api_sec = env.TET_API_SEC # Build URL url = f"https://{host}" restclient = RestClient(url, api_key=api_key, api_secret=api_sec, verify=True) print(" Getting supported agent version...") get_ver_url = "/sw_assets/download?platform=" + agent_platform + "&agent_type=" + agent_type + "&arch=" + agent_arch + "&list_version=True" response = restclient.get(get_ver_url) if response.status_code == 200: versions = response.content.decode('utf-8').splitlines() agent_version = versions[0].strip() else: print(f"Error {response.status_code} retrieving agent version.") sys.exit() # Now that we retrieved the supported version, we can form the complete filename agent_filename = agent_metadata[platform_opt][ 'prefix'] + agent_version + agent_metadata[platform_opt][ 'suffix'] + '.' + agent_arch + agent_metadata[platform_opt][ 'extension'] # Now that we have the filename, we can create the download URL download_url = "/sw_assets/download?platform=" + agent_platform + "&agent_type=" + agent_type + "&pkg_type=" + agent_pkg_type + "&arch=" + agent_arch # Download agent print(" Downloading agent...") response = restclient.download(agent_filename, download_url) if not response.status_code == 200: print( f"Error code: {response.status_code} returned downloading agent.") sys.exit() return agent_filename
#!/usr/bin/env python # Imports from tetpyclient import RestClient, MultiPartOption import requests.packages.urllib3 CLUSTER_URL = "https://andromeda-aus.cisco.com" CRED_FILE = "./cred.json" CSV_FILE = "./tags.csv" ROOT_SCOPE = "Lab User 23" requests.packages.urllib3.disable_warnings() rc = RestClient(CLUSTER_URL, credentials_file=CRED_FILE, verify=False) # Get annotations csv (insert code to download annotations here) resp = rc.download(CSV_FILE, '/assets/cmdb/download/' + ROOT_SCOPE) # Checking result if resp.status_code == 200: print("Annotations download successful!") else: print("Error: HTTP status code is " + str(resp.status_code) + " and message is " + resp.content)
""" Script used for testing only. This just downloads the annotations file. During debug, it's easier to download the annotations via script than through the GUI. """ # pylint: disable=invalid-name import os import requests.packages.urllib3 from tetpyclient import RestClient restclient = RestClient(os.environ['TETRATION_ENDPOINT'], api_key=os.environ['TETRATION_API_KEY'], api_secret=os.environ['TETRATION_API_SECRET'], verify=False) requests.packages.urllib3.disable_warnings() file_path = 'output.csv' restclient.download(file_path, '/assets/cmdb/download')