11 type checker interface {
19 StateSoft StateType = 0 + iota
23 func (st StateType) String() string {
30 return "unsupported state type"
33 func (s Service) Check(c *Client) error {
37 func (h Host) Check(c *Client) error {
41 func splitServiceName(name string) []string {
42 return strings.SplitN(name, "!", 2)
45 func (c *Client) check(ch checker) error {
47 Type string `json:"type"`
48 Expr string `json:"filter"`
50 switch v := ch.(type) {
53 filter.Expr = fmt.Sprintf("host.name == %q", v.Name)
55 filter.Type = "Service"
56 a := splitServiceName(v.Name)
58 return fmt.Errorf("check %s: invalid service name", v.Name)
62 filter.Expr = fmt.Sprintf("host.name == %q && service.name == %q", host, service)
64 return fmt.Errorf("cannot check %T", v)
67 buf := &bytes.Buffer{}
68 if err := json.NewEncoder(buf).Encode(filter); err != nil {
71 resp, err := c.post("/actions/reschedule-check", buf)
73 return fmt.Errorf("check %s: %w", ch.name(), err)
75 switch resp.StatusCode {
78 case http.StatusNotFound:
79 return fmt.Errorf("check %s: %w", ch.name(), ErrNotExist)
81 return fmt.Errorf("check %s: %s", ch.name(), resp.Status)