创建

Description 说明

object trigger.create(object/array triggers)

This method allows to create new triggers. 此方法允许创建新的触发器。

Parameters 参数

(object/array) Triggers to create. (object/array)需要创建的触发器。 Additionally to the standard trigger properties the method accepts the following parameters. 除standard trigger properties之外,该方法接受以下参数。

Parameter 参数 Tpe 类型 Desription 说明
dependenciesarray 数组 Tiggers that the trigger is dependent on. 依赖触发的触发器。

The triggers must have the triggerid property defined. 触发器必须已定义triggerid属性。
tagsarray 数组 Tigger tags. 触发器标签。

The trigger expression has to be given in its expanded form. 指定的触发器表达式必须为展开式。

Return values 返回值

(object) Returns an object containing the IDs of the created triggers under the triggerids property. The order of the returned IDs matches the order of the passed triggers. (object)返回一个对象,该对象包含在triggerids属性中已创建触发器的ID,返回ID的顺序与传递触发器的顺序相匹配。

Examples 范例

Creating a trigger 创建触发器

Create a trigger with a single trigger dependency. 创建具有单个触发依赖关系的触发器。

Request 请求:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "trigger.create",
  4. "params": [
  5. {
  6. "description": "Processor load is too high on {HOST.NAME}",
  7. "expression": "{Linux server:system.cpu.load[percpu,avg1].last()}>5",
  8. "dependencies": [
  9. {
  10. "triggerid": "17367"
  11. }
  12. ]
  13. },
  14. {
  15. "description": "Service status",
  16. "expression": "{Linux server:log[/var/log/system,Service .* has stopped].strlen()}<>0",
  17. "dependencies": [
  18. {
  19. "triggerid": "17368"
  20. }
  21. ],
  22. "tags": [
  23. {
  24. "tag": "service",
  25. "value": "{{ITEM.VALUE}.regsub(\"Service (.*) has stopped\", \"\\1\")}"
  26. },
  27. {
  28. "tag": "error",
  29. "value": ""
  30. }
  31. ]
  32. }
  33. ],
  34. "auth": "038e1d7b1735c6a5436ee9eae095879e",
  35. "id": 1
  36. }

Response 响应:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": {
  4. "triggerids": [
  5. "17369",
  6. "17370"
  7. ]
  8. },
  9. "id": 1
  10. }

Source 源码

CTrigger::create() in frontends/php/include/classes/api/services/CTrigger.php. CTrigger::create()方法可在frontends/php/include/classes/api/services/CTrigger.php中参考。