Skip to content

List agents

import requests
import base64
import json

# Configuration
baseUrl = "https://localhost:8443"
username = "---USERNAME---"
password = "---PASSWORD---"

# Login & get JWT token
headers = {
    "Authorization":
        "Basic " +
        base64
        .b64encode(
            (username + ":" + password)
            .encode('utf-8')
        )
        .decode('utf-8')
}
response = requests.request("POST", "%s/api/v1/auth/login" % baseUrl, headers=headers, verify=False)
if response.status_code != 200:
    print("Login failed")
    exit()

authToken = response.text
headers = {"Authorization": "Bearer " + authToken}

# List Agents
response = requests.get("%s/api/v1/agents" % baseUrl, headers=headers, verify=False)
if response.status_code != 200:
    print("Could not get agent list")
    print(response.text)
    exit()

for agent in json.loads(response.text):
    print(" # %s" % agent["guid"])
    for metadataName in agent["metadata"]:
        if metadataName != "guid":
            print("    * %s = %s" % (metadataName, agent["metadata"][metadataName]))