Skip to main content

Rules API

Create, update, and manage alert rules.

List Rules

GET /api/v1/rules

Parameters

ParameterTypeDescription
sourcestringFilter by source
severitystringFilter by severity
enabledbooleanFilter by enabled status

Response

{
  "data": [
    {
      "id": "rule_xyz",
      "name": "High Error Rate",
      "source": "reflex",
      "source_name": "error_count",
      "rule_type": "threshold",
      "operator": "gt",
      "threshold": 100,
      "window": "5m",
      "severity": "critical",
      "enabled": true,
      "last_evaluation": "2024-01-15T10:30:00Z",
      "status": "firing"
    }
  ]
}

Create Rule

POST /api/v1/rules

Request

curl -X POST "https://signal.brainzlab.ai/api/v1/rules" \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "rule": {
      "name": "High P95 Latency",
      "source": "pulse",
      "source_name": "response_time.p95",
      "rule_type": "threshold",
      "operator": "gt",
      "threshold": 500,
      "window": "5m",
      "severity": "warning",
      "notify_channels": ["channel_abc"],
      "tags": {
        "team": "backend"
      }
    }
  }'

Parameters

FieldTypeRequiredDescription
namestringYesRule name
sourcestringYesData source: flux, pulse, reflex, recall
source_namestringYesMetric/event name
rule_typestringYesthreshold, anomaly, absence, composite
operatorstringThresholdgt, gte, lt, lte, eq
thresholdnumberThresholdThreshold value
deviationnumberAnomalyStandard deviations
windowstringYesEvaluation window
severitystringYesinfo, warning, critical
notify_channelsarrayNoChannel IDs to notify
tagsobjectNoRule tags
enabledbooleanNoEnable rule (default: true)

Response

{
  "data": {
    "id": "rule_new123",
    "name": "High P95 Latency",
    "enabled": true,
    "created_at": "2024-01-15T10:30:00Z"
  }
}

Get Rule

GET /api/v1/rules/:id

Update Rule

PATCH /api/v1/rules/:id

Request

curl -X PATCH "https://signal.brainzlab.ai/api/v1/rules/rule_xyz" \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "rule": {
      "threshold": 200,
      "severity": "critical"
    }
  }'

Delete Rule

DELETE /api/v1/rules/:id

Mute Rule

Temporarily disable a rule:
POST /api/v1/rules/:id/mute

Request

curl -X POST "https://signal.brainzlab.ai/api/v1/rules/rule_xyz/mute" \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "duration": "2h",
    "reason": "Deploying new version"
  }'

Unmute Rule

POST /api/v1/rules/:id/unmute

Enable/Disable Rule

POST /api/v1/rules/:id/enable
POST /api/v1/rules/:id/disable

Errors

CodeDescription
rule_not_foundRule does not exist
invalid_rule_typeInvalid rule type
invalid_sourceInvalid data source
invalid_operatorInvalid operator for rule type