From 193e4d3884e99d1eeb2f3d71c4fd7e8be8e20a13 Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Thu, 6 Jul 2017 14:00:11 +0200 Subject: [PATCH] Support shortening hostnames to first part Signed-off-by: Knut Ahlers --- main.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/main.go b/main.go index 33ae15b..4112e4a 100644 --- a/main.go +++ b/main.go @@ -4,6 +4,7 @@ import ( "fmt" "io/ioutil" "os" + "strings" "time" "github.com/Luzifer/rconfig" @@ -16,6 +17,8 @@ var ( cfg = struct { LogLevel string `flag:"log-level" default:"info" description:"Log level (debug, info, warning, error)"` + UseFullHostname bool `flag:"full-hostname" default:"true" description:"Use the full reported hostname (true) or only the first part (false)"` + VaultAddress string `flag:"vault-addr" env:"VAULT_ADDR" default:"https://127.0.0.1:8200" description:"Vault API address"` VaultRoleID string `flag:"vault-role-id" env:"VAULT_ROLE_ID" default:"" description:"ID of the role to use"` @@ -52,6 +55,10 @@ func init() { if hostname, err = os.Hostname(); err != nil { log.Fatalf("Could not resolve hostname: %s", err) } + + if parts := strings.Split(hostname, "."); !cfg.UseFullHostname && len(parts) > 1 { + hostname = parts[0] + } } func main() {