Core
IoT Platform v2.x
2

create #

Creates a new alert rule inside a tenant index.

Return an error if the rule already exists.


Query Syntax #

HTTP #

URL: http://kuzzle:7512/_/alert-rules/:index
Method: POST
Body:
{
    "rule": {
        "name": "string",
        "description": "string",
        "scope": {
            "collection": "string", // eg. measures
            "filters": [
                {
                    "model": "string",
                    "references": ["string"],
                    "measureSlots": ["string"]
                }
            ]
        },
        "plannings": {
            "days": {
                "mon": "boolean",
                "tue": "boolean",
                "wed": "boolean",
                "thu": "boolean",
                "fri": "boolean",
                "sat": "boolean",
                "sun": "boolean"
            },
            "range": {
                "allDay": "boolean",
                "start": "string", // HH:mm
                "end": "string", // HH:mm
            },
            "timezone": "string" // Europe/Paris
        },
        "rule": {
            "type": "string", // threshold
            "threshold": {
                "field": "string",
                "operator": "string",
                "value": "number",
                "debounce": {
                    "down": "number",
                    "levels": [
                        {
                            "delay": "number",
                            "severity": "string"
                        }
                    ]
                }
            }
        },
        "linkedNotificationRules": ["string"]
    }
}

Javascript #

kuzzle.query({
  controller: 'alert-rules',
  action: 'create',
  index: '<index>',
  body: {
    rule: {
      name: '<rule name>',
      description: '<rule description>',
      scope: {
        collection: '<rule collection>',
        filters: {
          model: '<model>',
          references: ['<reference1>', '<reference2>'],
          measureSlots: ['<slot1>', '<slot2>'],
        },
      },
      planning: {
        days: {
          mon: true,
          tue: true,
          wed: true,
          thu: true,
          fri: true,
          sat: true,
          sun: true,
        },
        range: {
          allDay: true,
          start: '00:00',
          end: '23:59',
        },
        timezone: 'Europe/Paris',
      },
      rule: {
        type: 'threshold',
        threshold: {
          field: '<field>',
          operator: '<operator>',
          value: 100,
          debounce: {
            down: 5,
            levels: [
              {
                delay: 10,
                severity: 'warning',
              },
            ],
          },
        },
      },
      linkedNotificationRules: ['<notificationRuleId>'],
    },
  },
});

Arguments #

ArgumentsTypeDescription
index
string
Index name

Rule Properties #

ArgumentsTypeDescription
name
string
Alert rule name. Must be unique as it identifies the rule
description
string
Alert rule description
scope
object
Alert rule scope
plannings
object
Alert rule plannings
rule
object
Alert rule
linkedNotificationRules
string[]
Alert rule linked notification rules

Scope Properties #

ArgumentsTypeDescription
collection
string
Collection name to watch for documents holding the timeserie to monitor, usually measures
filters.model
string
Model filter
filters.references
string[]
References filter
filters.measureSlots
string[]
Measure slots filter

Planning Properties #

This allow defining a weekly planing of when the rule is active (time range and days of the week)

ArgumentsTypeDescription
days
object
Days configuration
range
object
Time range configuration
timezone
string
Timezone

Rule Properties #

ArgumentsTypeDescription
type
string
Rule type (threshold)
threshold.field
string
Field to monitor
threshold.operator
string
Comparison operator
threshold.value
number
Threshold value
threshold.debounce.down
number
Number of consecutive matches before alert is cleared
threshold.debounce.levels
object[]
Alert levels configuration