Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3ef06fb78d | ||
|
|
0535bdf156 | ||
|
|
03f0ab69fe | ||
|
|
312821fa8d |
+2
-1
@@ -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
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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|
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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) {
|
||||||
|
|||||||
Reference in New Issue
Block a user