object action.create(object/array actions)
此方法允许 create 新动作。
此方法仅对 管理员 和 超级管理员 用户类型可用。 可以在用户角色设置中撤销调用该方法的权限。更多信息请参见 User roles。
(object/array)
要创建的操作。
除了 动作 外, 该方法还接受以下参数。
参数 | 数据类型 | 说明 |
---|---|---|
filter | object | 该操作的 操作过滤器 object。 |
operations | array | 该操作的 action-操作,用于 create。 |
recovery_operations | array | 该操作的 action-恢复操作,用于 create。 |
update_operations | array | 该操作的 Action update operations,用于 create。 |
(object)
返回一个object,其中包含在actionids
属性下列出的已创建动作的ID。返回的ID顺序与传入的动作顺序一致。
创建一个触发器动作,当来自主机"10084"的触发器(名称中包含单词"memory")进入PROBLEM状态时,该动作将开始执行。 此动作将配置4操作。 第一个即时操作将通过媒介类型"1"向用户组"7"中的所有用户发送消息。 如果事件在30分钟内未解决,则第二个操作将在属于"2"组的所有主机上run 配置全局脚本"5"(作用域为"Action operation"的脚本)。 如果事件得到解决,恢复操作将通知所有收到过有关此问题消息的用户。 如果事件被更新,确认/update操作将向所有收到过有关此问题消息的用户发送通知(使用自定义主题和消息)。
执行请求:
{
"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"
}
}
]
},
"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"
}
]
}
]
},
"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"
}
}
]
},
"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"
}
]
}
]
},
"id": 1
}
响应:
创建一个自动注册动作,将 一个主机 添加到 主机组 "2",并添加两个 主机 标签。
执行请求:
{
"jsonrpc": "2.0",
"method": "action.create",
"params": {
"name": "Register Linux servers with tags",
"eventsource": "2",
"operations": [
{
"operationtype": "4",
"opgroup": [
{
"groupid": "2"
}
]
},
{
"operationtype": "13",
"optag": [
{
"tag": "location",
"value": "office"
},
{
"tag": "city",
"value": "Riga"
}
]
}
]
},
"id": 1
}
响应:
CAction::create() 在 ui/include/classes/api/services/CAction.php 中。