Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: socks5 proxy support for websocket #10672

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions plugins/outputs/websocket/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
15 changes: 15 additions & 0 deletions plugins/outputs/websocket/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down