{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/logbrew/json-schema/logbrew-create-alert-rule-request-schema.json",
  "title": "CreateAlertRuleRequest",
  "description": "A new alert rule. Fields a kind does not use are refused.",
  "x-generated": "2026-11-10",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/logbrew-alerts-api-openapi.yml#/components/schemas/CreateAlertRuleRequest",
  "additionalProperties": false,
  "properties": {
    "environment": {
      "default": null,
      "description": "The environment it watches; all when absent.",
      "type": [
        "string",
        "null"
      ]
    },
    "factor": {
      "default": null,
      "description": "Escalation: how many times its usual rate an issue must reach, 5 when absent.",
      "format": "uint32",
      "minimum": 0,
      "type": [
        "integer",
        "null"
      ]
    },
    "issue_id": {
      "default": null,
      "description": "Event count: the issue counted; all when absent.",
      "format": "uuid",
      "type": [
        "string",
        "null"
      ]
    },
    "kind": {
      "$ref": "#/$defs/AlertRuleKind",
      "description": "What it watches."
    },
    "level": {
      "anyOf": [
        {
          "$ref": "#/$defs/AlertRuleLevel"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "description": "Event count: the lowest level counted; all when absent."
    },
    "muted": {
      "default": false,
      "description": "Whether it starts muted.",
      "type": "boolean"
    },
    "name": {
      "default": "",
      "description": "Name shown with its alerts; empty for none.",
      "type": "string"
    },
    "recipients": {
      "$ref": "#/$defs/AlertRuleRecipientsInput",
      "description": "Who it alerts; at least one recipient."
    },
    "service": {
      "default": null,
      "description": "Event count: the service counted; quiet period: the service watched, required.",
      "type": [
        "string",
        "null"
      ]
    },
    "threshold": {
      "default": null,
      "description": "Event count: fewest events that alert, required. Escalation: fewest events in the window\nthat can escalate, 10 when absent.",
      "format": "uint64",
      "minimum": 0,
      "type": [
        "integer",
        "null"
      ]
    },
    "window_minutes": {
      "default": null,
      "description": "Window length in minutes for escalation (60 when absent), event count (60), and quiet\nperiod (30).",
      "format": "uint32",
      "minimum": 0,
      "type": [
        "integer",
        "null"
      ]
    }
  },
  "required": [
    "kind",
    "recipients"
  ],
  "type": "object",
  "$defs": {
    "AlertRuleKind": {
      "description": "What a rule watches.",
      "oneOf": [
        {
          "const": "new_issue",
          "description": "An issue appears for the first time, in the rule's environment when it has one.",
          "type": "string"
        },
        {
          "const": "regression",
          "description": "A resolved issue happens again.",
          "type": "string"
        },
        {
          "const": "escalation",
          "description": "An issue's event rate in the window reaches `factor` times its rate over the day before.",
          "type": "string"
        },
        {
          "const": "event_count",
          "description": "The window holds at least `threshold` matching events.",
          "type": "string"
        },
        {
          "const": "quiet_period",
          "description": "A service sends nothing for the whole window, like a missed heartbeat.",
          "type": "string"
        }
      ]
    },
    "AlertRuleLevel": {
      "description": "The lowest event level an event count counts; higher levels count too.",
      "oneOf": [
        {
          "const": "info",
          "description": "Info and above.",
          "type": "string"
        },
        {
          "const": "warning",
          "description": "Warning and above.",
          "type": "string"
        },
        {
          "const": "error",
          "description": "Error and above.",
          "type": "string"
        },
        {
          "const": "critical",
          "description": "Critical only.",
          "type": "string"
        }
      ]
    },
    "AlertRuleRecipientsInput": {
      "additionalProperties": false,
      "description": "Who a rule alerts. A recipient gets an alert only while they can read the project.",
      "properties": {
        "members": {
          "default": [],
          "description": "Account IDs.",
          "items": {
            "format": "uuid",
            "type": "string"
          },
          "type": "array"
        },
        "project_members": {
          "default": false,
          "description": "Everyone who can read the project.",
          "type": "boolean"
        },
        "teams": {
          "default": [],
          "description": "Organization team IDs; their members when the rule fires.",
          "items": {
            "format": "uuid",
            "type": "string"
          },
          "type": "array"
        }
      },
      "type": "object"
    }
  }
}