Add cloudflared tunnel health command
This commit is contained in:
parent
00cd7c333c
commit
f10247db90
|
@ -128,6 +128,7 @@ func Commands() []*cli.Command {
|
||||||
buildVirtualNetworkSubcommand(false),
|
buildVirtualNetworkSubcommand(false),
|
||||||
buildRunCommand(),
|
buildRunCommand(),
|
||||||
buildListCommand(),
|
buildListCommand(),
|
||||||
|
buildHealthCommand(),
|
||||||
buildInfoCommand(),
|
buildInfoCommand(),
|
||||||
buildIngressSubcommand(),
|
buildIngressSubcommand(),
|
||||||
buildDeleteCommand(),
|
buildDeleteCommand(),
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
@ -397,6 +398,31 @@ func fmtConnections(connections []cfapi.Connection, showRecentlyDisconnected boo
|
||||||
return strings.Join(output, ", ")
|
return strings.Join(output, ", ")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func buildHealthCommand() *cli.Command {
|
||||||
|
return &cli.Command{
|
||||||
|
Name: "health",
|
||||||
|
Action: cliutil.ConfiguredAction(healthCommand),
|
||||||
|
Usage: "Tunnel health exit code",
|
||||||
|
UsageText: "cloudflared tunnel [tunnel command options] health [subcommand options]",
|
||||||
|
Description: "cloudflared tunnel health will return proper exit code if tunnel is healthy or unhealthy",
|
||||||
|
Flags: []cli.Flag{},
|
||||||
|
CustomHelpTemplate: commandHelpTemplate(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func healthCommand(c *cli.Context) error {
|
||||||
|
metrics := strings.Split(c.String("metrics"), ":")
|
||||||
|
requestURL := fmt.Sprintf("http://%s:%s/ready", metrics[0], metrics[1])
|
||||||
|
res, err := http.Get(requestURL)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if res.StatusCode != 200 {
|
||||||
|
return fmt.Errorf("health /ready endpoint returned status code %d", res.StatusCode)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func buildInfoCommand() *cli.Command {
|
func buildInfoCommand() *cli.Command {
|
||||||
return &cli.Command{
|
return &cli.Command{
|
||||||
Name: "info",
|
Name: "info",
|
||||||
|
|
Loading…
Reference in New Issue