-
Notifications
You must be signed in to change notification settings - Fork 13
/
autoscaling_event.go
60 lines (51 loc) · 1.45 KB
/
autoscaling_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
package gobizfly
import (
"context"
"encoding/json"
"errors"
"net/http"
"strconv"
)
// AutoScalingEvent is represents for a event of auto scaling group
type AutoScalingEvent struct {
ActionName string `json:"action"`
ActionType string `json:"type"`
Metadata struct {
Action struct {
Outputs map[string]interface{} `json:"outputs"`
} `json:"action"`
} `json:"meta_data"`
ClusterID string `json:"cluster_id"`
ID string `json:"id"`
Level string `json:"level"`
ObjectType string `json:"otype"`
StatusReason string `json:"status_reason"`
Timestamp string `json:"timestamp"`
}
// List autoscaling events of a cluster
func (e *event) List(ctx context.Context, clusterID string, page, total int) ([]*AutoScalingEvent, error) {
if clusterID == "" {
return nil, errors.New("Auto Scaling Group ID is required")
}
req, err := e.client.NewRequest(ctx, http.MethodGet, autoScalingServiceName, e.resourcePath(clusterID, page, total), nil)
if err != nil {
return nil, err
}
q := req.URL.Query()
q.Add("cluster_id", clusterID)
q.Add("page", strconv.Itoa(page))
q.Add("total", strconv.Itoa(total))
req.URL.RawQuery = q.Encode()
resp, err := e.client.Do(ctx, req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
var data struct {
AutoScalingEvents []*AutoScalingEvent `json:"events"`
}
if err := json.NewDecoder(resp.Body).Decode(&data); err != nil {
return nil, err
}
return data.AutoScalingEvents, nil
}