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 option to set CLI flags via env variables #92

Merged
merged 2 commits into from
Oct 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,24 @@ 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 <user:password>
--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 <user:password> (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
```

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.
Expand Down
12 changes: 6 additions & 6 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 8 additions & 6 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,23 @@ 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,
"Use a HTTPS connection")
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 <user:password>")
"Specify the user name and password for server authentication <user:password> (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")

Expand All @@ -65,6 +65,8 @@ func init() {

help := rootCmd.HelpTemplate()
rootCmd.SetHelpTemplate(help + Copyright)

check.LoadFromEnv(&cliConfig)
}

func Usage(cmd *cobra.Command, _ []string) {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
Expand Down