-
Notifications
You must be signed in to change notification settings - Fork 6
/
node_collector_tag_create.go
60 lines (56 loc) · 1.26 KB
/
node_collector_tag_create.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 omcmd
import (
"fmt"
"github.com/opensvc/om3/core/nodeaction"
"github.com/opensvc/om3/core/object"
)
type (
CmdNodeCollectorTagCreate struct {
OptsGlobal
Name string
Data *string
Exclude *string
}
)
func (t *CmdNodeCollectorTagCreate) Run() error {
return nodeaction.New(
nodeaction.WithLocal(t.Local),
nodeaction.WithFormat(t.Output),
nodeaction.WithColor(t.Color),
nodeaction.WithLocalFunc(func() (interface{}, error) {
n, err := object.NewNode()
if err != nil {
return nil, err
}
cli, err := n.CollectorFeedClient()
if err != nil {
return nil, err
}
options := make(map[string]any)
//options["svcname"] =
options["tag_name"] = t.Name
if t.Name == "" {
return nil, fmt.Errorf("the tag name must not be empty")
}
if t.Data != nil {
options["tag_data"] = *t.Data
}
if t.Exclude != nil {
options["tag_exclude"] = *t.Exclude
}
type respType struct {
Ret int `json:"ret"`
Msg string `json:"msg"`
}
var resp respType
if err := cli.CallFor(&resp, "collector_create_tag", options); err != nil {
return nil, err
} else if resp.Ret == 0 {
fmt.Println(resp.Msg)
return nil, nil
} else {
return nil, fmt.Errorf("%s", resp.Msg)
}
}),
).Do()
}