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"`
19 type HostGroup struct {
20 Name string `json:"name"`
21 DisplayName string `json:"display_name"`
27 HostUp HostState = 0 + iota
32 func (s HostState) String() string {
39 return "HostUnreachable"
41 return "unhandled host state"
44 func (h Host) name() string {
48 func (h Host) path() string {
49 return "/objects/hosts/" + h.Name
52 func (hg HostGroup) name() string {
56 func (hg HostGroup) path() string {
57 return "/objects/hostgroups/" + hg.Name
60 func (h Host) MarshalJSON() ([]byte, error) {
61 attrs := make(map[string]interface{})
62 attrs["address"] = h.Address
63 attrs["address6"] = h.Address6
64 if len(h.Groups) > 0 {
65 attrs["groups"] = h.Groups
67 attrs["check_command"] = h.CheckCommand
68 attrs["display_name"] = h.DisplayName
69 m := make(map[string]interface{})
71 return json.Marshal(m)
74 // UnmarhsalJSON unmarshals host attributes into more meaningful Host field types.
75 func (h *Host) UnmarshalJSON(data []byte) error {
83 if err := json.Unmarshal(data, &aux); err != nil {
86 if aux.Acknowledgement != 0 {
87 h.Acknowledgement = true
92 func (hg HostGroup) MarshalJSON() ([]byte, error) {
94 DisplayName string `json:"display_name"`
97 Attrs attrs `json:"attrs"`
99 return json.Marshal(&group{
101 DisplayName: hg.DisplayName,