-
Notifications
You must be signed in to change notification settings - Fork 1
/
mysql_api.go
126 lines (112 loc) · 3.53 KB
/
mysql_api.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package service
import (
"fmt"
"net/http"
"github.com/juju/errors"
commonSling "github.com/fwtpe/owl-backend/common/http/client"
"github.com/fwtpe/owl-backend/common/model"
nqmModel "github.com/fwtpe/owl-backend/common/model/nqm"
)
var annotateErr = errors.Annotate
func agentHeartbeatCall(agents []*model.FalconAgentHeartbeat) (rowsAffectedCnt int64, agentsDroppedCnt int64) {
param := struct {
UpdateOnly bool `json:"update_only"`
}{updateOnlyFlag}
req := NewSlingBase().Post("api/v1/agent/heartbeat").BodyJSON(agents).QueryStruct(¶m)
res := model.FalconAgentHeartbeatResult{}
err := annotateErr(
commonSling.ToSlintExt(req).DoReceive(http.StatusOK, &res),
"calling of [api/v1/agent/heartbeat] has error",
)
if err != nil {
logger.Errorf("[Service] AgentHeartbeat HTTP error: %v", errors.Details(err))
return 0, int64(len(agents))
}
return res.RowsAffected, 0
}
func NqmAgentHeartbeat(req *nqmModel.HeartbeatRequest) (*nqmModel.AgentView, error) {
resp := &nqmModel.AgentView{}
err := commonSling.ToSlintExt(
NewSlingBase().
Post("api/v1/heartbeat/nqm/agent").
BodyJSON(req),
).DoReceive(http.StatusOK, &resp)
if err != nil {
return nil, annotateErr(err, "calling of [api/v1/heartbeat/nqm/agent] has error")
}
return resp, nil
}
func NqmAgentHeartbeatTargetList(agentID int32) ([]*nqmModel.HeartbeatTarget, error) {
var resp []*nqmModel.HeartbeatTarget
err := commonSling.ToSlintExt(
NewSlingBase().
Get(fmt.Sprintf("api/v1/heartbeat/nqm/agent/%d/targets", agentID)),
).DoReceive(http.StatusOK, &resp)
if err != nil {
return nil, annotateErr(err, "calling of [api/v1/heartbeat/nqm/agent/] has error")
}
return resp, nil
}
func MinePlugins(hostname string) (*model.NewAgentPluginsResponse, error) {
var resp *model.NewAgentPluginsResponse
err := commonSling.ToSlintExt(
NewSlingBase().Get("api/v1/agent/mineplugins").QueryStruct(struct {
Hostname string `url:"hostname"`
}{hostname}),
).DoReceive(http.StatusOK, &resp)
if err != nil {
return nil, annotateErr(err, "calling of [api/v1/agent/mineplugins] has error")
}
return resp, nil
}
func Plugins(hostname string) ([]string, error) {
var resp []string
err := commonSling.ToSlintExt(
NewSlingBase().Get("api/v1/agent/plugins/"+hostname),
).DoReceive(http.StatusOK, &resp)
if err != nil {
return nil, annotateErr(err, "calling of [api/v1/agent/plugins/] has error")
}
return resp, nil
}
func BuiltinMetrics(hostname string, checksum string) (*model.NewBuiltinMetricResponse, error) {
var resp *model.NewBuiltinMetricResponse
err := commonSling.ToSlintExt(
NewSlingBase().
Get("api/v1/metrics/builtin").QueryStruct(struct {
Hostname string `url:"hostname,omitempty"`
Checksum string `url:"checksum,omitempty"`
}{hostname, checksum}),
).DoReceive(http.StatusOK, &resp)
if err != nil {
return nil, annotateErr(err, "calling of [api/v1/metrics/builtin] has error")
}
return resp, nil
}
func Strategies() ([]*model.NewHostStrategy, error) {
var resp []*model.NewHostStrategy
err := commonSling.ToSlintExt(
NewSlingBase().
Get("api/v1/strategies"),
).DoReceive(http.StatusOK, &resp)
if err != nil {
return nil, annotateErr(err, "calling of [api/v1/strategies] has error")
}
for _, hs := range resp {
for _, s := range hs.Strategies {
s.AfterLoad()
}
}
return resp, nil
}
func Expressions() ([]*model.NewExpression, error) {
var resp []*model.NewExpression
err := commonSling.ToSlintExt(
NewSlingBase().
Get("api/v1/expressions"),
).DoReceive(http.StatusOK, &resp)
if err != nil {
return nil, err
}
return resp, nil
}