{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://opentine.com/schemas/tine-cli-alert-1.schema.json",
  "title": "tine alert ACTION --json",
  "description": "Every `tine alert` action. `add`: the stored `rule`; `list`: `rules` and `webhook_key` (kid, alg, public_key: pin it in the receiver; absent until the first webhook delivery creates the key, which `list` never does); `remove`: the remaining `rules`; `test`: the `event` evaluated (id, kind) and one `alerts` entry per rule it tripped (or, with --always, a `test: true` alert per other rule), each with its `deliveries`. `ok` is false, and the command exits 1, when a delivery failed.",
  "type": "object",
  "required": [
    "command",
    "action",
    "ok"
  ],
  "properties": {
    "command": {
      "const": "alert"
    },
    "action": {
      "enum": [
        "add",
        "list",
        "remove",
        "test"
      ]
    },
    "ok": {
      "type": "boolean"
    },
    "rule": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "name",
        "on",
        "threshold",
        "webhook",
        "otlp",
        "allow_private"
      ],
      "properties": {
        "name": {
          "type": "string",
          "pattern": "^[a-z0-9][a-z0-9._-]{0,63}$"
        },
        "on": {
          "enum": [
            "verify.failed",
            "policy.denied",
            "cost.threshold",
            "witness.disagreement"
          ]
        },
        "threshold": {
          "anyOf": [
            {
              "type": "number"
            },
            {
              "type": "null"
            }
          ]
        },
        "webhook": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        },
        "otlp": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        },
        "allow_private": {
          "type": "boolean"
        }
      }
    },
    "rules": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "name",
          "on",
          "threshold",
          "webhook",
          "otlp",
          "allow_private"
        ],
        "properties": {
          "name": {
            "type": "string",
            "pattern": "^[a-z0-9][a-z0-9._-]{0,63}$"
          },
          "on": {
            "enum": [
              "verify.failed",
              "policy.denied",
              "cost.threshold",
              "witness.disagreement"
            ]
          },
          "threshold": {
            "anyOf": [
              {
                "type": "number"
              },
              {
                "type": "null"
              }
            ]
          },
          "webhook": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "otlp": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "allow_private": {
            "type": "boolean"
          }
        }
      }
    },
    "webhook_key": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "kid",
        "alg",
        "public_key"
      ],
      "properties": {
        "kid": {
          "type": "string",
          "pattern": "^ed25519:[0-9a-f]{16}$"
        },
        "alg": {
          "const": "ed25519"
        },
        "public_key": {
          "type": "string"
        }
      }
    },
    "event": {
      "type": "object",
      "required": [
        "id",
        "kind"
      ],
      "properties": {
        "id": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        },
        "kind": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        }
      }
    },
    "alerts": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "rule",
          "on",
          "subject",
          "detail",
          "value",
          "threshold",
          "test",
          "deliveries"
        ],
        "properties": {
          "rule": {
            "type": "string",
            "pattern": "^[a-z0-9][a-z0-9._-]{0,63}$"
          },
          "on": {
            "enum": [
              "verify.failed",
              "policy.denied",
              "cost.threshold",
              "witness.disagreement"
            ]
          },
          "subject": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "detail": {
            "type": "string"
          },
          "value": {
            "anyOf": [
              {
                "type": "number"
              },
              {
                "type": "null"
              }
            ]
          },
          "threshold": {
            "anyOf": [
              {
                "type": "number"
              },
              {
                "type": "null"
              }
            ]
          },
          "test": {
            "type": "boolean"
          },
          "deliveries": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "sink",
                "target",
                "outcome"
              ],
              "properties": {
                "sink": {
                  "enum": [
                    "webhook",
                    "otlp"
                  ]
                },
                "target": {
                  "type": "string"
                },
                "outcome": {
                  "enum": [
                    "delivered",
                    "failed",
                    "dry-run"
                  ]
                },
                "status": {
                  "type": [
                    "integer",
                    "string"
                  ]
                },
                "attempts": {
                  "type": "integer",
                  "minimum": 1
                },
                "delivery": {
                  "type": "string"
                },
                "detail": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    }
  }
}
