2016-02-07 23:16:07 +01:00
|
|
|
/*
|
|
|
|
* Datadog API for Go
|
|
|
|
*
|
|
|
|
* Please see the included LICENSE file for licensing information.
|
|
|
|
*
|
|
|
|
* Copyright 2013 by authors and contributors.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package datadog
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Recurrence struct {
|
2017-02-20 13:48:32 +01:00
|
|
|
Period *int `json:"period,omitempty"`
|
|
|
|
Type *string `json:"type,omitempty"`
|
|
|
|
UntilDate *int `json:"until_date,omitempty"`
|
|
|
|
UntilOccurrences *int `json:"until_occurrences,omitempty"`
|
2016-02-07 23:16:07 +01:00
|
|
|
WeekDays []string `json:"week_days,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type Downtime struct {
|
2017-02-20 13:48:32 +01:00
|
|
|
Active *bool `json:"active,omitempty"`
|
|
|
|
Canceled *int `json:"canceled,omitempty"`
|
|
|
|
Disabled *bool `json:"disabled,omitempty"`
|
|
|
|
End *int `json:"end,omitempty"`
|
|
|
|
Id *int `json:"id,omitempty"`
|
2017-06-05 13:47:15 +02:00
|
|
|
MonitorId *int `json:"monitor_id,omitempty"`
|
2017-02-20 13:48:32 +01:00
|
|
|
Message *string `json:"message,omitempty"`
|
2016-02-07 23:16:07 +01:00
|
|
|
Recurrence *Recurrence `json:"recurrence,omitempty"`
|
|
|
|
Scope []string `json:"scope,omitempty"`
|
2017-02-20 13:48:32 +01:00
|
|
|
Start *int `json:"start,omitempty"`
|
2016-02-07 23:16:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// reqDowntimes retrieves a slice of all Downtimes.
|
|
|
|
type reqDowntimes struct {
|
|
|
|
Downtimes []Downtime `json:"downtimes,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// CreateDowntime adds a new downtme to the system. This returns a pointer
|
|
|
|
// to a Downtime so you can pass that to UpdateDowntime or CancelDowntime
|
|
|
|
// later if needed.
|
2016-12-08 11:17:42 +01:00
|
|
|
func (client *Client) CreateDowntime(downtime *Downtime) (*Downtime, error) {
|
2016-02-07 23:16:07 +01:00
|
|
|
var out Downtime
|
2016-12-08 11:17:42 +01:00
|
|
|
if err := client.doJsonRequest("POST", "/v1/downtime", downtime, &out); err != nil {
|
2016-02-07 23:16:07 +01:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &out, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// UpdateDowntime takes a downtime that was previously retrieved through some method
|
|
|
|
// and sends it back to the server.
|
2016-12-08 11:17:42 +01:00
|
|
|
func (client *Client) UpdateDowntime(downtime *Downtime) error {
|
2017-02-20 13:48:32 +01:00
|
|
|
return client.doJsonRequest("PUT", fmt.Sprintf("/v1/downtime/%d", *downtime.Id),
|
2016-02-07 23:16:07 +01:00
|
|
|
downtime, nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Getdowntime retrieves an downtime by identifier.
|
2016-12-08 11:17:42 +01:00
|
|
|
func (client *Client) GetDowntime(id int) (*Downtime, error) {
|
2016-02-07 23:16:07 +01:00
|
|
|
var out Downtime
|
2016-12-08 11:17:42 +01:00
|
|
|
if err := client.doJsonRequest("GET", fmt.Sprintf("/v1/downtime/%d", id), nil, &out); err != nil {
|
2016-02-07 23:16:07 +01:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &out, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteDowntime removes an downtime from the system.
|
2016-12-08 11:17:42 +01:00
|
|
|
func (client *Client) DeleteDowntime(id int) error {
|
|
|
|
return client.doJsonRequest("DELETE", fmt.Sprintf("/v1/downtime/%d", id),
|
2016-02-07 23:16:07 +01:00
|
|
|
nil, nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetDowntimes returns a slice of all downtimes.
|
2016-12-08 11:17:42 +01:00
|
|
|
func (client *Client) GetDowntimes() ([]Downtime, error) {
|
2016-02-07 23:16:07 +01:00
|
|
|
var out reqDowntimes
|
2016-12-08 11:17:42 +01:00
|
|
|
if err := client.doJsonRequest("GET", "/v1/downtime", nil, &out.Downtimes); err != nil {
|
2016-02-07 23:16:07 +01:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return out.Downtimes, nil
|
|
|
|
}
|