Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cloudflared tunnel ready command #1135

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/cloudflared/tunnel/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ func Commands() []*cli.Command {
buildVirtualNetworkSubcommand(false),
buildRunCommand(),
buildListCommand(),
buildHealthCommand(),
buildInfoCommand(),
buildIngressSubcommand(),
buildDeleteCommand(),
Expand Down
26 changes: 26 additions & 0 deletions cmd/cloudflared/tunnel/subcommands.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
"net/http"
"os"
"path/filepath"
"regexp"
Expand Down Expand Up @@ -397,6 +398,31 @@ func fmtConnections(connections []cfapi.Connection, showRecentlyDisconnected boo
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])
firecow marked this conversation as resolved.
Show resolved Hide resolved
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 {
return &cli.Command{
Name: "info",
Expand Down