If you are like we are, you have regular maintenance windows for patching, etc at the same time every month. There is no way to clone scheduled maintenance alert suppression policies in Opsgenie. You have to create them one-at-a-time every month. If you have several, it can take a while to enter. I looked up their maintenance api examples for POST. They have the example listed in curl format. I converted the curl to Python, plugged in my api info, changed the description & start/stop dates/times and it worked beautifully. I just thought I would share something that will make my life a bit easier. Enjoy!
BTW: Be sure to convert the times to Zulu or UTC. I had to add 6 hours to my scripted entries to get the times right.
import requests
from requests.structures import CaseInsensitiveDict
url = "https://api.opsgenie.com/v1/maintenance"
headers = CaseInsensitiveDict()
headers["Authorization"] = "GenieKey <your API key here>"
headers["Content-Type"] = "application/json"
data = """
{
"description": "TEST Maintenance Description",
"time": {
"type" : "schedule",
"startDate": "2021-10-31T08:45:00Z",
"endDate": "2021-10-31T21:45:00Z"
},
"rules": [
{
"state": "enabled",
"entity": {
"id": "<id of notification policy>",
"type": "policy"
}
}
]
}
"""
resp = requests.post(url, headers=headers, data=data)
print(resp.status_code)