forked from signalfx/signalfx-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
incident.go
59 lines (47 loc) · 1.47 KB
/
incident.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
package signalfx
import (
"context"
"encoding/json"
"io"
"io/ioutil"
"net/http"
"net/url"
"strconv"
"github.com/signalfx/signalfx-go/detector"
)
// IncidentAPIURL is the base URL for interacting with alert muting rules.
const IncidentAPIURL = "/v2/incident"
// Get incident with the given id
func (c *Client) GetIncident(ctx context.Context, id string) (*detector.Incident, error) {
resp, err := c.doRequest(ctx, "GET", IncidentAPIURL+"/"+id, nil, nil)
if err != nil {
return nil, err
}
defer resp.Body.Close()
if err = newResponseError(resp, http.StatusOK); err != nil {
return nil, err
}
finalIncident := &detector.Incident{}
err = json.NewDecoder(resp.Body).Decode(finalIncident)
_, _ = io.Copy(ioutil.Discard, resp.Body)
return finalIncident, err
}
// Get all incidents
func (c *Client) GetIncidents(ctx context.Context, includeResolved bool, limit int, query string, offset int) ([]*detector.Incident, error) {
params := url.Values{}
params.Add("includeResolved", strconv.FormatBool(includeResolved))
params.Add("limit", strconv.Itoa(limit))
params.Add("query", query)
params.Add("offset", strconv.Itoa(offset))
resp, err := c.doRequest(ctx, "GET", IncidentAPIURL, params, nil)
if err != nil {
return nil, err
}
if err = newResponseError(resp, http.StatusOK); err != nil {
return nil, err
}
var incidents []*detector.Incident
err = json.NewDecoder(resp.Body).Decode(&incidents)
_, _ = io.Copy(ioutil.Discard, resp.Body)
return incidents, err
}