forked from neogan74/go-zabbix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate.go
51 lines (41 loc) · 1.3 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
package zabbix
// Template structure for mapping template object fields with JSON
type Template struct {
TemplateID string `json:"templateid,omitempty"`
Name string `json:"host,omitempty"`
Description string `json:"description,omitempty"`
DisplayName string `json:"name,omitempty"`
Macros string `json:"macros,omitempty"`
Groups string `json:"groups,omitempty"`
}
// Templates type for number of template returned from Zabbix API
type Templates []Template
type TemplateGetParams struct {
GetParameters
// GroupIDs filters search results to hosts that are members of the given
// Group IDs.
Output []string `json:"output,omitempty"`
// ApplicationIDs filters search results to hosts that have items in the
// given Application IDs.
Filter FilterTemplate `json:"filter,omitempty"`
}
type FilterTemplate struct {
Host []string `json:"host,omitempty"`
}
func (c *Session) GetTemplates(params TemplateGetParams) ([]Template, error) {
templates := make([]jTemplate, 0)
err := c.Get("template.get", params, &templates)
if err != nil {
return nil, err
}
if len(templates) == 0 {
return nil, ErrNotFound
}
// map JSON Events to Go Events
out := make([]Template, len(templates))
for i, jtemp := range templates {
host, _ := jtemp.Template()
out[i] = *host
}
return out, nil
}