adding api/v2 endpoints
All checks were successful
Check scripts syntax / check-scripts-syntax (push) Successful in 3s
Haven Notify Build and Deploy / Test Haven Notify (push) Successful in 46s
Haven Notify Build and Deploy / Build Haven Notify Image (PR) (push) Has been skipped
Haven Notify Build and Deploy / Build Haven Notify Image (push) Successful in 20s
Haven Notify Build and Deploy / Deploy Haven Notify (internal) (push) Successful in 3s
All checks were successful
Check scripts syntax / check-scripts-syntax (push) Successful in 3s
Haven Notify Build and Deploy / Test Haven Notify (push) Successful in 46s
Haven Notify Build and Deploy / Build Haven Notify Image (PR) (push) Has been skipped
Haven Notify Build and Deploy / Build Haven Notify Image (push) Successful in 20s
Haven Notify Build and Deploy / Deploy Haven Notify (internal) (push) Successful in 3s
This commit is contained in:
@@ -20,7 +20,11 @@ It runs as a standalone binary or container. Templates are embedded in the binar
|
||||
|
||||
All notification endpoints require `POST` and `Content-Type: application/json`. Request bodies are limited to 64 KiB, documented fields are required, and unknown fields are accepted for forward compatibility.
|
||||
|
||||
### Send Notification
|
||||
### V1 API
|
||||
|
||||
The original routes, request bodies, and Discord message appearance remain unchanged.
|
||||
|
||||
#### Send Notification
|
||||
|
||||
- **Endpoint**: `/notify`
|
||||
- **Request Body**:
|
||||
@@ -32,7 +36,7 @@ All notification endpoints require `POST` and `Content-Type: application/json`.
|
||||
}
|
||||
```
|
||||
|
||||
### Send Backup Notification
|
||||
#### Send Backup Notification
|
||||
|
||||
- **Endpoint**: `/template/notify/backup`
|
||||
- **Request Body**:
|
||||
@@ -51,7 +55,7 @@ All notification endpoints require `POST` and `Content-Type: application/json`.
|
||||
}
|
||||
```
|
||||
|
||||
### Send Update Notification
|
||||
#### Send Update Notification
|
||||
|
||||
- **Endpoint**: `/template/notify/update`
|
||||
- **Request Body**:
|
||||
@@ -66,7 +70,7 @@ All notification endpoints require `POST` and `Content-Type: application/json`.
|
||||
|
||||
`time` is expressed in seconds.
|
||||
|
||||
### Send Error Notification
|
||||
#### Send Error Notification
|
||||
|
||||
- **Endpoint**: `/template/notify/error`
|
||||
- **Request Body**:
|
||||
@@ -85,6 +89,104 @@ All notification endpoints require `POST` and `Content-Type: application/json`.
|
||||
}
|
||||
```
|
||||
|
||||
### V2 API
|
||||
|
||||
V2 notifications use compact, consistently styled Discord embeds. Colors, icons, timestamps, field ordering, and layout are controlled by Haven Notify rather than the caller.
|
||||
|
||||
Every v2 request may include:
|
||||
|
||||
- `source`: a nonblank string identifying the caller.
|
||||
- `occurredAt`: an RFC3339 timestamp. When omitted, Haven Notify uses the current UTC time.
|
||||
- `extra`: an array of nonblank `name` and `value` strings. Short single-line values render inline; multiline or long values render full-width.
|
||||
|
||||
V2 preserves caller field order. Fixed notification fields are placed before `extra` fields so that trailing extras are discarded first if Discord's 25-field or 6,000-character embed limits are reached. Oversized text is safely truncated and extra fields may be omitted from the delivered message.
|
||||
|
||||
#### Send a Message
|
||||
|
||||
- **Endpoint**: `/api/v2/messages`
|
||||
- **Required**: `message`
|
||||
- **Optional**: `title`, `source`, `occurredAt`, `extra`
|
||||
|
||||
```json
|
||||
{
|
||||
"title": "Maintenance complete",
|
||||
"message": "The storage job completed successfully.",
|
||||
"source": "scheduler",
|
||||
"extra": [
|
||||
{
|
||||
"name": "Region",
|
||||
"value": "home"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
#### Send a Backup Notification
|
||||
|
||||
- **Endpoint**: `/api/v2/notifications/backup`
|
||||
- **Required**: `asset`, nonnegative integer `sizeBytes`
|
||||
- **Optional**: `title`, `source`, nonnegative `durationSeconds`, `occurredAt`, `extra`
|
||||
|
||||
```json
|
||||
{
|
||||
"title": "Nightly backup",
|
||||
"asset": "Photos",
|
||||
"sizeBytes": 1610612736,
|
||||
"durationSeconds": 125,
|
||||
"source": "restic",
|
||||
"extra": [
|
||||
{
|
||||
"name": "Host",
|
||||
"value": "nebula"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
`sizeBytes` is displayed using IEC units such as KiB, MiB, and GiB. Durations use a compact form such as `42.5s`, `2m 5s`, or `1h 2m 3s`.
|
||||
|
||||
#### Send an Update Notification
|
||||
|
||||
- **Endpoint**: `/api/v2/notifications/update`
|
||||
- **Required**: `host`, `asset`, nonnegative `durationSeconds`
|
||||
- **Optional**: `source`, `fromVersion`, `toVersion`, `occurredAt`, `extra`
|
||||
|
||||
```json
|
||||
{
|
||||
"host": "nexus",
|
||||
"asset": "k3s",
|
||||
"durationSeconds": 42.5,
|
||||
"fromVersion": "1.32.5",
|
||||
"toVersion": "1.33.1",
|
||||
"source": "system-updater"
|
||||
}
|
||||
```
|
||||
|
||||
When both versions are supplied, the embed displays a transition such as `1.32.5 → 1.33.1`. A single supplied version is labeled as the previous or installed version.
|
||||
|
||||
#### Send an Error Notification
|
||||
|
||||
- **Endpoint**: `/api/v2/notifications/error`
|
||||
- **Required**: `source`, `message`, `severity`
|
||||
- **Optional**: `errorCode`, `occurredAt`, `extra`
|
||||
|
||||
```json
|
||||
{
|
||||
"source": "backup-job",
|
||||
"message": "The repository is unavailable.",
|
||||
"severity": "critical",
|
||||
"errorCode": "E_REPOSITORY",
|
||||
"extra": [
|
||||
{
|
||||
"name": "Path",
|
||||
"value": "/mnt/backups"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
`severity` must be `warning`, `error`, or `critical`; it selects the embed title, icon, and color.
|
||||
|
||||
### Health Probes
|
||||
|
||||
- `GET` or `HEAD /ready` returns `200 Ready` after configuration and templates initialize.
|
||||
|
||||
Reference in New Issue
Block a user