Skip to content

Commit

Permalink
feat(monitor): force non-empty error messages for Uptime Kuma (#624)
Browse files Browse the repository at this point in the history
  • Loading branch information
favonia authored Oct 24, 2023
1 parent 1832760 commit a9bce5c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit a9bce5c

Please sign in to comment.