go-healthchecks/cmd/log.go

33 lines
621 B
Go
Raw Normal View History

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 logCmd = &cobra.Command{
Use: "log <message>",
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)
}