forked from VadimIpatov/go-zabbix
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtemplate_json.go
60 lines (51 loc) · 1.5 KB
/
template_json.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
package zabbix
import (
"fmt"
)
// jTemplate is a private map for the Zabbix API Host object.
// See: https://www.zabbix.com/documentation/2.2/manual/api/reference/host/object
type jTemplate struct {
TemplateID string `json:"hostid"`
Hostname string `json:"host"`
Description string `json:"description,omitempty"`
DisplayName string `json:"name"`
Macros string `json:"-"`
Hosts []string `json:"hosts"`
Groups string `json:"groupids"`
}
// Host returns a native Go Host struct mapped from the given JSON Host data.
func (c *jTemplate) Template() (*Template, error) {
//var err error
template := &Template{}
template.TemplateID = c.TemplateID
template.Name = c.Hostname
template.DisplayName = c.DisplayName
template.Description = c.Description
template.Macros = c.Macros
template.Groups = c.Groups
/*
host.Source, err = strconv.Atoi(c.Flags)
if err != nil {
return nil, fmt.Errorf("Error parsing Host Flags: %v", err)
}
*/
return template, nil
}
// jHosts is a slice of jHost structs.
type jTemplates []jTemplate
// Hosts returns a native Go slice of Templates mapped from the given JSON Temlates
// data.
func (c jTemplates) Tempaltes() ([]Template, error) {
if c != nil {
templates := make([]Template, len(c))
for i, jTemplate := range c {
template, err := jTemplate.Template()
if err != nil {
return nil, fmt.Errorf("Error unmarshalling Host %d in JSON data: %v", i, err)
}
templates[i] = *template
}
return templates, nil
}
return nil, nil
}