9 func (s Service) name() string {
13 func (s Service) path() string {
14 return "/objects/services/" + s.Name
17 // Service represents a Service object.
19 Name string `json:"-"`
20 Groups []string `json:"groups,omitempty"`
21 State ServiceState `json:"state,omitempty"`
22 StateType StateType `json:"state_type,omitempty"`
23 CheckCommand string `json:"check_command"`
24 DisplayName string `json:"display_name,omitempty"`
25 LastCheck time.Time `json:",omitempty"`
26 LastCheckResult CheckResult `json:"last_check_result,omitempty"`
27 Acknowledgement bool `json:",omitempty"`
28 Notes string `json:"notes,omitempty"`
29 NotesURL string `json:"notes_url,omitempty"`
32 type CheckResult struct {
33 CheckSource string `json:"check_source"`
41 ServiceOK ServiceState = 0 + iota
47 func (state ServiceState) String() string {
59 // UnmarshalJSON unmarshals service attributes into more meaningful Service field types.
60 func (s *Service) UnmarshalJSON(data []byte) error {
63 Acknowledgement interface{} `json:"acknowledgement"`
64 State interface{} `json:"state"`
65 StateType interface{} `json:"state_type"`
66 LastCheck float64 `json:"last_check"`
71 if err := json.Unmarshal(data, &aux); err != nil {
74 switch v := aux.Acknowledgement.(type) {
77 s.Acknowledgement = true
81 s.Acknowledgement = true
84 switch v := aux.State.(type) {
86 s.State = ServiceState(v)
88 s.State = ServiceState(v)
90 switch v := aux.StateType.(type) {
92 s.StateType = StateType(v)
94 s.StateType = StateType(v)
96 s.LastCheck = time.Unix(int64(aux.LastCheck), 0)
100 func (s Service) Host() string {
101 return strings.SplitN(s.Name, "!", 2)[0]
104 func (cr CheckResult) RawCommand() string {
105 switch v := cr.Command.(type) {
111 if arg, ok := v[i].(string); ok {
112 cmd = append(cmd, arg)
115 return strings.Join(cmd, " ")