From 7715b84773906ecce0ec8b1654e2f05630636f37 Mon Sep 17 00:00:00 2001 From: Michael Hoffmann <88316042+mhoffm-aiven@users.noreply.github.com> Date: Tue, 22 Feb 2022 19:52:25 +0100 Subject: [PATCH] feat: socks5 proxy support for websocket (#10672) --- plugins/outputs/websocket/README.md | 6 ++++++ plugins/outputs/websocket/websocket.go | 15 +++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/plugins/outputs/websocket/README.md b/plugins/outputs/websocket/README.md index 51d329317..955c9fe67 100644 --- a/plugins/outputs/websocket/README.md +++ b/plugins/outputs/websocket/README.md @@ -27,6 +27,12 @@ It can output data in any of the [supported output formats](https://github.com/i ## Use TLS but skip chain & host verification # insecure_skip_verify = false + ## Optional SOCKS5 proxy to use + # socks5_enabled = true + # socks5_address = "127.0.0.1:1080" + # socks5_username = "alice" + # socks5_password = "pass123" + ## Data format to output. ## Each data format has it's own unique set of configuration options, read ## more about them here: diff --git a/plugins/outputs/websocket/websocket.go b/plugins/outputs/websocket/websocket.go index 17aea0542..402e6f5a9 100644 --- a/plugins/outputs/websocket/websocket.go +++ b/plugins/outputs/websocket/websocket.go @@ -36,6 +36,12 @@ var sampleConfig = ` ## Use TLS but skip chain & host verification # insecure_skip_verify = false + ## Optional SOCKS5 proxy to use + # socks5_enabled = true + # socks5_address = "127.0.0.1:1080" + # socks5_username = "alice" + # socks5_password = "pass123" + ## Data format to output. ## Each data format has it's own unique set of configuration options, read ## more about them here: @@ -63,6 +69,7 @@ type WebSocket struct { UseTextFrames bool `toml:"use_text_frames"` Log telegraf.Logger `toml:"-"` proxy.HTTPProxy + proxy.Socks5ProxyConfig tls.ClientConfig conn *ws.Conn @@ -112,6 +119,14 @@ func (w *WebSocket) Connect() error { TLSClientConfig: tlsCfg, } + if w.Socks5ProxyEnabled { + netDialer, err := w.Socks5ProxyConfig.GetDialer() + if err != nil { + return fmt.Errorf("error connecting to socks5 proxy: %v", err) + } + dialer.NetDial = netDialer.Dial + } + headers := http.Header{} for k, v := range w.Headers { headers.Set(k, v)