-
Notifications
You must be signed in to change notification settings - Fork 0
/
hostgroup.go
157 lines (137 loc) · 3.74 KB
/
hostgroup.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package gozbx
import (
"github.com/google/uuid"
)
type HostGroupModel struct {
GroupId string `json:"groupid"`
Name string `json:"name"`
Flags int `json:"flags"` // 0: a plain hostgroup 4: discovered hostgroup
Uuid string `json:"uuid"`
}
type HostGroupGet struct {
CommonGetParams
GroupIds []string `json:"groupids,omitempty"` // Return only host groups with the given host group IDs.
HostIds []string `json:"hostids,omitempty"` // Return only host groups that contain the given hosts.
MaintenanceIds []string `json:"maintenanceids,omitempty"` // Return only host groups with the given maintenance IDs.
TriggerIds []string `json:"triggerids,omitempty"` // Return only host groups that contain the given triggers.
}
type HostGroupCreate struct {
Host string `json:"name"`
Uuid uuid.UUID `json:"uuid,omitempty"`
}
type HostGroupIdResponse struct {
GroupIds []string `json:"groupids"`
}
type HostGroupUpdate struct {
GroupId string `json:"groupid"`
Name string `json:"name,omitempty"`
Flags int `json:"flags,omitempty"`
Uuid string `json:"uuid,omitempty"`
}
// This method allows to simultaneously add multiple related objects to all the given host groups.
type HostGroupMassAdd struct {
Groups []GroupId `json:"groups"`
Host []HostId `json:"hosts"`
}
// This method allows to remove related objects from multiple host groups.
type HostGroupMassRemove struct {
HostGroupMassAdd
}
// This method allows to replace hosts and templates with the specified ones in multiple host groups.
type HostGroupMassUpdate struct {
HostGroupMassAdd
}
// type HostGroupPropagate struct {
// groups []GroupId `json:"groups"`
// permission bool `json:"permission,omitempty"`
// tagFilters []TagFilter `json:"tag_filters,omitempty"`
// }
type HosGroupImpl struct {
z *ZbxAPI
}
func (hg *HosGroupImpl) Get(params HostGroupGet) (res []HostGroupModel, err error) {
request := &Request{
Params: params,
Method: "hostgroup.get",
}
resp, err := hg.z.Rpc(request)
if err != nil {
return nil, err
}
resp.GetResult(&res)
return
}
func (hg *HosGroupImpl) Create(params HostGroupCreate) (rsp string,err error) {
request := &Request{
Params: params,
Method: "hostgroup.create",
}
resp, err:= hg.z.Rpc(request)
if err != nil {
return "", err
}
hgr := HostGroupIdResponse{}
resp.GetResult(&hgr)
return hgr.GroupIds[0], nil
}
func (hg *HosGroupImpl) Update(params HostGroupUpdate) (rsp string, err error) {
request := &Request{
Params: params,
Method: "hostgroup.update",
}
resp, err:= hg.z.Rpc(request)
if err != nil {
return "nil", err
}
hgr := HostGroupIdResponse{}
resp.GetResult(&hgr)
return hgr.GroupIds[0], nil
}
func (hg *HosGroupImpl) Delete(hostgroupIds []string) (rsp []string , err error) {
request := &Request{
Params: hostgroupIds,
Method: "hostgroup.delete",
}
resp, err:= hg.z.Rpc(request)
if err != nil {
return nil, err
}
resp.GetResult(&rsp)
return
}
func (hg *HosGroupImpl) MassAdd(params HostGroupMassAdd) (rsp *HostGroupIdResponse, err error) {
request := &Request{
Params: params,
Method: "hostgroup.massadd",
}
resp, err:= hg.z.Rpc(request)
if err != nil {
return nil, err
}
resp.GetResult(&rsp)
return
}
func (hg *HosGroupImpl) MassRemove(params HostGroupMassRemove) (rsp *HostGroupIdResponse, err error) {
request := &Request{
Params: params,
Method: "hostgroup.massremove",
}
resp, err:= hg.z.Rpc(request)
if err != nil {
return nil, err
}
resp.GetResult(&rsp)
return
}
func (hg *HosGroupImpl) MassUpdate(params HostGroupMassUpdate) (rsp *HostGroupIdResponse, err error) {
request := &Request{
Params: params,
Method: "hostgroup.massupdate",
}
resp, err:= hg.z.Rpc(request)
if err != nil {
return nil, err
}
resp.GetResult(&rsp)
return
}