Skip to content

Commit 508cc33

Browse files
committed
Add option to set CLI flags via env variables
1 parent 65e3e86 commit 508cc33

File tree

3 files changed

+22
-18
lines changed

3 files changed

+22
-18
lines changed

README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,24 @@ Available Commands:
1414
pipeline Checks the status of the Logstash Pipelines
1515

1616
Flags:
17-
-H, --hostname string Hostname of the Logstash server (default "localhost")
17+
-H, --hostname string Hostname of the Logstash server (CHECK_LOGSTASH_HOSTNAME) (default "localhost")
1818
-p, --port int Port of the Logstash server (default 9600)
1919
-s, --secure Use a HTTPS connection
2020
-i, --insecure Skip the verification of the server's TLS certificate
21-
-b, --bearer string Specify the Bearer Token for server authentication
22-
-u, --user string Specify the user name and password for server authentication <user:password>
23-
--ca-file string Specify the CA File for TLS authentication
24-
--cert-file string Specify the Certificate File for TLS authentication
25-
--key-file string Specify the Key File for TLS authentication
21+
-b, --bearer string Specify the Bearer Token for server authentication (CHECK_LOGSTASH_BEARER)
22+
-u, --user string Specify the user name and password for server authentication <user:password> (CHECK_LOGSTASH_BASICAUTH)
23+
--ca-file string Specify the CA File for TLS authentication (CHECK_LOGSTASH_CA_FILE)
24+
--cert-file string Specify the Certificate File for TLS authentication (CHECK_LOGSTASH_CERT_FILE)
25+
--key-file string Specify the Key File for TLS authentication (CHECK_LOGSTASH_KEY_FILE)
2626
-t, --timeout int Timeout in seconds for the CheckPlugin (default 30)
2727
-h, --help help for check_logstash
2828
-v, --version version for check_logstash
2929
```
3030
3131
The check plugin respects the environment variables `HTTP_PROXY`, `HTTPS_PROXY` and `NO_PROXY`.
3232
33+
Various flags can be set with environment variables, refer to the help to see which flags.
34+
3335
### Health
3436
3537
Checks the health status of the Logstash server.

cmd/config.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ import (
1515
)
1616

1717
type Config struct {
18-
BasicAuth string
19-
Bearer string
20-
CAFile string
21-
CertFile string
22-
KeyFile string
23-
Hostname string
18+
BasicAuth string `env:"CHECK_LOGSTASH_BASICAUTH"`
19+
Bearer string `env:"CHECK_LOGSTASH_BEARER"`
20+
CAFile string `env:"CHECK_LOGSTASH_CA_FILE"`
21+
CertFile string `env:"CHECK_LOGSTASH_CERT_FILE"`
22+
KeyFile string `env:"CHECK_LOGSTASH_KEY_FILE"`
23+
Hostname string `env:"CHECK_LOGSTASH_HOSTNAME"`
2424
Port int
2525
Info bool
2626
Insecure bool

cmd/root.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,23 +40,23 @@ func init() {
4040

4141
pfs := rootCmd.PersistentFlags()
4242
pfs.StringVarP(&cliConfig.Hostname, "hostname", "H", "localhost",
43-
"Hostname of the Logstash server")
43+
"Hostname of the Logstash server (CHECK_LOGSTASH_HOSTNAME)")
4444
pfs.IntVarP(&cliConfig.Port, "port", "p", 9600,
4545
"Port of the Logstash server")
4646
pfs.BoolVarP(&cliConfig.Secure, "secure", "s", false,
4747
"Use a HTTPS connection")
4848
pfs.BoolVarP(&cliConfig.Insecure, "insecure", "i", false,
4949
"Skip the verification of the server's TLS certificate")
5050
pfs.StringVarP(&cliConfig.Bearer, "bearer", "b", "",
51-
"Specify the Bearer Token for server authentication")
51+
"Specify the Bearer Token for server authentication (CHECK_LOGSTASH_BEARER)")
5252
pfs.StringVarP(&cliConfig.BasicAuth, "user", "u", "",
53-
"Specify the user name and password for server authentication <user:password>")
53+
"Specify the user name and password for server authentication <user:password> (CHECK_LOGSTASH_BASICAUTH)")
5454
pfs.StringVarP(&cliConfig.CAFile, "ca-file", "", "",
55-
"Specify the CA File for TLS authentication")
55+
"Specify the CA File for TLS authentication (CHECK_LOGSTASH_CA_FILE)")
5656
pfs.StringVarP(&cliConfig.CertFile, "cert-file", "", "",
57-
"Specify the Certificate File for TLS authentication")
57+
"Specify the Certificate File for TLS authentication (CHECK_LOGSTASH_CERT_FILE)")
5858
pfs.StringVarP(&cliConfig.KeyFile, "key-file", "", "",
59-
"Specify the Key File for TLS authentication")
59+
"Specify the Key File for TLS authentication (CHECK_LOGSTASH_KEY_FILE)")
6060
pfs.IntVarP(&Timeout, "timeout", "t", Timeout,
6161
"Timeout in seconds for the CheckPlugin")
6262

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

6666
help := rootCmd.HelpTemplate()
6767
rootCmd.SetHelpTemplate(help + Copyright)
68+
69+
check.LoadFromEnv(&cliConfig)
6870
}
6971

7072
func Usage(cmd *cobra.Command, _ []string) {

0 commit comments

Comments
 (0)