-
Notifications
You must be signed in to change notification settings - Fork 7
/
results.go
93 lines (78 loc) · 2.45 KB
/
results.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
package alarmrule
import (
"fmt"
"github.com/huaweicloud/terraform-provider-hcs/huaweicloudstack/sdk/huaweicloud"
)
type CreateResponse struct {
AlarmID string `json:"alarm_id"`
}
type CreateResult struct {
golangsdk.Result
}
func (c CreateResult) Extract() (*CreateResponse, error) {
r := &CreateResponse{}
return r, c.ExtractInto(r)
}
type DimensionInfo struct {
Name string `json:"name"`
Value string `json:"value"`
}
type MetricInfo struct {
Namespace string `json:"namespace"`
MetricName string `json:"metric_name"`
Dimensions []DimensionInfo `json:"dimensions"`
}
type ConditionInfo struct {
Period int `json:"period"`
Filter string `json:"filter"`
ComparisonOperator string `json:"comparison_operator"`
Value float64 `json:"value"`
Unit string `json:"unit"`
Count int `json:"count"`
SuppressDuration int `json:"suppress_duration"`
}
type ActionInfo struct {
Type string `json:"type"`
NotificationList []string `json:"notificationList"`
}
type AlarmRule struct {
AlarmName string `json:"alarm_name"`
AlarmDescription string `json:"alarm_description"`
AlarmType string `json:"alarm_type"`
AlarmLevel int `json:"alarm_level"`
Metric MetricInfo `json:"metric"`
Condition ConditionInfo `json:"condition"`
AlarmActions []ActionInfo `json:"alarm_actions"`
InsufficientdataActions []ActionInfo `json:"insufficientdata_actions"`
OkActions []ActionInfo `json:"ok_actions"`
AlarmEnabled bool `json:"alarm_enabled"`
AlarmActionEnabled bool `json:"alarm_action_enabled"`
UpdateTime int64 `json:"update_time"`
AlarmState string `json:"alarm_state"`
EnterpriseProjectID string `json:"enterprise_project_id"`
}
type GetResult struct {
golangsdk.Result
}
func (g GetResult) Extract() (*AlarmRule, error) {
var r struct {
MetricAlarms []AlarmRule `json:"metric_alarms"`
}
err := g.ExtractInto(&r)
if err != nil {
return nil, err
}
if len(r.MetricAlarms) != 1 {
return nil, fmt.Errorf("get %d alarm rules", len(r.MetricAlarms))
}
return &(r.MetricAlarms[0]), nil
}
type UpdateResult struct {
golangsdk.ErrResult
}
type EnableResult struct {
golangsdk.ErrResult
}
type DeleteResult struct {
golangsdk.ErrResult
}