2020-06-28 13:26:22 +02:00
|
|
|
package notifier
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmalert/utils"
|
2020-06-29 21:21:03 +02:00
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/flagutil"
|
2020-06-28 13:26:22 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2020-06-29 21:21:03 +02:00
|
|
|
addrs = flagutil.NewArray("notifier.url", "Prometheus alertmanager URL. Required parameter. e.g. http://127.0.0.1:9093")
|
2020-12-24 11:48:59 +01:00
|
|
|
basicAuthUsername = flagutil.NewArray("notifier.basicAuth.username", "Optional basic auth username for -notifier.url")
|
|
|
|
basicAuthPassword = flagutil.NewArray("notifier.basicAuth.password", "Optional basic auth password for -notifier.url")
|
2020-06-29 21:21:03 +02:00
|
|
|
|
2020-12-22 21:23:04 +01:00
|
|
|
tlsInsecureSkipVerify = flagutil.NewArrayBool("notifier.tlsInsecureSkipVerify", "Whether to skip tls verification when connecting to -notifier.url")
|
2020-06-29 21:21:03 +02:00
|
|
|
tlsCertFile = flagutil.NewArray("notifier.tlsCertFile", "Optional path to client-side TLS certificate file to use when connecting to -notifier.url")
|
|
|
|
tlsKeyFile = flagutil.NewArray("notifier.tlsKeyFile", "Optional path to client-side TLS certificate key to use when connecting to -notifier.url")
|
|
|
|
tlsCAFile = flagutil.NewArray("notifier.tlsCAFile", "Optional path to TLS CA file to use for verifying connections to -notifier.url. "+
|
2020-06-28 13:26:22 +02:00
|
|
|
"By default system CA is used")
|
2020-06-29 21:21:03 +02:00
|
|
|
tlsServerName = flagutil.NewArray("notifier.tlsServerName", "Optional TLS server name to use for connections to -notifier.url. "+
|
2020-06-28 13:26:22 +02:00
|
|
|
"By default the server name from -notifier.url is used")
|
|
|
|
)
|
|
|
|
|
|
|
|
// Init creates a Notifier object based on provided flags.
|
2020-06-29 21:21:03 +02:00
|
|
|
func Init(gen AlertURLGenerator) ([]Notifier, error) {
|
|
|
|
if len(*addrs) == 0 {
|
|
|
|
return nil, fmt.Errorf("at least one `-notifier.url` must be set")
|
2020-06-28 13:26:22 +02:00
|
|
|
}
|
2020-06-29 21:21:03 +02:00
|
|
|
|
|
|
|
var notifiers []Notifier
|
|
|
|
for i, addr := range *addrs {
|
|
|
|
cert, key := tlsCertFile.GetOptionalArg(i), tlsKeyFile.GetOptionalArg(i)
|
|
|
|
ca, serverName := tlsCAFile.GetOptionalArg(i), tlsServerName.GetOptionalArg(i)
|
2020-12-22 21:23:04 +01:00
|
|
|
tr, err := utils.Transport(addr, cert, key, ca, serverName, tlsInsecureSkipVerify.GetOptionalArg(i))
|
2020-06-29 21:21:03 +02:00
|
|
|
if err != nil {
|
2020-06-30 21:58:18 +02:00
|
|
|
return nil, fmt.Errorf("failed to create transport: %w", err)
|
2020-06-29 21:21:03 +02:00
|
|
|
}
|
|
|
|
user, pass := basicAuthUsername.GetOptionalArg(i), basicAuthPassword.GetOptionalArg(i)
|
|
|
|
am := NewAlertManager(addr, user, pass, gen, &http.Client{Transport: tr})
|
|
|
|
notifiers = append(notifiers, am)
|
2020-06-28 13:26:22 +02:00
|
|
|
}
|
2020-06-29 21:21:03 +02:00
|
|
|
|
|
|
|
return notifiers, nil
|
2020-06-28 13:26:22 +02:00
|
|
|
}
|