Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1140d773f8 | |||
| e04cfcf433 | |||
| 6834302622 | |||
| 24c2e6003a | |||
| f8e085e610 |
@@ -0,0 +1,57 @@
|
|||||||
|
name: Release
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- 'v*'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
include:
|
||||||
|
- goos: linux
|
||||||
|
goarch: amd64
|
||||||
|
- goos: linux
|
||||||
|
goarch: arm64
|
||||||
|
- goos: darwin
|
||||||
|
goarch: amd64
|
||||||
|
- goos: darwin
|
||||||
|
goarch: arm64
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- uses: actions/setup-go@v5
|
||||||
|
with:
|
||||||
|
go-version-file: go.mod
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
env:
|
||||||
|
GOOS: ${{ matrix.goos }}
|
||||||
|
GOARCH: ${{ matrix.goarch }}
|
||||||
|
run: |
|
||||||
|
go build \
|
||||||
|
-ldflags "-X main.version=${{ github.ref_name }}" \
|
||||||
|
-o terdut-tui-${{ github.ref_name }}-${{ matrix.goos }}-${{ matrix.goarch }} \
|
||||||
|
.
|
||||||
|
|
||||||
|
- uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: terdut-tui-${{ github.ref_name }}-${{ matrix.goos }}-${{ matrix.goarch }}
|
||||||
|
path: terdut-tui-${{ github.ref_name }}-${{ matrix.goos }}-${{ matrix.goarch }}
|
||||||
|
|
||||||
|
release:
|
||||||
|
needs: build
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
steps:
|
||||||
|
- uses: actions/download-artifact@v4
|
||||||
|
with:
|
||||||
|
merge-multiple: true
|
||||||
|
|
||||||
|
- uses: softprops/action-gh-release@v2
|
||||||
|
with:
|
||||||
|
files: 'terdut-tui-*'
|
||||||
@@ -1,6 +1,19 @@
|
|||||||
# terdut-tui
|
# terdut-tui
|
||||||
|
|
||||||
TUI client for [terdut-server](https://github.com/terdut-server), a Prometheus Alertmanager receiver and on-call scheduler.
|
TUI client for [terdut-server](https://github.com/terdut-server), a Prometheus Alertmanager receiver and incident manager. Requires server **v0.4.0+**.
|
||||||
|
|
||||||
|
## Domain model
|
||||||
|
|
||||||
|
The server splits alerts from incidents, and this client mirrors it:
|
||||||
|
|
||||||
|
- **Alert** — Alertmanager's record. Firing or resolved, read-only, no workflow state.
|
||||||
|
- **Incident** — the work item: triggered → acknowledged → resolved, with an
|
||||||
|
assignee, snooze, notes and an append-only timeline. Many alerts to one incident,
|
||||||
|
correlated by Alertmanager's `groupKey`.
|
||||||
|
|
||||||
|
All user actions target incidents. Two server behaviours the UI has to respect:
|
||||||
|
manual resolve is **terminal** (hence the confirmation prompt), and snooze is the
|
||||||
|
non-destructive "not now" alternative.
|
||||||
|
|
||||||
## Tech stack
|
## Tech stack
|
||||||
|
|
||||||
@@ -57,6 +70,11 @@ go run . --self-update
|
|||||||
go build -ldflags="-X main.version=v0.1.0" -o terdut-tui .
|
go build -ldflags="-X main.version=v0.1.0" -o terdut-tui .
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Sections
|
||||||
|
|
||||||
|
`Incidents` (the queue, and the default) · `Alerts` (raw read-only feed) ·
|
||||||
|
`Archived` (archived incidents) · `Schedule` · `Users`
|
||||||
|
|
||||||
## Development stages
|
## Development stages
|
||||||
|
|
||||||
| Stage | Feature |
|
| Stage | Feature |
|
||||||
@@ -66,3 +84,17 @@ go build -ldflags="-X main.version=v0.1.0" -o terdut-tui .
|
|||||||
| 3 | Alert detail: acknowledge, comment, statistics charts |
|
| 3 | Alert detail: acknowledge, comment, statistics charts |
|
||||||
| 4 | On-call schedule calendar view |
|
| 4 | On-call schedule calendar view |
|
||||||
| 5 | User management and API key lifecycle |
|
| 5 | User management and API key lifecycle |
|
||||||
|
| 6 | Incidents: queue, timeline, ack/assign/snooze/resolve, MTTA/MTTR |
|
||||||
|
|
||||||
|
<!-- graymatter:instructions:begin — managed by `graymatter init`; edits inside this block are overwritten -->
|
||||||
|
## Memory (GrayMatter)
|
||||||
|
|
||||||
|
This project has persistent agent memory via the `graymatter` MCP tools:
|
||||||
|
|
||||||
|
- `memory_search` (`agent_id`, `query`) — call at the **start of a task** when prior context might matter.
|
||||||
|
- `memory_add` (`agent_id`, `text`) — call whenever you learn something **durable**: user preferences, decisions, conventions, gotchas.
|
||||||
|
- `memory_reflect` (`action`, `agent`, `text`/`target`) — update or forget stale facts. ⚠ takes `agent`, not `agent_id`.
|
||||||
|
- `checkpoint_save` / `checkpoint_resume` (`agent_id`) — snapshot/restore session state before major refactors or across restarts.
|
||||||
|
|
||||||
|
Use a stable `agent_id` of the form `<project>-<role>` (e.g. `myapp-backend`). Store conclusions, not conversation logs. Err on the side of remembering.
|
||||||
|
<!-- graymatter:instructions:end -->
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
VERSION := $(shell git describe --tags --always --dirty)
|
||||||
|
|
||||||
|
.PHONY: build install test
|
||||||
|
|
||||||
|
build:
|
||||||
|
go build -ldflags "-X main.version=$(VERSION)" -o terdut-tui .
|
||||||
|
|
||||||
|
install:
|
||||||
|
go install -ldflags "-X main.version=$(VERSION)" .
|
||||||
|
|
||||||
|
test:
|
||||||
|
go test ./...
|
||||||
@@ -6,11 +6,37 @@ Written in Go using [Bubbletea](https://github.com/charmbracelet/bubbletea).
|
|||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
- **Alert dashboard** — live view of firing and resolved alerts with auto-refresh
|
- **Incident queue** — open incidents with severity, status, assignee and age, auto-refreshing
|
||||||
- **Alert actions** — acknowledge, comment, and view per-alert statistics
|
- **Incident actions** — acknowledge, assign, snooze, note, resolve and archive
|
||||||
|
- **Timeline** — the full history of an incident, system events and notes together
|
||||||
|
- **Alert feed** — the raw read-only alerts underneath, each linked to its incident
|
||||||
- **On-call schedule** — visual calendar of who is on duty, assign and remove entries
|
- **On-call schedule** — visual calendar of who is on duty, assign and remove entries
|
||||||
|
- **Statistics** — MTTA and MTTR, plus alert frequency by name, hour and day
|
||||||
- **User management** — add and remove users, manage API keys
|
- **User management** — add and remove users, manage API keys
|
||||||
|
|
||||||
|
> Requires terdut-server **v0.4.0 or later**. Earlier servers have no incidents API;
|
||||||
|
> use terdut-tui v0.3.x with those.
|
||||||
|
|
||||||
|
## Alerts and incidents
|
||||||
|
|
||||||
|
The server keeps two objects and this client follows that split:
|
||||||
|
|
||||||
|
- An **alert** is Alertmanager's record — firing or resolved, and read-only here.
|
||||||
|
- An **incident** is the work item. It is what you acknowledge, assign, snooze,
|
||||||
|
discuss and resolve, and it is where all the actions live.
|
||||||
|
|
||||||
|
Incidents are correlated by the `groupKey` Alertmanager already computed from your
|
||||||
|
`group_by` configuration, so several alerts commonly share one incident.
|
||||||
|
|
||||||
|
Two behaviours worth knowing before you press a key:
|
||||||
|
|
||||||
|
- **Resolving is final.** The server treats a manual resolve as terminal: a later
|
||||||
|
occurrence opens a *new* incident rather than reopening this one, and if the alert
|
||||||
|
underneath never stops firing the incident stays closed. The TUI asks for
|
||||||
|
confirmation before doing it.
|
||||||
|
- **Snooze is the "not now" button.** It hides an incident from the default queue
|
||||||
|
without closing it, and expires on its own.
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
Download the latest release binary for your platform from the [releases page](https://github.com/yeniklas/terdut-tui/releases), or build from source:
|
Download the latest release binary for your platform from the [releases page](https://github.com/yeniklas/terdut-tui/releases), or build from source:
|
||||||
@@ -41,13 +67,59 @@ terdut-tui --self-update update to the latest release
|
|||||||
|
|
||||||
### Keybindings
|
### Keybindings
|
||||||
|
|
||||||
|
Global:
|
||||||
|
|
||||||
| Key | Action |
|
| Key | Action |
|
||||||
|-----|--------|
|
|-----|--------|
|
||||||
| `j` / `↓` | Move down |
|
| `j` / `↓` | Move down |
|
||||||
| `k` / `↑` | Move up |
|
| `k` / `↑` | Move up |
|
||||||
| `tab` | Switch section (Alerts / Schedule / Users) |
|
| `tab` / `shift+tab` | Next / previous section |
|
||||||
| `enter` | Select / open detail |
|
| `enter` | Open detail |
|
||||||
| `esc` | Go back |
|
| `esc` | Go back |
|
||||||
| `r` | Refresh |
|
| `r` | Refresh |
|
||||||
| `f` | Filter / cycle filter |
|
| `f` | Cycle filter |
|
||||||
|
| `S` | Statistics |
|
||||||
| `q` | Quit |
|
| `q` | Quit |
|
||||||
|
|
||||||
|
Incidents section:
|
||||||
|
|
||||||
|
| Key | Action |
|
||||||
|
|-----|--------|
|
||||||
|
| `f` | Cycle: open → triggered → acknowledged → resolved → snoozed |
|
||||||
|
| `x` | Archive (resolved incidents only) |
|
||||||
|
|
||||||
|
Incident detail:
|
||||||
|
|
||||||
|
| Key | Action |
|
||||||
|
|-----|--------|
|
||||||
|
| `a` / `A` | Acknowledge / clear acknowledgement |
|
||||||
|
| `R` | Resolve — asks to confirm, and is final |
|
||||||
|
| `s` | Assign to a user |
|
||||||
|
| `z` / `Z` | Snooze for a duration / un-snooze |
|
||||||
|
| `c` | Add a note |
|
||||||
|
| `[` / `]` | Select a note |
|
||||||
|
| `d` | Delete the selected note (your own only) |
|
||||||
|
| `x` | Archive / un-archive |
|
||||||
|
|
||||||
|
Alerts section (read-only):
|
||||||
|
|
||||||
|
| Key | Action |
|
||||||
|
|-----|--------|
|
||||||
|
| `f` | Cycle: firing → resolved → all → archived |
|
||||||
|
| `i` | In detail: jump to the alert's incident |
|
||||||
|
|
||||||
|
Schedule section:
|
||||||
|
|
||||||
|
| Key | Action |
|
||||||
|
|-----|--------|
|
||||||
|
| `+` / `W` | Assign a day / a whole week |
|
||||||
|
| `d` | Remove the assignment |
|
||||||
|
| `←` / `→` | Shift the week window |
|
||||||
|
|
||||||
|
Users section:
|
||||||
|
|
||||||
|
| Key | Action |
|
||||||
|
|-----|--------|
|
||||||
|
| `n` | Create a user |
|
||||||
|
| `d` | Delete a user |
|
||||||
|
| `k` | API keys for the selected user |
|
||||||
|
|||||||
+152
-19
@@ -61,12 +61,20 @@ func (c *Client) do(req *http.Request, out any) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListAlerts fetches alerts from the server. status may be "firing", "resolved", or "" for all.
|
// ListAlerts fetches alerts. status may be "firing", "resolved", or "" for all.
|
||||||
func (c *Client) ListAlerts(status string, limit int) ([]Alert, error) {
|
// Set archived=true to fetch only archived alerts; false returns only non-archived.
|
||||||
|
//
|
||||||
|
// Alerts are read-only on the server — there is nothing to acknowledge or
|
||||||
|
// archive here. This is the raw feed, useful for checking what Alertmanager is
|
||||||
|
// actually sending; the work queue is ListIncidents.
|
||||||
|
func (c *Client) ListAlerts(status string, archived bool, limit int) ([]Alert, error) {
|
||||||
q := url.Values{}
|
q := url.Values{}
|
||||||
if status != "" {
|
if status != "" {
|
||||||
q.Set("status", status)
|
q.Set("status", status)
|
||||||
}
|
}
|
||||||
|
if archived {
|
||||||
|
q.Set("archived", "true")
|
||||||
|
}
|
||||||
if limit > 0 {
|
if limit > 0 {
|
||||||
q.Set("limit", strconv.Itoa(limit))
|
q.Set("limit", strconv.Itoa(limit))
|
||||||
}
|
}
|
||||||
@@ -117,49 +125,172 @@ func (c *Client) GetAlert(id int64) (*Alert, error) {
|
|||||||
return &alert, c.do(req, &alert)
|
return &alert, c.do(req, &alert)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) AcknowledgeAlert(id int64) (*Alert, error) {
|
// ── Incidents ──────────────────────────────────────────────────────────────
|
||||||
req, err := c.newRequest(http.MethodPost, fmt.Sprintf("/api/alerts/%d/acknowledge", id))
|
|
||||||
|
// ListIncidents fetches the work queue. status may be "triggered",
|
||||||
|
// "acknowledged", "resolved", or "" for the server default of open incidents
|
||||||
|
// only. archived and snoozed each switch the list to that set rather than
|
||||||
|
// adding to it, matching the server's filters.
|
||||||
|
func (c *Client) ListIncidents(status string, archived, snoozed bool, limit int) ([]Incident, error) {
|
||||||
|
q := url.Values{}
|
||||||
|
if status != "" {
|
||||||
|
q.Set("status", status)
|
||||||
|
}
|
||||||
|
if archived {
|
||||||
|
q.Set("archived", "true")
|
||||||
|
}
|
||||||
|
if snoozed {
|
||||||
|
q.Set("snoozed", "true")
|
||||||
|
}
|
||||||
|
if limit > 0 {
|
||||||
|
q.Set("limit", strconv.Itoa(limit))
|
||||||
|
}
|
||||||
|
path := "/api/incidents"
|
||||||
|
if len(q) > 0 {
|
||||||
|
path += "?" + q.Encode()
|
||||||
|
}
|
||||||
|
|
||||||
|
req, err := c.newRequest(http.MethodGet, path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var alert Alert
|
var incidents []Incident
|
||||||
return &alert, c.do(req, &alert)
|
return incidents, c.do(req, &incidents)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) UnacknowledgeAlert(id int64) error {
|
// GetIncident returns one incident with its member alerts inline.
|
||||||
req, err := c.newRequest(http.MethodDelete, fmt.Sprintf("/api/alerts/%d/acknowledge", id))
|
func (c *Client) GetIncident(id int64) (*Incident, error) {
|
||||||
|
req, err := c.newRequest(http.MethodGet, fmt.Sprintf("/api/incidents/%d", id))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
var incident Incident
|
||||||
|
return &incident, c.do(req, &incident)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) GetIncidentTimeline(id int64) ([]IncidentEvent, error) {
|
||||||
|
req, err := c.newRequest(http.MethodGet, fmt.Sprintf("/api/incidents/%d/timeline", id))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
var events []IncidentEvent
|
||||||
|
return events, c.do(req, &events)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) AcknowledgeIncident(id int64) (*Incident, error) {
|
||||||
|
req, err := c.newRequest(http.MethodPost, fmt.Sprintf("/api/incidents/%d/acknowledge", id))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
var incident Incident
|
||||||
|
return &incident, c.do(req, &incident)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) UnacknowledgeIncident(id int64) error {
|
||||||
|
req, err := c.newRequest(http.MethodDelete, fmt.Sprintf("/api/incidents/%d/acknowledge", id))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return c.do(req, nil)
|
return c.do(req, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) GetComments(alertID int64) ([]Comment, error) {
|
// ResolveIncident closes an incident by hand. This is terminal on the server: a
|
||||||
req, err := c.newRequest(http.MethodGet, fmt.Sprintf("/api/alerts/%d/comments", alertID))
|
// later occurrence in the same group opens a new incident rather than reopening
|
||||||
|
// this one, and if the alert underneath never stops firing the incident stays
|
||||||
|
// closed. Use SnoozeIncident for "not now".
|
||||||
|
func (c *Client) ResolveIncident(id int64) (*Incident, error) {
|
||||||
|
req, err := c.newRequest(http.MethodPost, fmt.Sprintf("/api/incidents/%d/resolve", id))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var comments []Comment
|
var incident Incident
|
||||||
return comments, c.do(req, &comments)
|
return &incident, c.do(req, &incident)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) AddComment(alertID int64, content string) (*Comment, error) {
|
func (c *Client) AssignIncident(id, userID int64) (*Incident, error) {
|
||||||
req, err := c.newRequestWithBody(http.MethodPost, fmt.Sprintf("/api/alerts/%d/comments", alertID), map[string]string{"content": content})
|
body := struct {
|
||||||
|
UserID int64 `json:"user_id"`
|
||||||
|
}{UserID: userID}
|
||||||
|
req, err := c.newRequestWithBody(http.MethodPost, fmt.Sprintf("/api/incidents/%d/assign", id), body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var comment Comment
|
var incident Incident
|
||||||
return &comment, c.do(req, &comment)
|
return &incident, c.do(req, &incident)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) DeleteComment(alertID, commentID int64) error {
|
// SnoozeIncident hides an incident from the default queue for a duration,
|
||||||
req, err := c.newRequest(http.MethodDelete, fmt.Sprintf("/api/alerts/%d/comments/%d", alertID, commentID))
|
// without closing it.
|
||||||
|
func (c *Client) SnoozeIncident(id int64, duration string) (*Incident, error) {
|
||||||
|
body := struct {
|
||||||
|
Duration string `json:"duration"`
|
||||||
|
}{Duration: duration}
|
||||||
|
req, err := c.newRequestWithBody(http.MethodPost, fmt.Sprintf("/api/incidents/%d/snooze", id), body)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
var incident Incident
|
||||||
|
return &incident, c.do(req, &incident)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) UnsnoozeIncident(id int64) error {
|
||||||
|
req, err := c.newRequest(http.MethodDelete, fmt.Sprintf("/api/incidents/%d/snooze", id))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return c.do(req, nil)
|
return c.do(req, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Client) ArchiveIncident(id int64) (*Incident, error) {
|
||||||
|
req, err := c.newRequest(http.MethodPost, fmt.Sprintf("/api/incidents/%d/archive", id))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
var incident Incident
|
||||||
|
return &incident, c.do(req, &incident)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) UnarchiveIncident(id int64) error {
|
||||||
|
req, err := c.newRequest(http.MethodDelete, fmt.Sprintf("/api/incidents/%d/archive", id))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return c.do(req, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddNote appends a note to the incident's timeline.
|
||||||
|
func (c *Client) AddNote(incidentID int64, content string) (*IncidentEvent, error) {
|
||||||
|
req, err := c.newRequestWithBody(http.MethodPost,
|
||||||
|
fmt.Sprintf("/api/incidents/%d/notes", incidentID), map[string]string{"content": content})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
var event IncidentEvent
|
||||||
|
return &event, c.do(req, &event)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteNote removes one of your own notes. Only notes are deletable — the rest
|
||||||
|
// of the timeline is a record of what happened.
|
||||||
|
func (c *Client) DeleteNote(incidentID, eventID int64) error {
|
||||||
|
req, err := c.newRequest(http.MethodDelete,
|
||||||
|
fmt.Sprintf("/api/incidents/%d/notes/%d", incidentID, eventID))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return c.do(req, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) GetIncidentStats() (*IncidentStats, error) {
|
||||||
|
req, err := c.newRequest(http.MethodGet, "/api/stats/incidents")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
var stats IncidentStats
|
||||||
|
return &stats, c.do(req, &stats)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Statistics ─────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
func (c *Client) GetTopAlerts(limit int) ([]TopAlert, error) {
|
func (c *Client) GetTopAlerts(limit int) ([]TopAlert, error) {
|
||||||
req, err := c.newRequest(http.MethodGet, fmt.Sprintf("/api/stats/alerts/top?limit=%d", limit))
|
req, err := c.newRequest(http.MethodGet, fmt.Sprintf("/api/stats/alerts/top?limit=%d", limit))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -211,7 +342,9 @@ func (c *Client) GetCurrentOnCall() (*ScheduleEntry, error) {
|
|||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
if resp.StatusCode >= 400 {
|
if resp.StatusCode >= 400 {
|
||||||
var e struct{ Error string `json:"error"` }
|
var e struct {
|
||||||
|
Error string `json:"error"`
|
||||||
|
}
|
||||||
_ = json.NewDecoder(resp.Body).Decode(&e)
|
_ = json.NewDecoder(resp.Body).Decode(&e)
|
||||||
if e.Error != "" {
|
if e.Error != "" {
|
||||||
return nil, fmt.Errorf("server returned %d: %s", resp.StatusCode, e.Error)
|
return nil, fmt.Errorf("server returned %d: %s", resp.StatusCode, e.Error)
|
||||||
|
|||||||
+106
-10
@@ -2,6 +2,9 @@ package api
|
|||||||
|
|
||||||
import "time"
|
import "time"
|
||||||
|
|
||||||
|
// Alert is the server's record of what Alertmanager said. It is read-only:
|
||||||
|
// acknowledging, assigning, noting and resolving all happen on the Incident an
|
||||||
|
// alert belongs to.
|
||||||
type Alert struct {
|
type Alert struct {
|
||||||
ID int64 `json:"id"`
|
ID int64 `json:"id"`
|
||||||
Fingerprint string `json:"fingerprint"`
|
Fingerprint string `json:"fingerprint"`
|
||||||
@@ -13,9 +16,99 @@ type Alert struct {
|
|||||||
EndsAt *time.Time `json:"ends_at"`
|
EndsAt *time.Time `json:"ends_at"`
|
||||||
GeneratorURL string `json:"generator_url"`
|
GeneratorURL string `json:"generator_url"`
|
||||||
ReceivedAt time.Time `json:"received_at"`
|
ReceivedAt time.Time `json:"received_at"`
|
||||||
AcknowledgedByID *int64 `json:"acknowledged_by_id"`
|
ArchivedAt *time.Time `json:"archived_at,omitempty"`
|
||||||
AcknowledgedBy string `json:"acknowledged_by"`
|
|
||||||
AcknowledgedAt *time.Time `json:"acknowledged_at"`
|
// IncidentID is the most recent incident this alert belongs to. An alert row
|
||||||
|
// is reused across occurrences of the same fingerprint, so it belongs to a
|
||||||
|
// series of incidents over its life and this is only the newest.
|
||||||
|
IncidentID *int64 `json:"incident_id,omitempty"`
|
||||||
|
|
||||||
|
// ResolutionSource records why a resolved alert left the firing state:
|
||||||
|
// "alertmanager" for a real resolved webhook, "expiry" when the server
|
||||||
|
// inferred it after the alert stopped being refreshed.
|
||||||
|
ResolutionSource *string `json:"resolution_source,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Incident statuses.
|
||||||
|
const (
|
||||||
|
StatusTriggered = "triggered"
|
||||||
|
StatusAcknowledged = "acknowledged"
|
||||||
|
StatusResolved = "resolved"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Incident is the work item: what a person acknowledges, assigns, snoozes,
|
||||||
|
// discusses and resolves. Many alerts map to one incident, correlated by the
|
||||||
|
// groupKey Alertmanager computed from the operator's group_by configuration.
|
||||||
|
type Incident struct {
|
||||||
|
ID int64 `json:"id"`
|
||||||
|
GroupKey string `json:"group_key"`
|
||||||
|
Title string `json:"title"`
|
||||||
|
GroupLabels map[string]string `json:"group_labels"`
|
||||||
|
Status string `json:"status"`
|
||||||
|
|
||||||
|
// Severity is a high-water mark across the incident's alerts, never lowered,
|
||||||
|
// so a resolved incident still says how bad it got.
|
||||||
|
Severity string `json:"severity,omitempty"`
|
||||||
|
|
||||||
|
TriggeredAt time.Time `json:"triggered_at"`
|
||||||
|
|
||||||
|
AcknowledgedByID *int64 `json:"acknowledged_by_id,omitempty"`
|
||||||
|
AcknowledgedBy string `json:"acknowledged_by,omitempty"`
|
||||||
|
AcknowledgedAt *time.Time `json:"acknowledged_at,omitempty"`
|
||||||
|
|
||||||
|
AssignedToID *int64 `json:"assigned_to_id,omitempty"`
|
||||||
|
AssignedTo string `json:"assigned_to,omitempty"`
|
||||||
|
|
||||||
|
SnoozedUntil *time.Time `json:"snoozed_until,omitempty"`
|
||||||
|
|
||||||
|
ResolvedAt *time.Time `json:"resolved_at,omitempty"`
|
||||||
|
|
||||||
|
// ResolutionSource is "alerts" when every alert stopped firing, or "manual"
|
||||||
|
// when a person closed it. Treat the value set as open.
|
||||||
|
ResolutionSource *string `json:"resolution_source,omitempty"`
|
||||||
|
|
||||||
|
ArchivedAt *time.Time `json:"archived_at,omitempty"`
|
||||||
|
|
||||||
|
// Alerts is populated by GET /api/incidents/{id} only.
|
||||||
|
Alerts []Alert `json:"alerts,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsSnoozed reports whether the incident is currently quietened. A snooze
|
||||||
|
// expires by falling into the past; nothing on the server sweeps it.
|
||||||
|
func (i Incident) IsSnoozed() bool {
|
||||||
|
return i.SnoozedUntil != nil && i.SnoozedUntil.After(time.Now())
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsOpen reports whether the incident is still work in progress.
|
||||||
|
func (i Incident) IsOpen() bool { return i.ResolvedAt == nil }
|
||||||
|
|
||||||
|
// Incident timeline event types written by the server. New ones may be added,
|
||||||
|
// so render unrecognised types generically rather than dropping them.
|
||||||
|
const (
|
||||||
|
EventTriggered = "triggered"
|
||||||
|
EventAlertAdded = "alert_added"
|
||||||
|
EventAlertResolved = "alert_resolved"
|
||||||
|
EventAcknowledged = "acknowledged"
|
||||||
|
EventUnacknowledged = "unacknowledged"
|
||||||
|
EventAssigned = "assigned"
|
||||||
|
EventSnoozed = "snoozed"
|
||||||
|
EventUnsnoozed = "unsnoozed"
|
||||||
|
EventResolved = "resolved"
|
||||||
|
EventNote = "note"
|
||||||
|
)
|
||||||
|
|
||||||
|
// IncidentEvent is one entry in an incident's timeline. An empty Username means
|
||||||
|
// the server acted rather than a person. On an "assigned" event the user is the
|
||||||
|
// assignee, not the actor.
|
||||||
|
type IncidentEvent struct {
|
||||||
|
ID int64 `json:"id"`
|
||||||
|
IncidentID int64 `json:"incident_id"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
UserID *int64 `json:"user_id,omitempty"`
|
||||||
|
Username string `json:"username,omitempty"`
|
||||||
|
AlertID *int64 `json:"alert_id,omitempty"`
|
||||||
|
Detail string `json:"detail,omitempty"`
|
||||||
|
CreatedAt time.Time `json:"created_at"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type AlertStats struct {
|
type AlertStats struct {
|
||||||
@@ -24,13 +117,16 @@ type AlertStats struct {
|
|||||||
Resolved int `json:"resolved"`
|
Resolved int `json:"resolved"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Comment struct {
|
// IncidentStats carries the queue counts plus mean time to acknowledge and to
|
||||||
ID int64 `json:"id"`
|
// resolve. Both averages are nil until something has actually been acknowledged
|
||||||
AlertID int64 `json:"alert_id"`
|
// or resolved — that is "no data", not zero.
|
||||||
UserID int64 `json:"user_id"`
|
type IncidentStats struct {
|
||||||
Username string `json:"username"`
|
Total int `json:"total"`
|
||||||
Content string `json:"content"`
|
Triggered int `json:"triggered"`
|
||||||
CreatedAt time.Time `json:"created_at"`
|
Acknowledged int `json:"acknowledged"`
|
||||||
|
Resolved int `json:"resolved"`
|
||||||
|
MTTASeconds *float64 `json:"mtta_seconds"`
|
||||||
|
MTTRSeconds *float64 `json:"mttr_seconds"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type TopAlert struct {
|
type TopAlert struct {
|
||||||
|
|||||||
+388
-139
@@ -18,20 +18,27 @@ import (
|
|||||||
type section int
|
type section int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
sectionAlerts section = iota
|
// Incidents lead: they are the work. Alerts is the raw feed underneath.
|
||||||
|
sectionIncidents section = iota
|
||||||
|
sectionAlerts
|
||||||
|
sectionArchived
|
||||||
sectionSchedule
|
sectionSchedule
|
||||||
sectionUsers
|
sectionUsers
|
||||||
|
|
||||||
|
sectionCount = 5
|
||||||
)
|
)
|
||||||
|
|
||||||
type mode int
|
type mode int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
modeDashboard mode = iota
|
modeDashboard mode = iota
|
||||||
modeDetail
|
modeIncidentDetail
|
||||||
modeComment
|
modeAlertDetail
|
||||||
modeConfirmDelete
|
modeNote
|
||||||
|
modeSnooze
|
||||||
|
modeConfirm
|
||||||
modeStats
|
modeStats
|
||||||
modeScheduleUserPicker
|
modeUserPicker
|
||||||
modeUserCreate
|
modeUserCreate
|
||||||
modeAPIKeyMenu
|
modeAPIKeyMenu
|
||||||
modeAPIKeyCreate
|
modeAPIKeyCreate
|
||||||
@@ -42,28 +49,70 @@ const (
|
|||||||
type confirmTarget int
|
type confirmTarget int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
confirmDeleteComment confirmTarget = iota
|
confirmDeleteNote confirmTarget = iota
|
||||||
|
confirmResolveIncident
|
||||||
confirmDeleteScheduleEntry
|
confirmDeleteScheduleEntry
|
||||||
confirmDeleteUser
|
confirmDeleteUser
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// pickerTarget says what the user picker is choosing a person for.
|
||||||
|
type pickerTarget int
|
||||||
|
|
||||||
|
const (
|
||||||
|
pickerSchedule pickerTarget = iota
|
||||||
|
pickerIncidentAssignee
|
||||||
|
)
|
||||||
|
|
||||||
|
// incidentFilters is the cycle the f key walks in the Incidents section. The
|
||||||
|
// empty string is the server default: open, unsnoozed incidents — the queue.
|
||||||
|
var incidentFilters = []string{"", api.StatusTriggered, api.StatusAcknowledged, api.StatusResolved, "snoozed"}
|
||||||
|
|
||||||
|
// alertFilters is the equivalent cycle for the raw alert feed.
|
||||||
|
var alertFilters = []string{"firing", "resolved", "", "archived"}
|
||||||
|
|
||||||
|
// incidentQuery translates a filter from the cycle into server query terms.
|
||||||
|
func incidentQuery(filter string) (status string, snoozed bool) {
|
||||||
|
if filter == "snoozed" {
|
||||||
|
return "", true
|
||||||
|
}
|
||||||
|
return filter, false
|
||||||
|
}
|
||||||
|
|
||||||
|
// filterLabel renders a filter for the status bar.
|
||||||
|
func filterLabel(filter string) string {
|
||||||
|
if filter == "" {
|
||||||
|
return "open"
|
||||||
|
}
|
||||||
|
return filter
|
||||||
|
}
|
||||||
|
|
||||||
// ── Messages ───────────────────────────────────────────────────────────────
|
// ── Messages ───────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
// dashboard
|
// dashboard
|
||||||
type connectedMsg struct{}
|
type connectedMsg struct{}
|
||||||
type connectErrMsg struct{ err error }
|
type connectErrMsg struct{ err error }
|
||||||
|
type incidentsFetchedMsg struct{ incidents []api.Incident }
|
||||||
|
type archivedIncidentsFetchedMsg struct{ incidents []api.Incident }
|
||||||
|
type incidentActionDoneMsg struct {
|
||||||
|
incidents []api.Incident
|
||||||
|
status string
|
||||||
|
}
|
||||||
type alertsFetchedMsg struct{ alerts []api.Alert }
|
type alertsFetchedMsg struct{ alerts []api.Alert }
|
||||||
type statsFetchedMsg struct{ stats api.AlertStats }
|
type statsFetchedMsg struct {
|
||||||
|
incidents api.IncidentStats
|
||||||
|
alerts api.AlertStats
|
||||||
|
}
|
||||||
type fetchDataErrMsg struct{ err error }
|
type fetchDataErrMsg struct{ err error }
|
||||||
type tickMsg time.Time
|
type tickMsg time.Time
|
||||||
type clearStatusMsg struct{}
|
type clearStatusMsg struct{}
|
||||||
|
|
||||||
// detail
|
// detail
|
||||||
type alertDetailFetchedMsg struct {
|
type incidentDetailFetchedMsg struct {
|
||||||
alert api.Alert
|
incident api.Incident
|
||||||
comments []api.Comment
|
timeline []api.IncidentEvent
|
||||||
}
|
}
|
||||||
type alertDetailErrMsg struct{ err error }
|
type alertDetailFetchedMsg struct{ alert api.Alert }
|
||||||
|
type detailErrMsg struct{ err error }
|
||||||
type actionErrMsg struct{ err error }
|
type actionErrMsg struct{ err error }
|
||||||
type detailStatsFetchedMsg struct {
|
type detailStatsFetchedMsg struct {
|
||||||
top []api.TopAlert
|
top []api.TopAlert
|
||||||
@@ -108,24 +157,41 @@ type Model struct {
|
|||||||
loading bool
|
loading bool
|
||||||
err error
|
err error
|
||||||
statusMsg string
|
statusMsg string
|
||||||
|
incidentStats *api.IncidentStats
|
||||||
|
alertStats *api.AlertStats
|
||||||
|
|
||||||
|
// Incidents
|
||||||
|
incidents []api.Incident
|
||||||
|
incidentFilter string
|
||||||
|
incidentTable table.Model
|
||||||
|
|
||||||
|
// Alerts (read-only feed)
|
||||||
alerts []api.Alert
|
alerts []api.Alert
|
||||||
stats *api.AlertStats
|
alertFilter string
|
||||||
filterStatus string
|
|
||||||
alertTable table.Model
|
alertTable table.Model
|
||||||
|
|
||||||
// Detail
|
// Archived incidents
|
||||||
selectedAlert api.Alert
|
archivedIncidents []api.Incident
|
||||||
comments []api.Comment
|
archivedLoading bool
|
||||||
commentCursor int
|
archivedTable table.Model
|
||||||
|
|
||||||
|
// Incident detail
|
||||||
|
selectedIncident api.Incident
|
||||||
|
timeline []api.IncidentEvent
|
||||||
|
noteCursor int
|
||||||
detailLoading bool
|
detailLoading bool
|
||||||
detailViewport viewport.Model
|
detailViewport viewport.Model
|
||||||
|
|
||||||
// Comment compose
|
// Alert detail
|
||||||
commentInput textinput.Model
|
selectedAlert api.Alert
|
||||||
|
|
||||||
// Confirm delete
|
// Note compose & snooze
|
||||||
|
noteInput textinput.Model
|
||||||
|
snoozeInput textinput.Model
|
||||||
|
|
||||||
|
// Confirm
|
||||||
confirmTarget confirmTarget
|
confirmTarget confirmTarget
|
||||||
pendingDeleteID int64 // comment ID
|
pendingDeleteID int64 // note event ID
|
||||||
pendingDeleteEntry *api.ScheduleEntry
|
pendingDeleteEntry *api.ScheduleEntry
|
||||||
|
|
||||||
// Stats
|
// Stats
|
||||||
@@ -134,6 +200,9 @@ type Model struct {
|
|||||||
dayStats []api.DayStat
|
dayStats []api.DayStat
|
||||||
statsLoading bool
|
statsLoading bool
|
||||||
statsViewport viewport.Model
|
statsViewport viewport.Model
|
||||||
|
// statsReturnMode is where esc goes back to, since stats opens from both
|
||||||
|
// the dashboard and an incident.
|
||||||
|
statsReturnMode mode
|
||||||
|
|
||||||
// Schedule
|
// Schedule
|
||||||
scheduleWindow time.Time
|
scheduleWindow time.Time
|
||||||
@@ -143,10 +212,11 @@ type Model struct {
|
|||||||
scheduleLoading bool
|
scheduleLoading bool
|
||||||
scheduleTable table.Model
|
scheduleTable table.Model
|
||||||
|
|
||||||
// User picker (schedule assignment)
|
// User picker (schedule assignment and incident assignee)
|
||||||
users []api.User
|
users []api.User
|
||||||
usersLoading bool
|
usersLoading bool
|
||||||
userPickerTable table.Model
|
userPickerTable table.Model
|
||||||
|
pickerTarget pickerTarget
|
||||||
pickerAssignWeek bool
|
pickerAssignWeek bool
|
||||||
|
|
||||||
// User management section
|
// User management section
|
||||||
@@ -165,9 +235,15 @@ type Model struct {
|
|||||||
func NewModel(client *api.Client, serverURL string, refreshInterval time.Duration) Model {
|
func NewModel(client *api.Client, serverURL string, refreshInterval time.Duration) Model {
|
||||||
ts := defaultTableStyles()
|
ts := defaultTableStyles()
|
||||||
|
|
||||||
|
incidentT := table.New(table.WithFocused(true))
|
||||||
|
incidentT.SetStyles(ts)
|
||||||
|
|
||||||
alertT := table.New(table.WithFocused(true))
|
alertT := table.New(table.WithFocused(true))
|
||||||
alertT.SetStyles(ts)
|
alertT.SetStyles(ts)
|
||||||
|
|
||||||
|
archivedT := table.New(table.WithFocused(true))
|
||||||
|
archivedT.SetStyles(ts)
|
||||||
|
|
||||||
schedT := table.New(table.WithFocused(true))
|
schedT := table.New(table.WithFocused(true))
|
||||||
schedT.SetStyles(ts)
|
schedT.SetStyles(ts)
|
||||||
|
|
||||||
@@ -177,9 +253,13 @@ func NewModel(client *api.Client, serverURL string, refreshInterval time.Duratio
|
|||||||
manageT := table.New(table.WithFocused(true))
|
manageT := table.New(table.WithFocused(true))
|
||||||
manageT.SetStyles(ts)
|
manageT.SetStyles(ts)
|
||||||
|
|
||||||
ti := textinput.New()
|
noteIn := textinput.New()
|
||||||
ti.Placeholder = "type your comment…"
|
noteIn.Placeholder = "type your note…"
|
||||||
ti.CharLimit = 1000
|
noteIn.CharLimit = 1000
|
||||||
|
|
||||||
|
snoozeIn := textinput.New()
|
||||||
|
snoozeIn.Placeholder = "duration, e.g. 2h or 30m"
|
||||||
|
snoozeIn.CharLimit = 16
|
||||||
|
|
||||||
usernameIn := textinput.New()
|
usernameIn := textinput.New()
|
||||||
usernameIn.Placeholder = "username"
|
usernameIn.Placeholder = "username"
|
||||||
@@ -198,19 +278,28 @@ func NewModel(client *api.Client, serverURL string, refreshInterval time.Duratio
|
|||||||
revokeIn.CharLimit = 20
|
revokeIn.CharLimit = 20
|
||||||
|
|
||||||
now := time.Now().UTC()
|
now := time.Now().UTC()
|
||||||
window := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.UTC)
|
today := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.UTC)
|
||||||
|
weekday := int(today.Weekday())
|
||||||
|
if weekday == 0 {
|
||||||
|
weekday = 7 // ISO: Sunday = 7
|
||||||
|
}
|
||||||
|
window := today.AddDate(0, 0, -(weekday - 1))
|
||||||
|
|
||||||
return Model{
|
return Model{
|
||||||
client: client,
|
client: client,
|
||||||
serverURL: serverURL,
|
serverURL: serverURL,
|
||||||
refreshInterval: refreshInterval,
|
refreshInterval: refreshInterval,
|
||||||
activeSection: sectionAlerts,
|
activeSection: sectionIncidents,
|
||||||
mode: modeDashboard,
|
mode: modeDashboard,
|
||||||
loading: true,
|
loading: true,
|
||||||
filterStatus: "firing",
|
incidentFilter: "",
|
||||||
commentCursor: -1,
|
alertFilter: "firing",
|
||||||
|
noteCursor: -1,
|
||||||
|
incidentTable: incidentT,
|
||||||
alertTable: alertT,
|
alertTable: alertT,
|
||||||
commentInput: ti,
|
archivedTable: archivedT,
|
||||||
|
noteInput: noteIn,
|
||||||
|
snoozeInput: snoozeIn,
|
||||||
scheduleWindow: window,
|
scheduleWindow: window,
|
||||||
scheduleTable: schedT,
|
scheduleTable: schedT,
|
||||||
userPickerTable: pickerT,
|
userPickerTable: pickerT,
|
||||||
@@ -239,24 +328,28 @@ func defaultTableStyles() table.Styles {
|
|||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *Model) rebuildIncidentTable() {
|
||||||
|
m.incidentTable.SetColumns(incidentColumns(m.width))
|
||||||
|
m.incidentTable.SetRows(incidentRows(m.incidents))
|
||||||
|
m.incidentTable.SetHeight(tableHeight(m.height, 8))
|
||||||
|
}
|
||||||
|
|
||||||
func (m *Model) rebuildTable() {
|
func (m *Model) rebuildTable() {
|
||||||
m.alertTable.SetColumns(alertColumns(m.width))
|
m.alertTable.SetColumns(alertColumns(m.width))
|
||||||
m.alertTable.SetRows(alertRows(m.alerts))
|
m.alertTable.SetRows(alertRows(m.alerts))
|
||||||
h := m.height - 8
|
m.alertTable.SetHeight(tableHeight(m.height, 8))
|
||||||
if h < 1 {
|
|
||||||
h = 1
|
|
||||||
}
|
}
|
||||||
m.alertTable.SetHeight(h)
|
|
||||||
|
func (m *Model) rebuildArchivedTable() {
|
||||||
|
m.archivedTable.SetColumns(incidentColumns(m.width))
|
||||||
|
m.archivedTable.SetRows(incidentRows(m.archivedIncidents))
|
||||||
|
m.archivedTable.SetHeight(tableHeight(m.height, 8))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Model) rebuildScheduleTable() {
|
func (m *Model) rebuildScheduleTable() {
|
||||||
m.scheduleTable.SetColumns(scheduleColumns(m.width))
|
m.scheduleTable.SetColumns(scheduleColumns(m.width))
|
||||||
m.scheduleTable.SetRows(scheduleRows(m.scheduleDays))
|
m.scheduleTable.SetRows(scheduleRows(m.scheduleDays))
|
||||||
h := m.height - 10
|
m.scheduleTable.SetHeight(tableHeight(m.height, 10))
|
||||||
if h < 1 {
|
|
||||||
h = 1
|
|
||||||
}
|
|
||||||
m.scheduleTable.SetHeight(h)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Model) rebuildUserPickerTable() {
|
func (m *Model) rebuildUserPickerTable() {
|
||||||
@@ -266,11 +359,7 @@ func (m *Model) rebuildUserPickerTable() {
|
|||||||
rows[i] = table.Row{u.Username, u.Email}
|
rows[i] = table.Row{u.Username, u.Email}
|
||||||
}
|
}
|
||||||
m.userPickerTable.SetRows(rows)
|
m.userPickerTable.SetRows(rows)
|
||||||
h := m.height - 10
|
m.userPickerTable.SetHeight(tableHeight(m.height, 10))
|
||||||
if h < 1 {
|
|
||||||
h = 1
|
|
||||||
}
|
|
||||||
m.userPickerTable.SetHeight(h)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Model) rebuildUserManageTable() {
|
func (m *Model) rebuildUserManageTable() {
|
||||||
@@ -280,27 +369,37 @@ func (m *Model) rebuildUserManageTable() {
|
|||||||
rows[i] = table.Row{u.Username, u.Email, u.CreatedAt.UTC().Format("2006-01-02")}
|
rows[i] = table.Row{u.Username, u.Email, u.CreatedAt.UTC().Format("2006-01-02")}
|
||||||
}
|
}
|
||||||
m.userManageTable.SetRows(rows)
|
m.userManageTable.SetRows(rows)
|
||||||
h := m.height - 10
|
m.userManageTable.SetHeight(tableHeight(m.height, 10))
|
||||||
|
}
|
||||||
|
|
||||||
|
func tableHeight(windowHeight, chrome int) int {
|
||||||
|
h := windowHeight - chrome
|
||||||
if h < 1 {
|
if h < 1 {
|
||||||
h = 1
|
h = 1
|
||||||
}
|
}
|
||||||
m.userManageTable.SetHeight(h)
|
return h
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Model) refreshDetailContent() {
|
func (m *Model) refreshDetailContent() {
|
||||||
if m.width == 0 {
|
if m.width == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
m.detailViewport.SetContent(buildDetailContent(m.selectedAlert, m.comments, m.commentCursor, m.width))
|
if m.mode == modeAlertDetail {
|
||||||
|
m.detailViewport.SetContent(buildAlertDetailContent(m.selectedAlert, m.width))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
m.detailViewport.SetContent(
|
||||||
|
buildIncidentDetailContent(m.selectedIncident, m.timeline, m.noteCursor, m.width))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Model) refreshStatsContent() {
|
func (m *Model) refreshStatsContent() {
|
||||||
m.statsViewport.SetContent(buildStatsContent(m.topAlerts, m.hourStats, m.dayStats, m.width))
|
m.statsViewport.SetContent(
|
||||||
|
buildStatsContent(m.incidentStats, m.topAlerts, m.hourStats, m.dayStats, m.width))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m Model) detailViewportHeight() int {
|
func (m Model) detailViewportHeight() int {
|
||||||
h := m.height - 5
|
h := m.height - 5
|
||||||
if m.mode == modeComment {
|
if m.mode == modeNote || m.mode == modeSnooze {
|
||||||
h -= 2
|
h -= 2
|
||||||
}
|
}
|
||||||
if h < 1 {
|
if h < 1 {
|
||||||
@@ -309,22 +408,57 @@ func (m Model) detailViewportHeight() int {
|
|||||||
return h
|
return h
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// noteEvents filters a timeline down to the deletable entries, which is what
|
||||||
|
// the [ and ] cursor walks.
|
||||||
|
func noteEvents(timeline []api.IncidentEvent) []api.IncidentEvent {
|
||||||
|
notes := make([]api.IncidentEvent, 0, len(timeline))
|
||||||
|
for _, e := range timeline {
|
||||||
|
if e.Type == api.EventNote {
|
||||||
|
notes = append(notes, e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return notes
|
||||||
|
}
|
||||||
|
|
||||||
// ── Column definitions ─────────────────────────────────────────────────────
|
// ── Column definitions ─────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
func incidentColumns(width int) []table.Column {
|
||||||
|
const sevW, statusW, timeW = 9, 15, 12
|
||||||
|
titleW := width/2 - 10
|
||||||
|
if titleW < 20 {
|
||||||
|
titleW = 20
|
||||||
|
}
|
||||||
|
// 10 = bubbles' Padding(0, 1) on each of the five cells.
|
||||||
|
assigneeW := width - sevW - titleW - statusW - timeW - 10
|
||||||
|
if assigneeW < 8 {
|
||||||
|
assigneeW = 8
|
||||||
|
}
|
||||||
|
return []table.Column{
|
||||||
|
{Title: "Sev", Width: sevW},
|
||||||
|
{Title: "Incident", Width: titleW},
|
||||||
|
{Title: "Status", Width: statusW},
|
||||||
|
{Title: "Assignee", Width: assigneeW},
|
||||||
|
{Title: "Triggered", Width: timeW},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func alertColumns(width int) []table.Column {
|
func alertColumns(width int) []table.Column {
|
||||||
nameW := width/2 - 8
|
const statusW, timeW = 10, 12
|
||||||
|
nameW := width/2 - 14
|
||||||
if nameW < 20 {
|
if nameW < 20 {
|
||||||
nameW = 20
|
nameW = 20
|
||||||
}
|
}
|
||||||
ackW := width - nameW - 10 - 12 - 6
|
// 10 = bubbles' Padding(0, 1) on each of the five cells.
|
||||||
if ackW < 8 {
|
incW := width - nameW - statusW - 2*timeW - 10
|
||||||
ackW = 8
|
if incW < 8 {
|
||||||
|
incW = 8
|
||||||
}
|
}
|
||||||
return []table.Column{
|
return []table.Column{
|
||||||
{Title: "Name", Width: nameW},
|
{Title: "Name", Width: nameW},
|
||||||
{Title: "Status", Width: 10},
|
{Title: "Status", Width: statusW},
|
||||||
{Title: "Started", Width: 12},
|
{Title: "Started", Width: timeW},
|
||||||
{Title: "Ack By", Width: ackW},
|
{Title: "Last Seen", Width: timeW},
|
||||||
|
{Title: "Incident", Width: incW},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -368,11 +502,38 @@ func userManageColumns(width int) []table.Column {
|
|||||||
|
|
||||||
// ── Row builders ───────────────────────────────────────────────────────────
|
// ── Row builders ───────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
func incidentRows(incidents []api.Incident) []table.Row {
|
||||||
|
now := time.Now()
|
||||||
|
rows := make([]table.Row, len(incidents))
|
||||||
|
for i, inc := range incidents {
|
||||||
|
severity := inc.Severity
|
||||||
|
if severity == "" {
|
||||||
|
severity = "—"
|
||||||
|
}
|
||||||
|
// bubbles' table renders plain strings, so a snoozed incident is marked
|
||||||
|
// in the status cell rather than styled.
|
||||||
|
status := inc.Status
|
||||||
|
if inc.IsSnoozed() {
|
||||||
|
status += " (zzz)"
|
||||||
|
}
|
||||||
|
assignee := inc.AssignedTo
|
||||||
|
if assignee == "" {
|
||||||
|
assignee = "—"
|
||||||
|
}
|
||||||
|
rows[i] = table.Row{severity, inc.Title, status, assignee, humanAgo(now, inc.TriggeredAt)}
|
||||||
|
}
|
||||||
|
return rows
|
||||||
|
}
|
||||||
|
|
||||||
func alertRows(alerts []api.Alert) []table.Row {
|
func alertRows(alerts []api.Alert) []table.Row {
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
rows := make([]table.Row, len(alerts))
|
rows := make([]table.Row, len(alerts))
|
||||||
for i, a := range alerts {
|
for i, a := range alerts {
|
||||||
rows[i] = table.Row{a.Name, a.Status, humanAgo(now, a.StartsAt), a.AcknowledgedBy}
|
incident := "—"
|
||||||
|
if a.IncidentID != nil {
|
||||||
|
incident = fmt.Sprintf("#%d", *a.IncidentID)
|
||||||
|
}
|
||||||
|
rows[i] = table.Row{a.Name, a.Status, humanAgo(now, a.StartsAt), humanAgo(now, a.ReceivedAt), incident}
|
||||||
}
|
}
|
||||||
return rows
|
return rows
|
||||||
}
|
}
|
||||||
@@ -406,7 +567,7 @@ func buildScheduleDays(window time.Time, entries []api.ScheduleEntry) []schedule
|
|||||||
for _, e := range entries {
|
for _, e := range entries {
|
||||||
entryMap[e.Date] = e
|
entryMap[e.Date] = e
|
||||||
}
|
}
|
||||||
days := make([]scheduleDay, 14)
|
days := make([]scheduleDay, 7)
|
||||||
for i := range days {
|
for i := range days {
|
||||||
date := window.AddDate(0, 0, i)
|
date := window.AddDate(0, 0, i)
|
||||||
day := scheduleDay{date: date}
|
day := scheduleDay{date: date}
|
||||||
@@ -426,28 +587,49 @@ func humanAgo(now, t time.Time) string {
|
|||||||
if d < 0 {
|
if d < 0 {
|
||||||
d = 0
|
d = 0
|
||||||
}
|
}
|
||||||
|
return humanDuration(d) + " ago"
|
||||||
|
}
|
||||||
|
|
||||||
|
// humanUntil renders a future deadline, used for snooze expiry.
|
||||||
|
func humanUntil(now, t time.Time) string {
|
||||||
|
d := t.Sub(now)
|
||||||
|
if d <= 0 {
|
||||||
|
return "expired"
|
||||||
|
}
|
||||||
|
return "in " + humanDuration(d)
|
||||||
|
}
|
||||||
|
|
||||||
|
func humanDuration(d time.Duration) string {
|
||||||
switch {
|
switch {
|
||||||
case d < time.Minute:
|
case d < time.Minute:
|
||||||
return "just now"
|
return "moments"
|
||||||
case d < time.Hour:
|
case d < time.Hour:
|
||||||
return fmt.Sprintf("%dm ago", int(d.Minutes()))
|
return fmt.Sprintf("%dm", int(d.Minutes()))
|
||||||
case d < 24*time.Hour:
|
case d < 24*time.Hour:
|
||||||
h := int(d.Hours())
|
h := int(d.Hours())
|
||||||
m := int(d.Minutes()) % 60
|
m := int(d.Minutes()) % 60
|
||||||
if m == 0 {
|
if m == 0 {
|
||||||
return fmt.Sprintf("%dh ago", h)
|
return fmt.Sprintf("%dh", h)
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("%dh %dm ago", h, m)
|
return fmt.Sprintf("%dh %dm", h, m)
|
||||||
default:
|
default:
|
||||||
days := int(d.Hours()) / 24
|
days := int(d.Hours()) / 24
|
||||||
h := int(d.Hours()) % 24
|
h := int(d.Hours()) % 24
|
||||||
if h == 0 {
|
if h == 0 {
|
||||||
return fmt.Sprintf("%dd ago", days)
|
return fmt.Sprintf("%dd", days)
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("%dd %dh ago", days, h)
|
return fmt.Sprintf("%dd %dh", days, h)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// humanSeconds renders an MTTA/MTTR average.
|
||||||
|
func humanSeconds(secs *float64) string {
|
||||||
|
if secs == nil {
|
||||||
|
return "—"
|
||||||
|
}
|
||||||
|
return humanDuration(time.Duration(*secs) * time.Second)
|
||||||
|
}
|
||||||
|
|
||||||
// ── Commands ───────────────────────────────────────────────────────────────
|
// ── Commands ───────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
func connectCmd(client *api.Client) tea.Cmd {
|
func connectCmd(client *api.Client) tea.Cmd {
|
||||||
@@ -459,9 +641,36 @@ func connectCmd(client *api.Client) tea.Cmd {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func fetchAlertsCmd(client *api.Client, status string) tea.Cmd {
|
func fetchIncidentsCmd(client *api.Client, filter string) tea.Cmd {
|
||||||
return func() tea.Msg {
|
return func() tea.Msg {
|
||||||
alerts, err := client.ListAlerts(status, 500)
|
status, snoozed := incidentQuery(filter)
|
||||||
|
incidents, err := client.ListIncidents(status, false, snoozed, 500)
|
||||||
|
if err != nil {
|
||||||
|
return fetchDataErrMsg{err}
|
||||||
|
}
|
||||||
|
return incidentsFetchedMsg{incidents}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func fetchArchivedIncidentsCmd(client *api.Client) tea.Cmd {
|
||||||
|
return func() tea.Msg {
|
||||||
|
// Archived incidents are all resolved, so the status filter has to be
|
||||||
|
// widened past the server's open-only default or nothing comes back.
|
||||||
|
incidents, err := client.ListIncidents(api.StatusResolved, true, false, 500)
|
||||||
|
if err != nil {
|
||||||
|
return fetchDataErrMsg{err}
|
||||||
|
}
|
||||||
|
return archivedIncidentsFetchedMsg{incidents}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func fetchAlertsCmd(client *api.Client, filter string) tea.Cmd {
|
||||||
|
return func() tea.Msg {
|
||||||
|
status, archived := filter, false
|
||||||
|
if filter == "archived" {
|
||||||
|
status, archived = "", true
|
||||||
|
}
|
||||||
|
alerts, err := client.ListAlerts(status, archived, 500)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fetchDataErrMsg{err}
|
return fetchDataErrMsg{err}
|
||||||
}
|
}
|
||||||
@@ -471,11 +680,120 @@ func fetchAlertsCmd(client *api.Client, status string) tea.Cmd {
|
|||||||
|
|
||||||
func fetchStatsCmd(client *api.Client) tea.Cmd {
|
func fetchStatsCmd(client *api.Client) tea.Cmd {
|
||||||
return func() tea.Msg {
|
return func() tea.Msg {
|
||||||
stats, err := client.GetAlertStats()
|
incidents, err := client.GetIncidentStats()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fetchDataErrMsg{err}
|
return fetchDataErrMsg{err}
|
||||||
}
|
}
|
||||||
return statsFetchedMsg{*stats}
|
alerts, err := client.GetAlertStats()
|
||||||
|
if err != nil {
|
||||||
|
return fetchDataErrMsg{err}
|
||||||
|
}
|
||||||
|
return statsFetchedMsg{incidents: *incidents, alerts: *alerts}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// incidentDetail reloads an incident and its timeline. Every detail-mode action
|
||||||
|
// funnels through it so the view always reflects what the server just did.
|
||||||
|
func incidentDetail(client *api.Client, id int64) tea.Msg {
|
||||||
|
incident, err := client.GetIncident(id)
|
||||||
|
if err != nil {
|
||||||
|
return detailErrMsg{err}
|
||||||
|
}
|
||||||
|
timeline, err := client.GetIncidentTimeline(id)
|
||||||
|
if err != nil {
|
||||||
|
return detailErrMsg{err}
|
||||||
|
}
|
||||||
|
return incidentDetailFetchedMsg{incident: *incident, timeline: timeline}
|
||||||
|
}
|
||||||
|
|
||||||
|
func fetchIncidentDetailCmd(client *api.Client, id int64) tea.Cmd {
|
||||||
|
return func() tea.Msg { return incidentDetail(client, id) }
|
||||||
|
}
|
||||||
|
|
||||||
|
// incidentActionCmd performs an action then reloads the detail view, reporting
|
||||||
|
// the server's error rather than a stale success.
|
||||||
|
func incidentActionCmd(client *api.Client, id int64, action func() error) tea.Cmd {
|
||||||
|
return func() tea.Msg {
|
||||||
|
if err := action(); err != nil {
|
||||||
|
return actionErrMsg{err}
|
||||||
|
}
|
||||||
|
return incidentDetail(client, id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func acknowledgeIncidentCmd(client *api.Client, id int64) tea.Cmd {
|
||||||
|
return incidentActionCmd(client, id, func() error {
|
||||||
|
_, err := client.AcknowledgeIncident(id)
|
||||||
|
return err
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func unacknowledgeIncidentCmd(client *api.Client, id int64) tea.Cmd {
|
||||||
|
return incidentActionCmd(client, id, func() error { return client.UnacknowledgeIncident(id) })
|
||||||
|
}
|
||||||
|
|
||||||
|
func resolveIncidentCmd(client *api.Client, id int64) tea.Cmd {
|
||||||
|
return incidentActionCmd(client, id, func() error {
|
||||||
|
_, err := client.ResolveIncident(id)
|
||||||
|
return err
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func assignIncidentCmd(client *api.Client, id, userID int64) tea.Cmd {
|
||||||
|
return incidentActionCmd(client, id, func() error {
|
||||||
|
_, err := client.AssignIncident(id, userID)
|
||||||
|
return err
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func snoozeIncidentCmd(client *api.Client, id int64, duration string) tea.Cmd {
|
||||||
|
return incidentActionCmd(client, id, func() error {
|
||||||
|
_, err := client.SnoozeIncident(id, duration)
|
||||||
|
return err
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func unsnoozeIncidentCmd(client *api.Client, id int64) tea.Cmd {
|
||||||
|
return incidentActionCmd(client, id, func() error { return client.UnsnoozeIncident(id) })
|
||||||
|
}
|
||||||
|
|
||||||
|
func addNoteCmd(client *api.Client, id int64, content string) tea.Cmd {
|
||||||
|
return incidentActionCmd(client, id, func() error {
|
||||||
|
_, err := client.AddNote(id, content)
|
||||||
|
return err
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func deleteNoteCmd(client *api.Client, id, eventID int64) tea.Cmd {
|
||||||
|
return incidentActionCmd(client, id, func() error { return client.DeleteNote(id, eventID) })
|
||||||
|
}
|
||||||
|
|
||||||
|
// archiveIncidentCmd archives from the list view, so it reloads the list rather
|
||||||
|
// than a detail pane.
|
||||||
|
func archiveIncidentCmd(client *api.Client, id int64, filter string) tea.Cmd {
|
||||||
|
return func() tea.Msg {
|
||||||
|
if _, err := client.ArchiveIncident(id); err != nil {
|
||||||
|
return actionErrMsg{err}
|
||||||
|
}
|
||||||
|
status, snoozed := incidentQuery(filter)
|
||||||
|
incidents, err := client.ListIncidents(status, false, snoozed, 500)
|
||||||
|
if err != nil {
|
||||||
|
return actionErrMsg{err}
|
||||||
|
}
|
||||||
|
return incidentActionDoneMsg{incidents: incidents, status: "Incident archived"}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func unarchiveIncidentCmd(client *api.Client, id int64) tea.Cmd {
|
||||||
|
return func() tea.Msg {
|
||||||
|
if err := client.UnarchiveIncident(id); err != nil {
|
||||||
|
return actionErrMsg{err}
|
||||||
|
}
|
||||||
|
incidents, err := client.ListIncidents(api.StatusResolved, true, false, 500)
|
||||||
|
if err != nil {
|
||||||
|
return actionErrMsg{err}
|
||||||
|
}
|
||||||
|
return archivedIncidentsFetchedMsg{incidents}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -483,78 +801,9 @@ func fetchAlertDetailCmd(client *api.Client, alertID int64) tea.Cmd {
|
|||||||
return func() tea.Msg {
|
return func() tea.Msg {
|
||||||
alert, err := client.GetAlert(alertID)
|
alert, err := client.GetAlert(alertID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return alertDetailErrMsg{err}
|
return detailErrMsg{err}
|
||||||
}
|
}
|
||||||
comments, err := client.GetComments(alertID)
|
return alertDetailFetchedMsg{alert: *alert}
|
||||||
if err != nil {
|
|
||||||
return alertDetailErrMsg{err}
|
|
||||||
}
|
|
||||||
return alertDetailFetchedMsg{alert: *alert, comments: comments}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func acknowledgeCmd(client *api.Client, alertID int64) tea.Cmd {
|
|
||||||
return func() tea.Msg {
|
|
||||||
alert, err := client.AcknowledgeAlert(alertID)
|
|
||||||
if err != nil {
|
|
||||||
return actionErrMsg{err}
|
|
||||||
}
|
|
||||||
comments, err := client.GetComments(alertID)
|
|
||||||
if err != nil {
|
|
||||||
return actionErrMsg{err}
|
|
||||||
}
|
|
||||||
return alertDetailFetchedMsg{alert: *alert, comments: comments}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func unacknowledgeCmd(client *api.Client, alertID int64) tea.Cmd {
|
|
||||||
return func() tea.Msg {
|
|
||||||
if err := client.UnacknowledgeAlert(alertID); err != nil {
|
|
||||||
return actionErrMsg{err}
|
|
||||||
}
|
|
||||||
alert, err := client.GetAlert(alertID)
|
|
||||||
if err != nil {
|
|
||||||
return actionErrMsg{err}
|
|
||||||
}
|
|
||||||
comments, err := client.GetComments(alertID)
|
|
||||||
if err != nil {
|
|
||||||
return actionErrMsg{err}
|
|
||||||
}
|
|
||||||
return alertDetailFetchedMsg{alert: *alert, comments: comments}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func addCommentCmd(client *api.Client, alertID int64, content string) tea.Cmd {
|
|
||||||
return func() tea.Msg {
|
|
||||||
if _, err := client.AddComment(alertID, content); err != nil {
|
|
||||||
return actionErrMsg{err}
|
|
||||||
}
|
|
||||||
alert, err := client.GetAlert(alertID)
|
|
||||||
if err != nil {
|
|
||||||
return actionErrMsg{err}
|
|
||||||
}
|
|
||||||
comments, err := client.GetComments(alertID)
|
|
||||||
if err != nil {
|
|
||||||
return actionErrMsg{err}
|
|
||||||
}
|
|
||||||
return alertDetailFetchedMsg{alert: *alert, comments: comments}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func deleteCommentCmd(client *api.Client, alertID, commentID int64) tea.Cmd {
|
|
||||||
return func() tea.Msg {
|
|
||||||
if err := client.DeleteComment(alertID, commentID); err != nil {
|
|
||||||
return actionErrMsg{err}
|
|
||||||
}
|
|
||||||
alert, err := client.GetAlert(alertID)
|
|
||||||
if err != nil {
|
|
||||||
return actionErrMsg{err}
|
|
||||||
}
|
|
||||||
comments, err := client.GetComments(alertID)
|
|
||||||
if err != nil {
|
|
||||||
return actionErrMsg{err}
|
|
||||||
}
|
|
||||||
return alertDetailFetchedMsg{alert: *alert, comments: comments}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+55
-1
@@ -1,6 +1,11 @@
|
|||||||
package tui
|
package tui
|
||||||
|
|
||||||
import "github.com/charmbracelet/lipgloss"
|
import (
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/charmbracelet/lipgloss"
|
||||||
|
"github.com/yeniklas/terdut-tui/internal/api"
|
||||||
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
colorPrimary = lipgloss.Color("69") // blue
|
colorPrimary = lipgloss.Color("69") // blue
|
||||||
@@ -9,6 +14,11 @@ var (
|
|||||||
colorResolved = lipgloss.Color("70") // green
|
colorResolved = lipgloss.Color("70") // green
|
||||||
colorAccent = lipgloss.Color("214") // orange
|
colorAccent = lipgloss.Color("214") // orange
|
||||||
|
|
||||||
|
colorSevCritical = lipgloss.Color("196") // red
|
||||||
|
colorSevError = lipgloss.Color("202") // dark orange
|
||||||
|
colorSevWarning = lipgloss.Color("214") // orange
|
||||||
|
colorSevInfo = lipgloss.Color("39") // cyan
|
||||||
|
|
||||||
styleHeader = lipgloss.NewStyle().
|
styleHeader = lipgloss.NewStyle().
|
||||||
Bold(true).
|
Bold(true).
|
||||||
Foreground(colorPrimary).
|
Foreground(colorPrimary).
|
||||||
@@ -42,4 +52,48 @@ var (
|
|||||||
styleBold = lipgloss.NewStyle().Bold(true)
|
styleBold = lipgloss.NewStyle().Bold(true)
|
||||||
styleSelected = lipgloss.NewStyle().Foreground(colorPrimary).Bold(true)
|
styleSelected = lipgloss.NewStyle().Foreground(colorPrimary).Bold(true)
|
||||||
styleAccent = lipgloss.NewStyle().Foreground(colorAccent)
|
styleAccent = lipgloss.NewStyle().Foreground(colorAccent)
|
||||||
|
|
||||||
|
// Incident status. Triggered is unclaimed work and reads as loudly as a
|
||||||
|
// firing alert; acknowledged means somebody has it.
|
||||||
|
styleTriggered = lipgloss.NewStyle().Foreground(colorFiring).Bold(true)
|
||||||
|
styleAcknowledged = lipgloss.NewStyle().Foreground(colorAccent).Bold(true)
|
||||||
|
styleSnoozed = lipgloss.NewStyle().Foreground(colorMuted).Italic(true)
|
||||||
|
|
||||||
|
// Severity, over the conventional Alertmanager label values.
|
||||||
|
styleSevCritical = lipgloss.NewStyle().Foreground(colorSevCritical).Bold(true)
|
||||||
|
styleSevError = lipgloss.NewStyle().Foreground(colorSevError).Bold(true)
|
||||||
|
styleSevWarning = lipgloss.NewStyle().Foreground(colorSevWarning)
|
||||||
|
styleSevInfo = lipgloss.NewStyle().Foreground(colorSevInfo)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// severityStyle picks the style for a severity label, falling back to muted for
|
||||||
|
// values this client does not recognise rather than dropping them.
|
||||||
|
func severityStyle(severity string) lipgloss.Style {
|
||||||
|
switch strings.ToLower(severity) {
|
||||||
|
case "critical":
|
||||||
|
return styleSevCritical
|
||||||
|
case "error":
|
||||||
|
return styleSevError
|
||||||
|
case "warning":
|
||||||
|
return styleSevWarning
|
||||||
|
case "info":
|
||||||
|
return styleSevInfo
|
||||||
|
default:
|
||||||
|
return styleMuted
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// incidentStatusStyle picks the style for an incident status, falling back to
|
||||||
|
// muted for statuses added after this client was built.
|
||||||
|
func incidentStatusStyle(status string) lipgloss.Style {
|
||||||
|
switch status {
|
||||||
|
case api.StatusTriggered:
|
||||||
|
return styleTriggered
|
||||||
|
case api.StatusAcknowledged:
|
||||||
|
return styleAcknowledged
|
||||||
|
case api.StatusResolved:
|
||||||
|
return styleResolved
|
||||||
|
default:
|
||||||
|
return styleMuted
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
+437
-165
@@ -15,7 +15,9 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
case tea.WindowSizeMsg:
|
case tea.WindowSizeMsg:
|
||||||
m.width = msg.Width
|
m.width = msg.Width
|
||||||
m.height = msg.Height
|
m.height = msg.Height
|
||||||
|
m.rebuildIncidentTable()
|
||||||
m.rebuildTable()
|
m.rebuildTable()
|
||||||
|
m.rebuildArchivedTable()
|
||||||
m.rebuildScheduleTable()
|
m.rebuildScheduleTable()
|
||||||
m.rebuildUserPickerTable()
|
m.rebuildUserPickerTable()
|
||||||
m.rebuildUserManageTable()
|
m.rebuildUserManageTable()
|
||||||
@@ -34,7 +36,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
m.err = nil
|
m.err = nil
|
||||||
return m, tea.Batch(
|
return m, tea.Batch(
|
||||||
tickCmd(m.refreshInterval),
|
tickCmd(m.refreshInterval),
|
||||||
fetchAlertsCmd(m.client, m.filterStatus),
|
fetchIncidentsCmd(m.client, m.incidentFilter),
|
||||||
fetchStatsCmd(m.client),
|
fetchStatsCmd(m.client),
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -43,6 +45,27 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
m.err = msg.err
|
m.err = msg.err
|
||||||
return m, nil
|
return m, nil
|
||||||
|
|
||||||
|
case incidentsFetchedMsg:
|
||||||
|
m.incidents = msg.incidents
|
||||||
|
m.loading = false
|
||||||
|
m.rebuildIncidentTable()
|
||||||
|
return m, nil
|
||||||
|
|
||||||
|
case archivedIncidentsFetchedMsg:
|
||||||
|
m.archivedIncidents = msg.incidents
|
||||||
|
m.archivedLoading = false
|
||||||
|
m.rebuildArchivedTable()
|
||||||
|
m.mode = modeDashboard
|
||||||
|
return m, nil
|
||||||
|
|
||||||
|
case incidentActionDoneMsg:
|
||||||
|
m.incidents = msg.incidents
|
||||||
|
m.loading = false
|
||||||
|
m.rebuildIncidentTable()
|
||||||
|
m.mode = modeDashboard
|
||||||
|
m.statusMsg = msg.status
|
||||||
|
return m, clearStatusCmd()
|
||||||
|
|
||||||
case alertsFetchedMsg:
|
case alertsFetchedMsg:
|
||||||
m.alerts = msg.alerts
|
m.alerts = msg.alerts
|
||||||
m.loading = false
|
m.loading = false
|
||||||
@@ -50,33 +73,38 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
return m, nil
|
return m, nil
|
||||||
|
|
||||||
case statsFetchedMsg:
|
case statsFetchedMsg:
|
||||||
m.stats = &msg.stats
|
m.incidentStats = &msg.incidents
|
||||||
|
m.alertStats = &msg.alerts
|
||||||
return m, nil
|
return m, nil
|
||||||
|
|
||||||
case fetchDataErrMsg:
|
case fetchDataErrMsg:
|
||||||
|
m.loading = false
|
||||||
|
m.archivedLoading = false
|
||||||
m.statusMsg = "refresh error: " + msg.err.Error()
|
m.statusMsg = "refresh error: " + msg.err.Error()
|
||||||
return m, clearStatusCmd()
|
return m, clearStatusCmd()
|
||||||
|
|
||||||
case tickMsg:
|
case tickMsg:
|
||||||
return m, tea.Batch(
|
return m, tea.Batch(tickCmd(m.refreshInterval), m.refreshActiveSection())
|
||||||
tickCmd(m.refreshInterval),
|
|
||||||
fetchAlertsCmd(m.client, m.filterStatus),
|
|
||||||
fetchStatsCmd(m.client),
|
|
||||||
)
|
|
||||||
|
|
||||||
// ── Detail messages ───────────────────────────────────────────────────
|
// ── Detail messages ───────────────────────────────────────────────────
|
||||||
|
|
||||||
case alertDetailFetchedMsg:
|
case incidentDetailFetchedMsg:
|
||||||
m.selectedAlert = msg.alert
|
m.selectedIncident = msg.incident
|
||||||
m.comments = msg.comments
|
m.timeline = msg.timeline
|
||||||
m.detailLoading = false
|
m.detailLoading = false
|
||||||
if m.commentCursor >= len(m.comments) {
|
if m.noteCursor >= len(noteEvents(m.timeline)) {
|
||||||
m.commentCursor = -1
|
m.noteCursor = -1
|
||||||
}
|
}
|
||||||
m.refreshDetailContent()
|
m.refreshDetailContent()
|
||||||
return m, nil
|
return m, nil
|
||||||
|
|
||||||
case alertDetailErrMsg:
|
case alertDetailFetchedMsg:
|
||||||
|
m.selectedAlert = msg.alert
|
||||||
|
m.detailLoading = false
|
||||||
|
m.refreshDetailContent()
|
||||||
|
return m, nil
|
||||||
|
|
||||||
|
case detailErrMsg:
|
||||||
m.detailLoading = false
|
m.detailLoading = false
|
||||||
m.statusMsg = "error: " + msg.err.Error()
|
m.statusMsg = "error: " + msg.err.Error()
|
||||||
return m, clearStatusCmd()
|
return m, clearStatusCmd()
|
||||||
@@ -96,7 +124,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
case detailStatsErrMsg:
|
case detailStatsErrMsg:
|
||||||
m.statsLoading = false
|
m.statsLoading = false
|
||||||
m.statusMsg = "stats error: " + msg.err.Error()
|
m.statusMsg = "stats error: " + msg.err.Error()
|
||||||
m.mode = modeDetail
|
m.mode = modeDashboard
|
||||||
return m, clearStatusCmd()
|
return m, clearStatusCmd()
|
||||||
|
|
||||||
// ── Schedule messages ─────────────────────────────────────────────────
|
// ── Schedule messages ─────────────────────────────────────────────────
|
||||||
@@ -155,22 +183,60 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
return m, nil
|
return m, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// refreshActiveSection reloads whatever the auto-refresh tick should keep fresh.
|
||||||
|
// Detail views reload too — an incident someone else acknowledged should stop
|
||||||
|
// looking unclaimed while you are staring at it.
|
||||||
|
func (m Model) refreshActiveSection() tea.Cmd {
|
||||||
|
switch m.mode {
|
||||||
|
case modeIncidentDetail:
|
||||||
|
return fetchIncidentDetailCmd(m.client, m.selectedIncident.ID)
|
||||||
|
case modeAlertDetail:
|
||||||
|
return fetchAlertDetailCmd(m.client, m.selectedAlert.ID)
|
||||||
|
case modeDashboard:
|
||||||
|
// fall through to the section refresh below
|
||||||
|
default:
|
||||||
|
// Modal states (compose, pickers, confirmations) are left alone: a
|
||||||
|
// refresh underneath a prompt would move the ground under the user.
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
switch m.activeSection {
|
||||||
|
case sectionIncidents:
|
||||||
|
return tea.Batch(fetchIncidentsCmd(m.client, m.incidentFilter), fetchStatsCmd(m.client))
|
||||||
|
case sectionAlerts:
|
||||||
|
return tea.Batch(fetchAlertsCmd(m.client, m.alertFilter), fetchStatsCmd(m.client))
|
||||||
|
case sectionArchived:
|
||||||
|
return fetchArchivedIncidentsCmd(m.client)
|
||||||
|
case sectionSchedule:
|
||||||
|
return fetchScheduleCmd(m.client, m.scheduleWindow, m.scheduleWindow.AddDate(0, 0, 6))
|
||||||
|
case sectionUsers:
|
||||||
|
return fetchUsersCmd(m.client)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// routeKey passes the key to the active component then to our handler.
|
// routeKey passes the key to the active component then to our handler.
|
||||||
func (m Model) routeKey(msg tea.KeyMsg) (Model, tea.Cmd) {
|
func (m Model) routeKey(msg tea.KeyMsg) (Model, tea.Cmd) {
|
||||||
switch m.mode {
|
switch m.mode {
|
||||||
case modeDetail:
|
case modeIncidentDetail, modeAlertDetail:
|
||||||
var vpCmd tea.Cmd
|
var vpCmd tea.Cmd
|
||||||
m.detailViewport, vpCmd = m.detailViewport.Update(msg)
|
m.detailViewport, vpCmd = m.detailViewport.Update(msg)
|
||||||
m2, ourCmd := m.handleKey(msg)
|
m2, ourCmd := m.handleKey(msg)
|
||||||
return m2, tea.Batch(vpCmd, ourCmd)
|
return m2, tea.Batch(vpCmd, ourCmd)
|
||||||
|
|
||||||
case modeConfirmDelete:
|
case modeConfirm:
|
||||||
// No component to scroll; just handle y/n.
|
// No component to scroll; just handle y/n.
|
||||||
return m.handleKey(msg)
|
return m.handleKey(msg)
|
||||||
|
|
||||||
case modeComment:
|
case modeNote:
|
||||||
var inputCmd tea.Cmd
|
var inputCmd tea.Cmd
|
||||||
m.commentInput, inputCmd = m.commentInput.Update(msg)
|
m.noteInput, inputCmd = m.noteInput.Update(msg)
|
||||||
|
m2, ourCmd := m.handleKey(msg)
|
||||||
|
return m2, tea.Batch(inputCmd, ourCmd)
|
||||||
|
|
||||||
|
case modeSnooze:
|
||||||
|
var inputCmd tea.Cmd
|
||||||
|
m.snoozeInput, inputCmd = m.snoozeInput.Update(msg)
|
||||||
m2, ourCmd := m.handleKey(msg)
|
m2, ourCmd := m.handleKey(msg)
|
||||||
return m2, tea.Batch(inputCmd, ourCmd)
|
return m2, tea.Batch(inputCmd, ourCmd)
|
||||||
|
|
||||||
@@ -180,7 +246,7 @@ func (m Model) routeKey(msg tea.KeyMsg) (Model, tea.Cmd) {
|
|||||||
m2, ourCmd := m.handleKey(msg)
|
m2, ourCmd := m.handleKey(msg)
|
||||||
return m2, tea.Batch(vpCmd, ourCmd)
|
return m2, tea.Batch(vpCmd, ourCmd)
|
||||||
|
|
||||||
case modeScheduleUserPicker:
|
case modeUserPicker:
|
||||||
var tableCmd tea.Cmd
|
var tableCmd tea.Cmd
|
||||||
m.userPickerTable, tableCmd = m.userPickerTable.Update(msg)
|
m.userPickerTable, tableCmd = m.userPickerTable.Update(msg)
|
||||||
m2, ourCmd := m.handleKey(msg)
|
m2, ourCmd := m.handleKey(msg)
|
||||||
@@ -210,11 +276,21 @@ func (m Model) routeKey(msg tea.KeyMsg) (Model, tea.Cmd) {
|
|||||||
default: // modeDashboard
|
default: // modeDashboard
|
||||||
if m.connected {
|
if m.connected {
|
||||||
switch m.activeSection {
|
switch m.activeSection {
|
||||||
|
case sectionIncidents:
|
||||||
|
var tableCmd tea.Cmd
|
||||||
|
m.incidentTable, tableCmd = m.incidentTable.Update(msg)
|
||||||
|
m2, ourCmd := m.handleKey(msg)
|
||||||
|
return m2, tea.Batch(tableCmd, ourCmd)
|
||||||
case sectionAlerts:
|
case sectionAlerts:
|
||||||
var tableCmd tea.Cmd
|
var tableCmd tea.Cmd
|
||||||
m.alertTable, tableCmd = m.alertTable.Update(msg)
|
m.alertTable, tableCmd = m.alertTable.Update(msg)
|
||||||
m2, ourCmd := m.handleKey(msg)
|
m2, ourCmd := m.handleKey(msg)
|
||||||
return m2, tea.Batch(tableCmd, ourCmd)
|
return m2, tea.Batch(tableCmd, ourCmd)
|
||||||
|
case sectionArchived:
|
||||||
|
var tableCmd tea.Cmd
|
||||||
|
m.archivedTable, tableCmd = m.archivedTable.Update(msg)
|
||||||
|
m2, ourCmd := m.handleKey(msg)
|
||||||
|
return m2, tea.Batch(tableCmd, ourCmd)
|
||||||
case sectionSchedule:
|
case sectionSchedule:
|
||||||
var tableCmd tea.Cmd
|
var tableCmd tea.Cmd
|
||||||
m.scheduleTable, tableCmd = m.scheduleTable.Update(msg)
|
m.scheduleTable, tableCmd = m.scheduleTable.Update(msg)
|
||||||
@@ -233,15 +309,19 @@ func (m Model) routeKey(msg tea.KeyMsg) (Model, tea.Cmd) {
|
|||||||
|
|
||||||
func (m Model) handleKey(msg tea.KeyMsg) (Model, tea.Cmd) {
|
func (m Model) handleKey(msg tea.KeyMsg) (Model, tea.Cmd) {
|
||||||
switch m.mode {
|
switch m.mode {
|
||||||
case modeDetail:
|
case modeIncidentDetail:
|
||||||
return m.handleDetailKey(msg)
|
return m.handleIncidentDetailKey(msg)
|
||||||
case modeComment:
|
case modeAlertDetail:
|
||||||
return m.handleCommentKey(msg)
|
return m.handleAlertDetailKey(msg)
|
||||||
case modeConfirmDelete:
|
case modeNote:
|
||||||
|
return m.handleNoteKey(msg)
|
||||||
|
case modeSnooze:
|
||||||
|
return m.handleSnoozeKey(msg)
|
||||||
|
case modeConfirm:
|
||||||
return m.handleConfirmKey(msg)
|
return m.handleConfirmKey(msg)
|
||||||
case modeStats:
|
case modeStats:
|
||||||
return m.handleStatsKey(msg)
|
return m.handleStatsKey(msg)
|
||||||
case modeScheduleUserPicker:
|
case modeUserPicker:
|
||||||
return m.handleUserPickerKey(msg)
|
return m.handleUserPickerKey(msg)
|
||||||
case modeUserCreate:
|
case modeUserCreate:
|
||||||
return m.handleUserCreateKey(msg)
|
return m.handleUserCreateKey(msg)
|
||||||
@@ -266,63 +346,50 @@ func (m Model) handleDashboardKey(msg tea.KeyMsg) (Model, tea.Cmd) {
|
|||||||
return m, tea.Quit
|
return m, tea.Quit
|
||||||
|
|
||||||
case "tab":
|
case "tab":
|
||||||
next := section((int(m.activeSection) + 1) % 3)
|
m.activeSection = section((int(m.activeSection) + 1) % sectionCount)
|
||||||
m.activeSection = next
|
return m, m.loadSectionIfEmpty()
|
||||||
if next == sectionSchedule && len(m.scheduleDays) == 0 {
|
|
||||||
m.scheduleLoading = true
|
case "shift+tab":
|
||||||
from := m.scheduleWindow
|
m.activeSection = section((int(m.activeSection) + sectionCount - 1) % sectionCount)
|
||||||
to := m.scheduleWindow.AddDate(0, 0, 13)
|
return m, m.loadSectionIfEmpty()
|
||||||
return m, fetchScheduleCmd(m.client, from, to)
|
|
||||||
}
|
|
||||||
if next == sectionUsers && len(m.users) == 0 {
|
|
||||||
m.usersLoading = true
|
|
||||||
return m, fetchUsersCmd(m.client)
|
|
||||||
}
|
|
||||||
return m, nil
|
|
||||||
|
|
||||||
case "r":
|
case "r":
|
||||||
if !m.connected {
|
if !m.connected {
|
||||||
return m, connectCmd(m.client)
|
return m, connectCmd(m.client)
|
||||||
}
|
}
|
||||||
if m.activeSection == sectionSchedule {
|
|
||||||
m.scheduleLoading = true
|
|
||||||
from := m.scheduleWindow
|
|
||||||
to := m.scheduleWindow.AddDate(0, 0, 13)
|
|
||||||
return m, fetchScheduleCmd(m.client, from, to)
|
|
||||||
}
|
|
||||||
if m.activeSection == sectionUsers {
|
|
||||||
m.usersLoading = true
|
|
||||||
return m, fetchUsersCmd(m.client)
|
|
||||||
}
|
|
||||||
m.statusMsg = "Refreshing…"
|
m.statusMsg = "Refreshing…"
|
||||||
return m, tea.Batch(
|
return m, tea.Batch(m.refreshActiveSection(), clearStatusCmd())
|
||||||
fetchAlertsCmd(m.client, m.filterStatus),
|
|
||||||
fetchStatsCmd(m.client),
|
|
||||||
clearStatusCmd(),
|
|
||||||
)
|
|
||||||
|
|
||||||
case "f":
|
case "f":
|
||||||
if m.activeSection != sectionAlerts || !m.connected {
|
if !m.connected {
|
||||||
return m, nil
|
return m, nil
|
||||||
}
|
}
|
||||||
switch m.filterStatus {
|
switch m.activeSection {
|
||||||
case "firing":
|
case sectionIncidents:
|
||||||
m.filterStatus = "resolved"
|
m.incidentFilter = nextFilter(incidentFilters, m.incidentFilter)
|
||||||
case "resolved":
|
|
||||||
m.filterStatus = ""
|
|
||||||
default:
|
|
||||||
m.filterStatus = "firing"
|
|
||||||
}
|
|
||||||
m.loading = true
|
m.loading = true
|
||||||
return m, fetchAlertsCmd(m.client, m.filterStatus)
|
return m, fetchIncidentsCmd(m.client, m.incidentFilter)
|
||||||
|
case sectionAlerts:
|
||||||
|
m.alertFilter = nextFilter(alertFilters, m.alertFilter)
|
||||||
|
m.loading = true
|
||||||
|
return m, fetchAlertsCmd(m.client, m.alertFilter)
|
||||||
|
}
|
||||||
|
return m, nil
|
||||||
|
|
||||||
case "enter":
|
case "enter":
|
||||||
if m.activeSection == sectionAlerts && len(m.alerts) > 0 {
|
switch m.activeSection {
|
||||||
cursor := m.alertTable.Cursor()
|
case sectionIncidents:
|
||||||
if cursor < len(m.alerts) {
|
if inc, ok := m.incidentAtCursor(); ok {
|
||||||
m.selectedAlert = m.alerts[cursor]
|
return m.openIncident(inc)
|
||||||
m.mode = modeDetail
|
}
|
||||||
m.commentCursor = -1
|
case sectionArchived:
|
||||||
|
if i := m.archivedTable.Cursor(); i >= 0 && i < len(m.archivedIncidents) {
|
||||||
|
return m.openIncident(m.archivedIncidents[i])
|
||||||
|
}
|
||||||
|
case sectionAlerts:
|
||||||
|
if i := m.alertTable.Cursor(); i >= 0 && i < len(m.alerts) {
|
||||||
|
m.selectedAlert = m.alerts[i]
|
||||||
|
m.mode = modeAlertDetail
|
||||||
m.detailLoading = true
|
m.detailLoading = true
|
||||||
m.detailViewport = viewport.New(m.width, m.detailViewportHeight())
|
m.detailViewport = viewport.New(m.width, m.detailViewportHeight())
|
||||||
return m, fetchAlertDetailCmd(m.client, m.selectedAlert.ID)
|
return m, fetchAlertDetailCmd(m.client, m.selectedAlert.ID)
|
||||||
@@ -330,14 +397,34 @@ func (m Model) handleDashboardKey(msg tea.KeyMsg) (Model, tea.Cmd) {
|
|||||||
}
|
}
|
||||||
return m, nil
|
return m, nil
|
||||||
|
|
||||||
|
case "x":
|
||||||
|
switch m.activeSection {
|
||||||
|
case sectionIncidents:
|
||||||
|
inc, ok := m.incidentAtCursor()
|
||||||
|
if !ok {
|
||||||
|
return m, nil
|
||||||
|
}
|
||||||
|
if inc.IsOpen() {
|
||||||
|
m.statusMsg = "resolve the incident before archiving it"
|
||||||
|
return m, clearStatusCmd()
|
||||||
|
}
|
||||||
|
return m, archiveIncidentCmd(m.client, inc.ID, m.incidentFilter)
|
||||||
|
case sectionArchived:
|
||||||
|
i := m.archivedTable.Cursor()
|
||||||
|
if i < 0 || i >= len(m.archivedIncidents) {
|
||||||
|
return m, nil
|
||||||
|
}
|
||||||
|
m.archivedLoading = true
|
||||||
|
return m, unarchiveIncidentCmd(m.client, m.archivedIncidents[i].ID)
|
||||||
|
}
|
||||||
|
return m, nil
|
||||||
|
|
||||||
// Schedule-specific keys
|
// Schedule-specific keys
|
||||||
case "left", "h":
|
case "left", "h":
|
||||||
if m.activeSection == sectionSchedule {
|
if m.activeSection == sectionSchedule {
|
||||||
m.scheduleWindow = m.scheduleWindow.AddDate(0, 0, -7)
|
m.scheduleWindow = m.scheduleWindow.AddDate(0, 0, -7)
|
||||||
m.scheduleLoading = true
|
m.scheduleLoading = true
|
||||||
from := m.scheduleWindow
|
return m, fetchScheduleCmd(m.client, m.scheduleWindow, m.scheduleWindow.AddDate(0, 0, 6))
|
||||||
to := m.scheduleWindow.AddDate(0, 0, 13)
|
|
||||||
return m, fetchScheduleCmd(m.client, from, to)
|
|
||||||
}
|
}
|
||||||
return m, nil
|
return m, nil
|
||||||
|
|
||||||
@@ -345,9 +432,7 @@ func (m Model) handleDashboardKey(msg tea.KeyMsg) (Model, tea.Cmd) {
|
|||||||
if m.activeSection == sectionSchedule {
|
if m.activeSection == sectionSchedule {
|
||||||
m.scheduleWindow = m.scheduleWindow.AddDate(0, 0, 7)
|
m.scheduleWindow = m.scheduleWindow.AddDate(0, 0, 7)
|
||||||
m.scheduleLoading = true
|
m.scheduleLoading = true
|
||||||
from := m.scheduleWindow
|
return m, fetchScheduleCmd(m.client, m.scheduleWindow, m.scheduleWindow.AddDate(0, 0, 6))
|
||||||
to := m.scheduleWindow.AddDate(0, 0, 13)
|
|
||||||
return m, fetchScheduleCmd(m.client, from, to)
|
|
||||||
}
|
}
|
||||||
return m, nil
|
return m, nil
|
||||||
|
|
||||||
@@ -356,26 +441,14 @@ func (m Model) handleDashboardKey(msg tea.KeyMsg) (Model, tea.Cmd) {
|
|||||||
return m, nil
|
return m, nil
|
||||||
}
|
}
|
||||||
m.pickerAssignWeek = false
|
m.pickerAssignWeek = false
|
||||||
m.mode = modeScheduleUserPicker
|
return m.openUserPicker(pickerSchedule)
|
||||||
if len(m.users) == 0 {
|
|
||||||
m.usersLoading = true
|
|
||||||
return m, fetchUsersCmd(m.client)
|
|
||||||
}
|
|
||||||
m.rebuildUserPickerTable()
|
|
||||||
return m, nil
|
|
||||||
|
|
||||||
case "W":
|
case "W":
|
||||||
if m.activeSection != sectionSchedule || !m.connected {
|
if m.activeSection != sectionSchedule || !m.connected {
|
||||||
return m, nil
|
return m, nil
|
||||||
}
|
}
|
||||||
m.pickerAssignWeek = true
|
m.pickerAssignWeek = true
|
||||||
m.mode = modeScheduleUserPicker
|
return m.openUserPicker(pickerSchedule)
|
||||||
if len(m.users) == 0 {
|
|
||||||
m.usersLoading = true
|
|
||||||
return m, fetchUsersCmd(m.client)
|
|
||||||
}
|
|
||||||
m.rebuildUserPickerTable()
|
|
||||||
return m, nil
|
|
||||||
|
|
||||||
case "d":
|
case "d":
|
||||||
switch m.activeSection {
|
switch m.activeSection {
|
||||||
@@ -394,7 +467,7 @@ func (m Model) handleDashboardKey(msg tea.KeyMsg) (Model, tea.Cmd) {
|
|||||||
}
|
}
|
||||||
m.pendingDeleteEntry = day.entry
|
m.pendingDeleteEntry = day.entry
|
||||||
m.confirmTarget = confirmDeleteScheduleEntry
|
m.confirmTarget = confirmDeleteScheduleEntry
|
||||||
m.mode = modeConfirmDelete
|
m.mode = modeConfirm
|
||||||
case sectionUsers:
|
case sectionUsers:
|
||||||
if !m.connected || len(m.users) == 0 {
|
if !m.connected || len(m.users) == 0 {
|
||||||
return m, nil
|
return m, nil
|
||||||
@@ -405,10 +478,16 @@ func (m Model) handleDashboardKey(msg tea.KeyMsg) (Model, tea.Cmd) {
|
|||||||
}
|
}
|
||||||
m.selectedUser = m.users[cursor]
|
m.selectedUser = m.users[cursor]
|
||||||
m.confirmTarget = confirmDeleteUser
|
m.confirmTarget = confirmDeleteUser
|
||||||
m.mode = modeConfirmDelete
|
m.mode = modeConfirm
|
||||||
}
|
}
|
||||||
return m, nil
|
return m, nil
|
||||||
|
|
||||||
|
case "S":
|
||||||
|
if !m.connected {
|
||||||
|
return m, nil
|
||||||
|
}
|
||||||
|
return m.openStats()
|
||||||
|
|
||||||
case "n":
|
case "n":
|
||||||
if m.activeSection != sectionUsers || !m.connected {
|
if m.activeSection != sectionUsers || !m.connected {
|
||||||
return m, nil
|
return m, nil
|
||||||
@@ -437,9 +516,76 @@ func (m Model) handleDashboardKey(msg tea.KeyMsg) (Model, tea.Cmd) {
|
|||||||
return m, nil
|
return m, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── Detail ────────────────────────────────────────────────────────────────
|
// loadSectionIfEmpty fetches a section's data the first time it is opened.
|
||||||
|
func (m *Model) loadSectionIfEmpty() tea.Cmd {
|
||||||
|
switch m.activeSection {
|
||||||
|
case sectionAlerts:
|
||||||
|
if len(m.alerts) == 0 {
|
||||||
|
m.loading = true
|
||||||
|
return fetchAlertsCmd(m.client, m.alertFilter)
|
||||||
|
}
|
||||||
|
case sectionArchived:
|
||||||
|
if len(m.archivedIncidents) == 0 {
|
||||||
|
m.archivedLoading = true
|
||||||
|
return fetchArchivedIncidentsCmd(m.client)
|
||||||
|
}
|
||||||
|
case sectionSchedule:
|
||||||
|
if len(m.scheduleDays) == 0 {
|
||||||
|
m.scheduleLoading = true
|
||||||
|
return fetchScheduleCmd(m.client, m.scheduleWindow, m.scheduleWindow.AddDate(0, 0, 6))
|
||||||
|
}
|
||||||
|
case sectionUsers:
|
||||||
|
if len(m.users) == 0 {
|
||||||
|
m.usersLoading = true
|
||||||
|
return fetchUsersCmd(m.client)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m Model) incidentAtCursor() (api.Incident, bool) {
|
||||||
|
i := m.incidentTable.Cursor()
|
||||||
|
if i < 0 || i >= len(m.incidents) {
|
||||||
|
return api.Incident{}, false
|
||||||
|
}
|
||||||
|
return m.incidents[i], true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m Model) openIncident(inc api.Incident) (Model, tea.Cmd) {
|
||||||
|
m.selectedIncident = inc
|
||||||
|
m.mode = modeIncidentDetail
|
||||||
|
m.noteCursor = -1
|
||||||
|
m.detailLoading = true
|
||||||
|
m.detailViewport = viewport.New(m.width, m.detailViewportHeight())
|
||||||
|
return m, fetchIncidentDetailCmd(m.client, inc.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m Model) openUserPicker(target pickerTarget) (Model, tea.Cmd) {
|
||||||
|
m.pickerTarget = target
|
||||||
|
m.mode = modeUserPicker
|
||||||
|
if len(m.users) == 0 {
|
||||||
|
m.usersLoading = true
|
||||||
|
return m, fetchUsersCmd(m.client)
|
||||||
|
}
|
||||||
|
m.rebuildUserPickerTable()
|
||||||
|
return m, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// nextFilter advances a filter cycle, wrapping at the end.
|
||||||
|
func nextFilter(cycle []string, current string) string {
|
||||||
|
for i, f := range cycle {
|
||||||
|
if f == current {
|
||||||
|
return cycle[(i+1)%len(cycle)]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return cycle[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Incident detail ───────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
func (m Model) handleIncidentDetailKey(msg tea.KeyMsg) (Model, tea.Cmd) {
|
||||||
|
inc := m.selectedIncident
|
||||||
|
|
||||||
func (m Model) handleDetailKey(msg tea.KeyMsg) (Model, tea.Cmd) {
|
|
||||||
switch msg.String() {
|
switch msg.String() {
|
||||||
case "esc", "backspace":
|
case "esc", "backspace":
|
||||||
m.mode = modeDashboard
|
m.mode = modeDashboard
|
||||||
@@ -447,137 +593,245 @@ func (m Model) handleDetailKey(msg tea.KeyMsg) (Model, tea.Cmd) {
|
|||||||
return m, nil
|
return m, nil
|
||||||
|
|
||||||
case "a":
|
case "a":
|
||||||
if m.selectedAlert.AcknowledgedByID != nil {
|
if !inc.IsOpen() {
|
||||||
m.statusMsg = "already acknowledged"
|
return m.rejectClosed()
|
||||||
|
}
|
||||||
|
if inc.AcknowledgedByID != nil {
|
||||||
|
m.statusMsg = "already acknowledged by " + inc.AcknowledgedBy
|
||||||
return m, clearStatusCmd()
|
return m, clearStatusCmd()
|
||||||
}
|
}
|
||||||
return m, acknowledgeCmd(m.client, m.selectedAlert.ID)
|
return m, acknowledgeIncidentCmd(m.client, inc.ID)
|
||||||
|
|
||||||
case "A":
|
case "A":
|
||||||
if m.selectedAlert.AcknowledgedByID == nil {
|
if !inc.IsOpen() {
|
||||||
|
return m.rejectClosed()
|
||||||
|
}
|
||||||
|
if inc.AcknowledgedByID == nil {
|
||||||
m.statusMsg = "not acknowledged"
|
m.statusMsg = "not acknowledged"
|
||||||
return m, clearStatusCmd()
|
return m, clearStatusCmd()
|
||||||
}
|
}
|
||||||
return m, unacknowledgeCmd(m.client, m.selectedAlert.ID)
|
return m, unacknowledgeIncidentCmd(m.client, inc.ID)
|
||||||
|
|
||||||
|
case "R":
|
||||||
|
if !inc.IsOpen() {
|
||||||
|
return m.rejectClosed()
|
||||||
|
}
|
||||||
|
m.confirmTarget = confirmResolveIncident
|
||||||
|
m.mode = modeConfirm
|
||||||
|
return m, nil
|
||||||
|
|
||||||
|
case "s":
|
||||||
|
if !inc.IsOpen() {
|
||||||
|
return m.rejectClosed()
|
||||||
|
}
|
||||||
|
return m.openUserPicker(pickerIncidentAssignee)
|
||||||
|
|
||||||
|
case "z":
|
||||||
|
if !inc.IsOpen() {
|
||||||
|
return m.rejectClosed()
|
||||||
|
}
|
||||||
|
m.mode = modeSnooze
|
||||||
|
m.snoozeInput.Reset()
|
||||||
|
m.snoozeInput.Focus()
|
||||||
|
m.detailViewport.Height = m.detailViewportHeight()
|
||||||
|
return m, nil
|
||||||
|
|
||||||
|
case "Z":
|
||||||
|
if !inc.IsOpen() {
|
||||||
|
return m.rejectClosed()
|
||||||
|
}
|
||||||
|
if !inc.IsSnoozed() {
|
||||||
|
m.statusMsg = "not snoozed"
|
||||||
|
return m, clearStatusCmd()
|
||||||
|
}
|
||||||
|
return m, unsnoozeIncidentCmd(m.client, inc.ID)
|
||||||
|
|
||||||
|
case "x":
|
||||||
|
if inc.IsOpen() {
|
||||||
|
m.statusMsg = "resolve the incident before archiving it"
|
||||||
|
return m, clearStatusCmd()
|
||||||
|
}
|
||||||
|
if inc.ArchivedAt != nil {
|
||||||
|
m.archivedLoading = true
|
||||||
|
m.mode = modeDashboard
|
||||||
|
return m, unarchiveIncidentCmd(m.client, inc.ID)
|
||||||
|
}
|
||||||
|
m.mode = modeDashboard
|
||||||
|
return m, archiveIncidentCmd(m.client, inc.ID, m.incidentFilter)
|
||||||
|
|
||||||
case "c":
|
case "c":
|
||||||
m.mode = modeComment
|
m.mode = modeNote
|
||||||
m.commentInput.Reset()
|
m.noteInput.Reset()
|
||||||
m.commentInput.Focus()
|
m.noteInput.Focus()
|
||||||
m.detailViewport.Height = m.detailViewportHeight()
|
m.detailViewport.Height = m.detailViewportHeight()
|
||||||
return m, nil
|
return m, nil
|
||||||
|
|
||||||
case "d":
|
case "d":
|
||||||
if m.commentCursor < 0 || m.commentCursor >= len(m.comments) {
|
notes := noteEvents(m.timeline)
|
||||||
m.statusMsg = "select a comment first with [ / ]"
|
if m.noteCursor < 0 || m.noteCursor >= len(notes) {
|
||||||
|
m.statusMsg = "select a note first with [ / ]"
|
||||||
return m, clearStatusCmd()
|
return m, clearStatusCmd()
|
||||||
}
|
}
|
||||||
m.pendingDeleteID = m.comments[m.commentCursor].ID
|
m.pendingDeleteID = notes[m.noteCursor].ID
|
||||||
m.confirmTarget = confirmDeleteComment
|
m.confirmTarget = confirmDeleteNote
|
||||||
m.mode = modeConfirmDelete
|
m.mode = modeConfirm
|
||||||
return m, nil
|
return m, nil
|
||||||
|
|
||||||
case "s":
|
|
||||||
m.statusMsg = "assign not yet supported by server"
|
|
||||||
return m, clearStatusCmd()
|
|
||||||
|
|
||||||
case "S":
|
case "S":
|
||||||
m.mode = modeStats
|
return m.openStats()
|
||||||
m.statsLoading = true
|
|
||||||
m.statsViewport = viewport.New(m.width, m.height-5)
|
|
||||||
return m, fetchDetailStatsCmd(m.client)
|
|
||||||
|
|
||||||
case "[":
|
case "[":
|
||||||
if len(m.comments) == 0 {
|
return m.moveNoteCursor(-1), nil
|
||||||
return m, nil
|
|
||||||
}
|
|
||||||
if m.commentCursor <= 0 {
|
|
||||||
m.commentCursor = len(m.comments) - 1
|
|
||||||
} else {
|
|
||||||
m.commentCursor--
|
|
||||||
}
|
|
||||||
m.refreshDetailContent()
|
|
||||||
return m, nil
|
|
||||||
|
|
||||||
case "]":
|
case "]":
|
||||||
if len(m.comments) == 0 {
|
return m.moveNoteCursor(1), nil
|
||||||
|
}
|
||||||
|
|
||||||
return m, nil
|
return m, nil
|
||||||
}
|
}
|
||||||
if m.commentCursor >= len(m.comments)-1 {
|
|
||||||
m.commentCursor = 0
|
// rejectClosed reports why an action did nothing on a resolved incident. The
|
||||||
|
// server answers 409 anyway; saying so up front is friendlier than a round trip.
|
||||||
|
func (m Model) rejectClosed() (Model, tea.Cmd) {
|
||||||
|
m.statusMsg = "incident is resolved — a new occurrence opens a new incident"
|
||||||
|
return m, clearStatusCmd()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m Model) moveNoteCursor(delta int) Model {
|
||||||
|
notes := noteEvents(m.timeline)
|
||||||
|
if len(notes) == 0 {
|
||||||
|
return m
|
||||||
|
}
|
||||||
|
switch {
|
||||||
|
case m.noteCursor < 0:
|
||||||
|
if delta > 0 {
|
||||||
|
m.noteCursor = 0
|
||||||
} else {
|
} else {
|
||||||
m.commentCursor++
|
m.noteCursor = len(notes) - 1
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
m.noteCursor = (m.noteCursor + delta + len(notes)) % len(notes)
|
||||||
}
|
}
|
||||||
m.refreshDetailContent()
|
m.refreshDetailContent()
|
||||||
|
return m
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Alert detail (read-only) ──────────────────────────────────────────────
|
||||||
|
|
||||||
|
func (m Model) handleAlertDetailKey(msg tea.KeyMsg) (Model, tea.Cmd) {
|
||||||
|
switch msg.String() {
|
||||||
|
case "esc", "backspace":
|
||||||
|
m.mode = modeDashboard
|
||||||
|
m.statusMsg = ""
|
||||||
return m, nil
|
return m, nil
|
||||||
|
|
||||||
|
case "i":
|
||||||
|
// Jump to the incident this alert belongs to — the place where anything
|
||||||
|
// can actually be done about it.
|
||||||
|
if m.selectedAlert.IncidentID == nil {
|
||||||
|
m.statusMsg = "this alert has no incident"
|
||||||
|
return m, clearStatusCmd()
|
||||||
|
}
|
||||||
|
return m.openIncident(api.Incident{ID: *m.selectedAlert.IncidentID})
|
||||||
|
|
||||||
|
case "S":
|
||||||
|
return m.openStats()
|
||||||
}
|
}
|
||||||
|
|
||||||
return m, nil
|
return m, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── Comment compose ───────────────────────────────────────────────────────
|
// ── Note compose ──────────────────────────────────────────────────────────
|
||||||
|
|
||||||
func (m Model) handleCommentKey(msg tea.KeyMsg) (Model, tea.Cmd) {
|
func (m Model) handleNoteKey(msg tea.KeyMsg) (Model, tea.Cmd) {
|
||||||
switch msg.String() {
|
switch msg.String() {
|
||||||
case "esc":
|
case "esc":
|
||||||
m.mode = modeDetail
|
m.mode = modeIncidentDetail
|
||||||
m.commentInput.Blur()
|
m.noteInput.Blur()
|
||||||
m.detailViewport.Height = m.detailViewportHeight()
|
m.detailViewport.Height = m.detailViewportHeight()
|
||||||
return m, nil
|
return m, nil
|
||||||
|
|
||||||
case "enter":
|
case "enter":
|
||||||
content := strings.TrimSpace(m.commentInput.Value())
|
content := strings.TrimSpace(m.noteInput.Value())
|
||||||
if content == "" {
|
if content == "" {
|
||||||
return m, nil
|
return m, nil
|
||||||
}
|
}
|
||||||
m.mode = modeDetail
|
m.mode = modeIncidentDetail
|
||||||
m.commentInput.Blur()
|
m.noteInput.Blur()
|
||||||
m.detailViewport.Height = m.detailViewportHeight()
|
m.detailViewport.Height = m.detailViewportHeight()
|
||||||
return m, addCommentCmd(m.client, m.selectedAlert.ID, content)
|
return m, addNoteCmd(m.client, m.selectedIncident.ID, content)
|
||||||
}
|
}
|
||||||
|
|
||||||
return m, nil
|
return m, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── Confirm delete ────────────────────────────────────────────────────────
|
// ── Snooze ────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
func (m Model) handleSnoozeKey(msg tea.KeyMsg) (Model, tea.Cmd) {
|
||||||
|
switch msg.String() {
|
||||||
|
case "esc":
|
||||||
|
m.mode = modeIncidentDetail
|
||||||
|
m.snoozeInput.Blur()
|
||||||
|
m.detailViewport.Height = m.detailViewportHeight()
|
||||||
|
return m, nil
|
||||||
|
|
||||||
|
case "enter":
|
||||||
|
duration := strings.TrimSpace(m.snoozeInput.Value())
|
||||||
|
if duration == "" {
|
||||||
|
return m, nil
|
||||||
|
}
|
||||||
|
m.mode = modeIncidentDetail
|
||||||
|
m.snoozeInput.Blur()
|
||||||
|
m.detailViewport.Height = m.detailViewportHeight()
|
||||||
|
return m, snoozeIncidentCmd(m.client, m.selectedIncident.ID, duration)
|
||||||
|
}
|
||||||
|
|
||||||
|
return m, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Confirm ───────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
func (m Model) handleConfirmKey(msg tea.KeyMsg) (Model, tea.Cmd) {
|
func (m Model) handleConfirmKey(msg tea.KeyMsg) (Model, tea.Cmd) {
|
||||||
switch strings.ToLower(msg.String()) {
|
if strings.ToLower(msg.String()) != "y" {
|
||||||
case "y":
|
|
||||||
switch m.confirmTarget {
|
switch m.confirmTarget {
|
||||||
case confirmDeleteComment:
|
case confirmDeleteNote, confirmResolveIncident:
|
||||||
alertID := m.selectedAlert.ID
|
m.mode = modeIncidentDetail
|
||||||
commentID := m.pendingDeleteID
|
default:
|
||||||
m.mode = modeDetail
|
m.mode = modeDashboard
|
||||||
m.commentCursor = -1
|
}
|
||||||
m.pendingDeleteID = 0
|
m.pendingDeleteID = 0
|
||||||
return m, deleteCommentCmd(m.client, alertID, commentID)
|
m.pendingDeleteEntry = nil
|
||||||
|
return m, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
switch m.confirmTarget {
|
||||||
|
case confirmDeleteNote:
|
||||||
|
incidentID := m.selectedIncident.ID
|
||||||
|
eventID := m.pendingDeleteID
|
||||||
|
m.mode = modeIncidentDetail
|
||||||
|
m.noteCursor = -1
|
||||||
|
m.pendingDeleteID = 0
|
||||||
|
return m, deleteNoteCmd(m.client, incidentID, eventID)
|
||||||
|
|
||||||
|
case confirmResolveIncident:
|
||||||
|
m.mode = modeIncidentDetail
|
||||||
|
return m, resolveIncidentCmd(m.client, m.selectedIncident.ID)
|
||||||
|
|
||||||
case confirmDeleteScheduleEntry:
|
case confirmDeleteScheduleEntry:
|
||||||
entry := m.pendingDeleteEntry
|
entry := m.pendingDeleteEntry
|
||||||
m.mode = modeDashboard
|
m.mode = modeDashboard
|
||||||
m.pendingDeleteEntry = nil
|
m.pendingDeleteEntry = nil
|
||||||
m.scheduleLoading = true
|
m.scheduleLoading = true
|
||||||
from := m.scheduleWindow
|
return m, deleteScheduleEntryCmd(m.client, entry.ID,
|
||||||
to := m.scheduleWindow.AddDate(0, 0, 13)
|
m.scheduleWindow, m.scheduleWindow.AddDate(0, 0, 6))
|
||||||
return m, deleteScheduleEntryCmd(m.client, entry.ID, from, to)
|
|
||||||
case confirmDeleteUser:
|
case confirmDeleteUser:
|
||||||
userID := m.selectedUser.ID
|
userID := m.selectedUser.ID
|
||||||
m.mode = modeDashboard
|
m.mode = modeDashboard
|
||||||
m.usersLoading = true
|
m.usersLoading = true
|
||||||
return m, deleteUserCmd(m.client, userID)
|
return m, deleteUserCmd(m.client, userID)
|
||||||
}
|
}
|
||||||
default:
|
|
||||||
switch m.confirmTarget {
|
|
||||||
case confirmDeleteComment:
|
|
||||||
m.mode = modeDetail
|
|
||||||
case confirmDeleteScheduleEntry:
|
|
||||||
m.mode = modeDashboard
|
|
||||||
case confirmDeleteUser:
|
|
||||||
m.mode = modeDashboard
|
|
||||||
}
|
|
||||||
m.pendingDeleteID = 0
|
|
||||||
m.pendingDeleteEntry = nil
|
|
||||||
}
|
|
||||||
return m, nil
|
return m, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -585,26 +839,45 @@ func (m Model) handleConfirmKey(msg tea.KeyMsg) (Model, tea.Cmd) {
|
|||||||
|
|
||||||
func (m Model) handleStatsKey(msg tea.KeyMsg) (Model, tea.Cmd) {
|
func (m Model) handleStatsKey(msg tea.KeyMsg) (Model, tea.Cmd) {
|
||||||
if msg.String() == "esc" {
|
if msg.String() == "esc" {
|
||||||
m.mode = modeDetail
|
m.mode = m.statsReturnMode
|
||||||
return m, nil
|
return m, nil
|
||||||
}
|
}
|
||||||
return m, nil
|
return m, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// openStats enters the statistics view, remembering where to go back to.
|
||||||
|
func (m Model) openStats() (Model, tea.Cmd) {
|
||||||
|
m.statsReturnMode = m.mode
|
||||||
|
m.mode = modeStats
|
||||||
|
m.statsLoading = true
|
||||||
|
m.statsViewport = viewport.New(m.width, m.height-5)
|
||||||
|
return m, fetchDetailStatsCmd(m.client)
|
||||||
|
}
|
||||||
|
|
||||||
// ── User picker ───────────────────────────────────────────────────────────
|
// ── User picker ───────────────────────────────────────────────────────────
|
||||||
|
|
||||||
func (m Model) handleUserPickerKey(msg tea.KeyMsg) (Model, tea.Cmd) {
|
func (m Model) handleUserPickerKey(msg tea.KeyMsg) (Model, tea.Cmd) {
|
||||||
switch msg.String() {
|
switch msg.String() {
|
||||||
case "esc":
|
case "esc":
|
||||||
|
if m.pickerTarget == pickerIncidentAssignee {
|
||||||
|
m.mode = modeIncidentDetail
|
||||||
|
} else {
|
||||||
m.mode = modeDashboard
|
m.mode = modeDashboard
|
||||||
|
}
|
||||||
return m, nil
|
return m, nil
|
||||||
|
|
||||||
case "enter":
|
case "enter":
|
||||||
cursor := m.userPickerTable.Cursor()
|
cursor := m.userPickerTable.Cursor()
|
||||||
if cursor >= len(m.users) {
|
if cursor < 0 || cursor >= len(m.users) {
|
||||||
return m, nil
|
return m, nil
|
||||||
}
|
}
|
||||||
user := m.users[cursor]
|
user := m.users[cursor]
|
||||||
|
|
||||||
|
if m.pickerTarget == pickerIncidentAssignee {
|
||||||
|
m.mode = modeIncidentDetail
|
||||||
|
return m, assignIncidentCmd(m.client, m.selectedIncident.ID, user.ID)
|
||||||
|
}
|
||||||
|
|
||||||
scheduleCursor := m.scheduleTable.Cursor()
|
scheduleCursor := m.scheduleTable.Cursor()
|
||||||
if scheduleCursor >= len(m.scheduleDays) {
|
if scheduleCursor >= len(m.scheduleDays) {
|
||||||
m.mode = modeDashboard
|
m.mode = modeDashboard
|
||||||
@@ -624,11 +897,10 @@ func (m Model) handleUserPickerKey(msg tea.KeyMsg) (Model, tea.Cmd) {
|
|||||||
} else {
|
} else {
|
||||||
dates = []string{d.Format("2006-01-02")}
|
dates = []string{d.Format("2006-01-02")}
|
||||||
}
|
}
|
||||||
from := m.scheduleWindow
|
|
||||||
to := m.scheduleWindow.AddDate(0, 0, 13)
|
|
||||||
m.mode = modeDashboard
|
m.mode = modeDashboard
|
||||||
m.scheduleLoading = true
|
m.scheduleLoading = true
|
||||||
return m, assignScheduleCmd(m.client, user.ID, dates, from, to)
|
return m, assignScheduleCmd(m.client, user.ID, dates,
|
||||||
|
m.scheduleWindow, m.scheduleWindow.AddDate(0, 0, 6))
|
||||||
}
|
}
|
||||||
|
|
||||||
return m, nil
|
return m, nil
|
||||||
|
|||||||
+431
-221
@@ -10,7 +10,7 @@ import (
|
|||||||
"github.com/yeniklas/terdut-tui/internal/api"
|
"github.com/yeniklas/terdut-tui/internal/api"
|
||||||
)
|
)
|
||||||
|
|
||||||
var sectionNames = []string{"Alerts", "Schedule", "Users"}
|
var sectionNames = []string{"Incidents", "Alerts", "Archived", "Schedule", "Users"}
|
||||||
|
|
||||||
func (m Model) View() string {
|
func (m Model) View() string {
|
||||||
if m.width == 0 {
|
if m.width == 0 {
|
||||||
@@ -27,11 +27,7 @@ func (m Model) View() string {
|
|||||||
func (m Model) renderHeader() string {
|
func (m Model) renderHeader() string {
|
||||||
title := styleHeader.Render("terdut-tui")
|
title := styleHeader.Render("terdut-tui")
|
||||||
right := styleMuted.Render(m.serverURL)
|
right := styleMuted.Render(m.serverURL)
|
||||||
gap := m.width - lipgloss.Width(title) - lipgloss.Width(right)
|
return spread(title, right, m.width)
|
||||||
if gap < 0 {
|
|
||||||
gap = 0
|
|
||||||
}
|
|
||||||
return title + strings.Repeat(" ", gap) + right
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m Model) renderTabs() string {
|
func (m Model) renderTabs() string {
|
||||||
@@ -57,13 +53,15 @@ func (m Model) renderBody() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch m.mode {
|
switch m.mode {
|
||||||
case modeDetail:
|
case modeIncidentDetail, modeAlertDetail:
|
||||||
return m.renderDetail()
|
return m.renderDetail()
|
||||||
case modeComment:
|
case modeNote:
|
||||||
return m.renderCommentCompose()
|
return m.renderPrompt(styleHeader.Render("Note: ") + m.noteInput.View())
|
||||||
case modeConfirmDelete:
|
case modeSnooze:
|
||||||
|
return m.renderPrompt(styleHeader.Render("Snooze for: ") + m.snoozeInput.View())
|
||||||
|
case modeConfirm:
|
||||||
switch m.confirmTarget {
|
switch m.confirmTarget {
|
||||||
case confirmDeleteComment:
|
case confirmDeleteNote, confirmResolveIncident:
|
||||||
return m.renderDetail()
|
return m.renderDetail()
|
||||||
case confirmDeleteUser:
|
case confirmDeleteUser:
|
||||||
return m.renderUsers()
|
return m.renderUsers()
|
||||||
@@ -72,7 +70,7 @@ func (m Model) renderBody() string {
|
|||||||
}
|
}
|
||||||
case modeStats:
|
case modeStats:
|
||||||
return m.renderStats()
|
return m.renderStats()
|
||||||
case modeScheduleUserPicker:
|
case modeUserPicker:
|
||||||
return m.renderUserPicker()
|
return m.renderUserPicker()
|
||||||
case modeUserCreate:
|
case modeUserCreate:
|
||||||
return m.renderUserCreate()
|
return m.renderUserCreate()
|
||||||
@@ -90,112 +88,107 @@ func (m Model) renderBody() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m Model) renderFooter() string {
|
func (m Model) renderFooter() string {
|
||||||
switch m.mode {
|
withStatus := func(actions string) string {
|
||||||
case modeDetail:
|
rendered := styleFooter.Render(actions)
|
||||||
actions := styleFooter.Render(" a·ack A·unack c·comment [/]·select d·del s·assign S·stats esc·back")
|
|
||||||
if m.statusMsg != "" {
|
if m.statusMsg != "" {
|
||||||
return styleStatus.Render(" "+m.statusMsg) + "\n" + actions
|
return styleStatus.Render(" "+m.statusMsg) + "\n" + rendered
|
||||||
|
}
|
||||||
|
return "\n" + rendered
|
||||||
}
|
}
|
||||||
return "\n" + actions
|
|
||||||
|
|
||||||
case modeComment:
|
switch m.mode {
|
||||||
|
case modeIncidentDetail:
|
||||||
|
if !m.selectedIncident.IsOpen() {
|
||||||
|
return withStatus(" x·archive c·note [/]·select d·del S·stats esc·back")
|
||||||
|
}
|
||||||
|
return withStatus(" a·ack A·unack R·resolve s·assign z·snooze Z·unsnooze c·note [/]·select d·del S·stats esc·back")
|
||||||
|
|
||||||
|
case modeAlertDetail:
|
||||||
|
return withStatus(" i·open incident S·stats esc·back")
|
||||||
|
|
||||||
|
case modeNote:
|
||||||
return "\n" + styleFooter.Render(" enter·submit esc·cancel")
|
return "\n" + styleFooter.Render(" enter·submit esc·cancel")
|
||||||
|
|
||||||
case modeConfirmDelete:
|
case modeSnooze:
|
||||||
var deleteDesc string
|
return "\n" + styleFooter.Render(" enter·snooze esc·cancel (e.g. 30m, 2h, 24h)")
|
||||||
switch m.confirmTarget {
|
|
||||||
case confirmDeleteComment:
|
case modeConfirm:
|
||||||
if m.commentCursor >= 0 && m.commentCursor < len(m.comments) {
|
return "\n" + styleError.Render(" "+m.confirmPrompt())
|
||||||
deleteDesc = fmt.Sprintf("comment by %s", m.comments[m.commentCursor].Username)
|
|
||||||
} else {
|
|
||||||
deleteDesc = "comment"
|
|
||||||
}
|
|
||||||
case confirmDeleteScheduleEntry:
|
|
||||||
if m.pendingDeleteEntry != nil {
|
|
||||||
deleteDesc = fmt.Sprintf("on-call for %s (%s)", m.pendingDeleteEntry.Date, m.pendingDeleteEntry.Username)
|
|
||||||
} else {
|
|
||||||
deleteDesc = "schedule entry"
|
|
||||||
}
|
|
||||||
case confirmDeleteUser:
|
|
||||||
deleteDesc = fmt.Sprintf("user %s (cascades all API keys)", m.selectedUser.Username)
|
|
||||||
}
|
|
||||||
return "\n" + styleError.Render(fmt.Sprintf(" Delete %s? [y/N]", deleteDesc))
|
|
||||||
|
|
||||||
case modeStats:
|
case modeStats:
|
||||||
if m.statusMsg != "" {
|
return withStatus(" esc·back")
|
||||||
return styleStatus.Render(" "+m.statusMsg) + "\n" + styleFooter.Render(" esc·back")
|
|
||||||
}
|
|
||||||
return "\n" + styleFooter.Render(" esc·back")
|
|
||||||
|
|
||||||
case modeScheduleUserPicker:
|
case modeUserPicker:
|
||||||
mode := "day"
|
if m.pickerTarget == pickerIncidentAssignee {
|
||||||
if m.pickerAssignWeek {
|
return withStatus(" j/k·navigate enter·assign incident esc·cancel")
|
||||||
mode = "week"
|
|
||||||
}
|
}
|
||||||
return "\n" + styleFooter.Render(fmt.Sprintf(" j/k·navigate enter·assign %s esc·cancel", mode))
|
scope := "day"
|
||||||
|
if m.pickerAssignWeek {
|
||||||
|
scope = "week"
|
||||||
|
}
|
||||||
|
return withStatus(fmt.Sprintf(" j/k·navigate enter·assign %s esc·cancel", scope))
|
||||||
|
|
||||||
case modeUserCreate:
|
case modeUserCreate:
|
||||||
if m.statusMsg != "" {
|
return withStatus(" tab·next field enter·create esc·cancel")
|
||||||
return styleStatus.Render(" "+m.statusMsg) + "\n" + styleFooter.Render(" tab·next field enter·create esc·cancel")
|
|
||||||
}
|
|
||||||
return "\n" + styleFooter.Render(" tab·next field enter·create esc·cancel")
|
|
||||||
|
|
||||||
case modeAPIKeyMenu:
|
case modeAPIKeyMenu:
|
||||||
return "\n" + styleFooter.Render(" n·new key r·revoke by ID esc·back")
|
return withStatus(" n·new key r·revoke by ID esc·back")
|
||||||
|
|
||||||
case modeAPIKeyCreate:
|
case modeAPIKeyCreate:
|
||||||
if m.statusMsg != "" {
|
return withStatus(" enter·create esc·back")
|
||||||
return styleStatus.Render(" "+m.statusMsg) + "\n" + styleFooter.Render(" enter·create esc·back")
|
|
||||||
}
|
|
||||||
return "\n" + styleFooter.Render(" enter·create esc·back")
|
|
||||||
|
|
||||||
case modeAPIKeyReveal:
|
case modeAPIKeyReveal:
|
||||||
footer := " c·copy to clipboard esc·done"
|
return withStatus(" c·copy to clipboard esc·done")
|
||||||
if m.statusMsg != "" {
|
|
||||||
return styleStatus.Render(" "+m.statusMsg) + "\n" + styleFooter.Render(footer)
|
|
||||||
}
|
|
||||||
return "\n" + styleFooter.Render(footer)
|
|
||||||
|
|
||||||
case modeAPIKeyRevokeByID:
|
case modeAPIKeyRevokeByID:
|
||||||
if m.statusMsg != "" {
|
return withStatus(" enter·revoke esc·back")
|
||||||
return styleStatus.Render(" "+m.statusMsg) + "\n" + styleFooter.Render(" enter·revoke esc·back")
|
|
||||||
}
|
|
||||||
return "\n" + styleFooter.Render(" enter·revoke esc·back")
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if m.activeSection == sectionSchedule {
|
switch m.activeSection {
|
||||||
actions := styleFooter.Render(" +·assign day W·assign week d·del ←/→·shift week tab·section r·refresh q·quit")
|
case sectionIncidents:
|
||||||
if m.statusMsg != "" {
|
return withStatus(" enter·detail x·archive f·filter S·stats r·refresh tab·section q·quit")
|
||||||
return styleStatus.Render(" "+m.statusMsg) + "\n" + actions
|
case sectionAlerts:
|
||||||
|
return withStatus(" enter·detail f·filter S·stats r·refresh tab·section q·quit")
|
||||||
|
case sectionArchived:
|
||||||
|
return withStatus(" enter·detail x·unarchive r·refresh tab·section q·quit")
|
||||||
|
case sectionSchedule:
|
||||||
|
return withStatus(" +·assign day W·assign week d·del ←/→·shift week tab·section r·refresh q·quit")
|
||||||
|
case sectionUsers:
|
||||||
|
return withStatus(" n·new user d·delete k·API keys r·refresh tab·section q·quit")
|
||||||
}
|
}
|
||||||
return "\n" + actions
|
return "\n" + styleFooter.Render(m.help.ShortHelpView(m.keys.ShortHelp()))
|
||||||
}
|
}
|
||||||
if m.activeSection == sectionUsers {
|
|
||||||
actions := styleFooter.Render(" n·new user d·delete k·API keys r·refresh tab·section q·quit")
|
|
||||||
if m.statusMsg != "" {
|
|
||||||
return styleStatus.Render(" "+m.statusMsg) + "\n" + actions
|
|
||||||
}
|
}
|
||||||
return "\n" + actions
|
|
||||||
|
func (m Model) confirmPrompt() string {
|
||||||
|
switch m.confirmTarget {
|
||||||
|
case confirmDeleteNote:
|
||||||
|
return "Delete this note? [y/N]"
|
||||||
|
case confirmResolveIncident:
|
||||||
|
// Manual resolution is terminal on the server, so say so before asking.
|
||||||
|
return "Resolve incident? This is final — a new occurrence opens a new incident. [y/N]"
|
||||||
|
case confirmDeleteScheduleEntry:
|
||||||
|
if m.pendingDeleteEntry != nil {
|
||||||
|
return fmt.Sprintf("Delete on-call for %s (%s)? [y/N]",
|
||||||
|
m.pendingDeleteEntry.Date, m.pendingDeleteEntry.Username)
|
||||||
}
|
}
|
||||||
helpView := styleFooter.Render(m.help.ShortHelpView(m.keys.ShortHelp()))
|
return "Delete schedule entry? [y/N]"
|
||||||
if m.statusMsg != "" {
|
case confirmDeleteUser:
|
||||||
status := styleStatus.Render(m.statusMsg)
|
return fmt.Sprintf("Delete user %s (cascades all API keys)? [y/N]", m.selectedUser.Username)
|
||||||
gap := m.width - lipgloss.Width(status) - lipgloss.Width(helpView)
|
|
||||||
if gap < 0 {
|
|
||||||
gap = 0
|
|
||||||
}
|
|
||||||
return "\n" + status + strings.Repeat(" ", gap) + helpView
|
|
||||||
}
|
|
||||||
return "\n" + helpView
|
|
||||||
}
|
}
|
||||||
|
return "Are you sure? [y/N]"
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── Dashboard ──────────────────────────────────────────────────────────────
|
// ── Dashboard ──────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
func (m Model) renderDashboard() string {
|
func (m Model) renderDashboard() string {
|
||||||
switch m.activeSection {
|
switch m.activeSection {
|
||||||
|
case sectionIncidents:
|
||||||
|
return m.renderIncidents()
|
||||||
case sectionAlerts:
|
case sectionAlerts:
|
||||||
return m.renderAlerts()
|
return m.renderAlerts()
|
||||||
|
case sectionArchived:
|
||||||
|
return m.renderArchived()
|
||||||
case sectionSchedule:
|
case sectionSchedule:
|
||||||
return m.renderSchedule()
|
return m.renderSchedule()
|
||||||
case sectionUsers:
|
case sectionUsers:
|
||||||
@@ -204,6 +197,90 @@ func (m Model) renderDashboard() string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m Model) renderIncidents() string {
|
||||||
|
bar := m.renderIncidentStatsBar()
|
||||||
|
var content string
|
||||||
|
switch {
|
||||||
|
case m.loading && len(m.incidents) == 0:
|
||||||
|
content = styleMuted.Render(" Loading incidents…")
|
||||||
|
case len(m.incidents) == 0:
|
||||||
|
content = styleMuted.Render(
|
||||||
|
fmt.Sprintf(" No %s incidents.", filterLabel(m.incidentFilter)))
|
||||||
|
default:
|
||||||
|
content = m.incidentTable.View()
|
||||||
|
}
|
||||||
|
return lipgloss.JoinVertical(lipgloss.Left, bar, content)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m Model) renderAlerts() string {
|
||||||
|
bar := m.renderAlertStatsBar()
|
||||||
|
var content string
|
||||||
|
switch {
|
||||||
|
case m.loading && len(m.alerts) == 0:
|
||||||
|
content = styleMuted.Render(" Loading alerts…")
|
||||||
|
case len(m.alerts) == 0:
|
||||||
|
content = styleMuted.Render(fmt.Sprintf(" No %s alerts.", filterLabel(m.alertFilter)))
|
||||||
|
default:
|
||||||
|
content = m.alertTable.View()
|
||||||
|
}
|
||||||
|
return lipgloss.JoinVertical(lipgloss.Left, bar, content)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m Model) renderArchived() string {
|
||||||
|
if m.archivedLoading {
|
||||||
|
return "\n" + styleMuted.Render(" Loading archived incidents…")
|
||||||
|
}
|
||||||
|
if len(m.archivedIncidents) == 0 {
|
||||||
|
return "\n" + styleMuted.Render(" No archived incidents.")
|
||||||
|
}
|
||||||
|
return "\n" + m.archivedTable.View()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m Model) renderIncidentStatsBar() string {
|
||||||
|
var triggered, acked, resolved int
|
||||||
|
mtta, mttr := "—", "—"
|
||||||
|
if m.incidentStats != nil {
|
||||||
|
triggered = m.incidentStats.Triggered
|
||||||
|
acked = m.incidentStats.Acknowledged
|
||||||
|
resolved = m.incidentStats.Resolved
|
||||||
|
mtta = humanSeconds(m.incidentStats.MTTASeconds)
|
||||||
|
mttr = humanSeconds(m.incidentStats.MTTRSeconds)
|
||||||
|
}
|
||||||
|
left := fmt.Sprintf(" %s %s %s %s",
|
||||||
|
styleTriggered.Render(fmt.Sprintf("Triggered: %d", triggered)),
|
||||||
|
styleAcknowledged.Render(fmt.Sprintf("Acked: %d", acked)),
|
||||||
|
styleResolved.Render(fmt.Sprintf("Resolved: %d", resolved)),
|
||||||
|
styleMuted.Render(fmt.Sprintf("MTTA %s · MTTR %s", mtta, mttr)),
|
||||||
|
)
|
||||||
|
right := styleMuted.Render(fmt.Sprintf("filter: %s [f] ", filterLabel(m.incidentFilter)))
|
||||||
|
return spread(left, right, m.width)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m Model) renderAlertStatsBar() string {
|
||||||
|
total, firing, resolved := 0, 0, 0
|
||||||
|
if m.alertStats != nil {
|
||||||
|
total = m.alertStats.Total
|
||||||
|
firing = m.alertStats.Firing
|
||||||
|
resolved = m.alertStats.Resolved
|
||||||
|
}
|
||||||
|
left := fmt.Sprintf(" Total: %d %s %s",
|
||||||
|
total,
|
||||||
|
styleFiring.Render(fmt.Sprintf("Firing: %d", firing)),
|
||||||
|
styleResolved.Render(fmt.Sprintf("Resolved: %d", resolved)),
|
||||||
|
)
|
||||||
|
right := styleMuted.Render(fmt.Sprintf("filter: %s [f] ", filterLabel(m.alertFilter)))
|
||||||
|
return spread(left, right, m.width)
|
||||||
|
}
|
||||||
|
|
||||||
|
// spread pushes left and right to the edges of a width.
|
||||||
|
func spread(left, right string, width int) string {
|
||||||
|
gap := width - lipgloss.Width(left) - lipgloss.Width(right)
|
||||||
|
if gap < 0 {
|
||||||
|
gap = 0
|
||||||
|
}
|
||||||
|
return left + strings.Repeat(" ", gap) + right
|
||||||
|
}
|
||||||
|
|
||||||
// ── Schedule ───────────────────────────────────────────────────────────────
|
// ── Schedule ───────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
func (m Model) renderSchedule() string {
|
func (m Model) renderSchedule() string {
|
||||||
@@ -211,7 +288,6 @@ func (m Model) renderSchedule() string {
|
|||||||
return "\n" + styleMuted.Render(" Loading schedule…")
|
return "\n" + styleMuted.Render(" Loading schedule…")
|
||||||
}
|
}
|
||||||
|
|
||||||
// On-call header
|
|
||||||
var onCallLine string
|
var onCallLine string
|
||||||
if m.currentOnCall != nil {
|
if m.currentOnCall != nil {
|
||||||
onCallLine = fmt.Sprintf(" On-call today: %s",
|
onCallLine = fmt.Sprintf(" On-call today: %s",
|
||||||
@@ -220,17 +296,12 @@ func (m Model) renderSchedule() string {
|
|||||||
onCallLine = styleMuted.Render(" On-call today: nobody scheduled")
|
onCallLine = styleMuted.Render(" On-call today: nobody scheduled")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Window label
|
|
||||||
from := m.scheduleWindow
|
from := m.scheduleWindow
|
||||||
to := m.scheduleWindow.AddDate(0, 0, 13)
|
to := m.scheduleWindow.AddDate(0, 0, 6)
|
||||||
windowLabel := styleMuted.Render(fmt.Sprintf(" %s — %s",
|
windowLabel := styleMuted.Render(fmt.Sprintf(" %s — %s",
|
||||||
from.Format("Jan 02"), to.Format("Jan 02, 2006")))
|
from.Format("Jan 02"), to.Format("Jan 02, 2006")))
|
||||||
|
|
||||||
gap := m.width - lipgloss.Width(onCallLine) - lipgloss.Width(windowLabel)
|
header := "\n" + spread(onCallLine, windowLabel, m.width) + "\n"
|
||||||
if gap < 0 {
|
|
||||||
gap = 0
|
|
||||||
}
|
|
||||||
header := "\n" + onCallLine + strings.Repeat(" ", gap) + windowLabel + "\n"
|
|
||||||
return header + m.scheduleTable.View()
|
return header + m.scheduleTable.View()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -239,6 +310,12 @@ func (m Model) renderUserPicker() string {
|
|||||||
return "\n" + styleMuted.Render(" Loading users…")
|
return "\n" + styleMuted.Render(" Loading users…")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if m.pickerTarget == pickerIncidentAssignee {
|
||||||
|
header := fmt.Sprintf("\n Assign %s to:\n\n",
|
||||||
|
styleBold.Render(m.selectedIncident.Title))
|
||||||
|
return header + m.userPickerTable.View()
|
||||||
|
}
|
||||||
|
|
||||||
var scope string
|
var scope string
|
||||||
cursor := m.scheduleTable.Cursor()
|
cursor := m.scheduleTable.Cursor()
|
||||||
if cursor >= 0 && cursor < len(m.scheduleDays) {
|
if cursor >= 0 && cursor < len(m.scheduleDays) {
|
||||||
@@ -253,75 +330,30 @@ func (m Model) renderUserPicker() string {
|
|||||||
_, week := d.ISOWeek()
|
_, week := d.ISOWeek()
|
||||||
scope = fmt.Sprintf("week W%02d (%s–%s)",
|
scope = fmt.Sprintf("week W%02d (%s–%s)",
|
||||||
week, monday.Format("Jan 02"), sunday.Format("Jan 02"))
|
week, monday.Format("Jan 02"), sunday.Format("Jan 02"))
|
||||||
} else {
|
} else if d.Format("2006-01-02") == time.Now().UTC().Format("2006-01-02") {
|
||||||
if d.Format("2006-01-02") == time.Now().UTC().Format("2006-01-02") {
|
|
||||||
scope = "Today (" + d.Format("Mon") + ")"
|
scope = "Today (" + d.Format("Mon") + ")"
|
||||||
} else {
|
} else {
|
||||||
scope = d.Format("Jan 02 (Mon)")
|
scope = d.Format("Jan 02 (Mon)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
header := fmt.Sprintf("\n Assign on-call for %s — select a user:\n\n",
|
header := fmt.Sprintf("\n Assign on-call for %s — select a user:\n\n", styleBold.Render(scope))
|
||||||
styleBold.Render(scope))
|
|
||||||
return header + m.userPickerTable.View()
|
return header + m.userPickerTable.View()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m Model) renderAlerts() string {
|
|
||||||
statsBar := m.renderStatsBar()
|
|
||||||
var content string
|
|
||||||
if m.loading && len(m.alerts) == 0 {
|
|
||||||
content = styleMuted.Render(" Loading alerts…")
|
|
||||||
} else if len(m.alerts) == 0 {
|
|
||||||
label := m.filterStatus
|
|
||||||
if label == "" {
|
|
||||||
label = "all"
|
|
||||||
}
|
|
||||||
content = styleMuted.Render(fmt.Sprintf(" No %s alerts.", label))
|
|
||||||
} else {
|
|
||||||
content = m.alertTable.View()
|
|
||||||
}
|
|
||||||
return lipgloss.JoinVertical(lipgloss.Left, statsBar, content)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m Model) renderStatsBar() string {
|
|
||||||
total, firing, resolved := 0, 0, 0
|
|
||||||
if m.stats != nil {
|
|
||||||
total = m.stats.Total
|
|
||||||
firing = m.stats.Firing
|
|
||||||
resolved = m.stats.Resolved
|
|
||||||
}
|
|
||||||
filterLabel := m.filterStatus
|
|
||||||
if filterLabel == "" {
|
|
||||||
filterLabel = "all"
|
|
||||||
}
|
|
||||||
left := fmt.Sprintf(" Total: %d %s %s",
|
|
||||||
total,
|
|
||||||
styleFiring.Render(fmt.Sprintf("Firing: %d", firing)),
|
|
||||||
styleResolved.Render(fmt.Sprintf("Resolved: %d", resolved)),
|
|
||||||
)
|
|
||||||
right := styleMuted.Render(fmt.Sprintf("filter: %s [f] ", filterLabel))
|
|
||||||
gap := m.width - lipgloss.Width(left) - lipgloss.Width(right)
|
|
||||||
if gap < 0 {
|
|
||||||
gap = 0
|
|
||||||
}
|
|
||||||
return left + strings.Repeat(" ", gap) + right
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── Detail ─────────────────────────────────────────────────────────────────
|
// ── Detail ─────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
func (m Model) renderDetail() string {
|
func (m Model) renderDetail() string {
|
||||||
if m.detailLoading {
|
if m.detailLoading {
|
||||||
return "\n" + styleMuted.Render(" Loading alert details…")
|
return "\n" + styleMuted.Render(" Loading…")
|
||||||
}
|
}
|
||||||
return m.detailViewport.View()
|
return m.detailViewport.View()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m Model) renderCommentCompose() string {
|
// renderPrompt puts an input line under the detail pane.
|
||||||
vp := m.detailViewport.View()
|
func (m Model) renderPrompt(prompt string) string {
|
||||||
sep := styleMuted.Render(strings.Repeat("─", m.width))
|
sep := styleMuted.Render(strings.Repeat("─", m.width))
|
||||||
prompt := styleHeader.Render("Comment: ") + m.commentInput.View()
|
return m.detailViewport.View() + "\n" + sep + "\n" + prompt
|
||||||
return vp + "\n" + sep + "\n" + prompt
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── Stats ──────────────────────────────────────────────────────────────────
|
// ── Stats ──────────────────────────────────────────────────────────────────
|
||||||
@@ -335,100 +367,252 @@ func (m Model) renderStats() string {
|
|||||||
|
|
||||||
// ── Content builders ───────────────────────────────────────────────────────
|
// ── Content builders ───────────────────────────────────────────────────────
|
||||||
|
|
||||||
func buildDetailContent(alert api.Alert, comments []api.Comment, cursor, width int) string {
|
func buildIncidentDetailContent(inc api.Incident, timeline []api.IncidentEvent, cursor, width int) string {
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
var b strings.Builder
|
var b strings.Builder
|
||||||
contentW := width - 4
|
contentW := width - 4
|
||||||
|
|
||||||
// Name + status header
|
// Title + status header
|
||||||
name := styleAlertName.Render(alert.Name)
|
title := styleAlertName.Render(inc.Title)
|
||||||
var statusStr string
|
status := incidentStatusStyle(inc.Status).Render(incidentStatusLabel(inc))
|
||||||
if alert.Status == "firing" {
|
if inc.Severity != "" {
|
||||||
statusStr = styleFiring.Render("● FIRING")
|
status += " " + severityStyle(inc.Severity).Render(strings.ToUpper(inc.Severity))
|
||||||
|
}
|
||||||
|
gap := contentW - lipgloss.Width(title) - lipgloss.Width(status)
|
||||||
|
if gap < 1 {
|
||||||
|
gap = 1
|
||||||
|
}
|
||||||
|
b.WriteString("\n " + title + strings.Repeat(" ", gap) + status + "\n\n")
|
||||||
|
|
||||||
|
// Timing and ownership
|
||||||
|
b.WriteString(fmt.Sprintf(" Triggered: %s (%s)\n",
|
||||||
|
inc.TriggeredAt.UTC().Format("2006-01-02 15:04 UTC"), humanAgo(now, inc.TriggeredAt)))
|
||||||
|
|
||||||
|
if inc.AssignedTo != "" {
|
||||||
|
b.WriteString(fmt.Sprintf(" Assigned: %s\n", styleBold.Render(inc.AssignedTo)))
|
||||||
} else {
|
} else {
|
||||||
statusStr = styleResolved.Render("✓ RESOLVED")
|
b.WriteString(styleMuted.Render(" Assigned: nobody\n"))
|
||||||
}
|
|
||||||
nameGap := contentW - lipgloss.Width(name) - lipgloss.Width(statusStr)
|
|
||||||
if nameGap < 1 {
|
|
||||||
nameGap = 1
|
|
||||||
}
|
|
||||||
b.WriteString("\n " + name + strings.Repeat(" ", nameGap) + statusStr + "\n\n")
|
|
||||||
|
|
||||||
// Timeline
|
|
||||||
b.WriteString(fmt.Sprintf(" Started: %s (%s)\n",
|
|
||||||
alert.StartsAt.UTC().Format("2006-01-02 15:04 UTC"), humanAgo(now, alert.StartsAt)))
|
|
||||||
if alert.EndsAt != nil {
|
|
||||||
b.WriteString(fmt.Sprintf(" Ended: %s\n", alert.EndsAt.UTC().Format("2006-01-02 15:04 UTC")))
|
|
||||||
}
|
|
||||||
if alert.GeneratorURL != "" {
|
|
||||||
url := alert.GeneratorURL
|
|
||||||
if len(url) > contentW-12 {
|
|
||||||
url = url[:contentW-15] + "…"
|
|
||||||
}
|
|
||||||
b.WriteString(fmt.Sprintf(" Source: %s\n", url))
|
|
||||||
}
|
|
||||||
b.WriteString("\n")
|
|
||||||
|
|
||||||
// Labels
|
|
||||||
if len(alert.Labels) > 0 {
|
|
||||||
b.WriteString(divider("Labels", width))
|
|
||||||
for _, k := range sortedKeys(alert.Labels) {
|
|
||||||
v := alert.Labels[k]
|
|
||||||
if len(v) > contentW-24 {
|
|
||||||
v = v[:contentW-27] + "…"
|
|
||||||
}
|
|
||||||
b.WriteString(fmt.Sprintf(" %-22s %s\n", k, v))
|
|
||||||
}
|
|
||||||
b.WriteString("\n")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Annotations
|
if inc.AcknowledgedByID != nil {
|
||||||
if len(alert.Annotations) > 0 {
|
|
||||||
b.WriteString(divider("Annotations", width))
|
|
||||||
for _, k := range sortedKeys(alert.Annotations) {
|
|
||||||
v := alert.Annotations[k]
|
|
||||||
if len(v) > contentW-24 {
|
|
||||||
v = v[:contentW-27] + "…"
|
|
||||||
}
|
|
||||||
b.WriteString(fmt.Sprintf(" %-22s %s\n", k, v))
|
|
||||||
}
|
|
||||||
b.WriteString("\n")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Acknowledgement
|
|
||||||
b.WriteString(divider("Acknowledgement", width))
|
|
||||||
if alert.AcknowledgedByID != nil {
|
|
||||||
ackAt := ""
|
ackAt := ""
|
||||||
if alert.AcknowledgedAt != nil {
|
if inc.AcknowledgedAt != nil {
|
||||||
ackAt = " at " + alert.AcknowledgedAt.UTC().Format("2006-01-02 15:04 UTC")
|
ackAt = " at " + inc.AcknowledgedAt.UTC().Format("2006-01-02 15:04 UTC")
|
||||||
}
|
}
|
||||||
b.WriteString(styleResolved.Render(fmt.Sprintf(" ✓ Acknowledged by %s%s\n", alert.AcknowledgedBy, ackAt)))
|
b.WriteString(styleResolved.Render(
|
||||||
|
fmt.Sprintf(" Acked: %s%s\n", inc.AcknowledgedBy, ackAt)))
|
||||||
} else {
|
} else {
|
||||||
b.WriteString(styleMuted.Render(" Not acknowledged\n"))
|
b.WriteString(styleMuted.Render(" Acked: not acknowledged\n"))
|
||||||
|
}
|
||||||
|
|
||||||
|
if inc.IsSnoozed() {
|
||||||
|
b.WriteString(styleSnoozed.Render(fmt.Sprintf(" Snoozed: until %s (%s)\n",
|
||||||
|
inc.SnoozedUntil.UTC().Format("2006-01-02 15:04 UTC"), humanUntil(now, *inc.SnoozedUntil))))
|
||||||
|
}
|
||||||
|
|
||||||
|
if inc.ResolvedAt != nil {
|
||||||
|
source := ""
|
||||||
|
if inc.ResolutionSource != nil {
|
||||||
|
source = " · " + *inc.ResolutionSource
|
||||||
|
}
|
||||||
|
b.WriteString(fmt.Sprintf(" Resolved: %s (%s)%s\n",
|
||||||
|
inc.ResolvedAt.UTC().Format("2006-01-02 15:04 UTC"), humanAgo(now, *inc.ResolvedAt), source))
|
||||||
|
}
|
||||||
|
if inc.ArchivedAt != nil {
|
||||||
|
b.WriteString(styleMuted.Render(" Archived: " +
|
||||||
|
inc.ArchivedAt.UTC().Format("2006-01-02 15:04 UTC") + "\n"))
|
||||||
}
|
}
|
||||||
b.WriteString("\n")
|
b.WriteString("\n")
|
||||||
|
|
||||||
// Comments
|
// Group labels — the correlation Alertmanager applied.
|
||||||
b.WriteString(divider(fmt.Sprintf("Comments (%d)", len(comments)), width))
|
if len(inc.GroupLabels) > 0 {
|
||||||
if len(comments) == 0 {
|
b.WriteString(divider("Grouped By", width))
|
||||||
b.WriteString(styleMuted.Render(" No comments yet.\n"))
|
for _, k := range sortedKeys(inc.GroupLabels) {
|
||||||
} else {
|
b.WriteString(fmt.Sprintf(" %-22s %s\n", k, truncate(inc.GroupLabels[k], contentW-24)))
|
||||||
for i, c := range comments {
|
|
||||||
prefix := " "
|
|
||||||
authorLine := fmt.Sprintf("%s%s • %s", prefix, styleBold.Render(c.Username), humanAgo(now, c.CreatedAt))
|
|
||||||
if i == cursor {
|
|
||||||
authorLine = styleSelected.Render("> ") + styleBold.Render(c.Username) +
|
|
||||||
styleMuted.Render(fmt.Sprintf(" • %s", humanAgo(now, c.CreatedAt)))
|
|
||||||
}
|
}
|
||||||
b.WriteString(authorLine + "\n")
|
b.WriteString("\n")
|
||||||
b.WriteString(" " + c.Content + "\n\n")
|
}
|
||||||
|
|
||||||
|
// Member alerts
|
||||||
|
b.WriteString(divider(fmt.Sprintf("Alerts (%d)", len(inc.Alerts)), width))
|
||||||
|
if len(inc.Alerts) == 0 {
|
||||||
|
b.WriteString(styleMuted.Render(" No alerts.\n"))
|
||||||
|
} else {
|
||||||
|
for _, a := range inc.Alerts {
|
||||||
|
marker := styleFiring.Render("●")
|
||||||
|
if a.Status != "firing" {
|
||||||
|
marker = styleResolved.Render("✓")
|
||||||
|
}
|
||||||
|
instance := a.Labels["instance"]
|
||||||
|
if instance == "" {
|
||||||
|
instance = a.Fingerprint
|
||||||
|
}
|
||||||
|
b.WriteString(fmt.Sprintf(" %s %-28s %-26s %s\n",
|
||||||
|
marker, truncate(a.Name, 28), truncate(instance, 26),
|
||||||
|
styleMuted.Render("last seen "+humanAgo(now, a.ReceivedAt))))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
b.WriteString("\n")
|
||||||
|
|
||||||
|
// Timeline — the only history the server keeps.
|
||||||
|
notes := noteEvents(timeline)
|
||||||
|
b.WriteString(divider(fmt.Sprintf("Timeline (%d events, %d notes)", len(timeline), len(notes)), width))
|
||||||
|
if len(timeline) == 0 {
|
||||||
|
b.WriteString(styleMuted.Render(" Nothing recorded yet.\n"))
|
||||||
|
} else {
|
||||||
|
noteIndex := 0
|
||||||
|
for _, e := range timeline {
|
||||||
|
when := styleMuted.Render(humanAgo(now, e.CreatedAt))
|
||||||
|
if e.Type != api.EventNote {
|
||||||
|
b.WriteString(fmt.Sprintf(" %-52s %s\n", eventLabel(e), when))
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
marker := " "
|
||||||
|
author := styleBold.Render(e.Username)
|
||||||
|
if noteIndex == cursor {
|
||||||
|
marker = styleSelected.Render("> ")
|
||||||
|
author = styleSelected.Render(e.Username)
|
||||||
|
}
|
||||||
|
b.WriteString(fmt.Sprintf("%s%-50s %s\n", marker, author+" wrote", when))
|
||||||
|
b.WriteString(" " + e.Detail + "\n")
|
||||||
|
noteIndex++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return b.String()
|
return b.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func buildStatsContent(top []api.TopAlert, byHour []api.HourStat, byDay []api.DayStat, width int) string {
|
// incidentStatusLabel is the headline badge for an incident.
|
||||||
|
func incidentStatusLabel(inc api.Incident) string {
|
||||||
|
switch inc.Status {
|
||||||
|
case api.StatusTriggered:
|
||||||
|
if inc.IsSnoozed() {
|
||||||
|
return "● TRIGGERED (snoozed)"
|
||||||
|
}
|
||||||
|
return "● TRIGGERED"
|
||||||
|
case api.StatusAcknowledged:
|
||||||
|
if inc.IsSnoozed() {
|
||||||
|
return "◐ ACKNOWLEDGED (snoozed)"
|
||||||
|
}
|
||||||
|
return "◐ ACKNOWLEDGED"
|
||||||
|
case api.StatusResolved:
|
||||||
|
return "✓ RESOLVED"
|
||||||
|
default:
|
||||||
|
return strings.ToUpper(inc.Status)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// eventLabel renders one timeline entry as a sentence. Unrecognised types fall
|
||||||
|
// back to their raw name rather than vanishing — the server may add more.
|
||||||
|
func eventLabel(e api.IncidentEvent) string {
|
||||||
|
who := e.Username
|
||||||
|
switch e.Type {
|
||||||
|
case api.EventTriggered:
|
||||||
|
return " Incident opened"
|
||||||
|
case api.EventAlertAdded:
|
||||||
|
if e.AlertID != nil {
|
||||||
|
return fmt.Sprintf(" Alert #%d joined", *e.AlertID)
|
||||||
|
}
|
||||||
|
return " Alert joined"
|
||||||
|
case api.EventAlertResolved:
|
||||||
|
if e.AlertID != nil {
|
||||||
|
return fmt.Sprintf(" Alert #%d resolved", *e.AlertID)
|
||||||
|
}
|
||||||
|
return " Alert resolved"
|
||||||
|
case api.EventAcknowledged:
|
||||||
|
return " Acknowledged by " + who
|
||||||
|
case api.EventUnacknowledged:
|
||||||
|
return " Acknowledgement cleared by " + who
|
||||||
|
case api.EventAssigned:
|
||||||
|
// On an assigned event the user is the assignee, not the actor.
|
||||||
|
return " Assigned to " + who
|
||||||
|
case api.EventSnoozed:
|
||||||
|
if e.Detail != "" {
|
||||||
|
return " Snoozed until " + e.Detail
|
||||||
|
}
|
||||||
|
return " Snoozed"
|
||||||
|
case api.EventUnsnoozed:
|
||||||
|
return " Snooze cleared by " + who
|
||||||
|
case api.EventResolved:
|
||||||
|
if who != "" {
|
||||||
|
return " Resolved by " + who
|
||||||
|
}
|
||||||
|
return " Resolved (all alerts stopped firing)"
|
||||||
|
default:
|
||||||
|
label := " " + e.Type
|
||||||
|
if e.Detail != "" {
|
||||||
|
label += " · " + e.Detail
|
||||||
|
}
|
||||||
|
return label
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func buildAlertDetailContent(alert api.Alert, width int) string {
|
||||||
|
now := time.Now()
|
||||||
|
var b strings.Builder
|
||||||
|
contentW := width - 4
|
||||||
|
|
||||||
|
name := styleAlertName.Render(alert.Name)
|
||||||
|
var statusStr string
|
||||||
|
if alert.Status == "firing" {
|
||||||
|
statusStr = styleFiring.Render("● FIRING")
|
||||||
|
} else {
|
||||||
|
label := "✓ RESOLVED"
|
||||||
|
if alert.ResolutionSource != nil {
|
||||||
|
label += " · " + *alert.ResolutionSource
|
||||||
|
}
|
||||||
|
statusStr = styleResolved.Render(label)
|
||||||
|
}
|
||||||
|
gap := contentW - lipgloss.Width(name) - lipgloss.Width(statusStr)
|
||||||
|
if gap < 1 {
|
||||||
|
gap = 1
|
||||||
|
}
|
||||||
|
b.WriteString("\n " + name + strings.Repeat(" ", gap) + statusStr + "\n\n")
|
||||||
|
|
||||||
|
b.WriteString(fmt.Sprintf(" Started: %s (%s)\n",
|
||||||
|
alert.StartsAt.UTC().Format("2006-01-02 15:04 UTC"), humanAgo(now, alert.StartsAt)))
|
||||||
|
b.WriteString(fmt.Sprintf(" Last Seen: %s (%s)\n",
|
||||||
|
alert.ReceivedAt.UTC().Format("2006-01-02 15:04 UTC"), humanAgo(now, alert.ReceivedAt)))
|
||||||
|
if alert.EndsAt != nil {
|
||||||
|
b.WriteString(fmt.Sprintf(" Ended: %s\n", alert.EndsAt.UTC().Format("2006-01-02 15:04 UTC")))
|
||||||
|
}
|
||||||
|
if alert.GeneratorURL != "" {
|
||||||
|
b.WriteString(fmt.Sprintf(" Source: %s\n", truncate(alert.GeneratorURL, contentW-12)))
|
||||||
|
}
|
||||||
|
if alert.IncidentID != nil {
|
||||||
|
b.WriteString(fmt.Sprintf(" Incident: %s %s\n",
|
||||||
|
styleBold.Render(fmt.Sprintf("#%d", *alert.IncidentID)),
|
||||||
|
styleMuted.Render("press i to open it")))
|
||||||
|
} else {
|
||||||
|
b.WriteString(styleMuted.Render(" Incident: none\n"))
|
||||||
|
}
|
||||||
|
b.WriteString("\n")
|
||||||
|
|
||||||
|
if len(alert.Labels) > 0 {
|
||||||
|
b.WriteString(divider("Labels", width))
|
||||||
|
for _, k := range sortedKeys(alert.Labels) {
|
||||||
|
b.WriteString(fmt.Sprintf(" %-22s %s\n", k, truncate(alert.Labels[k], contentW-24)))
|
||||||
|
}
|
||||||
|
b.WriteString("\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(alert.Annotations) > 0 {
|
||||||
|
b.WriteString(divider("Annotations", width))
|
||||||
|
for _, k := range sortedKeys(alert.Annotations) {
|
||||||
|
b.WriteString(fmt.Sprintf(" %-22s %s\n", k, truncate(alert.Annotations[k], contentW-24)))
|
||||||
|
}
|
||||||
|
b.WriteString("\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Alerts carry no workflow state: it all lives on the incident.
|
||||||
|
b.WriteString(divider("", width))
|
||||||
|
b.WriteString(styleMuted.Render(
|
||||||
|
" Alerts are read-only — acknowledge, assign, note and resolve on the incident.\n"))
|
||||||
|
|
||||||
|
return b.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
func buildStatsContent(incidents *api.IncidentStats, top []api.TopAlert, byHour []api.HourStat, byDay []api.DayStat, width int) string {
|
||||||
barWidth := width/2 - 10
|
barWidth := width/2 - 10
|
||||||
if barWidth < 8 {
|
if barWidth < 8 {
|
||||||
barWidth = 8
|
barWidth = 8
|
||||||
@@ -440,7 +624,29 @@ func buildStatsContent(top []api.TopAlert, byHour []api.HourStat, byDay []api.Da
|
|||||||
var b strings.Builder
|
var b strings.Builder
|
||||||
b.WriteString("\n")
|
b.WriteString("\n")
|
||||||
|
|
||||||
// Top alerts
|
// Response times first: they are what a rota is actually judged on.
|
||||||
|
b.WriteString(divider("Incident Response", width))
|
||||||
|
if incidents == nil {
|
||||||
|
b.WriteString(styleMuted.Render(" No data.\n"))
|
||||||
|
} else {
|
||||||
|
b.WriteString(fmt.Sprintf(" %-28s %s\n", "Incidents total",
|
||||||
|
styleBold.Render(fmt.Sprintf("%d", incidents.Total))))
|
||||||
|
b.WriteString(fmt.Sprintf(" %-28s %s\n", "Triggered",
|
||||||
|
styleTriggered.Render(fmt.Sprintf("%d", incidents.Triggered))))
|
||||||
|
b.WriteString(fmt.Sprintf(" %-28s %s\n", "Acknowledged",
|
||||||
|
styleAcknowledged.Render(fmt.Sprintf("%d", incidents.Acknowledged))))
|
||||||
|
b.WriteString(fmt.Sprintf(" %-28s %s\n", "Resolved",
|
||||||
|
styleResolved.Render(fmt.Sprintf("%d", incidents.Resolved))))
|
||||||
|
b.WriteString(fmt.Sprintf(" %-28s %s\n", "Mean time to acknowledge",
|
||||||
|
styleBold.Render(humanSeconds(incidents.MTTASeconds))))
|
||||||
|
b.WriteString(fmt.Sprintf(" %-28s %s\n", "Mean time to resolve",
|
||||||
|
styleBold.Render(humanSeconds(incidents.MTTRSeconds))))
|
||||||
|
if incidents.MTTASeconds == nil || incidents.MTTRSeconds == nil {
|
||||||
|
b.WriteString(styleMuted.Render(" (— means nothing has been acknowledged or resolved yet)\n"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
b.WriteString("\n")
|
||||||
|
|
||||||
b.WriteString(divider("Top Alerts", width))
|
b.WriteString(divider("Top Alerts", width))
|
||||||
if len(top) == 0 {
|
if len(top) == 0 {
|
||||||
b.WriteString(styleMuted.Render(" No data.\n"))
|
b.WriteString(styleMuted.Render(" No data.\n"))
|
||||||
@@ -453,7 +659,6 @@ func buildStatsContent(top []api.TopAlert, byHour []api.HourStat, byDay []api.Da
|
|||||||
}
|
}
|
||||||
b.WriteString("\n")
|
b.WriteString("\n")
|
||||||
|
|
||||||
// By hour
|
|
||||||
b.WriteString(divider("Alerts by Hour (UTC)", width))
|
b.WriteString(divider("Alerts by Hour (UTC)", width))
|
||||||
if len(byHour) > 0 {
|
if len(byHour) > 0 {
|
||||||
maxCount := 0
|
maxCount := 0
|
||||||
@@ -471,7 +676,6 @@ func buildStatsContent(top []api.TopAlert, byHour []api.HourStat, byDay []api.Da
|
|||||||
}
|
}
|
||||||
b.WriteString("\n")
|
b.WriteString("\n")
|
||||||
|
|
||||||
// By day
|
|
||||||
b.WriteString(divider("Alerts by Day", width))
|
b.WriteString(divider("Alerts by Day", width))
|
||||||
if len(byDay) > 0 {
|
if len(byDay) > 0 {
|
||||||
maxCount := 0
|
maxCount := 0
|
||||||
@@ -561,7 +765,10 @@ func (m Model) renderAPIKeyRevokeByID() string {
|
|||||||
// ── Helpers ────────────────────────────────────────────────────────────────
|
// ── Helpers ────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
func divider(title string, width int) string {
|
func divider(title string, width int) string {
|
||||||
prefix := "── " + title + " "
|
prefix := "── "
|
||||||
|
if title != "" {
|
||||||
|
prefix += title + " "
|
||||||
|
}
|
||||||
remaining := width - len(prefix) - 2
|
remaining := width - len(prefix) - 2
|
||||||
if remaining > 0 {
|
if remaining > 0 {
|
||||||
prefix += strings.Repeat("─", remaining)
|
prefix += strings.Repeat("─", remaining)
|
||||||
@@ -590,6 +797,9 @@ func renderBarWidth(count, maxCount, maxWidth int) int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func truncate(s string, max int) string {
|
func truncate(s string, max int) string {
|
||||||
|
if max < 1 {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
if len(s) <= max {
|
if len(s) <= max {
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user