Repository: favonia/cloudflare-ddns (go)

Issue:
Prevent Uptime Kuma from keeping previous successful messages
This is a triage of #615.

Uptime Kuma seems to have two (undesirable) behaviors: keeping the previous message or assuming the empty message means "OK" even if the status is "down". We can work around it by making sure a non-empty message is always sent when an error happens.

Pull request description:
feat(monitor): force non-empty error messages for Uptime Kuma
Close #616.

Patch:
diff --git a/internal/monitor/updatekuma.go b/internal/monitor/uptimekuma.go
similarity index 93%
rename from internal/monitor/updatekuma.go
rename to internal/monitor/uptimekuma.go
index de1edba..7f65ffe 100644
--- a/internal/monitor/updatekuma.go
+++ b/internal/monitor/uptimekuma.go
@@ -156,17 +156,22 @@ func (h *UptimeKuma) Success(ctx context.Context, ppfmt pp.PP, _message string)
 }
 
 // Start does nothing.
-func (h *UptimeKuma) Start(ctx context.Context, ppfmt pp.PP, message string) bool {
+func (h *UptimeKuma) Start(ctx context.Context, ppfmt pp.PP, _message string) bool {
 	return true
 }
 
 // Failure pings the server with status=down.
 func (h *UptimeKuma) Failure(ctx context.Context, ppfmt pp.PP, message string) bool {
+	if len(message) == 0 {
+		// Uptime Kuma seems to keep the previous message (even if it was for success) by default.
+		// We thus send an explicit message to overwrite it.
+		message = "Failing"
+	}
 	return h.ping(ctx, ppfmt, UptimeKumaRequest{Status: "down", Msg: message, Ping: ""})
 }
 
 // Log does nothing.
-func (h *UptimeKuma) Log(ctx context.Context, ppfmt pp.PP, message string) bool {
+func (h *UptimeKuma) Log(ctx context.Context, ppfmt pp.PP, _message string) bool {
 	return true
 }
 


Test patch:
diff --git a/internal/monitor/updatekuma_test.go b/internal/monitor/uptimekuma_test.go
similarity index 94%
rename from internal/monitor/updatekuma_test.go
rename to internal/monitor/uptimekuma_test.go
index 7471723..9d64aa0 100644
--- a/internal/monitor/updatekuma_test.go
+++ b/internal/monitor/uptimekuma_test.go
@@ -195,6 +195,21 @@ func TestUptimeKumaEndPoints(t *testing.T) {
 				)
 			},
 		},
+		"failure/empty": {
+			func(ppfmt pp.PP, m monitor.Monitor) bool {
+				return m.Failure(context.Background(), ppfmt, "")
+			},
+			"/", "down", "Failing", "",
+			[]action{ActionOk},
+			ActionAbort, true,
+			true,
+			func(m *mocks.MockPP) {
+				gomock.InOrder(
+					m.EXPECT().Warningf(pp.EmojiUserWarning, "The Uptime Kuma URL (redacted) uses HTTP; please consider using HTTPS"),
+					m.EXPECT().Infof(pp.EmojiNotification, "Successfully pinged Uptime Kuma"),
+				)
+			},
+		},
 		"log": {
 			func(ppfmt pp.PP, m monitor.Monitor) bool {
 				return m.Log(context.Background(), ppfmt, "message")