/
filebeat_forwarder.go
92 lines (76 loc) · 2.15 KB
/
filebeat_forwarder.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
package goaviatrix
import (
"strconv"
)
type FilebeatForwarder struct {
CID string
Server string
Port int
TrustedCAFile string
ConfigFile string
ExcludedGatewaysInput string
}
type FilebeatForwarderResp struct {
Server string `json:"server"`
Port string `json:"port"`
ExcludedGateways []string `json:"excluded_gateway"`
Status string `json:"status"`
}
func (c *Client) EnableFilebeatForwarder(r *FilebeatForwarder) error {
params := map[string]string{
"action": "enable_logstash_logging",
"CID": c.CID,
"server_ip": r.Server,
"port": strconv.Itoa(r.Port),
"exclude_gateway_list": r.ExcludedGatewaysInput,
"server_type": "other",
"forwarder_type": "filebeat",
}
var files []File
if r.TrustedCAFile != "" {
ca := File{
ParamName: "trusted_ca",
UseFileContent: true,
FileName: "ca.pem", // fake name for ca
FileContent: r.TrustedCAFile,
}
files = append(files, ca)
}
if r.ConfigFile != "" {
config := File{
ParamName: "config_file",
UseFileContent: true,
FileName: "config.txt", // fake name for config file
FileContent: r.ConfigFile,
}
files = append(files, config)
}
return c.PostFileAPI(params, files, BasicCheck)
}
func (c *Client) GetFilebeatForwarderStatus() (*FilebeatForwarderResp, error) {
params := map[string]string{
"action": "get_logstash_logging_status",
"CID": c.CID,
}
type Resp struct {
Return bool `json:"return,omitempty"`
Results FilebeatForwarderResp `json:"results,omitempty"`
Reason string `json:"reason,omitempty"`
}
var data Resp
err := c.GetAPI(&data, params["action"], params, BasicCheck)
if err != nil {
return nil, err
}
if data.Results.Status == "disabled" {
return nil, ErrNotFound
}
return &data.Results, nil
}
func (c *Client) DisableFilebeatForwarder() error {
params := map[string]string{
"action": "disable_logstash_logging",
"CID": c.CID,
}
return c.PostAPI(params["action"], params, BasicCheck)
}