20 Sep 2024 05:50 PM - last edited on 24 Sep 2024 07:27 AM by MaciejNeumann
Looking for a way to get a list of the Management Zones via the API.
Another option would be from the GUI. If a path to that functionality can be provided.
There is a large numeric value that is used in query request to specify the MZ. I would like to get a list of those.
Thanks all
20 Sep 2024 06:18 PM
Hello.
You can either use the Management Zone API (V1) or, in the new API v2, the builtin:management-zones schema Id, you can find info about it here.
20 Sep 2024 07:12 PM
I'm not seeing that option in the Docs. Can you post an example of the api request here please?
23 Sep 2024 12:05 PM - edited 23 Sep 2024 12:10 PM
You'll find more information on the links I provided above 🙂
Either way, here's a quick example of a python script to list management zones from a given environment using V2 API. You'll need to generate an access token with "Read Settings" v2 permissions:
import requests
# Dynatrace API endpoint and credentials
DT_API_TOKEN = '<Insert your token here>'
# environment id looks similar to , for e.g., abc12345 (the part that comes before the .live.dynatrace.com on the link)
URL = f'https://{environmentid}.live.dynatrace.com/api/v2/settings/objects'
# Headers
headers = {
'Authorization': f'Api-Token {DT_API_TOKEN}',
'Content-Type': 'application/json'
}
# Query params for the Management Zones schema
params = {
'schemaIds': 'builtin:management-zones',
'pageSize': 100
}
# Fetch management zones
response = requests.get(URL, headers=headers, params=params)
# Check if the response was successful
if response.status_code == 200:
management_zones = response.json().get('items', [])
for zone in management_zones:
print(f"Management Zone: {zone['value']['name']} (ID: {zone['objectId']})")
else:
print(f"Error fetching management zones: {response.status_code} - {response.text}")
Let me know if this works for solving your problem @CrazyHarry