5 func (s Service) name() string {
9 func (s Service) path() string {
10 return "/objects/services/" + s.Name
13 // Service represents a Service object.
15 Name string `json:"-"`
16 Groups []string `json:"groups,omitempty"`
18 StateType StateType `json:"state_type"`
19 CheckCommand string `json:"check_command"`
20 DisplayName string `json:"display_name,omitempty"`
21 LastCheckResult CheckResult `json:"last_check_result,omitempty"`
22 Acknowledgement bool `json:",omitempty"`
25 type CheckResult struct {
32 ServiceOK ServiceState = 0 + iota
38 func (s ServiceState) String() string {
43 return "ServiceWarning"
45 return "ServiceCritical"
47 return "ServiceUnknown"
49 return "unhandled service state"
52 func (s Service) MarshalJSON() ([]byte, error) {
53 attrs := make(map[string]interface{})
54 if len(s.Groups) > 0 {
55 attrs["groups"] = s.Groups
57 attrs["check_command"] = s.CheckCommand
58 attrs["display_name"] = s.DisplayName
60 Attrs map[string]interface{} `json:"attrs"`
62 return json.Marshal(jservice)
65 // UnmarshalJSON unmarshals service attributes into more meaningful Service field types.
66 func (s *Service) UnmarshalJSON(data []byte) error {
74 if err := json.Unmarshal(data, &aux); err != nil {
77 if aux.Acknowledgement != 0 {
78 s.Acknowledgement = true