Skip to content
Merged
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
43 changes: 20 additions & 23 deletions config/endpoint/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"errors"
"fmt"
"io"
"maps"
"math/rand"
"net"
"net/http"
Expand Down Expand Up @@ -460,22 +461,16 @@ func (e *Endpoint) call(result *Result) {
var err error
var certificate *x509.Certificate
endpointType := e.Type()
switch endpointType {
case TypeHTTP:
request = e.buildHTTPRequest()
case TypeDomain:
// domain expiration checked before call `call`
return
}
startTime := time.Now()
if endpointType == TypeDNS {
switch endpointType {
case TypeDNS:
result.Connected, result.DNSRCode, result.Body, err = client.QueryDNS(e.DNSConfig.QueryType, e.DNSConfig.QueryName, e.URL)
if err != nil {
result.AddError(err.Error())
return
}
result.Duration = time.Since(startTime)
} else if endpointType == TypeSTARTTLS || endpointType == TypeTLS {
case TypeSTARTTLS, TypeTLS:
if endpointType == TypeSTARTTLS {
result.Connected, certificate, err = client.CanPerformStartTLS(strings.TrimPrefix(e.URL, "starttls://"), e.ClientConfig)
} else {
Expand All @@ -487,24 +482,20 @@ func (e *Endpoint) call(result *Result) {
}
result.Duration = time.Since(startTime)
result.CertificateExpiration = time.Until(certificate.NotAfter)
} else if endpointType == TypeTCP {
case TypeTCP:
result.Connected, result.Body = client.CanCreateNetworkConnection("tcp", strings.TrimPrefix(e.URL, "tcp://"), e.getParsedBody(), e.ClientConfig)
result.Duration = time.Since(startTime)
} else if endpointType == TypeUDP {
case TypeUDP:
result.Connected, result.Body = client.CanCreateNetworkConnection("udp", strings.TrimPrefix(e.URL, "udp://"), e.getParsedBody(), e.ClientConfig)
result.Duration = time.Since(startTime)
} else if endpointType == TypeSCTP {
case TypeSCTP:
result.Connected = client.CanCreateSCTPConnection(strings.TrimPrefix(e.URL, "sctp://"), e.ClientConfig)
result.Duration = time.Since(startTime)
} else if endpointType == TypeICMP {
case TypeICMP:
result.Connected, result.Duration = client.Ping(strings.TrimPrefix(e.URL, "icmp://"), e.ClientConfig)
} else if endpointType == TypeWS {
case TypeWS:
wsHeaders := map[string]string{}
if e.Headers != nil {
for k, v := range e.Headers {
wsHeaders[k] = v
}
}
maps.Copy(wsHeaders, e.Headers)
if _, exists := wsHeaders["User-Agent"]; !exists {
wsHeaders["User-Agent"] = GatusUserAgent
}
Expand All @@ -514,7 +505,7 @@ func (e *Endpoint) call(result *Result) {
return
}
result.Duration = time.Since(startTime)
} else if endpointType == TypeSSH {
case TypeSSH:
// If there's no username, password or private key specified, attempt to validate just the SSH banner
if e.SSHConfig == nil || (len(e.SSHConfig.Username) == 0 && len(e.SSHConfig.Password) == 0 && len(e.SSHConfig.PrivateKey) == 0) {
result.Connected, result.HTTPStatus, err = client.CheckSSHBanner(strings.TrimPrefix(e.URL, "ssh://"), e.ClientConfig)
Expand Down Expand Up @@ -543,7 +534,7 @@ func (e *Endpoint) call(result *Result) {
result.Body = output
}
result.Duration = time.Since(startTime)
} else if endpointType == TypeGRPC {
case TypeGRPC:
useTLS := strings.HasPrefix(e.URL, "grpcs://")
address := strings.TrimPrefix(strings.TrimPrefix(e.URL, "grpcs://"), "grpc://")
connected, status, err, duration := client.PerformGRPCHealthCheck(address, useTLS, e.ClientConfig)
Expand All @@ -554,9 +545,15 @@ func (e *Endpoint) call(result *Result) {
result.Connected = connected
result.Duration = duration
if e.needsToReadBody() {
result.Body = []byte(fmt.Sprintf("{\"status\":\"%s\"}", status))
result.Body = fmt.Appendf(nil, "{\"status\":\"%s\"}", status)
}
} else {
case TypeDomain:
// domain expiration checked before call `call`
return
case TypeHTTP:
request = e.buildHTTPRequest()
fallthrough
default:
response, err = client.GetHTTPClient(e.ClientConfig).Do(request)
result.Duration = time.Since(startTime)
if err != nil {
Expand Down