Skip to content

Notifications API

Base path: /api/v1/notifications

Implementation reference: internal/notifications/ (handler, service, models, channels).

Note: Notification endpoints are registered under /api/v1 but the corresponding HTTP handlers are not yet wired into the router in cmd/slozy-web/main.go. The notification service (internal/notifications/service.go) supports email, Slack, and webhook delivery channels.

Endpoints

MethodPathDescriptionAuth Required
GET/notifications/historyList notification historyYes
GET/notifications/channelsList configured notification channelsYes
POST/notifications/rulesCreate a notification ruleYes
POST/notifications/testSend a test notificationYes

GET /notifications/history

Returns a paginated list of sent notifications, optionally filtered by SLO.

Query Parameters:

ParameterTypeDefaultDescription
slo_idintFilter by SLO ID
pageint1Page number
page_sizeint10Items per page

Response (200 OK):

json
{
  "notifications": [
    {
      "id": 123,
      "slo_id": 1,
      "rule_id": null,
      "channel_id": 1,
      "status": "delivered",
      "alert_type": "violation",
      "priority": "high",
      "subject": "SLO Violation Alert",
      "message": "API response time exceeded threshold of 99.95%",
      "sent_at": "2026-06-09T14:30:00Z",
      "delivered_at": "2026-06-09T14:30:05Z",
      "retry_count": 0,
      "max_retries": 3,
      "error_message": "",
      "metadata": {},
      "created_at": "2026-06-09T14:30:00Z",
      "updated_at": "2026-06-09T14:30:05Z"
    }
  ],
  "total": 1,
  "page": 1,
  "page_size": 10,
  "has_next": false
}

Notification status values: pending, sending, sent, failed, delivered.

Alert type values: violation, warning, recovery, manual.

Priority values: low, medium, high, critical.


GET /notifications/channels

Lists all configured notification channels for the user's organization.

Response (200 OK):

json
{
  "success": true,
  "count": 2,
  "data": [
    {
      "id": 1,
      "name": "Production Email Alerts",
      "channel_type": "email",
      "organization_id": 1,
      "configuration": {
        "to": "alerts@company.com",
        "from": "slozy@company.com"
      },
      "enabled": true,
      "max_retries": 3,
      "retry_policy": "exponential_backoff",
      "created_at": "2026-06-01T10:00:00Z",
      "updated_at": "2026-06-01T10:00:00Z"
    },
    {
      "id": 2,
      "name": "Operations Slack",
      "channel_type": "slack",
      "organization_id": 1,
      "configuration": {
        "webhook_url": "https://hooks.slack.com/services/T00/B00/xxx"
      },
      "enabled": true,
      "max_retries": 3,
      "retry_policy": "exponential_backoff",
      "created_at": "2026-06-01T10:00:00Z",
      "updated_at": "2026-06-01T10:00:00Z"
    }
  ]
}

Supported channel_type values: email, slack, webhook, pagerduty, opsgenie.

Delivery channel implementations are in internal/notifications/channels.go (EmailChannel, SlackChannel, WebhookChannel).


POST /notifications/rules

Creates a notification rule that triggers alerts when specific conditions are met.

Request:

json
{
  "slo_id": 1,
  "rule_id": null,
  "channel_id": 1,
  "alert_type": "violation",
  "priority": "high",
  "subject": "SLO Violation Alert",
  "message": "API response time exceeded threshold of 99.95%",
  "max_retries": 3
}

Response (201 Created):

json
{
  "success": true,
  "message": "Notification created successfully",
  "data": {
    "id": 123,
    "slo_id": 1,
    "channel_id": 1,
    "status": "pending",
    "priority": "high",
    "created_at": "2026-06-09T14:30:00Z"
  }
}

POST /notifications/test

Sends a test notification through a specified channel to verify its configuration.

Request:

json
{
  "channel_id": 1,
  "subject": "Test Notification",
  "message": "This is a test alert from SLOzy"
}

Response (200 OK):

json
{
  "success": true,
  "message": "Test notification sent successfully"
}

Delivery Mechanism

The notification service (internal/notifications/service.go:22) supports:

  • Async delivery: Notifications are queued and processed by background workers
  • Retry with exponential backoff: Configurable via RetryDelay and RetryBackoffMultiplier
  • Deduplication: Prevents duplicate notifications within a configurable time window
  • Concurrent delivery: Multiple notifications can be sent simultaneously with a configurable concurrency limit

Error Codes

HTTP StatusScenario
400Invalid request body, missing required fields
404Channel not found or disabled
409Duplicate notification (within deduplication window)
500Delivery failure, database error