object action.create(object/array actions)
此方法允许创建新的动作。
此方法仅适用于管理员和超级管理员用户类型。调用该方法的权限可在用户角色设置中撤销。更多信息请参阅User roles。
(object/array)
待创建的动作。
除动作外,该方法还接受以下参数。
参数 | 数据类型 | 描述 |
---|---|---|
filter | object | 动作的操作过滤器object配置。 |
operations | array | 为动作创建的action-操作配置。 |
recovery_operations | array | 为动作创建的action-恢复操作配置。 |
update_operations | array | 为动作创建的action-更新操作配置。 |
(object)
返回一个包含所创建动作ID的object,这些ID存储在actionids
属性下。返回的ID顺序与传入的动作顺序一致。
创建一个触发器动作,当来自主机 "10084"且名称包含"memory"的触发器进入PROBLEM状态时触发。 该动作将配置4个操作。 第一个即时操作将通过媒介类型"1"向用户组"7"中的所有用户发送消息。 如果事件在30分钟内未解决,第二个操作将在组"2"中的所有主机上运行配置全局脚本 "5"(作用域为"Action operation"的脚本)。 如果事件恢复,恢复操作将通知所有收到过问题消息的用户。 如果事件更新,确认/更新操作将以自定义主题和消息通知所有收到过问题消息的用户。
请求:
{
"jsonrpc": "2.0",
"method": "action.create",
"params": {
"name": "Trigger action",
"eventsource": 0,
"esc_period": "30m",
"filter": {
"evaltype": 0,
"conditions": [
{
"conditiontype": 1,
"operator": 0,
"value": "10084"
},
{
"conditiontype": 3,
"operator": 2,
"value": "memory"
}
]
},
"operations": [
{
"operationtype": 0,
"esc_step_from": 1,
"esc_step_to": 1,
"opmessage_grp": [
{
"usrgrpid": "7"
}
],
"opmessage": {
"default_msg": 1,
"mediatypeid": "1"
}
},
{
"operationtype": 1,
"esc_step_from": 2,
"esc_step_to": 2,
"opconditions": [
{
"conditiontype": 14,
"operator": 0,
"value": "0"
}
],
"opcommand_grp": [
{
"groupid": "2"
}
],
"opcommand": {
"scriptid": "5"
}
}
],
"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"
}
}
]
},
"auth": "038e1d7b1735c6a5436ee9eae095879e",
"id": 1
}
响应:
创建一个发现动作,将发现的主机关联到模板"10001"。
请求:
{
"jsonrpc": "2.0",
"method": "action.create",
"params": {
"name": "Discovery action",
"eventsource": 1,
"filter": {
"evaltype": 0,
"conditions": [
{
"conditiontype": 21,
"operator": 0,
"value": "1"
},
{
"conditiontype": 10,
"operator": 0,
"value": "2"
}
]
},
"operations": [
{
"operationtype": 6,
"optemplate": [
{
"templateid": "10001"
}
]
}
]
},
"auth": "038e1d7b1735c6a5436ee9eae095879e",
"id": 1
}
响应:
创建一个使用自定义表达式"A and (B or C)"来评估操作条件的触发器动作。 当来自主机"10084"或主机"10106"且严重性大于等于"警告"的触发器进入问题状态时, 该动作将通过媒介类型"1"向用户组"7"中的所有用户发送消息。 公式ID"A"、"B"和"C"是任意选择的。
请求:
{
"jsonrpc": "2.0",
"method": "action.create",
"params": {
"name": "Trigger action",
"eventsource": 0,
"esc_period": "15m",
"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_step_from": 1,
"esc_step_to": 1,
"opmessage_grp": [
{
"usrgrpid": "7"
}
],
"opmessage": {
"default_msg": 1,
"mediatypeid": "1"
}
}
]
},
"auth": "038e1d7b1735c6a5436ee9eae095879e",
"id": 1
}
响应:
创建自动注册动作,当主机名称包含"SRV"或元数据包含"AlmaLinux"时,将主机添加到"2"组。
请求:
{
"jsonrpc": "2.0",
"method": "action.create",
"params": {
"name": "Register Linux servers",
"eventsource": "2",
"filter": {
"evaltype": "2",
"conditions": [
{
"conditiontype": "22",
"operator": "2",
"value": "SRV"
},
{
"conditiontype": "24",
"operator": "2",
"value": "AlmaLinux"
}
]
},
"operations": [
{
"operationtype": "4",
"opgroup": [
{
"groupid": "2"
}
]
}
]
},
"auth": "038e1d7b1735c6a5436ee9eae095879e",
"id": 1
}
响应:
CAction::create() 位于 ui/include/classes/api/services/CAction.php 文件中。