Guías
Formato de regla de alerta (kyr/1)
El documento JSON portable que es una alerta: sus campos, condiciones, señales derivadas y semántica.
Campos
| Nombre | Tipo | Descripción |
|---|---|---|
kyr | 1 | La versión del formato. |
id | string | Un id único (un UUID). |
version | number | Aumenta en uno con cada edición guardada. |
name | string | De 1 a 120 caracteres. Visible dondequiera que se liste la alerta: no pongas valores en él. |
severity | 'info' | 'warning' | 'critical' | Cómo se muestra la alerta. |
enabled | boolean | Una regla desactivada se conserva pero no se comprueba. |
targets | { streams?, datasets? } | Listas opcionales de ids de flujo y nombres de archivo a los que se aplica la regla; ausente o null: todos. |
signals | Record<alias, { channel, stream?, dataset? } | { formula }> | Alias (letras, dígitos y guion bajo; hasta 32 caracteres) para los nombres de canal. Un ámbito (id de flujo o nombre de archivo) restringe dónde se busca el canal. formula nombra un canal matemático (solo en el navegador). |
derived | Record<alias, Derived> | { op: "rate" | "mean" | "min" | "max", of, windowS }, { op: "abs", of } o { op: "diff", a, b }. Una señal derivada puede usar otra. |
when | Condition | El árbol de condiciones (abajo). |
forS | number | Segundos que la condición debe cumplirse antes de que se genere la alerta. |
clearForS | number | Segundos que la condición debe ser falsa antes de que la alerta se despeje. |
staleS | number | null | Una señal sin muestras durante este tiempo se considera desconocida. Ausente o null: nunca. |
runWhere | ('browser' | 'collector')[] | Dónde se ejecuta la regla: ['browser'], o ['browser', 'collector'] para ejecutarla también en la máquina emisora (el colector o un emisor de Python; consulta Alertas sin nadie mirando). Una regla con fórmula solo se ejecuta en el navegador. |
origin | { workbookId, worksheetId, chartId, field, seriesId? } | null | La línea de alarma del gráfico a partir de la cual se creó la alerta, si la hay. |
Condiciones
| Condición | Verdadera cuando |
|---|---|
{ above: a, value, hysteresis? } | a > value; vuelve a ser falsa cuando a ≤ value − hysteresis. |
{ below: a, value, hysteresis? } | a < value; vuelve a ser falsa cuando a ≥ value + hysteresis. |
{ outside: a, lo, hi, hysteresis? } | a < lo o a > hi; vuelve a ser falsa cuando lo + h ≤ a ≤ hi − h. |
{ inside: a, lo, hi, hysteresis? } | lo ≤ a ≤ hi; vuelve a ser falsa cuando a < lo − h o a > hi + h. |
{ equals: a, value } | a es igual a value (números de estado, posiciones). |
{ changes: a } | En una muestra cuyo valor difiere del anterior. |
{ noData: a, forS } | Ninguna muestra de a durante forS segundos. |
{ all: [...] }, { any: [...] }, { not: c } | Combinaciones, hasta 3 niveles de profundidad y 16 condiciones en total. |
Ejemplos
{
"kyr": 1,
"id": "6f0c1c1e-0000-4000-8000-000000000001",
"version": 1,
"name": "Oil temperature high",
"severity": "critical",
"enabled": true,
"signals": { "oil": { "channel": "Oil_Temp" } },
"when": { "above": "oil", "value": 120, "hysteresis": 2 },
"forS": 3,
"clearForS": 10,
"runWhere": ["browser"]
}{
"kyr": 1, "id": "c1a2…", "version": 1, "name": "Pressure rising fast", "severity": "warning", "enabled": true,
"signals": { "p": { "channel": "Line_Pressure" } },
"derived": { "pRate": { "op": "rate", "of": "p", "windowS": 2 } },
"when": { "above": "pRate", "value": 5 },
"forS": 0, "clearForS": 5, "runWhere": ["browser"]
}{
"kyr": 1, "id": "9d3e…", "version": 1, "name": "Press 2 silent", "severity": "warning", "enabled": true,
"signals": { "rpm": { "channel": "RPM", "stream": "<stream id>" } },
"when": { "noData": "rpm", "forS": 60 },
"forS": 0, "clearForS": 0, "runWhere": ["browser"]
}Semántica
- El tiempo es el propio de los datos (el
tde la muestra), no el reloj del ordenador que comprueba. Solo «has no data for» en un flujo en directo usa también la hora de llegada. - Una regla se comprueba en cada muestra de cualquier canal que use, en orden temporal. Los demás canales conservan su último valor, así que se pueden combinar canales muestreados a distintas frecuencias.
- Un canal sin valor todavía, o sin ninguno durante
staleSsegundos, es desconocido. Una condición sobre él es desconocida; All of es falsa si alguna parte es falsa, y si no, desconocida si alguna es desconocida; Any of es verdadera si alguna parte es verdadera. Una regla desconocida ni salta ni se despeja. - La hora de inicio de la alerta es la primera muestra en que se cumplió la condición (el comienzo), aunque For at least retrase la alerta; su fin es la primera muestra en que fue falsa.
- Una muestra más antigua que la última comprobada se omite y se cuenta.
- Si un canal que usa la regla desaparece de un flujo, una alerta abierta termina en la última muestra comprobada y la regla vuelve a esperar.
JSON Schema
El esquema de abajo describe cada campo y límite; se incluye con el SDK como @kymoscope/sdk/rules/kyr1.schema.json. validateRule del SDK aplica las mismas comprobaciones y además que los alias existan y que las señales derivadas no formen un ciclo.
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://kymoscope.com/schemas/kyr1.schema.json",
"title": "Kymoscope alert rule (kyr/1)",
"description": "A portable alert rule. Channels are matched by exact, case-sensitive name on each target; a rule whose channels a target lacks waits there. Runtimes check the semantic limits (aliases referenced exist, derived signals are acyclic, at most 16 conditions) themselves.",
"type": "object",
"additionalProperties": true,
"required": [
"kyr",
"id",
"version",
"name",
"severity",
"enabled",
"signals",
"when",
"forS",
"clearForS",
"runWhere"
],
"properties": {
"kyr": {
"const": 1
},
"id": {
"type": "string",
"minLength": 1
},
"version": {
"type": "integer",
"minimum": 1
},
"name": {
"type": "string",
"minLength": 1,
"maxLength": 120,
"pattern": "\\S"
},
"severity": {
"enum": [
"info",
"warning",
"critical"
]
},
"enabled": {
"type": "boolean"
},
"targets": {
"type": "object",
"properties": {
"streams": {
"$ref": "#/definitions/idList"
},
"datasets": {
"$ref": "#/definitions/idList"
}
}
},
"signals": {
"type": "object",
"minProperties": 1,
"propertyNames": {
"$ref": "#/definitions/alias"
},
"additionalProperties": {
"$ref": "#/definitions/signal"
}
},
"derived": {
"type": "object",
"propertyNames": {
"$ref": "#/definitions/alias"
},
"additionalProperties": {
"$ref": "#/definitions/derived"
}
},
"when": {
"$ref": "#/definitions/condition"
},
"forS": {
"$ref": "#/definitions/seconds"
},
"clearForS": {
"$ref": "#/definitions/seconds"
},
"staleS": {
"oneOf": [
{
"$ref": "#/definitions/seconds"
},
{
"type": "null"
}
]
},
"notify": {
"type": "array",
"items": {
"type": "string"
}
},
"runWhere": {
"type": "array",
"minItems": 1,
"items": {
"enum": [
"browser",
"collector"
]
}
},
"keep": {
"oneOf": [
{
"type": "null"
},
{
"type": "object",
"required": [
"beforeS",
"afterS"
],
"properties": {
"beforeS": {
"$ref": "#/definitions/seconds"
},
"afterS": {
"$ref": "#/definitions/seconds"
}
}
}
]
},
"origin": {
"oneOf": [
{
"type": "null"
},
{
"type": "object",
"required": [
"workbookId",
"worksheetId",
"chartId",
"field"
],
"properties": {
"workbookId": {
"type": [
"string",
"null"
]
},
"worksheetId": {
"type": "string"
},
"chartId": {
"type": "string"
},
"field": {
"type": "string"
},
"seriesId": {
"type": "string"
}
}
}
]
}
},
"definitions": {
"alias": {
"type": "string",
"pattern": "^[A-Za-z_][A-Za-z0-9_]{0,31}$"
},
"channel": {
"type": "string",
"minLength": 1,
"maxLength": 200
},
"seconds": {
"type": "number",
"minimum": 0,
"maximum": 86400
},
"hysteresis": {
"type": "number",
"minimum": 0
},
"idList": {
"oneOf": [
{
"type": "null"
},
{
"type": "array",
"items": {
"type": "string"
}
}
]
},
"signal": {
"oneOf": [
{
"type": "object",
"required": [
"channel"
],
"additionalProperties": false,
"properties": {
"channel": {
"$ref": "#/definitions/channel"
},
"stream": {
"type": "string",
"description": "Only on this stream id."
},
"dataset": {
"type": "string",
"description": "Only on loaded files with this name."
},
"tag": {
"type": "string",
"description": "Collector only: bind by the source address (OPC UA node id) instead of the published name."
}
}
},
{
"type": "object",
"required": [
"formula"
],
"additionalProperties": false,
"description": "A math channel by name. The rule's runWhere must be exactly [\"browser\"].",
"properties": {
"formula": {
"$ref": "#/definitions/channel"
}
}
}
]
},
"derived": {
"oneOf": [
{
"type": "object",
"required": [
"op",
"of",
"windowS"
],
"additionalProperties": false,
"properties": {
"op": {
"enum": [
"rate",
"mean",
"min",
"max"
]
},
"of": {
"$ref": "#/definitions/alias"
},
"windowS": {
"type": "number",
"exclusiveMinimum": 0,
"maximum": 86400
}
}
},
{
"type": "object",
"required": [
"op",
"of"
],
"additionalProperties": false,
"properties": {
"op": {
"const": "abs"
},
"of": {
"$ref": "#/definitions/alias"
}
}
},
{
"type": "object",
"required": [
"op",
"a",
"b"
],
"additionalProperties": false,
"properties": {
"op": {
"const": "diff"
},
"a": {
"$ref": "#/definitions/alias"
},
"b": {
"$ref": "#/definitions/alias"
}
}
}
]
},
"condition": {
"description": "Nesting depth at most 3, at most 16 leaves. Other condition keys are refused (unsupported_condition).",
"oneOf": [
{
"type": "object",
"required": [
"above",
"value"
],
"additionalProperties": false,
"properties": {
"above": {
"$ref": "#/definitions/alias"
},
"value": {
"type": "number"
},
"hysteresis": {
"$ref": "#/definitions/hysteresis"
}
}
},
{
"type": "object",
"required": [
"below",
"value"
],
"additionalProperties": false,
"properties": {
"below": {
"$ref": "#/definitions/alias"
},
"value": {
"type": "number"
},
"hysteresis": {
"$ref": "#/definitions/hysteresis"
}
}
},
{
"type": "object",
"required": [
"outside",
"lo",
"hi"
],
"additionalProperties": false,
"properties": {
"outside": {
"$ref": "#/definitions/alias"
},
"lo": {
"type": "number"
},
"hi": {
"type": "number"
},
"hysteresis": {
"$ref": "#/definitions/hysteresis"
}
}
},
{
"type": "object",
"required": [
"inside",
"lo",
"hi"
],
"additionalProperties": false,
"properties": {
"inside": {
"$ref": "#/definitions/alias"
},
"lo": {
"type": "number"
},
"hi": {
"type": "number"
},
"hysteresis": {
"$ref": "#/definitions/hysteresis"
}
}
},
{
"type": "object",
"required": [
"equals",
"value"
],
"additionalProperties": false,
"properties": {
"equals": {
"$ref": "#/definitions/alias"
},
"value": {
"type": "number"
}
}
},
{
"type": "object",
"required": [
"changes"
],
"additionalProperties": false,
"properties": {
"changes": {
"$ref": "#/definitions/alias"
}
}
},
{
"type": "object",
"required": [
"noData",
"forS"
],
"additionalProperties": false,
"properties": {
"noData": {
"$ref": "#/definitions/alias"
},
"forS": {
"$ref": "#/definitions/seconds"
}
}
},
{
"type": "object",
"required": [
"all"
],
"additionalProperties": false,
"properties": {
"all": {
"type": "array",
"minItems": 1,
"items": {
"$ref": "#/definitions/condition"
}
}
}
},
{
"type": "object",
"required": [
"any"
],
"additionalProperties": false,
"properties": {
"any": {
"type": "array",
"minItems": 1,
"items": {
"$ref": "#/definitions/condition"
}
}
}
},
{
"type": "object",
"required": [
"not"
],
"additionalProperties": false,
"properties": {
"not": {
"$ref": "#/definitions/condition"
}
}
}
]
}
}
}