diff --git a/internal/event/target/webhook.go b/internal/event/target/webhook.go index 2178f0638..7eb6edfad 100644 --- a/internal/event/target/webhook.go +++ b/internal/event/target/webhook.go @@ -104,6 +104,8 @@ type WebhookTarget struct { loggerOnce logger.LogOnce cancel context.CancelFunc cancelCh <-chan struct{} + + addr string // full address ip/dns with a port number, e.g. x.x.x.x:8080 } // ID - returns target ID. @@ -130,7 +132,7 @@ func (target *WebhookTarget) Store() event.TargetStore { } func (target *WebhookTarget) isActive() (bool, error) { - conn, err := net.DialTimeout("tcp", target.args.Endpoint.Host, 5*time.Second) + conn, err := net.DialTimeout("tcp", target.addr, 5*time.Second) if err != nil { if xnet.IsNetworkOrHostDown(err, false) { return false, store.ErrNotConnected @@ -291,6 +293,19 @@ func NewWebhookTarget(ctx context.Context, id string, args WebhookArgs, loggerOn cancelCh: ctx.Done(), } + // Calculate the webhook addr with the port number format + target.addr = args.Endpoint.Host + if _, _, err := net.SplitHostPort(args.Endpoint.Host); err != nil && strings.Contains(err.Error(), "missing port in address") { + switch strings.ToLower(args.Endpoint.Scheme) { + case "http": + target.addr += ":80" + case "https": + target.addr += ":443" + default: + return nil, errors.New("unsupported scheme") + } + } + if target.store != nil { store.StreamItems(target.store, target, target.cancelCh, target.loggerOnce) }