# orca.ui.alerts

> A module of morca's API.

Ops › Alerts (`/ops/alerts`): every alert `orca.notify` sent or is sending, newest first, from `orca.alerts`: when, its kind, its title and message as sent, links to what it is about (the run, the pipelines, the watchdog's rules, a worker, Control), whether ntfy took it, and for those that resolve (a watchdog trip, a stalled fill, the disk, memory pressure, an `orca notify` that was later `--resolved`) whether it is still open.

`?kind=` and `?state=open|resolved` filter it; `?before=<id>` and
`?after=<id>` page it, 50 to a page (`?limit=`, at most 500), keyset like
the runs list. The newest page refreshes from `/ops/alerts/live` every
30 s. `/api/alerts` is the same as JSON.

## Structs

### `AlertsAsk`

```mojo
struct AlertsAsk
```

What a page of alerts is asked for: its filters and its cursor.

Implements: `Copyable`, `Movable`

Fields:

- `kind: String`
- `state: String`
- `before: Int`
- `after: Int`
- `size: Int`

#### `filters`

```mojo
def filters(self) -> String
```

The query string of its filters and size, no cursor.

#### `href`

```mojo
def href(self, base: StringSpan[ImmStaticOrigin] = StringSpan("/ops/alerts")) -> String
```

#### `with_cursor`

```mojo
def with_cursor(self, name: StringSpan[ImmStaticOrigin], id: Int) -> String
```

#### `first`

```mojo
def first(self) -> Bool
```

Whether it is the newest page.

### `AlertRow`

```mojo
struct AlertRow
```

Implements: `Copyable`, `Movable`

Fields:

- `id: Int`
- `kind: String`
- `subject: String`
- `event: String`
- `title: String`
- `body: String`
- `priority: String`
- `url: String`
- `pipelines: String`
- `run: Int`
- `created: String`
- `delivery: String`
- `attempts: Int`
- `sent: String`
- `error: String`
- `resolvable: Bool`
- `resolved: String`
- `resolved_by: Int`
- `resolved_by_event: String`

#### `state`

```mojo
def state(self) -> String
```

open, resolved, repeated (raised again before it resolved), or empty for an alert that doesn't resolve and for a 'resolved'.

### `AlertsPage`

```mojo
struct AlertsPage
```

Implements: `Movable`

Fields:

- `q: AlertsAsk`
- `rows: List[AlertRow]`
- `total: Int`
- `newer: Int`: How many under the filters are newer than the page.
- `older: Bool`
- `open: Int`: Open alerts, whatever the filters.
- `kinds: List[Tuple[String, Int]]`: Each kind's alerts under the state filter.

#### `__init__`

```mojo
def __init__(out self, var q: AlertsAsk)
```

#### `newer_href`

```mojo
def newer_href(self) -> String
```

#### `older_href`

```mojo
def older_href(self) -> String
```

#### `count_of`

```mojo
def count_of(self, kind: String) -> Int
```

### `Link`

```mojo
struct Link
```

Implements: `Copyable`, `Movable`

Fields:

- `href: String`
- `label: String`

## Functions

### `alerts_ask`

```mojo
def alerts_ask(url: String) -> AlertsAsk
```

The page `url` asks for; an unknown `state` is ignored.

### `alerts_page`

```mojo
def alerts_page(mut db: State, var q: AlertsAsk) -> AlertsPage
```

A page of alerts, newest first, with its counts.

### `kind_label`

```mojo
def kind_label(kind: String, event: String) -> String
```

A kind as the page names it: run failed, watchdog trip, memory pressure resolved.

### `links`

```mojo
def links(a: AlertRow) -> List[Link]
```

Where in the UI an alert points: its run, its pipelines, the watchdog's rule, the worker, Control; else the link it was sent with.

### `alerts_json`

```mojo
def alerts_json(on: Bool, p: AlertsPage) -> String
```

### `alerts_table_html`

```mojo
def alerts_table_html(mut h: Html, p: AlertsPage)
```

The table of a page of alerts and its pager: what `/ops/alerts/live` answers. An open alert's row is marked (`alerts__open`).

### `alerts_html`

```mojo
def alerts_html(mut h: Html, on: Bool, p: AlertsPage)
```

### `alerts`

```mojo
def alerts(mut db: State, url: String) -> Page
```

`/ops/alerts`: the alerts, a page of them.

### `alerts_live`

```mojo
def alerts_live(mut db: State, url: String) -> Page
```

`/ops/alerts/live`: the newest page's table, as the fragment it refreshes from every `IDLE_EVERY` seconds; an older page answers 286.

### `alerts_api`

```mojo
def alerts_api(mut db: State, url: String) -> Page
```

`/api/alerts`: the alerts as JSON, whatever is asked for.

## Aliases

### `ALERTS_PAGE`

```mojo
comptime ALERTS_PAGE = 50
```

### `ALERT_KINDS`

```mojo
comptime ALERT_KINDS = List(String("run-failed"), String("watchdog"), String("fill-stalled"), String("disk"), String("worker-lost"), String("memory-pressure"), String("backup-failed"), __list_literal__=NoneType(None))
```

The kinds orca raises (`orca.alerts`, `orca.admission`) and the one the Hetzner server's backup sends; the filter adds any others the table has.
