alerta/alerta

Make it possible to modify blackout periods using API and CLI

peteeckel opened this issue · 2 comments

We are currently investigating how to integrate Alerta with some other systems (CMDB, Monitoring etc.). One requirement is that we need to provide a way to define maintenance windows for systems and environments in the CMDB and mirror them as blackout periods in Alerta.

While Alerta provides an option to edit all aspects of blackouts in the GUI, the CLI does not provide any way to modify an existing blackout, while the API supports the undocumented PUT method, which is however limited in its functionality. During my experiments with PUT I was able to change the environment, resource and services for a blackout, but not the time-related properties such as start time, end time and/or duration.

The ideal solution would obviously be to provide full support for this in both the CLI and the API, with the API preferred (this steps also seems to be smaller as there is already incomplete support of PUT requests).

You can set the times and reason via the api with the follow extract from a python script I am using for a project.

def send_blackout(hostname, start_time, end_time, reason):

    alerta_uri = ALERTA_URL + '/blackout'


    headers = {
            "Content-Type": "application/json",
            "Authorization": "Key " + ALERTAKEY.decode('utf-8').strip()
        }

    data = {
            "environment": "Production",
            "resource": hostname,
            "startTime" : start_time,
            "endTime": end_time,
            "text" : reason
        }

You're right that there isn't an option to modify existing blackouts using the CLI. The API can be used to modify all aspects of a blackout using the PUT /blackout/<blackout-id> endpoint. This is exactly the same endpoint used by the web UI so it definitely works, even if it is "undocumented".