aboutsummaryrefslogtreecommitdiff
path: root/backend/internal/monitor/checker.go
diff options
context:
space:
mode:
Diffstat (limited to 'backend/internal/monitor/checker.go')
-rw-r--r--backend/internal/monitor/checker.go26
1 files changed, 22 insertions, 4 deletions
diff --git a/backend/internal/monitor/checker.go b/backend/internal/monitor/checker.go
index 07f807e..df386e6 100644
--- a/backend/internal/monitor/checker.go
+++ b/backend/internal/monitor/checker.go
@@ -12,14 +12,16 @@ import (
var httpClient = &http.Client{
Timeout: 10 * time.Second,
+ // do NOT set InsecureSkipVerify — we want proper TLS
}
-func CheckHTTP(ctx context.Context, url string, keyword string) model.Heartbeat {
+func CheckHTTP(ctx context.Context, url string, keyword string) (model.Heartbeat, *model.SSLInfo) {
start := time.Now()
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
if err != nil {
- return heartbeatFromError(start, err)
+ hb := heartbeatFromError(start, err)
+ return hb, nil
}
resp, err := httpClient.Do(req)
@@ -32,7 +34,7 @@ func CheckHTTP(ctx context.Context, url string, keyword string) model.Heartbeat
IsUp: false,
ErrorMessage: err.Error(),
TestedAt: time.Now(),
- }
+ }, nil
}
defer resp.Body.Close()
@@ -66,13 +68,29 @@ func CheckHTTP(ctx context.Context, url string, keyword string) model.Heartbeat
}
}
- return model.Heartbeat{
+ hb := model.Heartbeat{
StatusCode: resp.StatusCode,
ResponseTimeMs: elapsed,
IsUp: isUp,
ErrorMessage: errMsg,
TestedAt: time.Now(),
}
+
+ // Extract TLS certificate info
+ var ssl *model.SSLInfo
+ if resp.TLS != nil && len(resp.TLS.PeerCertificates) > 0 {
+ cert := resp.TLS.PeerCertificates[0]
+ days := int(time.Until(cert.NotAfter).Hours() / 24)
+ ssl = &model.SSLInfo{
+ ServiceID: 0, // filled in by caller
+ Issuer: cert.Issuer.CommonName,
+ ExpiresAt: cert.NotAfter,
+ DaysRemaining: days,
+ CheckedAt: time.Now(),
+ }
+ }
+
+ return hb, ssl
}
func heartbeatFromError(start time.Time, err error) model.Heartbeat {