From 65e3e86f49997138da84254fa42c4f8b57a3760b Mon Sep 17 00:00:00 2001 From: Markus Opolka Date: Fri, 27 Oct 2023 10:21:56 +0200 Subject: [PATCH 1/2] Bump go-check to v0.6.0 --- go.mod | 2 +- go.sum | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 99c4d76..3939170 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/NETWAYS/check_logstash go 1.21 require ( - github.com/NETWAYS/go-check v0.5.0 + github.com/NETWAYS/go-check v0.6.0 github.com/NETWAYS/go-check-network/http v0.0.0-20230928080609-57070f836e41 github.com/spf13/cobra v1.7.0 ) diff --git a/go.sum b/go.sum index 0c4ef63..d1f612d 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,7 @@ github.com/NETWAYS/go-check v0.5.0 h1:YahXTyveSOww3mTtKnvbsXZSk9kHi82mnvXHsNWx7AQ= github.com/NETWAYS/go-check v0.5.0/go.mod h1:3G1p9ZCv41UcKirl+nZWne8oKVPUY5HbtyjRwGgyw6A= +github.com/NETWAYS/go-check v0.6.0 h1:/fbQ3oVii4tei6vF/nuJQ2JUerT2rHNr3XQMUFdGg3A= +github.com/NETWAYS/go-check v0.6.0/go.mod h1:3G1p9ZCv41UcKirl+nZWne8oKVPUY5HbtyjRwGgyw6A= github.com/NETWAYS/go-check-network/http v0.0.0-20230928080609-57070f836e41 h1:5PdguRs5fRgYvok56yQDXJssKXY91vNq6Tmhb4dFH/I= github.com/NETWAYS/go-check-network/http v0.0.0-20230928080609-57070f836e41/go.mod h1:jZ62Y7P8/T/TqNy6I7RI/G9G9tXEcpuqrlkkO+xgCRE= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= From 508cc336b7468084c489aa05967bd43250006744 Mon Sep 17 00:00:00 2001 From: Markus Opolka Date: Fri, 27 Oct 2023 10:26:52 +0200 Subject: [PATCH 2/2] Add option to set CLI flags via env variables --- README.md | 14 ++++++++------ cmd/config.go | 12 ++++++------ cmd/root.go | 14 ++++++++------ 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 5e36e44..1bd5a5a 100644 --- a/README.md +++ b/README.md @@ -14,15 +14,15 @@ Available Commands: pipeline Checks the status of the Logstash Pipelines Flags: - -H, --hostname string Hostname of the Logstash server (default "localhost") + -H, --hostname string Hostname of the Logstash server (CHECK_LOGSTASH_HOSTNAME) (default "localhost") -p, --port int Port of the Logstash server (default 9600) -s, --secure Use a HTTPS connection -i, --insecure Skip the verification of the server's TLS certificate - -b, --bearer string Specify the Bearer Token for server authentication - -u, --user string Specify the user name and password for server authentication - --ca-file string Specify the CA File for TLS authentication - --cert-file string Specify the Certificate File for TLS authentication - --key-file string Specify the Key File for TLS authentication + -b, --bearer string Specify the Bearer Token for server authentication (CHECK_LOGSTASH_BEARER) + -u, --user string Specify the user name and password for server authentication (CHECK_LOGSTASH_BASICAUTH) + --ca-file string Specify the CA File for TLS authentication (CHECK_LOGSTASH_CA_FILE) + --cert-file string Specify the Certificate File for TLS authentication (CHECK_LOGSTASH_CERT_FILE) + --key-file string Specify the Key File for TLS authentication (CHECK_LOGSTASH_KEY_FILE) -t, --timeout int Timeout in seconds for the CheckPlugin (default 30) -h, --help help for check_logstash -v, --version version for check_logstash @@ -30,6 +30,8 @@ Flags: The check plugin respects the environment variables `HTTP_PROXY`, `HTTPS_PROXY` and `NO_PROXY`. +Various flags can be set with environment variables, refer to the help to see which flags. + ### Health Checks the health status of the Logstash server. diff --git a/cmd/config.go b/cmd/config.go index 50cc763..756f56b 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -15,12 +15,12 @@ import ( ) type Config struct { - BasicAuth string - Bearer string - CAFile string - CertFile string - KeyFile string - Hostname string + BasicAuth string `env:"CHECK_LOGSTASH_BASICAUTH"` + Bearer string `env:"CHECK_LOGSTASH_BEARER"` + CAFile string `env:"CHECK_LOGSTASH_CA_FILE"` + CertFile string `env:"CHECK_LOGSTASH_CERT_FILE"` + KeyFile string `env:"CHECK_LOGSTASH_KEY_FILE"` + Hostname string `env:"CHECK_LOGSTASH_HOSTNAME"` Port int Info bool Insecure bool diff --git a/cmd/root.go b/cmd/root.go index b8fdb0d..4154171 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -40,7 +40,7 @@ func init() { pfs := rootCmd.PersistentFlags() pfs.StringVarP(&cliConfig.Hostname, "hostname", "H", "localhost", - "Hostname of the Logstash server") + "Hostname of the Logstash server (CHECK_LOGSTASH_HOSTNAME)") pfs.IntVarP(&cliConfig.Port, "port", "p", 9600, "Port of the Logstash server") pfs.BoolVarP(&cliConfig.Secure, "secure", "s", false, @@ -48,15 +48,15 @@ func init() { pfs.BoolVarP(&cliConfig.Insecure, "insecure", "i", false, "Skip the verification of the server's TLS certificate") pfs.StringVarP(&cliConfig.Bearer, "bearer", "b", "", - "Specify the Bearer Token for server authentication") + "Specify the Bearer Token for server authentication (CHECK_LOGSTASH_BEARER)") pfs.StringVarP(&cliConfig.BasicAuth, "user", "u", "", - "Specify the user name and password for server authentication ") + "Specify the user name and password for server authentication (CHECK_LOGSTASH_BASICAUTH)") pfs.StringVarP(&cliConfig.CAFile, "ca-file", "", "", - "Specify the CA File for TLS authentication") + "Specify the CA File for TLS authentication (CHECK_LOGSTASH_CA_FILE)") pfs.StringVarP(&cliConfig.CertFile, "cert-file", "", "", - "Specify the Certificate File for TLS authentication") + "Specify the Certificate File for TLS authentication (CHECK_LOGSTASH_CERT_FILE)") pfs.StringVarP(&cliConfig.KeyFile, "key-file", "", "", - "Specify the Key File for TLS authentication") + "Specify the Key File for TLS authentication (CHECK_LOGSTASH_KEY_FILE)") pfs.IntVarP(&Timeout, "timeout", "t", Timeout, "Timeout in seconds for the CheckPlugin") @@ -65,6 +65,8 @@ func init() { help := rootCmd.HelpTemplate() rootCmd.SetHelpTemplate(help + Copyright) + + check.LoadFromEnv(&cliConfig) } func Usage(cmd *cobra.Command, _ []string) {