20 May 2024 02:50 PM - last edited on 07 Jun 2024 11:45 AM by Michal_Gebacki
Greetings everyone,
In the case of my internship, my job is to "automate" the deployement of maintenance windows without using the web interface.
As I'm beginner with Dynatrace, I was wondering how to use the Dynatrace's API to deploy a maintenance window ?
Furthermore, if you can give a detailled example of how to use the API, it would be great as I don't really understand how to use the endpoint or anything else.
Kind regards,
Arthur
Solved! Go to Solution.
21 May 2024 10:01 AM
Hi @alcq ,
First, you have to generate access token with settings.read and settings.write permissions. Explanation how to do this you can find here: https://docs.dynatrace.com/docs/manage/access-control/access-tokens
If you generated access token you have to click on your user icon in top right corner, then go to Environment API v2. Search for Settings – Objects and Settings – Schemas. This is your default tool to interact with Dynatrace API (of course you can use another tool like Postman if you want). Before you can use it you have to authorize yourself by clocking on locker icon and pass your previously generated token. Through button “Try it out” you can run your queries.
To work with maintenance windows you use schema: builtin:alerting.maintenance-window.
Any info about available schema fields you can find here: https://docs.dynatrace.com/docs/dynatrace-api/environment-api/settings/schemas/builtin-alerting-main...
How to use settings API you can read here: https://docs.dynatrace.com/docs/dynatrace-api/environment-api/settings
I highly recommend testing out Your payload/body using dynatrace built-in swagger before implementing it inside of some pipeline.
Bests
Michal
21 May 2024 02:23 PM
Thanks for your reply.
As I see, it appears I can only use "GET" methods to manipulate Maintenance Windows. Are "POST" methods available to create and deploy Maintenance Windows ?
Kind regards,
Arthur
22 May 2024 09:49 AM
Hi @alcq
Yes, of course. In "Settings – Objects" in Environment API v2 you can post an object to create a new settings object.
Bests
Michal
22 May 2024 01:35 PM
Hi,
You can have a look a Monaco, it is a command line tool to deploy Dynatrace's configurations. Maintenance windows API is supported.
Best regards
22 May 2024 02:21 PM - edited 22 May 2024 02:42 PM
Thanks for your reply.
As I see, I can deploy a maintenance window thanks to monaco. What I need to do is just to construct a YAML file to fit with all needed paramaters for a maintenance window, am I right ?
If it's the case, how should I find the structure to edit and put into the YAML file ?
Kind regards,
Arthur
23 May 2024 07:51 AM
Hi,
I would recommend you create some configuration in the UI, download configuration and analize YAML and JSON files created.
Later you can modify those files base on your needs but you do not need to start from scratch.
Best regards