Skip to content

Commit 7d8a736

Browse files
committed
Implemented tls probe #173
1 parent 7f7f462 commit 7d8a736

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

config/gobetween.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ protocol = "udp"
210210
# ## could be also matched using regular expression.
211211
# ##
212212
# kind = "probe"
213-
# probe_protocol = "udp" # (required) "udp" | "tcp"
213+
# probe_protocol = "udp" # (required) "udp" | "tcp" | "tls"
214214
# probe_strategy = "starts_with" # (optional) "starts_with" | "regexp"
215215
# probe_send = 'PING\xFF\n' # (required) string to send
216216
# probe_recv = 'PONG\xAA\n' # (required) string to expect in response (response starts with or regexp)

src/healthcheck/probe.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
package healthcheck
22

33
/**
4-
* probe.go - TCP/UDP probe healthcheck
4+
* probe.go - TCP/UDP and TLS probe healthcheck
55
*
66
* @author Yousong Zhou <[email protected]>
77
* @author Illarion Kovalchuk <[email protected]>
88
*/
99

1010
import (
1111
"bytes"
12+
"crypto/tls"
1213
"io"
1314
"net"
1415
"regexp"
@@ -37,7 +38,17 @@ func probe(t core.Target, cfg config.HealthcheckConfig, result chan<- CheckResul
3738
}
3839
}()
3940

40-
conn, err := net.DialTimeout(cfg.ProbeProtocol, t.Address(), timeout)
41+
var conn net.Conn
42+
var err error
43+
44+
switch cfg.ProbeProtocol {
45+
case "tls":
46+
conn, err = tls.DialWithDialer(&net.Dialer{
47+
Timeout: timeout,
48+
}, "tcp", t.Address(), &tls.Config{})
49+
default:
50+
conn, err = net.DialTimeout(cfg.ProbeProtocol, t.Address(), timeout)
51+
}
4152
if err != nil {
4253
checkResult.Live = false
4354
return

src/manager/manager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ func prepareConfig(name string, server config.Server, defaults config.Connection
316316
if server.Healthcheck.Kind == "probe" {
317317

318318
switch server.Healthcheck.ProbeProtocol {
319-
case "tcp", "udp":
319+
case "tcp", "udp", "tls":
320320
default:
321321
return config.Server{}, errors.New("Unsupported probe_protocol")
322322
}

0 commit comments

Comments
 (0)