3 26fb88e9 2022-01-12 o import "encoding/json"
5 e0c24850 2022-01-14 o // Host represents a Host object. To create a Host, the Name and CheckCommand
6 e0c24850 2022-01-14 o // fields must be set.
7 6e415953 2022-01-06 o type Host struct {
8 76669f9b 2022-01-11 o Name string `json:"name"`
9 76669f9b 2022-01-11 o Address string `json:"address"`
10 76669f9b 2022-01-11 o Address6 string `json:"address6"`
11 76669f9b 2022-01-11 o Groups []string `json:"groups"`
12 76669f9b 2022-01-11 o State HostState `json:"state"`
13 da19a2fd 2022-01-18 o StateType StateType `json:"state_type"`
14 76669f9b 2022-01-11 o CheckCommand string `json:"check_command"`
15 76669f9b 2022-01-11 o DisplayName string `json:"display_name"`
18 e0c24850 2022-01-14 o type HostGroup struct {
19 5105405e 2022-01-18 o Name string `json:"name"`
20 e0c24850 2022-01-14 o DisplayName string `json:"display_name"`
23 76669f9b 2022-01-11 o type HostState int
26 76669f9b 2022-01-11 o HostUp HostState = 0 + iota
28 76669f9b 2022-01-11 o HostUnreachable
31 76669f9b 2022-01-11 o func (s HostState) String() string {
34 76669f9b 2022-01-11 o return "HostUp"
36 76669f9b 2022-01-11 o return "HostDown"
37 76669f9b 2022-01-11 o case HostUnreachable:
38 76669f9b 2022-01-11 o return "HostUnreachable"
40 76669f9b 2022-01-11 o return "unhandled host state"
43 76669f9b 2022-01-11 o func (h Host) name() string {
47 76669f9b 2022-01-11 o func (h Host) path() string {
48 76669f9b 2022-01-11 o return "/objects/hosts/" + h.Name
51 e0c24850 2022-01-14 o func (hg HostGroup) name() string {
55 e0c24850 2022-01-14 o func (hg HostGroup) path() string {
56 e0c24850 2022-01-14 o return "/objects/hostgroups/" + hg.Name
59 50558780 2022-01-06 o func (h Host) MarshalJSON() ([]byte, error) {
60 dd0af5f7 2022-01-18 o attrs := make(map[string]interface{})
61 dd0af5f7 2022-01-18 o attrs["address"] = h.Address
62 dd0af5f7 2022-01-18 o attrs["address6"] = h.Address6
63 dd0af5f7 2022-01-18 o if len(h.Groups) > 0 {
64 dd0af5f7 2022-01-18 o attrs["groups"] = h.Groups
66 dd0af5f7 2022-01-18 o attrs["check_command"] = h.CheckCommand
67 dd0af5f7 2022-01-18 o attrs["display_name"] = h.DisplayName
68 dd0af5f7 2022-01-18 o m := make(map[string]interface{})
69 dd0af5f7 2022-01-18 o m["attrs"] = attrs
70 dd0af5f7 2022-01-18 o return json.Marshal(m)
73 e0c24850 2022-01-14 o func (hg HostGroup) MarshalJSON() ([]byte, error) {
74 e0c24850 2022-01-14 o type attrs struct {
75 5105405e 2022-01-18 o DisplayName string `json:"display_name"`
77 e0c24850 2022-01-14 o type group struct {
78 e0c24850 2022-01-14 o Attrs attrs `json:"attrs"`
80 e0c24850 2022-01-14 o return json.Marshal(&group{
82 e0c24850 2022-01-14 o DisplayName: hg.DisplayName,