action.create

描述

object action.create(object/array actions)

此方法用来创建新的动作

参数

(object/array) 创建新动作

除此之外 standard action properties, 该方法接受以下参数。

参数 类 描述
filter object 这个动作的动作过滤器对象。
operations array 为这个动作创建的动作操作。
recovery_operations array 为这个动作创建恢复操作。
acknowledge_operations array 为这个操作创建确认操作。

返回值

返回一个对象,其中包含 actionids 属性下已创建操作的 ID。 返回的 ID 的顺序与传递的操作的顺序相匹配。

示例

创建一个触发器动作

创建一个动作,当来自主机 "30045" 的触发器在其名称中出现 "memory" 进入问题状态时将运行该动作。 该操作必须首先向用户组 "7" 中的所有用户发送消息。 如果事件在 4 分钟内未得到解决,它将在组 "2" 中的所有主机上运行脚本 "3"。 在触发恢复时,它将通知所有收到有关此问题的消息的用户。 在触发确认时,带有自定义主题和正文的消息将发送给通过所有媒体类型留下确认和评论的所有人。

请求:

{  "jsonrpc": "2.0",  "method": "action.create",  "params": {  "name": "Trigger action",  "eventsource": 0,  "status": 0,  "esc_period": "2m",  "def_shortdata": "{TRIGGER.NAME}: {TRIGGER.STATUS}",  "def_longdata": "{TRIGGER.NAME}: {TRIGGER.STATUS}\r\nLast value: {ITEM.LASTVALUE}\r\n\r\n{TRIGGER.URL}",  "filter": {  "evaltype": 0,  "conditions": [  {  "conditiontype": 1,  "operator": 0,  "value": "10084"  },  {  "conditiontype": 3,  "operator": 2,  "value": "memory"  }  ]  },  "operations": [  {  "operationtype": 0,  "esc_period": "0s",  "esc_step_from": 1,  "esc_step_to": 2,  "evaltype": 0,  "opmessage_grp": [  {  "usrgrpid": "7"  }  ],  "opmessage": {  "default_msg": 1,  "mediatypeid": "1"  }  },  {  "operationtype": 1,  "esc_step_from": 3,  "esc_step_to": 4,  "evaltype": 0,  "opconditions": [  {  "conditiontype": 14,  "operator": 0,  "value": "0"  }  ],  "opcommand_grp": [  {  "groupid": "2"  }  ],  "opcommand": {  "type": 4,  "scriptid": "3"  }  }  ],  "recovery_operations": [  {  "operationtype": "11"  }  ],  "acknowledge_operations": [  {  "operationtype": "12",  "opmessage": {  "message": "Custom acknowledge operation message body",  "subject": "Custom acknowledge operation message subject"  }  }  ]  },  "auth": "038e1d7b1735c6a5436ee9eae095879e",  "id": 1 }

响应:

{  "jsonrpc": "2.0",  "result": {  "actionids": [  "17"  ]  },  "id": 1 }

创建一个发现动作

创建将已发现的主机链接到模板 "30085" 的操作。

请求:

{  "jsonrpc": "2.0",  "method": "action.create",  "params": {  "name": "Discovery action",  "eventsource": 1,  "status": 0,  "esc_period": "0s",  "filter": {  "evaltype": 0,  "conditions": [  {  "conditiontype": 21,  "value": "1"  },  {  "conditiontype": 10,  "value": "2"  }  ]  },  "operations": [  {  "esc_step_from": 1,  "esc_period": "0s",  "optemplate": [  {  "templateid": "10091"  }  ],  "operationtype": 6,  "esc_step_to": 1  }  ]  },  "auth": "038e1d7b1735c6a5436ee9eae095879e",  "id": 1 }

响应:

{  "jsonrpc": "2.0",  "result": {  "actionids": [  "18"  ]  },  "id": 1 }

使用自定义表达式过滤器

创建将使用自定义筛选条件的触发器动作。 对于主机 "10084" 和 "10106",操作必须为每个触发器发送一条消息,其严重性大于或等于 "警告"。 公式ID "A","B"和 "C"是任意选择的。

请求:

{  "jsonrpc": "2.0",  "method": "action.create",  "params": {  "name": "Trigger action",  "eventsource": 0,  "status": 0,  "esc_period": "2m",  "def_shortdata": "{TRIGGER.NAME}: {TRIGGER.STATUS}",  "def_longdata": "{TRIGGER.NAME}: {TRIGGER.STATUS}\r\nLast value: {ITEM.LASTVALUE}\r\n\r\n{TRIGGER.URL}",  "filter": {  "evaltype": 3,  "formula": "A and (B or C)",  "conditions": [  {  "conditiontype": 4,  "operator": 5,  "value": "2",  "formulaid": "A"  },  {  "conditiontype": 1,  "operator": 0,  "value": "10084",  "formulaid": "B"  },  {  "conditiontype": 1,  "operator": 0,  "value": "10106",  "formulaid": "C"  }  ]  },  "operations": [  {  "operationtype": 0,  "esc_period": "0s",  "esc_step_from": 1,  "esc_step_to": 2,  "evaltype": 0,  "opmessage_grp": [  {  "usrgrpid": "7"  }  ],  "opmessage": {  "default_msg": 1,  "mediatypeid": "1"  }  }  ]  },  "auth": "038e1d7b1735c6a5436ee9eae095879e",  "id": 1 }

响应:

{  "jsonrpc": "2.0",  "result": {  "actionids": [  "18"  ]  },  "id": 1 }

参见

Source

CAction::create() in frontends/php/include/classes/api/services/CAction.php.