From a9bce5c56df6dbabe9ca4ae973a92cadfef6735b Mon Sep 17 00:00:00 2001 From: favonia Date: Tue, 24 Oct 2023 10:51:50 -0500 Subject: [PATCH] feat(monitor): force non-empty error messages for Uptime Kuma (#624) --- internal/monitor/{updatekuma.go => uptimekuma.go} | 9 +++++++-- .../{updatekuma_test.go => uptimekuma_test.go} | 15 +++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) rename internal/monitor/{updatekuma.go => uptimekuma.go} (93%) rename internal/monitor/{updatekuma_test.go => uptimekuma_test.go} (94%) 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 de1edba9..7f65ffe8 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 } 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 7471723e..9d64aa08 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")