forked from zorkian/go-datadog-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
downtimes.go
81 lines (71 loc) · 2.52 KB
/
downtimes.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
* 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 {
Period *int `json:"period,omitempty"`
Type *string `json:"type,omitempty"`
UntilDate *int `json:"until_date,omitempty"`
UntilOccurrences *int `json:"until_occurrences,omitempty"`
WeekDays []string `json:"week_days,omitempty"`
}
type Downtime struct {
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"`
MonitorId *int `json:"monitor_id,omitempty"`
Message *string `json:"message,omitempty"`
Recurrence *Recurrence `json:"recurrence,omitempty"`
Scope []string `json:"scope,omitempty"`
Start *int `json:"start,omitempty"`
}
// 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.
func (client *Client) CreateDowntime(downtime *Downtime) (*Downtime, error) {
var out Downtime
if err := client.doJsonRequest("POST", "/v1/downtime", downtime, &out); err != nil {
return nil, err
}
return &out, nil
}
// UpdateDowntime takes a downtime that was previously retrieved through some method
// and sends it back to the server.
func (client *Client) UpdateDowntime(downtime *Downtime) error {
return client.doJsonRequest("PUT", fmt.Sprintf("/v1/downtime/%d", *downtime.Id),
downtime, nil)
}
// Getdowntime retrieves an downtime by identifier.
func (client *Client) GetDowntime(id int) (*Downtime, error) {
var out Downtime
if err := client.doJsonRequest("GET", fmt.Sprintf("/v1/downtime/%d", id), nil, &out); err != nil {
return nil, err
}
return &out, nil
}
// DeleteDowntime removes an downtime from the system.
func (client *Client) DeleteDowntime(id int) error {
return client.doJsonRequest("DELETE", fmt.Sprintf("/v1/downtime/%d", id),
nil, nil)
}
// GetDowntimes returns a slice of all downtimes.
func (client *Client) GetDowntimes() ([]Downtime, error) {
var out reqDowntimes
if err := client.doJsonRequest("GET", "/v1/downtime", nil, &out.Downtimes); err != nil {
return nil, err
}
return out.Downtimes, nil
}