5 // Host represents a Host object. To create a Host, the Name and CheckCommand
8 Name string `json:"name"`
9 Address string `json:"address"`
10 Address6 string `json:"address6"`
11 Groups []string `json:"groups"`
12 State HostState `json:"state"`
13 StateType StateType `json:"state_type"`
14 CheckCommand string `json:"check_command"`
15 DisplayName string `json:"display_name"`
18 type HostGroup struct {
19 Name string `json:"name"`
20 DisplayName string `json:"display_name"`
26 HostUp HostState = 0 + iota
31 func (s HostState) String() string {
38 return "HostUnreachable"
40 return "unhandled host state"
43 func (h Host) name() string {
47 func (h Host) path() string {
48 return "/objects/hosts/" + h.Name
51 func (hg HostGroup) name() string {
55 func (hg HostGroup) path() string {
56 return "/objects/hostgroups/" + hg.Name
59 func (h Host) MarshalJSON() ([]byte, error) {
60 attrs := make(map[string]interface{})
61 attrs["address"] = h.Address
62 attrs["address6"] = h.Address6
63 if len(h.Groups) > 0 {
64 attrs["groups"] = h.Groups
66 attrs["check_command"] = h.CheckCommand
67 attrs["display_name"] = h.DisplayName
68 m := make(map[string]interface{})
70 return json.Marshal(m)
73 func (hg HostGroup) MarshalJSON() ([]byte, error) {
75 DisplayName string `json:"display_name"`
78 Attrs attrs `json:"attrs"`
80 return json.Marshal(&group{
82 DisplayName: hg.DisplayName,