-
Notifications
You must be signed in to change notification settings - Fork 15
/
template.go
126 lines (101 loc) · 4.5 KB
/
template.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
package zabbix
// For `TemplateGetParams` field: `Evaltype`
const (
TemplateEvaltypeAndOr = 0
TemplateEvaltypeOr = 2
)
// For `TemplateTag` field: `Operator`
const (
TemplateTagOperatorContains = 0
TemplateTagOperatorEquals = 1
)
// TemplateObject struct is used to store template operations results
//
// see: https://www.zabbix.com/documentation/5.0/manual/api/reference/template/object
type TemplateObject struct {
TemplateID int `json:"templateid,omitempty"`
Host string `json:"host,omitempty"`
Description string `json:"description,omitempty"`
Name string `json:"name,omitempty"`
Groups []HostgroupObject `json:"groups,omitempty"`
Tags []TemplateTagObject `json:"tags,omitempty"`
Templates []TemplateObject `json:"templates,omitempty"`
ParentTemplates []TemplateObject `json:"parentTemplates,omitempty"`
Macros []UsermacroObject `json:"macros,omitempty"`
Hosts []HostObject `json:"hosts,omitempty"`
}
// TemplateTagObject struct is used to store template tag data
//
// see: https://www.zabbix.com/documentation/5.0/manual/api/reference/template/object#template_tag
type TemplateTagObject struct {
Tag string `json:"tag,omitempty"`
Value string `json:"value,omitempty"`
Operator int `json:"operator,omitempty"` // Used for `get` operations, has defined consts, see above
}
// TemplateGetParams struct is used for template get requests
//
// see: https://www.zabbix.com/documentation/5.0/manual/api/reference/template/get#parameters
type TemplateGetParams struct {
GetParameters
TemplateIDs []int `json:"templateids,omitempty"`
GroupIDs []int `json:"groupids,omitempty"`
ParentTemplateIDs []int `json:"parentTemplateids,omitempty"`
HostIDs []int `json:"hostids,omitempty"`
GraphIDs []int `json:"graphids,omitempty"`
ItemIDs []int `json:"itemids,omitempty"`
TriggerIDs []int `json:"triggerids,omitempty"`
WithItems bool `json:"with_items,omitempty"`
WithTriggers bool `json:"with_triggers,omitempty"`
WithGraphs bool `json:"with_graphs,omitempty"`
WithHttptests bool `json:"with_httptests,omitempty"`
Evaltype int `json:"evaltype,omitempty"` // has defined consts, see above
Tags []TemplateTagObject `json:"tags,omitempty"`
SelectGroups SelectQuery `json:"selectGroups,omitempty"`
SelectTags SelectQuery `json:"selectTags,omitempty"`
SelectHosts SelectQuery `json:"selectHosts,omitempty"`
SelectTemplates SelectQuery `json:"selectTemplates,omitempty"`
SelectParentTemplates SelectQuery `json:"selectParentTemplates,omitempty"`
SelectMacros SelectQuery `json:"selectMacros,omitempty"`
// SelectHttpTests SelectQuery `json:"selectHttpTests,omitempty"` // not implemented yet
// SelectItems SelectQuery `json:"selectItems,omitempty"` // not implemented yet
// SelectDiscoveries SelectQuery `json:"selectDiscoveries,omitempty"` // not implemented yet
// SelectTriggers SelectQuery `json:"selectTriggers,omitempty"` // not implemented yet
// SelectGraphs SelectQuery `json:"selectGraphs,omitempty"` // not implemented yet
// SelectApplications SelectQuery `json:"selectApplications,omitempty"` // not implemented yet
// SelectScreens SelectQuery `json:"selectScreens,omitempty"` // not implemented yet
}
// Structure to store creation result
type templateCreateResult struct {
TemplateIDs []int `json:"templateids"`
}
// Structure to store deletion result
type templateDeleteResult struct {
TemplateIDs []int `json:"templateids"`
}
// TemplateGet gets templates
func (z *Context) TemplateGet(params TemplateGetParams) ([]TemplateObject, int, error) {
var result []TemplateObject
status, err := z.request("template.get", params, &result)
if err != nil {
return nil, status, err
}
return result, status, nil
}
// TemplateCreate creates templates
func (z *Context) TemplateCreate(params []TemplateObject) ([]int, int, error) {
var result templateCreateResult
status, err := z.request("template.create", params, &result)
if err != nil {
return nil, status, err
}
return result.TemplateIDs, status, nil
}
// TemplateDelete deletes templates
func (z *Context) TemplateDelete(templateIDs []int) ([]int, int, error) {
var result templateDeleteResult
status, err := z.request("template.delete", templateIDs, &result)
if err != nil {
return nil, status, err
}
return result.TemplateIDs, status, nil
}