Skip to content

Commit

Permalink
fix(monitor): a more powerful hack for quirks of Uptime Kuma
Browse files Browse the repository at this point in the history
  • Loading branch information
favonia committed Jun 27, 2024
1 parent fd56d30 commit e111b1b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
12 changes: 6 additions & 6 deletions cmd/ddns/ddns.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions internal/monitor/uptimekuma.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net/http"
"net/url"
"slices"
"strings"
"time"

"github.com/google/go-querystring/query"
Expand Down Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit e111b1b

Please sign in to comment.