forked from zabbix-tools/go-zabbix
-
Notifications
You must be signed in to change notification settings - Fork 1
/
template.go
52 lines (43 loc) · 1.34 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
package zabbix
import "fmt"
type Template struct {
TemplateID string `json:"templateid,omitempty"`
Name string `json:"host,omitempty"`
Description string `json:"description,omitempty"`
DisplayName string `json:"name,omitempty"`
}
type Templates []Template
// TemplateGetParams represent the parameters for a `template.get` API call.
//
// See: https://www.zabbix.com/documentation/3.4/manual/api/reference/template/get#parameters
type TemplateGetParams struct {
GetParameters
// TODO
}
// GetTemplates queries the Zabbix API for Templates matching the given search
// parameters.
//
// ErrNotFound is returned if the search result set is empty.
// An error is returned if a transport, parsing or API error occurs.
//
// https://www.zabbix.com/documentation/3.4/manual/api/reference/template/get
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, jtemplate := range templates {
template, err := jtemplate.Template()
if err != nil {
return nil, fmt.Errorf("Error mapping Template %d in response: %v", i, err)
}
out[i] = *template
}
return out, nil
}