diff --git a/cmd/root.go b/cmd/root.go index 6e7d167..cadecf1 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -121,8 +121,8 @@ func init() { rootCmd.Flags().StringVar(&config.SendAPIAuthFile, "send-api-auth-file", config.SendAPIAuthFile, "A password file for Send API authentication") rootCmd.Flags().BoolVar(&config.SendAPIAuthAcceptAny, "send-api-auth-accept-any", config.SendAPIAuthAcceptAny, "Accept any username and password for the Send API endpoint, including none") - // Prometheus Metrics - rootCmd.Flags().StringVar(&config.PrometheusListen, "enable-prometheus", config.PrometheusListen, "Enable Prometheus metrics: false=disabled, 'true'=use web port, address=separate server (':9090')") + // Prometheus metrics + rootCmd.Flags().StringVar(&config.PrometheusListen, "enable-prometheus", config.PrometheusListen, "Enable Prometheus metrics: true|false| (eg:':9090')") // SMTP server rootCmd.Flags().StringVarP(&config.SMTPListen, "smtp", "s", config.SMTPListen, "SMTP bind interface and port") diff --git a/config/config.go b/config/config.go index a11f69c..8a6b770 100644 --- a/config/config.go +++ b/config/config.go @@ -192,7 +192,7 @@ var ( AllowUntrustedTLS bool // PrometheusListen address for Prometheus metrics server - // Empty = disabled, "true"= use existing web server, address = separate server + // Empty = disabled, true= use existing web server, address = separate server PrometheusListen string // Version is the default application version, updated on release @@ -362,6 +362,20 @@ func VerifyConfig() error { logger.Log().Info("[send-api] disabling authentication") } + // Prometheus configuration validation + if PrometheusListen != "" { + mode := strings.ToLower(strings.TrimSpace(PrometheusListen)) + if mode != "true" && mode != "false" { + // Validate as address for separate server mode + _, err := net.ResolveTCPAddr("tcp", PrometheusListen) + if err != nil { + return fmt.Errorf("[prometheus] %s", err.Error()) + } + } else if mode == "true" { + logger.Log().Info("[prometheus] enabling metrics") + } + } + // SMTP server if SMTPTLSCert != "" && SMTPTLSKey == "" || SMTPTLSCert == "" && SMTPTLSKey != "" { return errors.New("[smtp] you must provide both an SMTP TLS certificate and a key") @@ -571,17 +585,5 @@ func VerifyConfig() error { logger.Log().Info("demo mode enabled") } - // Prometheus configuration validation - if PrometheusListen != "" { - mode := strings.ToLower(strings.TrimSpace(PrometheusListen)) - if mode != "true" && mode != "false" { - // Validate as address for separate server mode - _, err := net.ResolveTCPAddr("tcp", PrometheusListen) - if err != nil { - return fmt.Errorf("[prometheus] %s", err.Error()) - } - } - } - return nil }