Получить все пользовательские триггеры

Возвращает список всех пользовательских триггеров классов в системе. пользовательские триггеры позволяют запускать скрипты при создании или удалении объектов.

Пользовательские триггеры запускаются сервером, а не агентом.

Запрос

HTTP Запрос

GET /node/api/entity-custom-triggers

Права

manage-classes

Тело запроса

Тело запроса пустое.

Ответ

Возвращает список всех пользовательских триггеров в системе. Информация о том, как пользовательские триггеры определяются в модели класса, доступна в статье Класс.

Пользовательские триггеры имеют следующие поля:

Поле Тип Описание

id

String

ID скрипта. ID должен быть частью пути дл триггера.

title

String

Название триггера.

icon

String

Иконка триггера в веб-интерфейсе.

args

Array<Object>

Массив агрументов скрипта.

Переменные скрипта

В скрипт можно передать следующие переменные:

Поле Тип Описание

{{body}}

String

Тело объекта в формате JSON.

{{class_id}}

String

ID класса объекта.

{{client_data}}

String

Данные клиента объекта.

{{created}}

Integer

Время создания объекта.

{{geoposition}}

String

Геопозиция объекта.

{{geopositionRadius}}

String

Радиус геопозиции объекта.

{{id}}

String

ID объекта.

{{entityId}}

String

ID сущности.

{{last_state_update}}

Integer

Время последнего обновления Состояния объекта.

{{name}}

String

Имя объекта.

{{parent_id}}

Array<String>

Массив ID родителей объекта.

{{state_id}}

String

ID Состояния объекта.

{{tags}}

Array<Тег>

Теги объекта.

{{updated}}

Integer

Время последнего обновления объекта.

Также, в скрипт можно передавать свойства объекта в качестве аргументов, используя следующий синтакс:

{{properties.prop_name}}

Пример

Запрос

  • Bash

  • JavaScript

  • NodeJS

  • Python

login=<...>
password=<...>
saymon_hostname=<...>
url=https://$saymon_hostname/node/api/entity-custom-triggers

curl -X GET $url -u $login:$password
let login = <...>
let password = <...>
let saymonHostname = <...>
let path = "/node/api/entity-custom-triggers";
let auth = "Basic " + btoa(login + ":" + password);

let headers = new Headers();
headers.append("Authorization", auth);

let requestOptions = {
    method: "GET",
    headers: headers
};

fetch(saymonHostname + path, requestOptions)
    .then(response => response.text())
    .then(result => console.log(result))
    .catch(error => console.log("error", error));
const http = require("http");

let login = <...>
let password = <...>
let saymonHostname = <...>
let path = "/node/api/entity-custom-triggers/";
let auth = "Basic " + Buffer.from(login + ":" + password).toString("base64");

let options = {
    "method": "GET",
    "hostname": saymonHostname,
    "headers": {
        "Authorization": auth
    },
    "path": path
};

let req = http.request(options, function (res) {
    let chunks = [];

    res.on("data", function (chunk) {
        chunks.push(chunk);
    });

    res.on("end", function (chunk) {
        let body = Buffer.concat(chunks);
        console.log(body.toString());
    });

    res.on("error", function (error) {
        console.error(error);
    });
});

req.end();
import requests

login = <...>
password = <...>
saymon_hostname = <...>
url = "https://" + saymon_hostname + "/node/api/entity-custom-triggers"

response = requests.request("GET", url, auth=(login, password))
print(response.text)

Ответ

[
    {
        "title": "Custom probe example",
        "icon": "fa fa-folder fa-fw",
        "excludeForClasses": [
            1,
            2
        ],
        "args": [
            {
                "name": "Unnamed (positional) argument"
            },
            {
                "name": "Named argument",
                "id": "--name"
            },
            {
                "name": "Argument with description",
                "description": "Argument description",
                "id": "--description"
            },
            {
                "name": "Argument with default value",
                "description": "Argument description",
                "id": "--defval",
                "default": "default_value"
            },
            {
                "name": "Required argument",
                "description": "This field is required to fill in",
                "id": "--required",
                "required": true
            },
            {
                "name": "Type - Text",
                "description": "This and all above fields have got text type",
                "id": "--text",
                "type": "text"
            },
            {
                "name": "Type - Text Area",
                "description": "This field is text area. \nIt is resizable in most browsers. \nAnd allows to enter multiline texts.",
                "id": "--textarea",
                "type": "textarea"
            },
            {
                "name": "Type - Checkbox",
                "description": "This is the checkbox type",
                "id": "--checkbox",
                "type": "checkbox"
            },
            {
                "name": "Type - Password",
                "description": "This is the password field",
                "id": "--pass",
                "default": "qwerty",
                "type": "password"
            },
            {
                "name": "Type - Select",
                "description": "This is the select type. This description is not displayed in the web interface. Use description for each option instead.",
                "id": "--select",
                "default": "option2",
                "type": "select",
                "options": [
                    {
                        "description": "== Not selected =="
                    },
                    {
                        "value": "option1",
                        "description": "OK"
                    },
                    {
                        "description": "== Divider =="
                    },
                    {
                        "value": "option2",
                        "description": "Warning"
                    },
                    {
                        "value": "description"
                    }
                ]
            }
        ]
    }
    {
        "title": "Check SSH",
        "icon": "fa fa-folder fa-fw",
        "args": [
            {
                "name": "Host IP-address or DNS name"
            },
            {
                "name": "Port",
                "id": "-p"
            }
        ],
        "id": "Extras/check_ssh.sh"
    },
    ...
]