3 26fb88e9 2022-01-12 o import "encoding/json"
5 76669f9b 2022-01-11 o func (s Service) name() string {
9 76669f9b 2022-01-11 o func (s Service) path() string {
10 76669f9b 2022-01-11 o return "/objects/services/" + s.Name
13 76669f9b 2022-01-11 o // Service represents a Service object.
14 76669f9b 2022-01-11 o type Service struct {
15 76669f9b 2022-01-11 o Name string `json:"__name"`
16 76669f9b 2022-01-11 o Groups []string
17 76669f9b 2022-01-11 o State ServiceState
18 76669f9b 2022-01-11 o CheckCommand string `json:"check_command"`
19 76669f9b 2022-01-11 o DisplayName string `json:"display_name:"`
22 76669f9b 2022-01-11 o type ServiceState int
25 76669f9b 2022-01-11 o ServiceOK ServiceState = 0 + iota
27 76669f9b 2022-01-11 o ServiceCritical
31 76669f9b 2022-01-11 o func (s ServiceState) String() string {
33 76669f9b 2022-01-11 o case ServiceOK:
34 76669f9b 2022-01-11 o return "ServiceOK"
35 76669f9b 2022-01-11 o case ServiceWarning:
36 76669f9b 2022-01-11 o return "ServiceWarning"
37 76669f9b 2022-01-11 o case ServiceCritical:
38 76669f9b 2022-01-11 o return "ServiceCritical"
39 76669f9b 2022-01-11 o case ServiceUnknown:
40 76669f9b 2022-01-11 o return "ServiceUnknown"
42 76669f9b 2022-01-11 o return "unhandled service state"
45 76669f9b 2022-01-11 o func (s Service) MarshalJSON() ([]byte, error) {
46 76669f9b 2022-01-11 o attrs := make(map[string]interface{})
47 76669f9b 2022-01-11 o if len(s.Groups) > 0 {
48 76669f9b 2022-01-11 o attrs["groups"] = s.Groups
50 76669f9b 2022-01-11 o attrs["check_command"] = s.CheckCommand
51 76669f9b 2022-01-11 o attrs["display_name"] = s.DisplayName
52 76669f9b 2022-01-11 o jservice := &struct {
53 76669f9b 2022-01-11 o Attrs map[string]interface{} `json:"attrs"`
54 76669f9b 2022-01-11 o }{Attrs: attrs}
55 76669f9b 2022-01-11 o return json.Marshal(jservice)