forked from nixys/nxs-go-zabbix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
host.go
293 lines (251 loc) · 10.8 KB
/
host.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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
package zabbix
// For `HostObject` field: `Available`
const (
HostAvailableUnknown = 0
HostAvailableAvailable = 1
HostAvailableUnavailable = 2
)
// For `HostObject` field: `Flags`
const (
HostFlagsPlain = 0
HostFlagsDiscovered = 4
)
// For `HostObject` field: `Flags`
const (
HostInventoryModeDisabled = -1
HostInventoryModeManual = 0
HostInventoryModeAutomatic = 1
)
// For `HostObject` field: `IpmiAuthtype`
const (
HostIpmiAuthtypeDefault = -1
HostIpmiAuthtypeNone = 0
HostIpmiAuthtypeMD2 = 1
HostIpmiAuthtypeMD5 = 2
HostIpmiAuthtypeStraight = 4
HostIpmiAuthtypeOEM = 5
HostIpmiAuthtypeRMCP = 6
)
// For `HostObject` field: `IpmiAvailable`
const (
HostIpmiAvailableUnknown = 0
HostIpmiAvailableAvailable = 1
HostIpmiAvailableUnavailable = 2
)
// For `HostObject` field: `IpmiPrivilege`
const (
HostIpmiPrivilegeCallback = 1
HostIpmiPrivilegeUser = 2
HostIpmiPrivilegeOperator = 3
HostIpmiPrivilegeAdmin = 4
HostIpmiPrivilegeOEM = 5
)
// For `HostObject` field: `JmxAvailable`
const (
HostJmxAvailableUnknown = 0
HostJmxAvailableAvailable = 1
HostJmxAvailableUnavailable = 2
)
// For `HostObject` field: `MaintenanceStatus`
const (
HostMaintenanceStatusDisable = 0
HostMaintenanceStatusEnable = 1
)
// For `HostObject` field: `MaintenanceType`
const (
HostMaintenanceTypeDataCollectionEnabled = 0
HostMaintenanceTypeDataCollectionDisabled = 1
)
// For `HostObject` field: `SnmpAvailable`
const (
HostSnmpAvailableUnknown = 0
HostSnmpAvailableAvailable = 1
HostSnmpAvailableUnavailable = 2
)
// For `HostObject` field: `Status`
const (
HostStatusMonitored = 0
HostStatusUnmonitored = 1
)
// For `HostObject` field: `TLSConnect`
const (
TLSConnectNoEncryption = 1
TLSConnectPSK = 2
TLSConnectCertificate = 4
)
// For `HostObject` field: `TLSAccept`
const (
TLSAcceptNoEncryption = 1
TLSAcceptPSK = 2
TLSAcceptCertificate = 4
)
// For `HostGetParams` field: `Evaltype`
const (
HostEvaltypeAndOr = 0
HostEvaltypeOr = 2
)
// For `HostTag` field: `Operator`
const (
HostTagOperatorContains = 0
HostTagOperatorEquals = 1
)
// HostObject struct is used to store host operations results
//
// see: https://www.zabbix.com/documentation/5.0/manual/api/reference/host/object#host
type HostObject struct {
HostID int `json:"hostid,omitempty"`
Host string `json:"host,omitempty"`
Available int `json:"available,omitempty"` // has defined consts, see above
Description string `json:"description,omitempty"`
DisableUntil int `json:"disable_until,omitempty"`
Error string `json:"error,omitempty"`
ErrorsFrom int `json:"errors_from,omitempty"`
Flags int `json:"flags,omitempty"` // has defined consts, see above
InventoryMode int `json:"inventory_mode,omitempty"` // has defined consts, see above
IpmiAuthtype int `json:"ipmi_authtype,omitempty"` // has defined consts, see above
IpmiAvailable int `json:"ipmi_available,omitempty"` // has defined consts, see above
IpmiDisableUntil int `json:"ipmi_disable_until,omitempty"`
IpmiError string `json:"ipmi_error,omitempty"`
IpmiErrorsFrom int `json:"ipmi_errors_from,omitempty"`
IpmiPassword string `json:"ipmi_password,omitempty"`
IpmiPrivilege int `json:"ipmi_privilege,omitempty"` // has defined consts, see above
IpmiUsername string `json:"ipmi_username,omitempty"`
JmxAvailable int `json:"jmx_available,omitempty"` // has defined consts, see above
JmxDisableUntil int `json:"jmx_disable_until,omitempty"`
JmxError string `json:"jmx_error,omitempty"`
JmxErrorsFrom int `json:"jmx_errors_from,omitempty"`
MaintenanceFrom int `json:"maintenance_from,omitempty"`
MaintenanceStatus int `json:"maintenance_status,omitempty"` // has defined consts, see above
MaintenanceType int `json:"maintenance_type,omitempty"` // has defined consts, see above
MaintenanceID int `json:"maintenanceid,omitempty"`
Name string `json:"name,omitempty"`
ProxyHostID int `json:"proxy_hostid,omitempty"`
SnmpAvailable int `json:"snmp_available,omitempty"` // has defined consts, see above
SnmpDisableUntil int `json:"snmp_disable_until,omitempty"`
SnmpError string `json:"snmp_error,omitempty"`
SnmpErrorsFrom int `json:"snmp_errors_from,omitempty"`
Status int `json:"status,omitempty"` // has defined consts, see above
TLSConnect int `json:"tls_connect,omitempty"` // has defined consts, see above
TLSAccept int `json:"tls_accept,omitempty"` // has defined consts, see above
TLSIssuer string `json:"tls_issuer,omitempty"`
TLSSubject string `json:"tls_subject,omitempty"`
TLSPSKIdentity string `json:"tls_psk_identity,omitempty"`
TLSPSK string `json:"tls_psk,omitempty"`
Groups []HostgroupObject `json:"groups,omitempty"`
Interfaces []HostinterfaceObject `json:"interfaces,omitempty"`
Tags []HostTagObject `json:"tags,omitempty"`
InheritedTags []HostTagObject `json:"inheritedTags,omitempty"`
Macros []UsermacroObject `json:"macros,omitempty"`
Templates []TemplateObject `json:"templates,omitempty"` // Used for `create` operations
ParentTemplates []TemplateObject `json:"parentTemplates,omitempty"` // Used to store result for `get` operations
}
// HostTagObject struct is used to store host tag
//
// see: https://www.zabbix.com/documentation/5.0/manual/api/reference/host/object#host_tag
type HostTagObject struct {
Tag string `json:"tag"`
Value string `json:"value,omitempty"`
Operator int `json:"operator,omitempty"` // Used for `get` operations, has defined consts, see above
}
// HostGetParams struct is used for host get requests
//
// see: https://www.zabbix.com/documentation/5.0/manual/api/reference/host/get#parameters
type HostGetParams struct {
GetParameters
GroupIDs []int `json:"groupids,omitempty"`
ApplicationIDs []int `json:"applicationids,omitempty"`
DserviceIDs []int `json:"dserviceids,omitempty"`
GraphIDs []int `json:"graphids,omitempty"`
HostIDs []int `json:"hostids,omitempty"`
HttptestIDs []int `json:"httptestids,omitempty"`
InterfaceIDs []int `json:"interfaceids,omitempty"`
ItemIDs []int `json:"itemids,omitempty"`
MaintenanceIDs []int `json:"maintenanceids,omitempty"`
MonitoredHosts bool `json:"monitored_hosts,omitempty"`
ProxyHosts bool `json:"proxy_hosts,omitempty"`
ProxyIDs []int `json:"proxyids,omitempty"`
TemplatedHosts bool `json:"templated_hosts,omitempty"`
TemplateIDs []int `json:"templateids,omitempty"`
TriggerIDs []int `json:"triggerids,omitempty"`
WithItems bool `json:"with_items,omitempty"`
WithItemPrototypes bool `json:"with_item_prototypes,omitempty"`
WithSimpleGraphItemPrototypes bool `json:"with_simple_graph_item_prototypes,omitempty"`
WithApplications bool `json:"with_applications,omitempty"`
WithGraphs bool `json:"with_graphs,omitempty"`
WithGraphPrototypes bool `json:"with_graph_prototypes,omitempty"`
WithHttptests bool `json:"with_httptests,omitempty"`
WithMonitoredHttptests bool `json:"with_monitored_httptests,omitempty"`
WithMonitoredItems bool `json:"with_monitored_items,omitempty"`
WithMonitoredTriggers bool `json:"with_monitored_triggers,omitempty"`
WithSimpleGraphItems bool `json:"with_simple_graph_items,omitempty"`
WithTriggers bool `json:"with_triggers,omitempty"`
WithProblemsSuppressed bool `json:"withProblemsSuppressed,omitempty"`
Evaltype int `json:"evaltype,omitempty"` // has defined consts, see above
Severities []int `json:"severities,omitempty"`
Tags []HostTagObject `json:"tags,omitempty"`
InheritedTags bool `json:"inheritedTags,omitempty"`
// SelectApplications SelectQuery `json:"selectApplications,omitempty"` // not implemented yet
// SelectDiscoveries SelectQuery `json:"selectDiscoveries,omitempty"` // not implemented yet
// SelectDiscoveryRule SelectQuery `json:"selectDiscoveryRule ,omitempty"` // not implemented yet
// SelectGraphs SelectQuery `json:"selectGraphs,omitempty"` // not implemented yet
SelectGroups SelectQuery `json:"selectGroups,omitempty"`
// SelectHostDiscovery SelectQuery `json:"selectHostDiscovery ,omitempty"` // not implemented yet
// SelectHTTPTests SelectQuery `json:"selectHttpTests,omitempty"` // not implemented yet
SelectInterfaces SelectQuery `json:"selectInterfaces,omitempty"`
// SelectInventory SelectQuery `json:"selectInventory,omitempty"` // not implemented yet
// SelectItems SelectQuery `json:"selectItems,omitempty"` // not implemented yet
SelectMacros SelectQuery `json:"selectMacros,omitempty"`
SelectParentTemplates SelectQuery `json:"selectParentTemplates,omitempty"`
// SelectScreens SelectQuery `json:"selectScreens,omitempty"` // not implemented yet
SelectTags SelectQuery `json:"selectTags,omitempty"`
SelectInheritedTags SelectQuery `json:"selectInheritedTags,omitempty"`
// SelectTriggers SelectQuery `json:"selectTriggers,omitempty"` // not implemented yet
}
// Structure to store creation result
type hostCreateResult struct {
HostIDs []int `json:"hostids"`
}
// Structure to store updation result
type hostUpdateResult struct {
HostIDs []int `json:"hostids"`
}
// Structure to store deletion result
type hostDeleteResult struct {
HostIDs []int `json:"hostids"`
}
// HostGet gets hosts
func (z *Context) HostGet(params HostGetParams) ([]HostObject, int, error) {
var result []HostObject
status, err := z.request("host.get", params, &result)
if err != nil {
return nil, status, err
}
return result, status, nil
}
// HostCreate creates hosts
func (z *Context) HostCreate(params []HostObject) ([]int, int, error) {
var result hostCreateResult
status, err := z.request("host.create", params, &result)
if err != nil {
return nil, status, err
}
return result.HostIDs, status, nil
}
// HostUpdate updates hosts
func (z *Context) HostUpdate(params []HostObject) ([]int, int, error) {
var result hostUpdateResult
status, err := z.request("host.update", params, &result)
if err != nil {
return nil, status, err
}
return result.HostIDs, status, nil
}
// HostDelete deletes hosts
func (z *Context) HostDelete(hostIDs []int) ([]int, int, error) {
var result hostDeleteResult
status, err := z.request("host.delete", hostIDs, &result)
if err != nil {
return nil, status, err
}
return result.HostIDs, status, nil
}