forked from nixys/nxs-go-zabbix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hostgroup.go
111 lines (89 loc) · 3.81 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
package zabbix
// For `HostgroupObject` field: `Status`
const (
HostgroupFlagsPlain = 0
HostgroupFlagsDiscrovered = 4
)
// For `HostgroupObject` field: `Internal`
const (
HostgroupInternalFalse = 0
HostgroupInternalTrue = 1
)
// HostgroupObject struct is used to store hostgroup operations results
//
// see: https://www.zabbix.com/documentation/5.0/manual/api/reference/hostgroup/object
type HostgroupObject struct {
GroupID int `json:"groupid,omitempty"`
Name string `json:"name,omitempty"`
Flags int `json:"flags,omitempty"` // has defined consts, see above
Internal int `json:"internal,omitempty"` // has defined consts, see above
Hosts []HostObject `json:"hosts,omitempty"`
Templates []TemplateObject `json:"templates,omitempty"`
}
// HostgroupGetParams struct is used for hostgroup get requests
//
// see: https://www.zabbix.com/documentation/5.0/manual/api/reference/hostgroup/get#parameters
type HostgroupGetParams struct {
GetParameters
GraphIDs []int `json:"graphids,omitempty"`
GroupIDs []int `json:"groupids,omitempty"`
HostIDs []int `json:"hostids,omitempty"`
MaintenanceIDs []int `json:"maintenanceids,omitempty"`
MonitoredHosts bool `json:"monitored_hosts,omitempty"`
RealHosts bool `json:"real_hosts,omitempty"`
TemplatedHosts bool `json:"templated_hosts,omitempty"`
TemplateIDs []int `json:"templateids,omitempty"`
TriggerIDs []int `json:"triggerids,omitempty"`
WithApplications bool `json:"with_applications,omitempty"`
WithGraphs bool `json:"with_graphs,omitempty"`
WithGraphPrototypes bool `json:"with_graph_prototypes,omitempty"`
WithHostsAndTemplates bool `json:"with_hosts_and_templates,omitempty"`
WithHttptests bool `json:"with_httptests,omitempty"`
WithItems bool `json:"with_items,omitempty"`
WithItemPrototypes bool `json:"with_item_prototypes,omitempty"`
WithSimpleGraphItemPrototypes bool `json:"with_simple_graph_item_prototypes,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"`
// SelectDiscoveryRule SelectQuery `json:"selectDiscoveryRule,omitempty"` // not implemented yet
// SelectGroupDiscovery SelectQuery `json:"selectGroupDiscovery,omitempty"` // not implemented yet
SelectHosts SelectQuery `json:"selectHosts,omitempty"`
SelectTemplates SelectQuery `json:"selectTemplates,omitempty"`
}
// Structure to store creation result
type hostgroupCreateResult struct {
GroupIDs []int `json:"groupids"`
}
// Structure to store deletion result
type hostgroupDeleteResult struct {
GroupIDs []int `json:"groupids"`
}
// HostgroupGet gets hostgroups
func (z *Context) HostgroupGet(params HostgroupGetParams) ([]HostgroupObject, int, error) {
var result []HostgroupObject
status, err := z.request("hostgroup.get", params, &result)
if err != nil {
return nil, status, err
}
return result, status, nil
}
// HostgroupCreate creates hostgroups
func (z *Context) HostgroupCreate(params []HostgroupObject) ([]int, int, error) {
var result hostgroupCreateResult
status, err := z.request("hostgroup.create", params, &result)
if err != nil {
return nil, status, err
}
return result.GroupIDs, status, nil
}
// HostgroupDelete deletes hostgroups
func (z *Context) HostgroupDelete(groupIDs []int) ([]int, int, error) {
var result hostgroupDeleteResult
status, err := z.request("hostgroup.delete", groupIDs, &result)
if err != nil {
return nil, status, err
}
return result.GroupIDs, status, nil
}