Compare commits

..

4 Commits

Author SHA1 Message Date
Ian Fijolek
3ef06fb78d Stop getting errors when tzdata updates 2025-02-13 13:28:06 -08:00
IamTheFij
0535bdf156 Fix incorrect alertCount 2025-02-13 12:12:01 -08:00
Ian Fijolek
03f0ab69fe Add documentation for default_alert_every 2025-02-13 11:26:39 -08:00
Ian Fijolek
312821fa8d Add pycompat warning 2024-11-14 13:09:23 -08:00
6 changed files with 51 additions and 2 deletions
+2 -1
View File
@@ -4,7 +4,8 @@ RUN mkdir /app
WORKDIR /app/ WORKDIR /app/
# Add common checking tools # Add common checking tools
RUN apk --no-cache add bash=~5 curl=~8 jq=~1 bind-tools=~9 tzdata~=2024a # hadolint ignore=DL3018
RUN apk --no-cache add bash=~5 curl=~8 jq=~1 bind-tools=~9 tzdata
# Add minitor user for running as non-root # Add minitor user for running as non-root
RUN addgroup -S minitor && adduser -S minitor -G minitor RUN addgroup -S minitor && adduser -S minitor -G minitor
+2 -1
View File
@@ -22,7 +22,8 @@ WORKDIR /app/
COPY --from=builder /app/minitor . COPY --from=builder /app/minitor .
# Add common checking tools # Add common checking tools
RUN apk --no-cache add bash=~5 curl=~8 jq=~1 bind-tools=~9 tzdata~=2024a # hadolint ignore=DL3018
RUN apk --no-cache add bash=~5 curl=~8 jq=~1 bind-tools=~9 tzdata
# Add minitor user for running as non-root # Add minitor user for running as non-root
RUN addgroup -S minitor && adduser -S minitor -G minitor RUN addgroup -S minitor && adduser -S minitor -G minitor
+1
View File
@@ -58,6 +58,7 @@ The global configurations are:
|---|---| |---|---|
|`check_interval`|Maximum frequency to run checks for each monitor as duration, eg. 1m2s.| |`check_interval`|Maximum frequency to run checks for each monitor as duration, eg. 1m2s.|
|`default_alert_after`|A default value used as an `alert_after` value for a monitor if not specified or 0.| |`default_alert_after`|A default value used as an `alert_after` value for a monitor if not specified or 0.|
|`default_alert_every`|A default value used as an `alert_every` value for a monitor if not specified.|
|`default_alert_down`|Default down alerts to used by a monitor in case none are provided.| |`default_alert_down`|Default down alerts to used by a monitor in case none are provided.|
|`default_alert_up`|Default up alerts to used by a monitor in case none are provided.| |`default_alert_up`|Default up alerts to used by a monitor in case none are provided.|
|`monitors`|List of all monitors. Detailed description below| |`monitors`|List of all monitors. Detailed description below|
+4
View File
@@ -138,6 +138,10 @@ func main() {
return return
} }
if PyCompat {
slog.Warningf("Python compatibility mode is enabled. This will be removed in the next major release. Please update your configuration.")
}
// Load configuration // Load configuration
config, err := LoadConfig(*configPath) config, err := LoadConfig(*configPath)
slog.OnErrFatalf(err, "Error loading config: %v", err) slog.OnErrFatalf(err, "Error loading config: %v", err)
+1
View File
@@ -149,6 +149,7 @@ func (monitor *Monitor) failure() (notice *AlertNotice) {
// If we're going to alert, increment count // If we're going to alert, increment count
if notice != nil { if notice != nil {
monitor.alertCount++ monitor.alertCount++
notice.AlertCount = monitor.alertCount
} }
return notice return notice
+41
View File
@@ -138,6 +138,47 @@ func TestMonitorSuccess(t *testing.T) {
} }
} }
func TestMonitorAlertCount(t *testing.T) {
var alertEvery int16 = 1
cases := []struct {
checkSuccess bool
alertCount int16
name string
}{
{false, 1, "First failure and first alert"},
{false, 2, "Second failure and first alert"},
{true, 2, "Success should preserve past alert count"},
{false, 1, "First failure and first alert after success"},
}
// Unlike previous tests, this one requires a static Monitor with repeated
// calls to the failure method
monitor := Monitor{failureCount: 0, AlertAfter: 1, AlertEvery: &alertEvery}
for _, c := range cases {
log.Printf("Testing case %s", c.name)
var notice *AlertNotice
if c.checkSuccess {
notice = monitor.success()
} else {
notice = monitor.failure()
}
if notice == nil {
t.Errorf("failure(%v) expected notice, got nil", c.name)
}
if notice.AlertCount != c.alertCount {
t.Errorf("failure(%v), expected=%v actual=%v", c.name, c.alertCount, notice.AlertCount)
log.Printf("Case failed: %s", c.name)
}
log.Println("-----")
}
}
// TestMonitorFailureAlertAfter tests that alerts will not trigger until // TestMonitorFailureAlertAfter tests that alerts will not trigger until
// hitting the threshold provided by AlertAfter // hitting the threshold provided by AlertAfter
func TestMonitorFailureAlertAfter(t *testing.T) { func TestMonitorFailureAlertAfter(t *testing.T) {