8 func (s Service) name() string {
12 func (s Service) path() string {
13 return "/objects/services/" + s.Name
16 func (s Service) attrs() map[string]interface{} {
17 m := make(map[string]interface{})
18 m["display_name"] = s.DisplayName
22 // Service represents a Service object.
24 Name string `json:"__name"`
27 CheckCommand string `json:"check_command"`
28 DisplayName string `json:"display_name:"`
34 ServiceOK ServiceState = 0 + iota
40 func (s ServiceState) String() string {
45 return "ServiceWarning"
47 return "ServiceCritical"
49 return "ServiceUnknown"
51 return "unhandled service state"
54 func (s Service) MarshalJSON() ([]byte, error) {
55 attrs := make(map[string]interface{})
56 if len(s.Groups) > 0 {
57 attrs["groups"] = s.Groups
59 attrs["check_command"] = s.CheckCommand
60 attrs["display_name"] = s.DisplayName
62 Attrs map[string]interface{} `json:"attrs"`
64 return json.Marshal(jservice)
67 func (c *Client) CreateService(service Service) error {
68 if err := c.createObject(service); err != nil {
69 return fmt.Errorf("create service %s: %w", service.Name, err)
74 func (c *Client) LookupService(name string) (Service, error) {
75 obj, err := c.lookupObject("/objects/services/" + name)
77 return Service{}, fmt.Errorf("lookup %s: %w", name, err)
79 v, ok := obj.(Service)
81 return Service{}, fmt.Errorf("lookup %s: result type %T is not service", name, obj)