{
  "jsonSchema": {
    "$schema": "http://json-schema.org/draft-07/schema#",
    "definitions": {
      "matchInstanceLabels": {
        "type": "string",
        "default": "*",
        "title": "Only for instances with these labels"
      },
      "matchHostLabels": {
        "type": "string",
        "default": "*",
        "title": "Only for nodes with these host labels"
      },
      "matchInstance": {
        "type": "object",
        "title": "Apply this rule to a single instance",
        "description": "This is a single alert rule that will be applied to the specific instance on all nodes hosted on this Netdata.",
        "properties": {
          "on": {
            "type": "string",
            "default": "",
            "title": "The instance this rule should be applied to.",
            "description": "You can find the instance names on all charts at the instances drop down menu. Do not include the host name in this field."
          },
          "host_labels": { "$ref": "#/definitions/matchHostLabels" },
          "instance_labels": { "$ref": "#/definitions/matchInstanceLabels" }
        },
        "required": [
          "on",
          "host_labels",
          "instance_labels"
        ]
      },
      "matchTemplate": {
        "type": "object",
        "title": "Apply this rule to all instances of a context",
        "description": "This rule defines a template, that will apply this alert to all instances (e.g. disks, network interfaces, nginx servers, etc) on all nodes hosted on this Netdata.",
        "properties": {
          "on": {
            "type": "string",
            "default": "",
            "title": "The context of the instances this rule should be applied to.",
            "description": "The context is the code-name of each chart on the dashboard, that appears at the chart title bar, between the chart title and its unit of measurement, like: system.cpu, disk.io, etc."
          },
          "host_labels": { "$ref": "#/definitions/matchHostLabels" },
          "instance_labels": { "$ref": "#/definitions/matchInstanceLabels" }
        },
        "required": [
          "on",
          "host_labels",
          "instance_labels"
        ]
      },
      "configSummary": {
        "type": "string",
        "title": "Short description of the alert",
        "description": "This field is used in notification as a short description of the alert. Variables, like ${label:key}, are replaced with the value of instance label called 'key'."
      },
      "configInfo": {
        "type": "string",
        "title": "Long description of the alert",
        "description": "This field is used to provide enough information about the type and nature of the alert. Variables, like ${label:key}, are replaced with the value of instance label called 'key'."
      },
      "configType": {
        "type": "string",
        "title": "Alert Type",
        "description": "Use categories like: 'System', 'Containers', 'Web Servers', 'Message Brokers', etc."
      },
      "configComponent": {
        "type": "string",
        "title": "Alert Component",
        "description": "Component is a sub-type of Alert Type. Examples: 'CPU', 'Memory', 'Network', 'Disk', 'Hardware', 'nginx', 'redis', 'postgresql', etc."
      },
      "configClassification": {
        "type": "string",
        "title": "Classification",
        "description": "Use 'Workload', 'Utilization', 'Latency', 'Availability', 'Errors', etc."
      },
      "configValue": {
        "type": "object",
        "title": "",
        "description": "Each alert has a value. This section defines how this value is calculated.",
        "properties": {
          "database_lookup": {
            "type": "object",
            "title": "Database Query to Get Value",
            "description": "The database query to be executed to calculate the value of the alert. When set, the query is executed before any other calculations. The result of the query will be available as $this in further calculations.",
            "properties": {
              "data_source": {
                "type": "string",
                "oneOf": [
                  { "const": "samples", "title": "Samples", "description": "Use the time-series values for each dimension" },
                  { "const": "percentages", "title": "Percentages", "description": "Use the percentage of each dimension vs the sum of all dimensions" },
                  { "const": "anomalies", "title": "Anomalies", "description": "Use the anomaly rate of each dimension" }
                ],
                "default": "samples",
                "title": " ",
                "description": ""
              },
              "time_group": {
                "type": "string",
                "oneOf": [
                  { "const": "average", "title": "Average" },
                  { "const": "median", "title": "Median" },
                  { "const": "min", "title": "Minimum" },
                  { "const": "max", "title": "Maximum" },
                  { "const": "sum", "title": "Sum" },
                  { "const": "incremental_sum", "title": "Incremental Sum" },
                  { "const": "stddev", "title": "Standard Deviation" },
                  { "const": "cv", "title": "Coefficient of Variation" },
                  { "const": "trimmed-mean", "title": "Trimmed Mean" },
                  { "const": "trimmed-median", "title": "Trimmed Median" },
                  { "const": "percentile", "title": "Percentile" },
                  { "const": "ses", "title": "Simple Exponential Smoothing" },
                  { "const": "des", "title": "Double Exponential Smoothing" },
                  { "const": "countif", "title": "Count If" }
                ],
                "default": "average",
                "title": "Time Aggregation",
                "description": ""
              },
              "after": {
                "type": "integer",
                "default": -600,
                "title": "From",
                "description": "Relative to 'To'"
              },
              "before": {
                "type": "integer",
                "default": 0,
                "title": "To",
                "description": "Ending timestamp"
              },
              "dims_group": {
                "type": "string",
                "oneOf": [
                  { "const": "average", "title": "Average", "description": "The average of all dimensions" },
                  { "const": "min", "title": "Minimum", "description": "The minimum of all dimensions" },
                  { "const": "max", "title": "Maximum", "description": "The maximum of all dimensions" },
                  { "const": "sum", "title": "Sum", "description": "The sum of all dimensions" },
                  { "const": "min2max", "title": "Min-to-Max", "description": "The delta between the minimum of the maximum of the dimensions" }
                ],
                "default": "sum",
                "title": "Dims Aggregation",
                "description": "on dimensions"
              },
              "dimensions": {
                "type": "string",
                "title": "Dimensions",
                "description": "Simple pattern",
                "default": "*"
              },
              "options": {
                "type": "array",
                "title": "Time-Series Query options",
                "description": "Options affecting the way the value is calculated",
                "uniqueItems": true,
                "items": {
                  "oneOf": [
                    { "const":  "unaligned", "title": "Do not shift the time-frame for visual presentation" },
                    { "const":  "abs", "title": "Make all values positive before using them" },
                    { "const":  "null2zero", "title": "Treat gaps in the time-series as a zero value" },
                    { "const":  "match_ids", "title": "Match only dimension IDs, not Names" },
                    { "const":  "match_names", "title": "Match only dimension Names, not IDs" }
                  ]
                },
                "default": [ "unaligned" ]
              }
            },
            "allOf": [
              {
                "if": {
                  "properties": {
                    "time_group": {
                      "enum": ["trimmed-mean"]
                    }
                  }
                },
                "then": {
                  "properties": {
                    "time_group_value": {
                      "type": "integer",
                      "default": 1,
                      "title": "Trim %",
                      "description": ""
                    }
                  },
                  "required": ["time_group_value"]
                }
              },
              {
                "if": {
                  "properties": {
                    "time_group": {
                      "enum": ["trimmed-median"]
                    }
                  }
                },
                "then": {
                  "properties": {
                    "time_group_value": {
                      "type": "integer",
                      "default": 1,
                      "title": "Trim %",
                      "description": ""
                    }
                  },
                  "required": ["time_group_value"]
                }
              },
              {
                "if": {
                  "properties": {
                    "time_group": {
                      "enum": ["percentile"]
                    }
                  }
                },
                "then": {
                  "properties": {
                    "time_group_value": {
                      "type": "integer",
                      "default": 95,
                      "title": "Percentage",
                      "description": ""
                    }
                  },
                  "required": ["time_group_value"]
                }
              },
              {
                "if": {
                  "properties": {
                    "time_group": {
                      "const": "countif"
                    }
                  }
                },
                "then": {
                  "properties": {
                    "time_group_condition": {
                      "type": "string",
                      "oneOf": [
                        { "const": "!=", "title": "!=" },
                        { "const": "=", "title": "==" },
                        { "const": ">=", "title": ">=" },
                        { "const": ">", "title": ">" },
                        { "const": "<=", "title": "<=" },
                        { "const": "<", "title": "<" }
                      ],
                      "default": "equal",
                      "title": "Condition",
                      "description": ""
                    },
                    "time_group_value": {
                      "type": "number",
                      "default": 1,
                      "title": "Value to match",
                      "description": ""
                    }
                  },
                  "required": ["time_group_condition", "time_group_value"]
                }
              }
            ]
          },
          "calculation": {
            "type": "string",
            "title": "Calculation",
            "description": "An expression to transform the value"
          },
          "units": {
            "type": "string",
            "title": "Unit",
            "description": "of measurement"
          },
          "update_every": {
            "type": "integer",
            "default": 10,
            "minimum": 1,
            "title": "Frequency",
            "description": "of evaluation"
          }
        }
      },
      "configConditions": {
        "type": "object",
        "title": "",
        "properties": {
          "warning_condition": {
            "type": "string",
            "title": "Warning Expression",
            "description": "The alert value is available as '$this'. If this expression evaluates to a non-zero value, the alert is considered to be in warning level."
          },
          "critical_condition": {
            "type": "string",
            "title": "Critical Expression",
            "description": "The alert value is available as '$this'. If this expression evaluates to a non-zero value, the alert is considered to be in critical level."
          }
        }
      },
      "configAction": {
        "type": "object",
        "title": "",
        "description": "The action the alert should take when it transitions states",
        "properties": {
          "execute": {
            "type": "string",
            "title": "Command to execute when the alert transitions states"
          },
          "recipient": {
            "type": "string",
            "title": "Recipient(s)"
          },
          "options": {
            "type": "array",
            "title": "Action Options",
            "uniqueItems": true,
            "items": {
              "oneOf": [
                { "const":  "no-clear-notification", "title": "Do not perform any action when the alert is cleared"}
              ]
            },
            "default": []
          },
          "delay": {
            "type": "object",
            "title": "Delay the action (notification)",
            "description": "Rules to postpone the action, to avoid multiple notifications on flapping alerts.",
            "properties": {
              "up": {
                "type": "integer",
                "title": "Delay when raising"
              },
              "down": {
                "type": "integer",
                "title": "Delay when going Down"
              },
              "multiplier": {
                "type": "number",
                "title": "Back-Off"
              },
              "max": {
                "type": "integer",
                "title": "Max"
              }
            }
          },
          "repeat": {
            "type": "object",
            "title": "Auto-Repeat Action",
            "description": "Repeat the action while the alert is raised.",
            "properties": {
              "enabled": {
                "type": "boolean"
              },
              "warning": {
                "type": "integer",
                "title": "Repeat on Warning"
              },
              "critical": {
                "type": "integer",
                "title": "Repeat on Critical"
              }
            }
          }
        }
      },
      "configInstance": {
        "type": "object",
        "title": "Alert Configuration",
        "description": "The properties that control the value the alert will get, the conditions it will trigger, the back-off for notifications, the auto-repeating of notifications, etc.",
        "properties": {
          "match": { "$ref": "#/definitions/matchInstance" },
          "summary": { "$ref": "#/definitions/configSummary" },
          "info": { "$ref": "#/definitions/configInfo" },
          "type": { "$ref": "#/definitions/configType" },
          "component": { "$ref": "#/definitions/configComponent" },
          "classification": { "$ref": "#/definitions/configClassification" },
          "value": { "$ref": "#/definitions/configValue" },
          "conditions": { "$ref": "#/definitions/configConditions" },
          "action": { "$ref": "#/definitions/configAction" }
        },
        "required": []
      },
      "configTemplate": {
        "type": "object",
        "title": "Alert Configuration",
        "description": "The properties that control the value the alert will get, the conditions it will trigger, the back-off for notifications, the auto-repeating of notifications, etc.",
        "properties": {
          "match": { "$ref": "#/definitions/matchTemplate" },
          "summary": { "$ref": "#/definitions/configSummary" },
          "info": { "$ref": "#/definitions/configInfo" },
          "type": { "$ref": "#/definitions/configType" },
          "component": { "$ref": "#/definitions/configComponent" },
          "classification": { "$ref": "#/definitions/configClassification" },
          "value": { "$ref": "#/definitions/configValue" },
          "conditions": { "$ref": "#/definitions/configConditions" },
          "action": { "$ref": "#/definitions/configAction" }
        },
        "required": []
      }
    },
    "type": "object",
    "properties": {
      "name": {
        "type": "string"
      },
      "format_version": {
        "type": "integer",
        "default": 1
      },
      "rules": {
        "type": "array",
        "items": {
          "type": "object",
          "properties": {
            "enabled": {
              "type": "boolean",
              "default": true,
              "title": "Enabled",
              "description": ""
            },
            "type": {
              "type": "string",
              "oneOf": [
                { "const":  "instance" , "title": "A specific Instance" },
                { "const":  "template" , "title": "Each of the Instances" }
              ],
              "default": "template",
              "title": "Apply this rule to:",
              "description": ""
            }
          },
          "required": [ "type", "enabled" ],
          "if": {
            "properties": {
              "type": { "const": "instance" }
            }
          },
          "then": {
            "properties": {
              "config": { "$ref": "#/definitions/configInstance" }
            }
          },
          "else": {
            "properties": {
              "config": { "$ref": "#/definitions/configTemplate" }
            }
          }
        }
      }
    },
    "required": [
      "rules"
    ]
  },
  "uiSchema": {
    "uiOptions": {
      "fullPage": true
    },
    "format_version": {
      "ui:widget": "hidden"
    },
    "name": {
      "ui:widget": "hidden"
    },
    "rules": {
      "ui:openEmptyItem":  true,
      "items": {
        "ui:classNames": "dyncfg-grid dyncfg-grid-col-6",
        "enabled": {
          "ui:classNames": "dyncfg-grid-col-span-1-2",
          "ui:widget": "checkbox"
        },
        "type": {
          "ui:classNames": "dyncfg-grid-col-span-5-2",
          "ui:help": "Rules can be configured to match a specific instance (like a specific disk), or match all the instances (like all the disks). All rules are always checked against all nodes streamed to this Netdata, so the matching rules include patterns to match both instances and nodes.",
          "ui:widget": "radio",
          "ui:options": {
            "flavour": "buttonGroup"
          }
        },
        "config": {
          "ui:classNames": "dyncfg-grid dyncfg-grid-col-6 dyncfg-grid-col-span-1-6",
          "ui:flavour": "tabs",
          "ui:options": {
            "tabs": [
              {
                "title": "Match",
                "fields": [
                  "match"
                ]
              },
              {
                "title": "Value",
                "fields": [
                  "value"
                ]
              },
              {
                "title": "Triggers",
                "fields": [
                  "conditions"
                ]
              },
              {
                "title": "Action",
                "fields": [
                  "action"
                ]
              },
              {
                "title": "Description",
                "fields": [
                  "summary",
                  "info",
                  "type",
                  "component",
                  "classification"
                ]
              }
            ]
          },
          "match": {
            "ui:classNames": "dyncfg-grid dyncfg-grid-col-6 dyncfg-grid-col-span-1-6",
            "on": {
              "ui:classNames": "dyncfg-grid-col-span-1-6"
            },
            "host_labels": {
              "ui:help": "A simple pattern to match the node labels of the nodes this rule is to be applied to. A space separated list of label=value pairs is accepted. Asterisks can be placed anywhere, including the label key. The label keys and their values are available at the labels filter of the charts on the dashboard.",
              "ui:classNames": "dyncfg-grid-col-span-1-3"
            },
            "instance_labels": {
              "ui:classNames": "dyncfg-grid-col-span-4-3",
              "ui:help": "A simple pattern to match the instance labels of the instances this rule is to be applied to. A space separated list of label=value pairs is accepted. Asterisks can be placed anywhere, including the label key. The label keys and their values are available at the labels filter of the charts on the dashboard."
            }
          },
          "summary": {
            "ui:classNames": "dyncfg-grid-col-span-1-3"
          },
          "info": {
            "ui:classNames": "dyncfg-grid-col-span-4-3"
          },
          "type": {
            "ui:classNames": "dyncfg-grid-col-span-1-2"
          },
          "component": {
            "ui:classNames": "dyncfg-grid-col-span-3-2"
          },
          "classification": {
            "ui:classNames": "dyncfg-grid-col-span-5-2"
          },
          "value": {
            "ui:classNames": "dyncfg-grid dyncfg-grid-col-6 dyncfg-grid-col-span-1-6",
            "database_lookup": {
              "ui:order": ["data_source", "time_group", "time_group_condition", "time_group_value", "after", "before", "dims_group", "dimensions", "options"],
              "ui:classNames": "dyncfg-grid dyncfg-grid-col-6 dyncfg-grid-col-span-1-6",
              "ui:collapsible": true,
              "ui:initiallyExpanded": true,
              "data_source": {
                "ui:widget": "radio",
                "ui:options": {
                  "flavour": "buttonGroup"
                },
                "ui:classNames": "dyncfg-grid-col-span-1-6"
              },
              "time_group": {
                "ui:help": "When querying time-series data we need to come up with a single value. This function is used to aggregate all the values of the time-series data to a single value.",
                "ui:classNames": "dyncfg-grid-col-span-1-2"
              },
              "time_group_condition": {
                "ui:classNames": "dyncfg-grid-col-span-3-1"
              },
              "time_group_value": {
                "ui:classNames": "dyncfg-grid-col-span-4-1"
              },
              "after": {
                "ui:help": "The oldest timestamp of the time-series data to be included in the query. Negative values define a duration in seconds in the past of 'To' (so, -60 means a minute ago from 'To').",
                "ui:classNames": "dyncfg-grid-col-span-1-1"
              },
              "before": {
                "ui:help": "The newest timestamp of the time-series data to be included in the query. Negative value define a duration in seconds in the past (so, -60 means a minute ago). Zero means now.",
                "ui:classNames": "dyncfg-grid-col-span-2-1"
              },
              "dims_group": {
                "ui:help": "After each dimension has a single computed value, use this algorithm to derive the final value.",
                "ui:classNames": "dyncfg-grid-col-span-3-2"
              },
              "dimensions": {
                "ui:help": "A simple pattern to match the dimensions that should be included in the query",
                "ui:classNames": "dyncfg-grid-col-span-5-2"
              },
              "options": {
                "ui:classNames": "dyncfg-grid-col-span-1-6"
              }
            },
            "calculation": {
              "ui:help": "The database value is available as '$this'. This expression can utilize variables to transform the value of the alert.",
              "ui:classNames": "dyncfg-grid-col-span-1-4",
              "ui:placeholder": "$this * 1"
            },
            "units": {
              "ui:help": "The unit of measurement the alert value is expressed with. If unset, the units of the instance the alert is attached to will be used.",
              "ui:classNames": "dyncfg-grid-col-span-5-1"
            },
            "update_every": {
              "ui:help": "The frequency this alarm is to be evaluated, in seconds.",
              "ui:classNames": "dyncfg-grid-col-span-6-1"
            }
          },
          "conditions": {
            "ui:classNames": "dyncfg-grid dyncfg-grid-col-6 dyncfg-grid-col-span-1-6",
            "warning_condition": {
              "ui:classNames": "dyncfg-grid-col-span-1-6"
            },
            "critical_condition": {
              "ui:classNames": "dyncfg-grid-col-span-1-6"
            }
          },
          "action": {
            "ui:classNames": "dyncfg-grid dyncfg-grid-col-6 dyncfg-grid-col-span-1-6",
            "execute": {
              "ui:classNames": "dyncfg-grid-col-span-1-3",
              "ui:help": "Leave this empty to get the default alert notification"
            },
            "recipient": {
              "ui:classNames": "dyncfg-grid-col-span-4-1",
              "ui:help": "A space separated list of the recipients of the alert notifications. The special recipient 'silent' prevents this alert from taking any action (i.e. sending notifications)."
            },
            "options": {
              "ui:classNames": "dyncfg-grid-col-span-5-2",
              "ui:help": "Options related to the actions this alert will take."
            },
            "delay": {
              "ui:collapsible": true,
              "ui:initiallyExpanded": false,
              "ui:classNames": "dyncfg-grid dyncfg-grid-col-6 dyncfg-grid-col-span-1-6",
              "up": {
                "ui:classNames": "dyncfg-grid-col-span-1-2",
                "ui:help": "Delay the action (notification) that many seconds, when the alert is rising."
              },
              "down": {
                "ui:classNames": "dyncfg-grid-col-span-3-2",
                "ui:help": "Delay the action (notification) that many seconds, when the alert is recovering."
              },
              "multiplier": {
                "ui:classNames": "dyncfg-grid-col-span-5-1",
                "ui:help": "Multiply the delay by this number, every time the alert transitions to a new state, while the action (notification) is being delayed."
              },
              "max": {
                "ui:classNames": "dyncfg-grid-col-span-6-1",
                "ui:help": "The maximum acceptable delay in seconds, for taking the action (notification)."
              }
            },
            "repeat": {
              "ui:collapsible": true,
              "ui:initiallyExpanded": false,
              "ui:classNames": "dyncfg-grid dyncfg-grid-col-6 dyncfg-grid-col-span-1-6",
              "enabled": {
                "ui:classNames": "dyncfg-grid-col-span-1-2"
              },
              "warning": {
                "ui:classNames": "dyncfg-grid-col-span-3-2",
                "ui:help": "The number of seconds to repeat the action while the alert is in warning state"
              },
              "critical": {
                "ui:classNames": "dyncfg-grid-col-span-5-2",
                "ui:help": "The number of seconds to repeat the action while the alert is in critical state"
              }
            }
          },
          "hash": {
            "ui:widget": "hidden"
          },
          "source_type": {
            "ui:widget": "hidden"
          },
          "source": {
            "ui:widget": "hidden"
          }
        }
      }
    }
  }
}
