11 type checker interface {
19 StateSoft StateType = 0 + iota
23 func (st StateType) String() string {
30 return "unsupported state type"
33 // Check reschedules the check for s via the provided Client.
34 func (s Service) Check(c *Client) error {
38 // Check reschedules the check for h via the provided Client.
39 func (h Host) Check(c *Client) error {
43 func splitServiceName(name string) []string {
44 return strings.SplitN(name, "!", 2)
47 func (c *Client) check(ch checker) error {
49 Type string `json:"type"`
50 Expr string `json:"filter"`
52 switch v := ch.(type) {
55 filter.Expr = fmt.Sprintf("host.name == %q", v.Name)
57 filter.Type = "Service"
58 a := splitServiceName(v.Name)
60 return fmt.Errorf("check %s: invalid service name", v.Name)
64 filter.Expr = fmt.Sprintf("host.name == %q && service.name == %q", host, service)
66 return fmt.Errorf("cannot check %T", v)
69 buf := &bytes.Buffer{}
70 if err := json.NewEncoder(buf).Encode(filter); err != nil {
73 resp, err := c.post("/actions/reschedule-check", buf)
75 return fmt.Errorf("check %s: %w", ch.name(), err)
77 switch resp.StatusCode {
80 case http.StatusNotFound:
81 return fmt.Errorf("check %s: %w", ch.name(), ErrNotExist)
83 return fmt.Errorf("check %s: %s", ch.name(), resp.Status)