Merge pull request #1135 from firecow/tunnel-health
Add cloudflared tunnel ready command
This commit is contained in:
commit
3480a33fce
|
@ -139,6 +139,7 @@ func Commands() []*cli.Command {
|
||||||
buildVirtualNetworkSubcommand(false),
|
buildVirtualNetworkSubcommand(false),
|
||||||
buildRunCommand(),
|
buildRunCommand(),
|
||||||
buildListCommand(),
|
buildListCommand(),
|
||||||
|
buildReadyCommand(),
|
||||||
buildInfoCommand(),
|
buildInfoCommand(),
|
||||||
buildIngressSubcommand(),
|
buildIngressSubcommand(),
|
||||||
buildDeleteCommand(),
|
buildDeleteCommand(),
|
||||||
|
|
|
@ -5,6 +5,8 @@ import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
@ -397,6 +399,39 @@ func fmtConnections(connections []cfapi.Connection, showRecentlyDisconnected boo
|
||||||
return strings.Join(output, ", ")
|
return strings.Join(output, ", ")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func buildReadyCommand() *cli.Command {
|
||||||
|
return &cli.Command{
|
||||||
|
Name: "ready",
|
||||||
|
Action: cliutil.ConfiguredAction(readyCommand),
|
||||||
|
Usage: "Call /ready endpoint and return proper exit code",
|
||||||
|
UsageText: "cloudflared tunnel [tunnel command options] ready [subcommand options]",
|
||||||
|
Description: "cloudflared tunnel ready will return proper exit code based on the /ready endpoint",
|
||||||
|
Flags: []cli.Flag{},
|
||||||
|
CustomHelpTemplate: commandHelpTemplate(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func readyCommand(c *cli.Context) error {
|
||||||
|
metricsOpts := c.String("metrics")
|
||||||
|
if !c.IsSet("metrics") {
|
||||||
|
return fmt.Errorf("--metrics has to be provided")
|
||||||
|
}
|
||||||
|
|
||||||
|
requestURL := fmt.Sprintf("http://%s/ready", metricsOpts)
|
||||||
|
res, err := http.Get(requestURL)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if res.StatusCode != 200 {
|
||||||
|
body, err := io.ReadAll(res.Body)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return fmt.Errorf("http://%s/ready endpoint returned status code %d\n%s", metricsOpts, res.StatusCode, body)
|
||||||
|
}
|
||||||
|
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