From e111b1bd84432d63e83c83a909a2567aa628aa72 Mon Sep 17 00:00:00 2001 From: favonia Date: Thu, 27 Jun 2024 00:46:50 -0500 Subject: [PATCH] fix(monitor): a more powerful hack for quirks of Uptime Kuma --- cmd/ddns/ddns.go | 12 ++++++------ internal/monitor/uptimekuma.go | 6 ++++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/cmd/ddns/ddns.go b/cmd/ddns/ddns.go index 637f6787..4625b9dd 100644 --- a/cmd/ddns/ddns.go +++ b/cmd/ddns/ddns.go @@ -56,9 +56,9 @@ func initConfig(ctx context.Context, ppfmt pp.PP) (*config.Config, setter.Setter func stopUpdating(ctx context.Context, ppfmt pp.PP, c *config.Config, s setter.Setter) { if c.DeleteOnStop { - resp := updater.DeleteIPs(ctx, ppfmt, c, s) - monitor.LogMessageAll(ctx, ppfmt, c.Monitors, resp) - notifier.SendMessageAll(ctx, ppfmt, c.Notifiers, resp) + msg := updater.DeleteIPs(ctx, ppfmt, c, s) + monitor.LogMessageAll(ctx, ppfmt, c.Monitors, msg) + notifier.SendMessageAll(ctx, ppfmt, c.Notifiers, msg) } } @@ -128,9 +128,9 @@ func realMain() int { //nolint:funlen if first && !c.UpdateOnStart { monitor.SuccessAll(ctx, ppfmt, c.Monitors, "Started (no action)") } else { - resp := updater.UpdateIPs(ctxWithSignals, ppfmt, c, s) - monitor.PingMessageAll(ctx, ppfmt, c.Monitors, resp) - notifier.SendMessageAll(ctx, ppfmt, c.Notifiers, resp) + msg := updater.UpdateIPs(ctxWithSignals, ppfmt, c, s) + monitor.PingMessageAll(ctx, ppfmt, c.Monitors, msg) + notifier.SendMessageAll(ctx, ppfmt, c.Notifiers, msg) } // Check if cron was disabled diff --git a/internal/monitor/uptimekuma.go b/internal/monitor/uptimekuma.go index 51e5beff..c4fefe17 100644 --- a/internal/monitor/uptimekuma.go +++ b/internal/monitor/uptimekuma.go @@ -7,6 +7,7 @@ import ( "net/http" "net/url" "slices" + "strings" "time" "github.com/google/go-querystring/query" @@ -81,7 +82,7 @@ func NewUptimeKuma(ppfmt pp.PP, rawURL string) (*UptimeKuma, bool) { default: // problematic case ppfmt.Warningf(pp.EmojiUserError, - `The Uptime Kuma URL (redacted) contains an unexpected query %s=... and it will not be used`, + `The Uptime Kuma URL (redacted) contains an unexpected query %s=... and it will be ignored`, k) } } @@ -165,7 +166,8 @@ func (h *UptimeKuma) Start(_ctx context.Context, _ppfmt pp.PP, _message string) // Failure pings the server with status=down. func (h *UptimeKuma) Failure(ctx context.Context, ppfmt pp.PP, message string) bool { - if len(message) == 0 { + message = strings.TrimSpace(message) + if message == "" { // If we do not send a non-empty message to Uptime Kuma, it seems to // either keep the previous message (even if it was for success) or // assume the message is "OK". Either is bad.