• Home
  • Dynatrace API
  • Configuration
  • Management zones
  • Copy management zones

Copy management zones between Dynatrace environments

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.

  1. Generate a new access token for the Dynatrace API. Make sure to assign Read configuration and Write configuration scopes to it.

  2. First, you need to obtain the configuration of management zones from the source environment. To do so:

    1. Execute the GET all management zones request.
      The response contains the list of short representations of management zones—just IDs and names, like in example below.
      json
      { "values": [ { "id": "-8706723556235787125", "name": "All" }, { "id": "1856893735401542875", "name": "easyTravel" } ] }
    2. Use the ID from the response to execute the GET a management zone requests, to obtain configuration of each management zone. The response contains parameters of a management zone. The example below shows parameters of the easyTravel management zone.
      json
      { "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 } } ] } ] }
    3. Save the JSON payload as a file on your computer and/or in a version control system.
      By storing the configuration in a version control system, you can get the delta of recent changes and you can use tagging mechanisms to decide which configuration you want to distribute into your Dynatrace environments.
    4. Repeat the sub-steps 2 and 3 for all management zones you want to copy.
  3. 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.

  4. Repeat the step 3 for all management zones you want to copy.

  1. Generate a new access token for the Dynatrace API. Make sure to assign Read configuration and Write configuration scopes to it. Copy the token to the clipboard.

  2. Open the User menu in the top right corner, and select Dynatrace API > Configuration API.

    Access API explorer

  3. In the API explorer click Authorize.

    The Available authorizations dialog appears.

  4. Paste your token to the ReadConfigToken and WriteConfigToken fields and click Authorize.

  5. Now, let's get the configurations of management zones from the source environment.

    1. Expand the Management zones group and then the GET /managementZones request.

    2. Click Try it out and then Execute.

      Execute request

    3. The response contains the list of short representations of management zones—just IDs and names, like in example below. The API explorer also shows the URL of the request and the Curl command, that you can use within your browser, automation script, or command line.

      GET all management zones

    4. Now, let's get the configuration of a management zone.

    5. Expand the GET /managementZones/{id} request and click Try it out.

    6. Paste the ID of the required management zone to the id field. Leave the includeProcessGroupReferences field as it is.

    7. Click Execute.

    8. The response contains parameters of the management zone. The example below shows parameters of the All management zone.

      GET a management zone

    9. Save the JSON payload as a file on your computer and/or in a version control system.
      By storing the configuration in a version control system, you can get the delta of recent changes and you can use tagging mechanisms to decide which configuration you want to distribute into your Dynatrace environments.

    10. Repeat sub-steps 5 to 9 to obtain parameters of all the required management zones.

  6. Now, let's upload configurations to the target environment.

    1. Log in to the target environment, and repeat steps 1 to 4 in it.

    2. Expand the PUT /managementZones/{id} request and click Try it out.

    3. In the id field, paste the ID of the required management zone.

    4. Paste the ID of the required management zone to the id field.

    5. Paste the JSON configuration of the management zone to the body field.

      PUT a management zone

    6. Click Execute.

    7. The request returns the 201 code and short representations of a management zone as confirmation. If a management zones with such ID already exists in the target environment, the successful request returns the 204 code and no content.

      Response

    8. Repeat sub-steps 2 to 7 to upload all the required management zones.

Script example

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:

  1. Replace <YOUR_ENVIRONMENT> with the URL of your Dynatrace environment:
    • Dynatrace Managed https://{your-domain}/e/{your-environment-id}
    • Dynatrace SaaS https://{your-environment-id}.live.dynatrace.com
  2. Replace <YOUR_API_TOKEN> with your API token which has the Read configuration and Write configuration scopes assigned.
py
""" Example script for fetching given Dynatrace config list items and store them on disk. """ import requests, ssl, os, sys ENV = '<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()
Related topics
  • Management zones

    Learn about management zones concepts, how to define management zones, and how to make the most of them.