feat(api): open incidents and notify channels when monitors go down

Results are evaluated as they arrive. Transitions open or resolve the
monitor's incident and queue a notification per enabled channel in the
same transaction; every API replica delivers the outbox with leases and
exponential retries. Organizations manage webhook and email channels,
can send test notifications and list incidents. Email requires
UPTIME_SMTP_URL.

Closes #14
Closes #15
Closes #16

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
Sebastian UnterschützandClaude Opus 5.5 committed 2026-11-22 01:23:37 +01:00
1 parent 01ef543e62
commit 5f42e3e650
12 files changed
+822 -13

No files matched your search

+11 -3
View File
@@ -28,6 +28,9 @@ type monitorRequest struct {
Config json.RawMessage `json:"config"`
Enabled *bool `json:"enabled"`
Regions []string `json:"regions" binding:"required,min=1,max=50"`
// Confirmations is how many failures in a row make a region count as
// down; 0 keeps the default of 2.
Confirmations int `json:"confirmations" binding:"min=0,max=10"`
}
type latestView struct {
@@ -48,6 +51,7 @@ type monitorView struct {
TimeoutMS int32 `json:"timeout_ms"`
Config json.RawMessage `json:"config"`
Enabled bool `json:"enabled"`
Confirmations int32 `json:"confirmations"`
Regions []string `json:"regions"`
Latest []latestView `json:"latest"`
}
@@ -55,7 +59,7 @@ type monitorView struct {
func viewMonitor(m store.Monitor, regions []string) monitorView {
return monitorView{
ID: m.ID, Name: m.Name, Type: m.Type, Target: m.Target, IntervalSeconds: m.IntervalSeconds,
TimeoutMS: m.TimeoutMs, Config: m.Config, Enabled: m.Enabled, Regions: regions, Latest: []latestView{},
TimeoutMS: m.TimeoutMs, Config: m.Config, Enabled: m.Enabled, Confirmations: m.Confirmations, Regions: regions, Latest: []latestView{},
}
}
@@ -80,6 +84,9 @@ func (s *Server) validateMonitor(c *gin.Context, req *monitorRequest) bool {
fail(c, http.StatusUnprocessableEntity, "invalid_interval", "Min", s.minInterval())
return false
}
if req.Confirmations == 0 {
req.Confirmations = 2
}
if req.TimeoutMS == 0 {
req.TimeoutMS = min(10000, req.IntervalSeconds*1000/2)
}
@@ -176,7 +183,7 @@ func (s *Server) createMonitor(c *gin.Context) {
m, err = q.CreateMonitor(ctx, store.CreateMonitorParams{
OrgID: p.Org.ID, Name: req.Name, Type: req.Type, Target: req.Target,
IntervalSeconds: int32(req.IntervalSeconds), TimeoutMs: int32(req.TimeoutMS),
Config: req.Config, Enabled: req.Enabled == nil || *req.Enabled,
Config: req.Config, Enabled: req.Enabled == nil || *req.Enabled, Confirmations: int32(req.Confirmations),
})
if err != nil {
return err
@@ -241,7 +248,7 @@ func (s *Server) updateMonitor(c *gin.Context) {
m, err = q.UpdateMonitor(ctx, store.UpdateMonitorParams{
ID: id, Name: req.Name, Type: req.Type, Target: req.Target,
IntervalSeconds: int32(req.IntervalSeconds), TimeoutMs: int32(req.TimeoutMS),
Config: req.Config, Enabled: req.Enabled == nil || *req.Enabled,
Config: req.Config, Enabled: req.Enabled == nil || *req.Enabled, Confirmations: int32(req.Confirmations),
})
if err != nil {
return err
@@ -295,6 +302,7 @@ func (s *Server) deleteMonitor(c *gin.Context) {
internalError(c, err)
return
}
_ = s.eval.Forget(ctx, id)
c.Status(http.StatusNoContent)
}