9 // Host represents a Host object. To create a Host, the Name and CheckCommand
10 // fields must be set.
12 Name string `json:"-"`
13 Address string `json:"address"`
14 Address6 string `json:"address6"`
15 Groups []string `json:"groups,omitempty"`
16 State HostState `json:"state,omitempty"`
17 StateType StateType `json:"state_type,omitempty"`
18 CheckCommand string `json:"check_command"`
19 DisplayName string `json:"display_name,omitempty"`
20 LastCheck time.Time `json:",omitempty"`
21 LastCheckResult CheckResult `json:"last_check_result,omitempty"`
22 Acknowledgement bool `json:",omitempty"`
23 Notes string `json:"notes,omitempty"`
24 NotesURL string `json:"notes_url,omitempty"`
27 type HostGroup struct {
28 Name string `json:"-"`
29 DisplayName string `json:"display_name"`
35 HostUp HostState = 0 + iota
40 func (state HostState) String() string {
47 return "HostUnreachable"
50 func (h Host) name() string {
54 func (h Host) path() string {
55 return "/objects/hosts/" + h.Name
58 func (hg HostGroup) name() string {
62 func (hg HostGroup) path() string {
63 return "/objects/hostgroups/" + hg.Name
66 // UnmarhsalJSON unmarshals host attributes into more meaningful Host field types.
67 func (h *Host) UnmarshalJSON(data []byte) error {
70 Acknowledgement interface{} `json:"acknowledgement"`
71 State interface{} `json:"state"`
72 StateType interface{} `json:"state_type"`
73 LastCheck float64 `json:"last_check"`
78 if err := json.Unmarshal(data, &aux); err != nil {
82 switch v := aux.Acknowledgement.(type) {
85 h.Acknowledgement = true
89 h.Acknowledgement = true
92 switch v := aux.State.(type) {
94 h.State = HostState(v)
96 h.State = HostState(v)
98 switch v := aux.StateType.(type) {
100 h.StateType = StateType(v)
102 h.StateType = StateType(v)
104 h.LastCheck = time.Unix(int64(aux.LastCheck), 0)