diff --git a/cmd/failure.go b/cmd/failure.go index a1bdf69..a5edc36 100644 --- a/cmd/failure.go +++ b/cmd/failure.go @@ -12,10 +12,17 @@ var failureCmd = &cobra.Command{ Use: "failure", Short: "Signal the check has failed", Long: ``, + Args: cobra.MaximumNArgs(1), Run: func(cmd *cobra.Command, args []string) { check := parseCheckFlags() + + msg := "" + if len(args) > 0 { + msg = args[0] + } + clt := gohealthchecks.NewPingClient(pingHost) - err := clt.ReportFailure(cmd.Context(), check) + err := clt.ReportFailure(cmd.Context(), check, msg) if err != nil { failf("Failed to notify failure: %s\n", err) } else { diff --git a/pingclient.go b/pingclient.go index 13354f4..17395c3 100644 --- a/pingclient.go +++ b/pingclient.go @@ -44,7 +44,7 @@ func addQueryParams(reqURL *url.URL, check Check) { type PingClient interface { ReportSuccess(ctx context.Context, check Check) error ReportStart(ctx context.Context, check Check) error - ReportFailure(ctx context.Context, check Check) error + ReportFailure(ctx context.Context, check Check, msg string) error LogMessage(ctx context.Context, check Check, log []byte) error ReportExitCode(ctx context.Context, check Check, exitCode int) error } @@ -91,13 +91,18 @@ func (c *pingClient) ReportStart(ctx context.Context, check Check) error { } return handleResponse(resp) } -func (c *pingClient) ReportFailure(ctx context.Context, check Check) error { +func (c *pingClient) ReportFailure(ctx context.Context, check Check, msg string) error { url, err := url.JoinPath(c.host, check.path(), "fail") if err != nil { return fmt.Errorf("invalid check or hostname provided: %w", err) } - req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, nil) + var body io.Reader + if msg != "" { + body = bytes.NewBufferString(msg + "\n") + } + + req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, body) if err != nil { return fmt.Errorf("failed to build ping request: %w", err) }