deprecated
This API is deprecated. Use the Settings API with the Management zones settings (builtin:management-zones
) schema instead.
This use case shows you how to use the Management zones API to copy management zones between Dynatrace environments.
The execution of REST calls is up to you—you can use any REST client or write a script, like the one, provided below.
You can also use Dynatrace API Explorer to familiarize yourself with endpoints and execute all the required requests.
Generate a new access token for the Dynatrace API. Make sure to assign Read configuration and Write configuration scopes to it.
First, you need to obtain the configuration of management zones from the source environment. To do so:
{"values": [{"id": "-8706723556235787125","name": "All"},{"id": "1856893735401542875","name": "easyTravel"}]}
{"metadata": {"clusterVersion": "1.163.0.20190128-084301","configurationVersions": [0]},"id": "1856893735401542875","name": "easyTravel","rules": [{"type": "WEB_APPLICATION","enabled": true,"propagationTypes": [],"conditions": [{"key": {"attribute": "WEB_APPLICATION_TAGS"},"comparisonInfo": {"type": "TAG","operator": "TAG_KEY_EQUALS","value": {"context": "CONTEXTLESS","key": "easyTravel"},"negate": false}}]},{"type": "SERVICE","enabled": true,"propagationTypes": ["SERVICE_TO_PROCESS_GROUP_LIKE","SERVICE_TO_HOST_LIKE"],"conditions": [{"key": {"attribute": "SERVICE_TAGS"},"comparisonInfo": {"type": "TAG","operator": "TAG_KEY_EQUALS","value": {"context": "CONTEXTLESS","key": "easyTravel"},"negate": false}}]}]}
Now let's upload the management zones to other Dynatrace environment. Execute the PUT a management zone request with the JSON from the previous steps as a payload. Make sure to use the id of the management zone in the URL—it will ensure the same IDs across all environments.
Repeat the step 3 for all management zones you want to copy.
This Python script saves configuration of all management zones of your environment to your computer. The folder structure reflects the API path. You can later save these configurations in a version control system and/or upload them to another Dynatrace environment.
You need Python version 3.5 or higher to use this script.
Make the following adjustments to the script:
<YOUR_ENVIRONMENT>
with the URL of your Dynatrace environment:
<YOUR_API_TOKEN>
with your API token which has the Read configuration and Write configuration scopes assigned."""Example script for fetching given Dynatrace config list items and store them on disk."""import requests, ssl, os, sysENV = '<YOUR_ENVIRONMENT>'TOKEN = '<YOUR_API_TOKEN>'HEADERS = {'Authorization': 'Api-Token ' + TOKEN}PATH = os.getcwd()def save(path, file, content):if not os.path.isdir(PATH + path):os.makedirs(PATH + path)with open(PATH + path + "/" + file, "w", encoding='utf8') as text_file:text_file.write("%s" % content)def saveList(list_type):try:r = requests.get(ENV + '/api/config/v1/' + list_type, headers=HEADERS)print("%s response code: %d" % (list_type, r.status_code))res = r.json()for entry in res['values']:print(entry['id'])tr = requests.get(ENV + '/api/config/v1/' + list_type + '/' + entry['id'], headers=HEADERS)save('/api/config/v1/' + list_type + '/', entry['id'], tr.json())except ssl.SSLError:print("SSL Error")def main():saveList('managementZones')if __name__ == '__main__':main()