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 50558780 2022-01-06 o type Attrs struct {
61 50558780 2022-01-06 o Address string `json:"address"`
62 50558780 2022-01-06 o CheckCommand string `json:"check_command"`
63 50558780 2022-01-06 o DisplayName string `json:"display_name"`
65 50558780 2022-01-06 o type host struct {
66 50558780 2022-01-06 o Attrs Attrs `json:"attrs"`
68 50558780 2022-01-06 o jhost := &host{
70 50558780 2022-01-06 o Address: h.Address,
71 50558780 2022-01-06 o CheckCommand: h.CheckCommand,
72 50558780 2022-01-06 o DisplayName: h.DisplayName,
75 50558780 2022-01-06 o return json.Marshal(jhost)
78 e0c24850 2022-01-14 o func (hg HostGroup) MarshalJSON() ([]byte, error) {
79 e0c24850 2022-01-14 o type attrs struct {
80 5105405e 2022-01-18 o DisplayName string `json:"display_name"`
82 e0c24850 2022-01-14 o type group struct {
83 e0c24850 2022-01-14 o Attrs attrs `json:"attrs"`
85 e0c24850 2022-01-14 o return json.Marshal(&group{
87 e0c24850 2022-01-14 o DisplayName: hg.DisplayName,