mirror of
https://github.com/axllent/mailpit.git
synced 2025-08-15 20:13:16 +02:00
Refactor Prometheus metrics configuration and validation
This commit is contained in:
@@ -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().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")
|
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
|
// Prometheus metrics
|
||||||
rootCmd.Flags().StringVar(&config.PrometheusListen, "enable-prometheus", config.PrometheusListen, "Enable Prometheus metrics: false=disabled, 'true'=use web port, address=separate server (':9090')")
|
rootCmd.Flags().StringVar(&config.PrometheusListen, "enable-prometheus", config.PrometheusListen, "Enable Prometheus metrics: true|false|<bind interface & port> (eg:':9090')")
|
||||||
|
|
||||||
// SMTP server
|
// SMTP server
|
||||||
rootCmd.Flags().StringVarP(&config.SMTPListen, "smtp", "s", config.SMTPListen, "SMTP bind interface and port")
|
rootCmd.Flags().StringVarP(&config.SMTPListen, "smtp", "s", config.SMTPListen, "SMTP bind interface and port")
|
||||||
|
@@ -192,7 +192,7 @@ var (
|
|||||||
AllowUntrustedTLS bool
|
AllowUntrustedTLS bool
|
||||||
|
|
||||||
// PrometheusListen address for Prometheus metrics server
|
// 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
|
PrometheusListen string
|
||||||
|
|
||||||
// Version is the default application version, updated on release
|
// Version is the default application version, updated on release
|
||||||
@@ -362,6 +362,20 @@ func VerifyConfig() error {
|
|||||||
logger.Log().Info("[send-api] disabling authentication")
|
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
|
// SMTP server
|
||||||
if SMTPTLSCert != "" && SMTPTLSKey == "" || SMTPTLSCert == "" && SMTPTLSKey != "" {
|
if SMTPTLSCert != "" && SMTPTLSKey == "" || SMTPTLSCert == "" && SMTPTLSKey != "" {
|
||||||
return errors.New("[smtp] you must provide both an SMTP TLS certificate and a key")
|
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")
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user