9 76669f9b 2022-01-11 o func (s Service) name() string {
13 76669f9b 2022-01-11 o func (s Service) path() string {
14 76669f9b 2022-01-11 o return "/objects/services/" + s.Name
17 76669f9b 2022-01-11 o // Service represents a Service object.
18 76669f9b 2022-01-11 o type Service struct {
19 c26e0f9d 2022-02-02 o Name string `json:"-"`
20 c26e0f9d 2022-02-02 o Groups []string `json:"groups,omitempty"`
21 c26e0f9d 2022-02-02 o State ServiceState `json:"state,omitempty"`
22 c26e0f9d 2022-02-02 o StateType StateType `json:"state_type,omitempty"`
23 c26e0f9d 2022-02-02 o CheckCommand string `json:"check_command"`
24 c26e0f9d 2022-02-02 o DisplayName string `json:"display_name,omitempty"`
25 8f08828e 2022-02-11 o LastCheck time.Time `json:",omitempty"`
26 a17d3f9d 2022-02-11 o LastCheckResult CheckResult `json:"last_check_result,omitempty"`
27 c26e0f9d 2022-02-02 o Acknowledgement bool `json:",omitempty"`
28 001c466e 2023-03-11 o Notes string `json:"notes,omitempty"`
29 001c466e 2023-03-11 o NotesURL string `json:"notes_url,omitempty"`
32 f5fde32e 2022-01-18 o type CheckResult struct {
33 8f08828e 2022-02-11 o CheckSource string `json:"check_source"`
34 8f08828e 2022-02-11 o Command interface{}
38 76669f9b 2022-01-11 o type ServiceState int
41 76669f9b 2022-01-11 o ServiceOK ServiceState = 0 + iota
43 76669f9b 2022-01-11 o ServiceCritical
47 dca9442c 2022-02-02 o func (state ServiceState) String() string {
49 76669f9b 2022-01-11 o case ServiceOK:
51 76669f9b 2022-01-11 o case ServiceWarning:
52 d65c457c 2023-04-22 o return "Warning"
53 76669f9b 2022-01-11 o case ServiceCritical:
54 d65c457c 2023-04-22 o return "Critical"
56 d65c457c 2023-04-22 o return "Unknown"
59 562d5c1e 2022-01-19 o // UnmarshalJSON unmarshals service attributes into more meaningful Service field types.
60 562d5c1e 2022-01-19 o func (s *Service) UnmarshalJSON(data []byte) error {
61 562d5c1e 2022-01-19 o type alias Service
62 562d5c1e 2022-01-19 o aux := &struct {
63 f21c51c7 2022-11-01 o Acknowledgement interface{} `json:"acknowledgement"`
64 f21c51c7 2022-11-01 o State interface{} `json:"state"`
65 f21c51c7 2022-11-01 o StateType interface{} `json:"state_type"`
66 f21c51c7 2022-11-01 o LastCheck float64 `json:"last_check"`
69 562d5c1e 2022-01-19 o alias: (*alias)(s),
71 562d5c1e 2022-01-19 o if err := json.Unmarshal(data, &aux); err != nil {
74 f21c51c7 2022-11-01 o switch v := aux.Acknowledgement.(type) {
77 f21c51c7 2022-11-01 o s.Acknowledgement = true
80 f21c51c7 2022-11-01 o if int(v) != 0 {
81 f21c51c7 2022-11-01 o s.Acknowledgement = true
84 f21c51c7 2022-11-01 o switch v := aux.State.(type) {
86 f21c51c7 2022-11-01 o s.State = ServiceState(v)
88 f21c51c7 2022-11-01 o s.State = ServiceState(v)
90 f21c51c7 2022-11-01 o switch v := aux.StateType.(type) {
92 f21c51c7 2022-11-01 o s.StateType = StateType(v)
94 f21c51c7 2022-11-01 o s.StateType = StateType(v)
96 8f08828e 2022-02-11 o s.LastCheck = time.Unix(int64(aux.LastCheck), 0)
100 8f08828e 2022-02-11 o func (s Service) Host() string {
101 8f08828e 2022-02-11 o return strings.SplitN(s.Name, "!", 2)[0]
104 8f08828e 2022-02-11 o func (cr CheckResult) RawCommand() string {
105 8f08828e 2022-02-11 o switch v := cr.Command.(type) {
108 8f08828e 2022-02-11 o case []interface{}:
109 8f08828e 2022-02-11 o var cmd []string
110 8f08828e 2022-02-11 o for i := range v {
111 8f08828e 2022-02-11 o if arg, ok := v[i].(string); ok {
112 8f08828e 2022-02-11 o cmd = append(cmd, arg)
115 8f08828e 2022-02-11 o return strings.Join(cmd, " ")
117 8f08828e 2022-02-11 o return "no command"