2024-10-02 14:00:40 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
gohealthchecks "git.faercol.me/faercol/go-healthchecks"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
var failureCmd = &cobra.Command{
|
|
|
|
Use: "failure",
|
|
|
|
Short: "Signal the check has failed",
|
|
|
|
Long: ``,
|
2024-10-03 13:26:03 +00:00
|
|
|
Args: cobra.MaximumNArgs(1),
|
2024-10-02 14:00:40 +00:00
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
|
|
check := parseCheckFlags()
|
2024-10-03 13:26:03 +00:00
|
|
|
|
|
|
|
msg := ""
|
|
|
|
if len(args) > 0 {
|
|
|
|
msg = args[0]
|
|
|
|
}
|
|
|
|
|
2024-10-02 14:00:40 +00:00
|
|
|
clt := gohealthchecks.NewPingClient(pingHost)
|
2024-10-03 13:26:03 +00:00
|
|
|
err := clt.ReportFailure(cmd.Context(), check, msg)
|
2024-10-02 14:00:40 +00:00
|
|
|
if err != nil {
|
|
|
|
failf("Failed to notify failure: %s\n", err)
|
|
|
|
} else {
|
|
|
|
fmt.Println("Notified check failure")
|
|
|
|
os.Exit(0)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
rootCmd.AddCommand(failureCmd)
|
|
|
|
}
|