diff --git a/cmd/failure.go b/cmd/failure.go new file mode 100644 index 0000000..a1bdf69 --- /dev/null +++ b/cmd/failure.go @@ -0,0 +1,30 @@ +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: ``, + Run: func(cmd *cobra.Command, args []string) { + check := parseCheckFlags() + clt := gohealthchecks.NewPingClient(pingHost) + err := clt.ReportFailure(cmd.Context(), check) + 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) +} diff --git a/cmd/log.go b/cmd/log.go new file mode 100644 index 0000000..fbfad29 --- /dev/null +++ b/cmd/log.go @@ -0,0 +1,32 @@ +package main + +import ( + "fmt" + "os" + + gohealthchecks "git.faercol.me/faercol/go-healthchecks" + "github.com/spf13/cobra" +) + +var logCmd = &cobra.Command{ + Use: "log ", + Short: "Send a log for the check", + Long: ``, + Args: cobra.ExactArgs(1), + Run: func(cmd *cobra.Command, args []string) { + check := parseCheckFlags() + msg := []byte(args[0]) + clt := gohealthchecks.NewPingClient(pingHost) + err := clt.LogMessage(cmd.Context(), check, msg) + if err != nil { + failf("Failed to send log: %s\n", err) + } else { + fmt.Println("Log sent") + os.Exit(0) + } + }, +} + +func init() { + rootCmd.AddCommand(logCmd) +} diff --git a/cmd/returncode.go b/cmd/returncode.go new file mode 100644 index 0000000..f4d7321 --- /dev/null +++ b/cmd/returncode.go @@ -0,0 +1,36 @@ +package main + +import ( + "fmt" + "os" + "strconv" + + gohealthchecks "git.faercol.me/faercol/go-healthchecks" + "github.com/spf13/cobra" +) + +var returncodeCmd = &cobra.Command{ + Use: "returncode ", + Short: "Notify specific returncode for the check", + Long: ``, + Args: cobra.ExactArgs(1), + Run: func(cmd *cobra.Command, args []string) { + check := parseCheckFlags() + returncode, err := strconv.Atoi(args[0]) + if err != nil { + failf("Invalid value for returncode: %s\n", err) + } + clt := gohealthchecks.NewPingClient(pingHost) + err = clt.ReportExitCode(cmd.Context(), check, returncode) + if err != nil { + failf("Failed to send log: %s\n", err) + } else { + fmt.Println("Log sent") + os.Exit(0) + } + }, +} + +func init() { + rootCmd.AddCommand(returncodeCmd) +}