go-healthchecks/cmd/log.go

32 lines
621 B
Go

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)
}