feat: Stage 2 — alert dashboard with live table and stats
Adds a bubbles/table alert list showing Name, Status, Started (relative time), and Ack By columns. Stats bar shows total/firing/resolved counts. Filter cycles firing → resolved → all with [f]. Auto-refresh fires on the configured interval via tea.Tick. Table scrolls with j/k.
This commit is contained in:
@@ -4,6 +4,8 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
@@ -58,6 +60,38 @@ func (c *Client) do(req *http.Request, out any) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// ListAlerts fetches alerts from the server. status may be "firing", "resolved", or "" for all.
|
||||
func (c *Client) ListAlerts(status string, limit int) ([]Alert, error) {
|
||||
q := url.Values{}
|
||||
if status != "" {
|
||||
q.Set("status", status)
|
||||
}
|
||||
if limit > 0 {
|
||||
q.Set("limit", strconv.Itoa(limit))
|
||||
}
|
||||
path := "/api/alerts"
|
||||
if len(q) > 0 {
|
||||
path += "?" + q.Encode()
|
||||
}
|
||||
|
||||
req, err := c.newRequest(http.MethodGet, path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var alerts []Alert
|
||||
return alerts, c.do(req, &alerts)
|
||||
}
|
||||
|
||||
// GetAlertStats fetches aggregate alert counts.
|
||||
func (c *Client) GetAlertStats() (*AlertStats, error) {
|
||||
req, err := c.newRequest(http.MethodGet, "/api/stats/alerts")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var stats AlertStats
|
||||
return &stats, c.do(req, &stats)
|
||||
}
|
||||
|
||||
// HealthCheck calls GET /healthz (unauthenticated path, no auth needed but we send it anyway).
|
||||
func (c *Client) HealthCheck() error {
|
||||
req, err := http.NewRequest(http.MethodGet, c.baseURL+"/healthz", nil)
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package api
|
||||
|
||||
import "time"
|
||||
|
||||
type Alert struct {
|
||||
ID int64 `json:"id"`
|
||||
Fingerprint string `json:"fingerprint"`
|
||||
Name string `json:"name"`
|
||||
Status string `json:"status"`
|
||||
Labels map[string]string `json:"labels"`
|
||||
Annotations map[string]string `json:"annotations"`
|
||||
StartsAt time.Time `json:"starts_at"`
|
||||
EndsAt *time.Time `json:"ends_at"`
|
||||
GeneratorURL string `json:"generator_url"`
|
||||
ReceivedAt time.Time `json:"received_at"`
|
||||
AcknowledgedByID *int64 `json:"acknowledged_by_id"`
|
||||
AcknowledgedBy string `json:"acknowledged_by"`
|
||||
AcknowledgedAt *time.Time `json:"acknowledged_at"`
|
||||
}
|
||||
|
||||
type AlertStats struct {
|
||||
Total int `json:"total"`
|
||||
Firing int `json:"firing"`
|
||||
Resolved int `json:"resolved"`
|
||||
}
|
||||
Reference in New Issue
Block a user