-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathincidents.go
141 lines (121 loc) · 5.01 KB
/
incidents.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package cachet
import (
"fmt"
)
const (
// Docs: https://docs.cachethq.io/docs/incident-statuses
// IncidentStatusScheduled means "This status is used for a scheduled status."
IncidentStatusScheduled = 0
// IncidentStatusInvestigating means "You have reports of a problem and you're currently looking into them."
IncidentStatusInvestigating = 1
// IncidentStatusIdentified means "You've found the issue and you're working on a fix."
IncidentStatusIdentified = 2
// IncidentStatusWatching means "You've since deployed a fix and you're currently watching the situation."
IncidentStatusWatching = 3
// IncidentStatusFixed means "The fix has worked, you're happy to close the incident."
IncidentStatusFixed = 4
// IncidentVisibilityPublic means "Viewable by public"
IncidentVisibilityPublic = 1
// IncidentVisibilityLoggedIn means "Only visible to logged in users"
IncidentVisibilityLoggedIn = 0
)
// IncidentsService contains REST endpoints that belongs to cachet incidents.
type IncidentsService struct {
client *Client
}
// Incident entity reflects one single incident
type Incident struct {
ID int `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Status int `json:"status,omitempty"`
Message string `json:"message,omitempty"`
Visible int `json:"visible,omitempty"`
ComponentID int `json:"component_id,omitempty"`
ComponentStatus int `json:"component_status,omitempty"`
Notify bool `json:"notify,omitempty"`
Stickied bool `json:"stickied,omitempty"`
OccurredAt string `json:"occurred_at,omitempty"`
Template string `json:"template,omitempty"`
Vars []string `json:"vars,omitempty"`
CreatedAt string `json:"created_at,omitempty"`
UpdatedAt string `json:"updated_at,omitempty"`
DeletedAt string `json:"deleted_at,omitempty"`
IsResolved bool `json:"is_resolved,omitempty"`
Updates []IncidentUpdate `json:"updates,omitempty"`
HumanStatus string `json:"human_status,omitempty"`
LatestUpdateID int `json:"latest_update_id,omitempty"`
LatestStatus int `json:"latest_status,omitempty"`
LatestHumanStatus string `json:"latest_human_status,omitempty"`
LatestIcon string `json:"latest_icon,omitempty"`
Permalink string `json:"permalink,omitempty"`
Duration int `json:"duration,omitempty"`
}
// IncidentResponse reflects the response of /incidents call
type IncidentResponse struct {
Meta Meta `json:"meta,omitempty"`
Incidents []Incident `json:"data,omitempty"`
}
// IncidentsQueryParams contains fields to filter returned results
type IncidentsQueryParams struct {
ID int `url:"id,omitempty"`
Name string `url:"name,omitempty"`
Status int `url:"status,omitempty"`
Visible int `url:"visible,omitempty"`
ComponentID int `url:"component_id,omitempty"`
Stickied bool `url:"stickied,omitempty"`
QueryOptions
}
// incidentsAPIResponse is an internal type to hide
// some the "data" nested level from the API.
// Some calls (e.g. Get or Create) return the incident in the "data" key.
type incidentsAPIResponse struct {
Data *Incident `json:"data"`
}
// GetAll return all incidents.
//
// Docs: https://docs.cachethq.io/reference#get-incidents
func (s *IncidentsService) GetAll(filter *IncidentsQueryParams) (*IncidentResponse, *Response, error) {
u := "api/v1/incidents"
v := new(IncidentResponse)
u, err := addOptions(u, filter)
if err != nil {
return nil, nil, err
}
resp, err := s.client.Call("GET", u, nil, v)
return v, resp, err
}
// Get returns a single incident.
//
// Docs: https://docs.cachethq.io/reference#get-an-incident
func (s *IncidentsService) Get(id int) (*Incident, *Response, error) {
u := fmt.Sprintf("api/v1/incidents/%d", id)
v := new(incidentsAPIResponse)
resp, err := s.client.Call("GET", u, nil, v)
return v.Data, resp, err
}
// Create a new incident.
//
// Docs: https://docs.cachethq.io/reference#incidents
func (s *IncidentsService) Create(i *Incident) (*Incident, *Response, error) {
u := "api/v1/incidents"
v := new(incidentsAPIResponse)
resp, err := s.client.Call("POST", u, i, v)
return v.Data, resp, err
}
// Update updates an incident.
//
// Docs: https://docs.cachethq.io/reference#update-an-incident
func (s *IncidentsService) Update(id int, i *Incident) (*Incident, *Response, error) {
u := fmt.Sprintf("api/v1/incidents/%d", id)
v := new(incidentsAPIResponse)
resp, err := s.client.Call("PUT", u, i, v)
return v.Data, resp, err
}
// Delete delete an incident.
//
// Docs: https://docs.cachethq.io/reference#delete-an-incident
func (s *IncidentsService) Delete(id int) (*Response, error) {
u := fmt.Sprintf("api/v1/incidents/%d", id)
resp, err := s.client.Call("DELETE", u, nil, nil)
return resp, err
}