object action.create(object/array actions)
此方法用于创建新动作。
此方法只有 Admin(管理员) 和 Super admin(超级管理员) 用户可用。可以在用户角色设置中撤销调用该方法的权限。更多信息请查看用户角色。
(object/array) 要创建的动作 。
此外,还有 标准动作参数,方法接受如下参数。
| 参数 | 类型 | 描述 |
|---|---|---|
| filter | object | 动作的动作过滤 对象。 |
| operations | array | 为这个动作创建的动作操作 。 |
| recovery_operations | array | 为这个动作创建的动作恢复操作。 |
| update_operations | array | 为这个动作创建的动作更新操作。 |
(object) 返回一个对象,其中 actionids 属性下包含已创建 动作 的 ID。 返回的 ID 的顺序与传递的 动作 顺序相匹配。
创建一个动作,它将在 主机 "10084" 名字中包含 "memory" 的触发器进入problem状态时运行。这个动作必须首先向用户组 "7" 中的所有用户发送消息。如果事件在 4 分钟内未被解决,它将在 "2" 组中的所有主机上运行脚本 "3"。在触发器恢复时,它将通知之前收到有关该问题的任何消息的所有用户。在触发器确认中,带有自定义主体和主体的消息将通过所有媒体类型发送给所有确认和评论的所有人。
请求:
{ "jsonrpc": "2.0", "method": "action.create", "params": { "name": "Trigger action", "eventsource": 0, "status": 0, "esc_period": "2m", "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": { "scriptid": "3" } } ], "recovery_operations": [ { "operationtype": "11", "opmessage": { "default_msg": 1 } } ], "update_operations": [ { "operationtype": "12", "opmessage": { "default_msg": 0, "message": "Custom update operation message body", "subject": "Custom update operation message subject" } } ], "pause_suppressed": "0", "notify_if_canceled": "0" }, "auth": "038e1d7b1735c6a5436ee9eae095879e", "id": 1 }响应:
创建一个将发现的主机链接到模板 "10091" 的动作。
请求:
{ "jsonrpc": "2.0", "method": "action.create", "params": { "name": "Discovery action", "eventsource": 1, "status": 0, "filter": { "evaltype": 0, "conditions": [ { "conditiontype": 21, "operator": 0, "value": "1" }, { "conditiontype": 10, "operator": 0, "value": "2" } ] }, "operations": [ { "operationtype": 6, "optemplate": [ { "templateid": "10091" } ] } ] }, "auth": "038e1d7b1735c6a5436ee9eae095879e", "id": 1 }响应:
创建使用自定义过滤条件的触发器动作。这个动作必须为主机 "10084" 和 "10106" 上每个严重程度等于或高于 "Warning" 的触发器发送一条消息。公式 ID 可以从 "A", "B" 和 "C" 中任选。
请求:
{ "jsonrpc": "2.0", "method": "action.create", "params": { "name": "Trigger action", "eventsource": 0, "status": 0, "esc_period": "2m", "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" } } ], "pause_suppressed": "0", "notify_if_canceled": "0" }, "auth": "038e1d7b1735c6a5436ee9eae095879e", "id": 1 }响应:
当主机名中包含 "SRV" 或元数据中包含 "AlmaLinux" 时,向 "Linux servers" 主机组中添加主机。
请求:
{ "jsonrpc": "2.0", "method": "action.create", "params": { "name": "Register Linux servers", "eventsource": "2", "status": "0", "filter": { "evaltype": "2", "conditions": [ { "conditiontype": "22", "operator": "2", "value": "SRV" }, { "conditiontype": "24", "operator": "2", "value": "CentOS" } ] }, "operations": [ { "operationtype": "4", "opgroup": [ { "groupid": "2" } ] } ] }, "auth": "038e1d7b1735c6a5436ee9eae095879e", "id": 1 }响应:
ui/include/classes/api/services/CAction.php 中的 CAction::create() 。