forked from bizflycloud/gobizfly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalert_histories.go
82 lines (72 loc) · 2.83 KB
/
alert_histories.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
package gobizfly
import (
"context"
"encoding/json"
"net/http"
"strings"
)
// AlarmsInHistories contains alarm information in a history
type AlarmsInHistories struct {
AlertInterval int `json:"alert_interval"`
ClusterID string `json:"cluster_id,omitempty"`
ClusterName string `json:"cluster_name,omitempty"`
Comparison *Comparison `json:"comparison,omitempty"`
Enable bool `json:"enable"`
Hostname string `json:"hostname,omitempty"`
HTTPExpectedCode int `json:"http_expected_code,omitempty"`
HTTPHeaders *[]HTTPHeaders `json:"http_headers,omitempty"`
HTTPURL string `json:"http_url,omitempty"`
ID string `json:"_id"`
Instances *[]AlarmInstancesMonitors `json:"instances,omitempty"`
LoadBalancers *[]AlarmLoadBalancersMonitor `json:"load_balancers,omitempty"`
Name string `json:"name"`
ProjectID string `json:"project_id"`
Receivers *[]struct {
ReceiverID string `json:"receiver_id"`
Methods []string `json:"methods"`
} `json:"receivers"`
ResourceType string `json:"resource_type"`
UserID string `json:"user_id"`
Volumes *[]AlarmVolumesMonitor `json:"volumes,omitempty"`
}
// Histories contains history information.
type Histories struct {
HistoryID string `json:"_id"`
Name string `json:"name"`
ProjectID string `json:"project_id,omitempty"`
UserID string `json:"user_id,omitempty"`
Resource interface{} `json:"resource,omitempty"`
State string `json:"state,omitempty"`
Measurement string `json:"measurement,omitempty"`
AlarmID string `json:"alarm_id"`
Alarm AlarmsInHistories `json:"alarm,omitempty"`
Created string `json:"_created,omitempty"`
}
func (h *histories) resourcePath() string {
return strings.Join([]string{historiesResourcePath}, "/")
}
// List histories
func (h *histories) List(ctx context.Context, filters *string) ([]*Histories, error) {
req, err := h.client.NewRequest(ctx, http.MethodGet, cloudwatcherServiceName, h.resourcePath(), nil)
if err != nil {
return nil, err
}
q := req.URL.Query()
if filters != nil {
q.Add("where", *filters)
}
q.Add("sort", "-_created")
req.URL.RawQuery = q.Encode()
resp, err := h.client.Do(ctx, req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
var data struct {
Histories []*Histories `json:"_items"`
}
if err := json.NewDecoder(resp.Body).Decode(&data); err != nil {
return nil, err
}
return data.Histories, nil
}