go-healthchecks/cmd/returncode.go

37 lines
771 B
Go
Raw Normal View History

2024-10-02 14:00:40 +00:00
package main
import (
"fmt"
"os"
"strconv"
gohealthchecks "git.faercol.me/faercol/go-healthchecks"
"github.com/spf13/cobra"
)
var returncodeCmd = &cobra.Command{
Use: "returncode <message>",
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)
}