6 Commits

Author SHA1 Message Date
lerko 60592ef810 feat(tui): add SLA reporting view
CI / test (pull_request) Successful in 2m35s
CI / lint (pull_request) Successful in 56s
CI / vulncheck (pull_request) Successful in 41s
Full-screen SLA report accessible via [s] from detail panel.
Computes uptime%, downtime, outage count, longest outage, MTTR,
and MTBF from state_changes table. Includes daily breakdown with
bar chart, switchable time periods (24h/7d/30d/90d), and
scrollable viewport. LATE/STALE treated as UP for SLA purposes.
2026-06-04 14:24:39 -04:00
lerko b2e92e8a2a fix(monitor): propagate STALE/LATE child status to group
checkGroup only checked for DOWN/SSL EXP and PENDING. Groups
now reflect STALE and LATE children with proper priority:
DOWN > STALE > LATE > PENDING > UP.
2026-06-04 18:23:57 +00:00
lerko 66b1c662c9 fix(tui): show correct push heartbeat curl command in detail panel 2026-06-04 18:23:57 +00:00
lerko 10c6ec348e fix(tui): show push token and URL in detail panel
Push monitors were missing token/endpoint info in the detail
view, making it impossible to know where to send heartbeats.
2026-06-04 18:23:57 +00:00
lerko ca43621c44 feat(monitor): add STALE state for push monitors
New intermediate state between LATE and DOWN at the midpoint of
the grace period. Gives operators earlier warning that a push
monitor has gone quiet. Includes dedicated orange theme color
across all 5 themes and proper styling in dashboard, detail
panel, and history view.
2026-06-04 18:23:57 +00:00
lerko f23014ab12 feat(alert): add Opsgenie provider
CI / test (pull_request) Successful in 2m37s
CI / lint (pull_request) Successful in 57s
CI / vulncheck (pull_request) Successful in 51s
Support Opsgenie Alert API v2 with US/EU endpoint selection,
configurable priority (P1-P5), and GenieKey auth. TUI form
includes API key, priority picker, and EU instance toggle.
2026-06-04 13:32:14 -04:00
11 changed files with 204 additions and 6 deletions
+32
View File
@@ -110,6 +110,24 @@ func gotifyPayload(priority string) PayloadFunc {
}
}
func opsgeniePayload(priority string) PayloadFunc {
return func(title, message string) ([]byte, error) {
return json.Marshal(map[string]any{
"message": limitMessage(title, 130),
"description": message,
"source": "uptop",
"priority": priority,
})
}
}
func limitMessage(s string, max int) string {
if len(s) <= max {
return s
}
return s[:max]
}
func GetProvider(cfg models.AlertConfig) Provider {
switch cfg.Type {
case "discord":
@@ -173,6 +191,20 @@ func GetProvider(cfg models.AlertConfig) Provider {
Payload: gotifyPayload(priority),
Headers: map[string]string{"X-Gotify-Key": cfg.Settings["token"]},
}
case "opsgenie":
priority := "P3"
if p, ok := cfg.Settings["priority"]; ok && p != "" {
priority = p
}
apiURL := "https://api.opsgenie.com/v2/alerts"
if eu, ok := cfg.Settings["eu"]; ok && eu == "true" {
apiURL = "https://api.eu.opsgenie.com/v2/alerts"
}
return &HTTPProvider{
URL: apiURL,
Payload: opsgeniePayload(priority),
Headers: map[string]string{"Authorization": "GenieKey " + cfg.Settings["api_key"]},
}
default:
return nil
}
+69 -1
View File
@@ -196,8 +196,76 @@ func TestHTTPProviderGotify(t *testing.T) {
}
}
func TestHTTPProviderOpsgenie(t *testing.T) {
var received map[string]any
var authHeader string
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
authHeader = r.Header.Get("Authorization")
json.NewDecoder(r.Body).Decode(&received)
w.WriteHeader(202)
}))
defer srv.Close()
p := GetProvider(models.AlertConfig{Type: "opsgenie", Settings: map[string]string{
"api_key": "test-genie-key",
"priority": "P1",
}})
hp := p.(*HTTPProvider)
hp.URL = srv.URL
if err := p.Send(context.Background(), "Site Down", "mysite.com is unreachable"); err != nil {
t.Fatalf("Send: %v", err)
}
if authHeader != "GenieKey test-genie-key" {
t.Errorf("expected auth 'GenieKey test-genie-key', got '%s'", authHeader)
}
if received["message"] != "Site Down" {
t.Errorf("unexpected message: %v", received["message"])
}
if received["description"] != "mysite.com is unreachable" {
t.Errorf("unexpected description: %v", received["description"])
}
if received["source"] != "uptop" {
t.Errorf("expected source 'uptop', got '%v'", received["source"])
}
if received["priority"] != "P1" {
t.Errorf("expected priority 'P1', got '%v'", received["priority"])
}
}
func TestOpsgenieEUEndpoint(t *testing.T) {
p := GetProvider(models.AlertConfig{Type: "opsgenie", Settings: map[string]string{
"api_key": "key", "eu": "true",
}})
hp := p.(*HTTPProvider)
if hp.URL != "https://api.eu.opsgenie.com/v2/alerts" {
t.Errorf("expected EU URL, got '%s'", hp.URL)
}
}
func TestOpsgenieUSEndpoint(t *testing.T) {
p := GetProvider(models.AlertConfig{Type: "opsgenie", Settings: map[string]string{
"api_key": "key",
}})
hp := p.(*HTTPProvider)
if hp.URL != "https://api.opsgenie.com/v2/alerts" {
t.Errorf("expected US URL, got '%s'", hp.URL)
}
}
func TestLimitMessage(t *testing.T) {
short := "short"
if got := limitMessage(short, 130); got != short {
t.Errorf("expected '%s', got '%s'", short, got)
}
long := string(make([]byte, 200))
if got := limitMessage(long, 130); len(got) != 130 {
t.Errorf("expected length 130, got %d", len(got))
}
}
func TestGetProviderNewTypes(t *testing.T) {
for _, typ := range []string{"telegram", "pagerduty", "pushover", "gotify"} {
for _, typ := range []string{"telegram", "pagerduty", "pushover", "gotify", "opsgenie"} {
p := GetProvider(models.AlertConfig{Type: typ, Settings: map[string]string{
"token": "x", "chat_id": "1", "routing_key": "k", "user": "u", "url": "http://localhost",
}})
+10 -1
View File
@@ -509,6 +509,7 @@ func (e *Engine) checkPush(site models.Site) {
}
overdue := site.LastCheck.Add(interval)
staleMark := overdue.Add(grace / 2)
graceEnd := overdue.Add(grace)
now := time.Now()
@@ -516,6 +517,10 @@ func (e *Engine) checkPush(site models.Site) {
if site.Status != "DOWN" {
e.handleStatusChange(site, "DOWN", 0, 0, "heartbeat missed")
}
} else if now.After(staleMark) {
if site.Status != "STALE" {
e.handleStatusChange(site, "STALE", 0, 0, "heartbeat stale")
}
} else if now.After(overdue) {
if site.Status != "LATE" {
e.handleStatusChange(site, "LATE", 0, 0, "heartbeat overdue")
@@ -743,7 +748,11 @@ func (e *Engine) checkGroup(site models.Site) {
}
if child.Status == "DOWN" || child.Status == "SSL EXP" {
status = "DOWN"
} else if child.Status == "PENDING" && status != "DOWN" {
} else if child.Status == "STALE" && status != "DOWN" {
status = "STALE"
} else if child.Status == "LATE" && status != "DOWN" && status != "STALE" {
status = "LATE"
} else if child.Status == "PENDING" && status != "DOWN" && status != "STALE" && status != "LATE" {
status = "PENDING"
}
}
+20
View File
@@ -574,6 +574,26 @@ func TestCheckPush_OverdueBecomesLate(t *testing.T) {
}
}
func TestCheckPush_OverdueBecomesStale(t *testing.T) {
ms := newMockStore()
e := newTestEngine(ms)
// interval=300, grace=150 (300/2), staleMark=overdue+75
// at 380s: past staleMark(375) but before graceEnd(450)
site := models.Site{
ID: 1, Name: "push", Type: "push", Status: "UP",
Interval: 300,
LastCheck: time.Now().Add(-380 * time.Second),
}
injectSite(e, site)
e.checkPush(site)
s, _ := getSite(e, 1)
if s.Status != "STALE" {
t.Errorf("expected STALE when past midpoint of grace, got %s", s.Status)
}
}
func TestCheckPush_WithinDeadline(t *testing.T) {
ms := newMockStore()
e := newTestEngine(ms)
+4
View File
@@ -22,6 +22,8 @@ func siteOrder(s models.Site) int {
switch s.Status {
case "DOWN", "SSL EXP":
return 0
case "STALE":
return 1
case "LATE":
return 1
case "PENDING":
@@ -142,6 +144,8 @@ func fmtStatus(status string, paused bool, inMaint bool, errCategory ErrorCatego
return dangerStyle.Render(status)
case "LATE":
return warnStyle.Render(status)
case "STALE":
return staleStyle.Render(status)
case "PENDING":
return subtleStyle.Render(status)
default:
+48
View File
@@ -39,6 +39,10 @@ type alertFormData struct {
GotifyURL string
GotifyToken string
GotifyPriority string
// Opsgenie
OpsgenieAPIKey string
OpsgeniePriority string
OpsgenieEU bool
}
func fmtAlertType(t string) string {
@@ -61,6 +65,8 @@ func fmtAlertType(t string) string {
return lipgloss.NewStyle().Foreground(lipgloss.Color("#249DF1")).Render(t)
case "gotify":
return lipgloss.NewStyle().Foreground(lipgloss.Color("#3F8BBA")).Render(t)
case "opsgenie":
return lipgloss.NewStyle().Foreground(lipgloss.Color("#2684FF")).Render(t)
default:
return t
}
@@ -108,6 +114,19 @@ func fmtAlertConfig(alert struct {
return limitStr(url, 34)
}
return subtleStyle.Render("—")
case "opsgenie":
key := alert.Settings["api_key"]
if key != "" {
masked := key
if len(masked) > 8 {
masked = masked[:4] + "…" + masked[len(masked)-4:]
}
if alert.Settings["eu"] == "true" {
return limitStr(fmt.Sprintf("EU %s", masked), 34)
}
return limitStr(masked, 34)
}
return subtleStyle.Render("—")
default:
if val, ok := alert.Settings["url"]; ok {
return limitStr(val, 34)
@@ -238,6 +257,7 @@ func (m *Model) initAlertHuhForm() tea.Cmd {
NtfyPri: "3",
PagerDutySeverity: "critical",
GotifyPriority: "5",
OpsgeniePriority: "P3",
}
if m.editID > 0 {
@@ -275,6 +295,10 @@ func (m *Model) initAlertHuhForm() tea.Cmd {
m.alertFormData.GotifyURL = alert.Settings["url"]
m.alertFormData.GotifyToken = alert.Settings["token"]
m.alertFormData.GotifyPriority = alert.Settings["priority"]
case "opsgenie":
m.alertFormData.OpsgenieAPIKey = alert.Settings["api_key"]
m.alertFormData.OpsgeniePriority = alert.Settings["priority"]
m.alertFormData.OpsgenieEU = alert.Settings["eu"] == "true"
}
break
}
@@ -303,6 +327,7 @@ func (m *Model) initAlertHuhForm() tea.Cmd {
huh.NewOption("PagerDuty", "pagerduty"),
huh.NewOption("Pushover", "pushover"),
huh.NewOption("Gotify", "gotify"),
huh.NewOption("Opsgenie", "opsgenie"),
).Value(&m.alertFormData.AlertType),
).Title("Alert Config"),
huh.NewGroup(
@@ -410,6 +435,23 @@ func (m *Model) initAlertHuhForm() tea.Cmd {
).Title("Gotify Settings").WithHideFunc(func() bool {
return m.alertFormData.AlertType != "gotify"
}),
huh.NewGroup(
huh.NewInput().Title("API Key").
Placeholder("your-opsgenie-api-key").
Value(&m.alertFormData.OpsgenieAPIKey),
huh.NewSelect[string]().Title("Priority").
Options(
huh.NewOption("Critical (P1)", "P1"),
huh.NewOption("High (P2)", "P2"),
huh.NewOption("Moderate (P3)", "P3"),
huh.NewOption("Low (P4)", "P4"),
huh.NewOption("Informational (P5)", "P5"),
).Value(&m.alertFormData.OpsgeniePriority),
huh.NewConfirm().Title("EU Instance?").
Value(&m.alertFormData.OpsgenieEU),
).Title("Opsgenie Settings").WithHideFunc(func() bool {
return m.alertFormData.AlertType != "opsgenie"
}),
).WithTheme(m.theme.HuhTheme())
return m.huhForm.Init()
@@ -446,6 +488,12 @@ func (m *Model) submitAlertForm() {
settings["url"] = d.GotifyURL
settings["token"] = d.GotifyToken
settings["priority"] = d.GotifyPriority
case "opsgenie":
settings["api_key"] = d.OpsgenieAPIKey
settings["priority"] = d.OpsgeniePriority
if d.OpsgenieEU {
settings["eu"] = "true"
}
default:
settings["url"] = d.WebhookURL
}
+1 -1
View File
@@ -158,7 +158,7 @@ func (m Model) viewSitesTab() string {
name = limitStr(name, nameW-2)
}
if (site.Status == "DOWN" || site.Status == "SSL EXP" || site.Status == "LATE") && site.LastError != "" {
if (site.Status == "DOWN" || site.Status == "SSL EXP" || site.Status == "LATE" || site.Status == "STALE") && site.LastError != "" {
nameLen := len([]rune(name))
errSpace := nameW - nameLen - 3
if errSpace > 10 {
+6
View File
@@ -22,6 +22,7 @@ type Theme struct {
// Semantic
Success lipgloss.Color
Warning lipgloss.Color
Stale lipgloss.Color
Danger lipgloss.Color
Info lipgloss.Color
Accent lipgloss.Color
@@ -54,6 +55,7 @@ var themeFlexokiDark = Theme{
Subtle: "#6F6E69",
Success: "#879A39",
Warning: "#D0A215",
Stale: "#DA702C",
Danger: "#D14D41",
Info: "#4385BE",
Accent: "#3AA99F",
@@ -74,6 +76,7 @@ var themeTokyoNight = Theme{
Subtle: "#565f89",
Success: "#9ece6a",
Warning: "#e0af68",
Stale: "#ff9e64",
Danger: "#f7768e",
Info: "#7aa2f7",
Accent: "#7dcfff",
@@ -94,6 +97,7 @@ var themeGruvbox = Theme{
Subtle: "#7c6f64",
Success: "#b8bb26",
Warning: "#fabd2f",
Stale: "#fe8019",
Danger: "#fb4934",
Info: "#83a598",
Accent: "#8ec07c",
@@ -114,6 +118,7 @@ var themeCatppuccinMocha = Theme{
Subtle: "#6c7086",
Success: "#a6e3a1",
Warning: "#f9e2af",
Stale: "#fab387",
Danger: "#f38ba8",
Info: "#89b4fa",
Accent: "#94e2d5",
@@ -134,6 +139,7 @@ var themeNord = Theme{
Subtle: "#4c566a",
Success: "#a3be8c",
Warning: "#ebcb8b",
Stale: "#d08770",
Danger: "#bf616a",
Info: "#81a1c1",
Accent: "#88c0d0",
+2
View File
@@ -20,6 +20,7 @@ var (
subtleStyle lipgloss.Style
specialStyle lipgloss.Style
warnStyle lipgloss.Style
staleStyle lipgloss.Style
dangerStyle lipgloss.Style
titleStyle lipgloss.Style
activeTab lipgloss.Style
@@ -30,6 +31,7 @@ func applyTheme(t Theme) {
subtleStyle = lipgloss.NewStyle().Foreground(t.Subtle)
specialStyle = lipgloss.NewStyle().Foreground(t.Success)
warnStyle = lipgloss.NewStyle().Foreground(t.Warning)
staleStyle = lipgloss.NewStyle().Foreground(t.Stale)
dangerStyle = lipgloss.NewStyle().Foreground(t.Danger)
titleStyle = lipgloss.NewStyle().Foreground(t.Accent).Bold(true)
activeTab = lipgloss.NewStyle().Border(lipgloss.NormalBorder(), false, false, true, false).BorderForeground(t.Accent).Foreground(t.Accent).Bold(true).Padding(0, 1)
+5 -1
View File
@@ -43,7 +43,7 @@ func (m Model) viewDetailPanel() string {
errCat := classifyError(site.LastError, site.Type, site.StatusCode)
row("Status", fmtStatus(site.Status, site.Paused, m.isMonitorInMaintenance(site.ID), errCat))
if (site.Status == "DOWN" || site.Status == "SSL EXP" || site.Status == "LATE") && site.LastError != "" {
if (site.Status == "DOWN" || site.Status == "SSL EXP" || site.Status == "LATE" || site.Status == "STALE") && site.LastError != "" {
errWidth := m.termWidth - chromePadH - 19
if errWidth < 30 {
errWidth = 30
@@ -105,6 +105,10 @@ func (m Model) viewDetailPanel() string {
section("ENDPOINT")
row("Type", site.Type)
if site.Type == "push" && site.Token != "" {
row("Token", site.Token)
row("Push", "curl -X POST -H 'Authorization: Bearer "+site.Token+"' <host>/api/push")
}
if site.URL != "" {
row("URL", site.URL)
}
+7 -2
View File
@@ -119,9 +119,14 @@ func (m Model) buildHistoryContent() string {
ts := sc.ChangedAt.Format("2006-01-02 15:04")
arrow := subtleStyle.Render(sc.FromStatus) + " → "
if sc.ToStatus == "UP" {
switch sc.ToStatus {
case "UP":
arrow += specialStyle.Render(sc.ToStatus)
} else {
case "LATE":
arrow += warnStyle.Render(sc.ToStatus)
case "STALE":
arrow += staleStyle.Render(sc.ToStatus)
default:
arrow += dangerStyle.Render(sc.ToStatus)
}