Enable SSH and TLS handshake on prober for TCP22 and TCP443 ports
This commit is contained in:
1 parent
af3453f19f
commit
550ce3fec4
11 files changed
+308
-20
No files matched your search
@@ -109,26 +109,46 @@ func (p *Prober) pollOnce(ctx context.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
// extraChecksForPort returns checks to run in addition to the base
|
||||
// TCPConnect for ports where a bare TCP handshake doesn't actually prove
|
||||
// the expected service is behind it: a real TLS handshake on 443, a real
|
||||
// SSH banner exchange on 22. nil for every other port.
|
||||
func extraChecksForPort(host string, port int, timeout time.Duration) []func(ctx context.Context) checkrunner.Result {
|
||||
switch port {
|
||||
case 443:
|
||||
return []func(ctx context.Context) checkrunner.Result{
|
||||
checkrunner.TLSHandshake(host, port, timeout),
|
||||
}
|
||||
case 22:
|
||||
return []func(ctx context.Context) checkrunner.Result{
|
||||
checkrunner.SSHBanner(host, timeout),
|
||||
}
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Prober) probeOne(ctx context.Context, a assignment) {
|
||||
tcpTimeout := time.Duration(p.cfg.Checks.TCPTimeoutSeconds) * time.Second
|
||||
icmpTimeout := time.Duration(p.cfg.Checks.ICMPTimeoutSeconds) * time.Second
|
||||
|
||||
var results []resultDTO
|
||||
for _, port := range a.Ports {
|
||||
res := checkrunner.TCPConnect(a.IPAddress, port, tcpTimeout)(ctx)
|
||||
record := func(res checkrunner.Result) {
|
||||
results = append(results, resultDTO{
|
||||
IPID: a.IPID, IPAddress: a.IPAddress, CheckType: res.CheckType,
|
||||
Success: res.Success, LatencyMS: res.LatencyMS, Detail: res.Detail,
|
||||
CheckedAt: res.CheckedAt.Format(time.RFC3339Nano),
|
||||
})
|
||||
}
|
||||
|
||||
for _, port := range a.Ports {
|
||||
record(checkrunner.TCPConnect(a.IPAddress, port, tcpTimeout)(ctx))
|
||||
for _, extra := range extraChecksForPort(a.IPAddress, port, tcpTimeout) {
|
||||
record(extra(ctx))
|
||||
}
|
||||
}
|
||||
if a.ICMP {
|
||||
res := checkrunner.ICMPEcho(a.IPAddress, p.cfg.Checks.ICMPCount, icmpTimeout)(ctx)
|
||||
results = append(results, resultDTO{
|
||||
IPID: a.IPID, IPAddress: a.IPAddress, CheckType: res.CheckType,
|
||||
Success: res.Success, LatencyMS: res.LatencyMS, Detail: res.Detail,
|
||||
CheckedAt: res.CheckedAt.Format(time.RFC3339Nano),
|
||||
})
|
||||
record(checkrunner.ICMPEcho(a.IPAddress, p.cfg.Checks.ICMPCount, icmpTimeout)(ctx))
|
||||
}
|
||||
if len(results) > 0 {
|
||||
results[len(results)-1].Complete = true
|
||||
|
||||
Reference in new issue
Block a user