|
|
@ -19,6 +19,7 @@ package notify |
|
|
|
import ( |
|
|
|
import ( |
|
|
|
"crypto/tls" |
|
|
|
"crypto/tls" |
|
|
|
"crypto/x509" |
|
|
|
"crypto/x509" |
|
|
|
|
|
|
|
"net/http" |
|
|
|
"strconv" |
|
|
|
"strconv" |
|
|
|
"strings" |
|
|
|
"strings" |
|
|
|
"time" |
|
|
|
"time" |
|
|
@ -38,15 +39,15 @@ const ( |
|
|
|
|
|
|
|
|
|
|
|
// TestNotificationTargets is similar to GetNotificationTargets()
|
|
|
|
// TestNotificationTargets is similar to GetNotificationTargets()
|
|
|
|
// avoids explicit registration.
|
|
|
|
// avoids explicit registration.
|
|
|
|
func TestNotificationTargets(cfg config.Config, doneCh <-chan struct{}, rootCAs *x509.CertPool) error { |
|
|
|
func TestNotificationTargets(cfg config.Config, doneCh <-chan struct{}, transport *http.Transport) error { |
|
|
|
_, err := RegisterNotificationTargets(cfg, doneCh, rootCAs, true) |
|
|
|
_, err := RegisterNotificationTargets(cfg, doneCh, transport, true) |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// GetNotificationTargets registers and initializes all notification
|
|
|
|
// GetNotificationTargets registers and initializes all notification
|
|
|
|
// targets, returns error if any.
|
|
|
|
// targets, returns error if any.
|
|
|
|
func GetNotificationTargets(cfg config.Config, doneCh <-chan struct{}, rootCAs *x509.CertPool) (*event.TargetList, error) { |
|
|
|
func GetNotificationTargets(cfg config.Config, doneCh <-chan struct{}, transport *http.Transport) (*event.TargetList, error) { |
|
|
|
return RegisterNotificationTargets(cfg, doneCh, rootCAs, false) |
|
|
|
return RegisterNotificationTargets(cfg, doneCh, transport, false) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// RegisterNotificationTargets - returns TargetList which contains enabled targets in serverConfig.
|
|
|
|
// RegisterNotificationTargets - returns TargetList which contains enabled targets in serverConfig.
|
|
|
@ -54,7 +55,7 @@ func GetNotificationTargets(cfg config.Config, doneCh <-chan struct{}, rootCAs * |
|
|
|
// * Add a new target in pkg/event/target package.
|
|
|
|
// * Add a new target in pkg/event/target package.
|
|
|
|
// * Add newly added target configuration to serverConfig.Notify.<TARGET_NAME>.
|
|
|
|
// * Add newly added target configuration to serverConfig.Notify.<TARGET_NAME>.
|
|
|
|
// * Handle the configuration in this function to create/add into TargetList.
|
|
|
|
// * Handle the configuration in this function to create/add into TargetList.
|
|
|
|
func RegisterNotificationTargets(cfg config.Config, doneCh <-chan struct{}, rootCAs *x509.CertPool, test bool) (*event.TargetList, error) { |
|
|
|
func RegisterNotificationTargets(cfg config.Config, doneCh <-chan struct{}, transport *http.Transport, test bool) (*event.TargetList, error) { |
|
|
|
targetList := event.NewTargetList() |
|
|
|
targetList := event.NewTargetList() |
|
|
|
if err := checkValidNotificationKeys(cfg); err != nil { |
|
|
|
if err := checkValidNotificationKeys(cfg); err != nil { |
|
|
|
return nil, err |
|
|
|
return nil, err |
|
|
@ -75,7 +76,7 @@ func RegisterNotificationTargets(cfg config.Config, doneCh <-chan struct{}, root |
|
|
|
return nil, err |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
mqttTargets, err := GetNotifyMQTT(cfg[config.NotifyMQTTSubSys], rootCAs) |
|
|
|
mqttTargets, err := GetNotifyMQTT(cfg[config.NotifyMQTTSubSys], transport.TLSClientConfig.RootCAs) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
} |
|
|
@ -85,7 +86,7 @@ func RegisterNotificationTargets(cfg config.Config, doneCh <-chan struct{}, root |
|
|
|
return nil, err |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
natsTargets, err := GetNotifyNATS(cfg[config.NotifyNATSSubSys], rootCAs) |
|
|
|
natsTargets, err := GetNotifyNATS(cfg[config.NotifyNATSSubSys], transport.TLSClientConfig.RootCAs) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
} |
|
|
@ -105,7 +106,7 @@ func RegisterNotificationTargets(cfg config.Config, doneCh <-chan struct{}, root |
|
|
|
return nil, err |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
webhookTargets, err := GetNotifyWebhook(cfg[config.NotifyWebhookSubSys], rootCAs) |
|
|
|
webhookTargets, err := GetNotifyWebhook(cfg[config.NotifyWebhookSubSys], transport) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
} |
|
|
@ -149,7 +150,7 @@ func RegisterNotificationTargets(cfg config.Config, doneCh <-chan struct{}, root |
|
|
|
if !args.Enable { |
|
|
|
if !args.Enable { |
|
|
|
continue |
|
|
|
continue |
|
|
|
} |
|
|
|
} |
|
|
|
args.TLS.RootCAs = rootCAs |
|
|
|
args.TLS.RootCAs = transport.TLSClientConfig.RootCAs |
|
|
|
newTarget, err := target.NewKafkaTarget(id, args, doneCh, logger.LogOnceIf) |
|
|
|
newTarget, err := target.NewKafkaTarget(id, args, doneCh, logger.LogOnceIf) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
return nil, err |
|
|
@ -167,7 +168,7 @@ func RegisterNotificationTargets(cfg config.Config, doneCh <-chan struct{}, root |
|
|
|
if !args.Enable { |
|
|
|
if !args.Enable { |
|
|
|
continue |
|
|
|
continue |
|
|
|
} |
|
|
|
} |
|
|
|
args.RootCAs = rootCAs |
|
|
|
args.RootCAs = transport.TLSClientConfig.RootCAs |
|
|
|
newTarget, err := target.NewMQTTTarget(id, args, doneCh, logger.LogOnceIf) |
|
|
|
newTarget, err := target.NewMQTTTarget(id, args, doneCh, logger.LogOnceIf) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
return nil, err |
|
|
@ -270,8 +271,7 @@ func RegisterNotificationTargets(cfg config.Config, doneCh <-chan struct{}, root |
|
|
|
if !args.Enable { |
|
|
|
if !args.Enable { |
|
|
|
continue |
|
|
|
continue |
|
|
|
} |
|
|
|
} |
|
|
|
args.RootCAs = rootCAs |
|
|
|
newTarget, err := target.NewWebhookTarget(id, args, doneCh, logger.LogOnceIf, transport) |
|
|
|
newTarget, err := target.NewWebhookTarget(id, args, doneCh, logger.LogOnceIf) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
} |
|
|
@ -1426,7 +1426,8 @@ var ( |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
// GetNotifyWebhook - returns a map of registered notification 'webhook' targets
|
|
|
|
// GetNotifyWebhook - returns a map of registered notification 'webhook' targets
|
|
|
|
func GetNotifyWebhook(webhookKVS map[string]config.KVS, rootCAs *x509.CertPool) (map[string]target.WebhookArgs, error) { |
|
|
|
func GetNotifyWebhook(webhookKVS map[string]config.KVS, transport *http.Transport) ( |
|
|
|
|
|
|
|
map[string]target.WebhookArgs, error) { |
|
|
|
webhookTargets := make(map[string]target.WebhookArgs) |
|
|
|
webhookTargets := make(map[string]target.WebhookArgs) |
|
|
|
for k, kv := range mergeTargets(webhookKVS, target.EnvWebhookEnable, DefaultWebhookKVS) { |
|
|
|
for k, kv := range mergeTargets(webhookKVS, target.EnvWebhookEnable, DefaultWebhookKVS) { |
|
|
|
enableEnv := target.EnvWebhookEnable |
|
|
|
enableEnv := target.EnvWebhookEnable |
|
|
@ -1468,7 +1469,7 @@ func GetNotifyWebhook(webhookKVS map[string]config.KVS, rootCAs *x509.CertPool) |
|
|
|
webhookArgs := target.WebhookArgs{ |
|
|
|
webhookArgs := target.WebhookArgs{ |
|
|
|
Enable: enabled, |
|
|
|
Enable: enabled, |
|
|
|
Endpoint: *url, |
|
|
|
Endpoint: *url, |
|
|
|
RootCAs: rootCAs, |
|
|
|
Transport: transport, |
|
|
|
AuthToken: env.Get(authEnv, kv.Get(target.WebhookAuthToken)), |
|
|
|
AuthToken: env.Get(authEnv, kv.Get(target.WebhookAuthToken)), |
|
|
|
QueueDir: env.Get(queueDirEnv, kv.Get(target.WebhookQueueDir)), |
|
|
|
QueueDir: env.Get(queueDirEnv, kv.Get(target.WebhookQueueDir)), |
|
|
|
QueueLimit: uint64(queueLimit), |
|
|
|
QueueLimit: uint64(queueLimit), |
|
|
|