feat: Archived alerts tab with archive/unarchive actions
Release / build (amd64, linux) (push) Failing after 6s
Release / release (push) Has been skipped
Release / build (amd64, darwin) (push) Failing after 5s
Release / build (arm64, darwin) (push) Failing after 6s
Release / build (arm64, linux) (push) Failing after 11s
Release / build (amd64, linux) (push) Failing after 6s
Release / release (push) Has been skipped
Release / build (amd64, darwin) (push) Failing after 5s
Release / build (arm64, darwin) (push) Failing after 6s
Release / build (arm64, linux) (push) Failing after 11s
Add a fourth tab (Alerts | Archived | Schedule | Users). Archived alerts are fetched lazily on first visit using the archived=true query param on GET /api/alerts. Press x from the Alerts list or detail to archive an alert; the non-archived list refreshes immediately. Press x from the Archived list or detail to unarchive; the archived list refreshes. Ack/unack are disabled in the Archived detail view. New API methods: ArchiveAlert (POST), UnarchiveAlert (DELETE). ArchivedAt field added to the Alert type.
This commit is contained in:
+23
-2
@@ -61,12 +61,16 @@ 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) {
|
||||
// ListAlerts fetches alerts. status may be "firing", "resolved", or "" for all.
|
||||
// Set archived=true to fetch only archived alerts; false returns only non-archived.
|
||||
func (c *Client) ListAlerts(status string, archived bool, limit int) ([]Alert, error) {
|
||||
q := url.Values{}
|
||||
if status != "" {
|
||||
q.Set("status", status)
|
||||
}
|
||||
if archived {
|
||||
q.Set("archived", "true")
|
||||
}
|
||||
if limit > 0 {
|
||||
q.Set("limit", strconv.Itoa(limit))
|
||||
}
|
||||
@@ -83,6 +87,23 @@ func (c *Client) ListAlerts(status string, limit int) ([]Alert, error) {
|
||||
return alerts, c.do(req, &alerts)
|
||||
}
|
||||
|
||||
func (c *Client) ArchiveAlert(id int64) (*Alert, error) {
|
||||
req, err := c.newRequest(http.MethodPost, fmt.Sprintf("/api/alerts/%d/archive", id))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var alert Alert
|
||||
return &alert, c.do(req, &alert)
|
||||
}
|
||||
|
||||
func (c *Client) UnarchiveAlert(id int64) error {
|
||||
req, err := c.newRequest(http.MethodDelete, fmt.Sprintf("/api/alerts/%d/archive", id))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return c.do(req, nil)
|
||||
}
|
||||
|
||||
// GetAlertStats fetches aggregate alert counts.
|
||||
func (c *Client) GetAlertStats() (*AlertStats, error) {
|
||||
req, err := c.newRequest(http.MethodGet, "/api/stats/alerts")
|
||||
|
||||
Reference in New Issue
Block a user