-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathroot.go
76 lines (61 loc) · 2.13 KB
/
root.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package cmd
import (
"os"
"github.com/NETWAYS/go-check"
"github.com/spf13/cobra"
)
var Timeout = 30
var rootCmd = &cobra.Command{
Use: "check_logstash",
Short: "An Icinga check plugin to check Logstash",
PersistentPreRun: func(_ *cobra.Command, _ []string) {
go check.HandleTimeout(Timeout)
},
Run: Usage,
}
func Execute(version string) {
defer check.CatchPanic()
rootCmd.Version = version
rootCmd.VersionTemplate()
if err := rootCmd.Execute(); err != nil {
check.ExitError(err)
}
}
func init() {
rootCmd.CompletionOptions.DisableDefaultCmd = true
rootCmd.DisableAutoGenTag = true
rootCmd.SetHelpCommand(&cobra.Command{
Use: "no-help",
Hidden: true,
})
pfs := rootCmd.PersistentFlags()
pfs.StringVarP(&cliConfig.Hostname, "hostname", "H", "localhost",
"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 (CHECK_LOGSTASH_BEARER)")
pfs.StringVarP(&cliConfig.BasicAuth, "user", "u", "",
"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 (CHECK_LOGSTASH_CA_FILE)")
pfs.StringVarP(&cliConfig.CertFile, "cert-file", "", "",
"Specify the Certificate File for TLS authentication (CHECK_LOGSTASH_CERT_FILE)")
pfs.StringVarP(&cliConfig.KeyFile, "key-file", "", "",
"Specify the Key File for TLS authentication (CHECK_LOGSTASH_KEY_FILE)")
pfs.IntVarP(&Timeout, "timeout", "t", Timeout,
"Timeout in seconds for the CheckPlugin")
rootCmd.Flags().SortFlags = false
pfs.SortFlags = false
help := rootCmd.HelpTemplate()
rootCmd.SetHelpTemplate(help + Copyright)
check.LoadFromEnv(&cliConfig)
}
func Usage(cmd *cobra.Command, _ []string) {
_ = cmd.Usage()
os.Exit(3)
}