larzmonitor
Alert on the first failure, then every Nth - not every one.
Ported from a real production gateway monitor: persist whether a scheduled health check is currently failing, and for how many runs in a row, so you alert on the first failure, then every Nth repeat (not every single failed check - an incident that lasts a day shouldn't send 24 emails for one hourly cron), and exactly once on recovery. Pairs directly with statuscard to format the alert and smtp to send it.
larzscript pkg install monitor
What you get
- Alert on first failure, then every Nth repeat
- Exactly one alert on recovery, not a flood
- State persists across separate runs/processes
- Pairs with statuscard + smtp for the actual alert
Try it
import "monitor" as monitor
let SP = "/tmp/demo_monitor.json"
for ok in [true, false, false, false, false, true] {
let r = monitor.check(SP, ok, 3)
print(ok, "->", r["status"], "fails=" + str(r["fails"]), "alert=" + str(r["should_alert"]))
}Output
true -> ok fails=0 alert=false false -> fail fails=1 alert=true false -> fail fails=2 alert=false false -> fail fails=3 alert=true false -> fail fails=4 alert=false true -> ok fails=0 alert=true
Why it's in the Larz Stack
larzmonitor is a real Larzscript package (larzscript pkg install monitor) - money-native, zero dependencies, the same language as the rest of the estate, not a separate Python runtime. It composes with the rest of the Larz Stack and the Larz framework.