-
Notifications
You must be signed in to change notification settings - Fork 4
/
event.go
65 lines (55 loc) · 1.86 KB
/
event.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
/*
List and resolve current events. Every event occurrence has a unique ID (random UUID).
https://sensuapp.org/docs/0.20/api-events
*/
package sensu
import (
"net/http"
"strings"
)
// EventsURI constant
const EventsURI string = "/events"
// Event represents an Event object in the Sensu API
type Event struct {
ID string `json:"id"`
Client Client `json:"client"`
Check Check `json:"check"`
Occurrences int `json:"occurrences"`
Action string `json:"action"`
}
// Resolution represents a Resolution object in the Sensu API
type Resolution struct {
ClientName string `json:"client"`
CheckName string `json:"check"`
}
// GetEvents gets all events
func (c *API) GetEvents(out interface{}) (*http.Response, error) {
resp, err := c.get(EventsURI, out)
return resp, err
}
// GetEventsByClient gets all events for a particular client name
func (c *API) GetEventsByClient(out interface{}, clientName string) (*http.Response, error) {
s := []string{EventsURI, clientName}
uri := strings.Join(s, "/")
resp, err := c.get(uri, out)
return resp, err
}
// GetEventByClientCheck gets an event by client name and check name
func (c *API) GetEventByClientCheck(out interface{}, clientName string, checkName string) (*http.Response, error) {
s := []string{EventsURI, clientName, checkName}
uri := strings.Join(s, "/")
resp, err := c.get(uri, out)
return resp, err
}
// ResolveEvent resolves an event given the client name and check name
func (c *API) ResolveEvent(clientName, checkName string) (*http.Response, error) {
s := []string{EventsURI, clientName}
uri := strings.Join(s, "/")
resp, err := c.delete(uri)
return resp, err
}
// ResolveEventPost resolves an event given the client name and check name in a POST payload
func (c *API) ResolveEventPost(payload interface{}) (*http.Response, error) {
resp, err := c.post(EventsURI, payload)
return resp, err
}