From 8f1f14fb3dc052851fd98a3ae3894b9552e65274 Mon Sep 17 00:00:00 2001 From: chenlichao <253004141@qq.com> Date: Mon, 28 Mar 2022 19:31:29 +0800 Subject: [PATCH] Enhance webhook sink, add template feature to http headers --- pkg/sinks/webhook.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pkg/sinks/webhook.go b/pkg/sinks/webhook.go index a207b308..8ee3d32e 100644 --- a/pkg/sinks/webhook.go +++ b/pkg/sinks/webhook.go @@ -42,7 +42,16 @@ func (w *Webhook) Send(ctx context.Context, ev *kube.EnhancedEvent) error { } req.Header.Add("Content-Type", "application/json") for k, v := range w.cfg.Headers { - req.Header.Add(k, v) + for k, v := range w.cfg.Headers { + realValue, err := GetString(ev, v) + if err != nil { + log.Debug().Err(err).Msgf("parse template failed: %s", v) + req.Header.Add(k, v) + } else { + log.Debug().Msgf("request header: {%s: %s}", k, realValue) + req.Header.Add(k, realValue) + } + } } tlsClientConfig, err := setupTLS(&w.cfg.TLS) if err != nil {