2022 Zabbix中国峰会
2022 Zabbix中国峰会

> 动作对象

下面是动作API相关的对象。

动作

动作对象具有以下属性。

属性 类 描述
actionid string (只读) 动作的IP。
esc_period
(必需)
string 默认操作步骤持续时间。必须大于60秒。接受秒,带后缀的时间单位和用户宏。
eventsource
(必需)
integer
(常量) 动作将处理的事件的类型。
请参阅 事件 "source" 属性 以获取支持的事件类型列表。
name
(必需)
string 动作的名称
def_longdata string 异常消息文本。
def_shortdata string 异常消息主题。
r_longdata string 恢复消息文本。
r_shortdata string 恢复消息主题。
status integer 动作是启动还是禁用。

取值:
0 - (默认) 启用;
1 - 禁用。

动作操作

动作操作对象定义执行动作时执行的操作。它具有以下属性。

属性 类 描述
operationid string (只读) 动作操作的ID。
operationtype
(必需)
integer
操作类型
可能的值:
0 - 发送消息;
1 - 远程命令;
2 - 添加主机;
3 - 删除主机
4 - 添加到主机组;
5 - 从主机组删除;
6 - 链接到模板;
7 - 取消与模板的关联;
8 - 启用主机;
9 - 禁用主机;
10 - 设置主机库存模式.
actionid string 该操作所属的操作的ID。
esc_period string 升级步骤的持续时间(秒)。必须大于60秒。接受秒,时间单位后缀和用户宏。如果设置为0或0,将使用默认动作升级期。

默认: 0s.
esc_step_from integer 步骤开始升级。

默认: 1.
esc_step_to integer 逐步结束升级

默认: 1.
evaltype integer 操作条件评估方法。

可能的值:
0 - (默认) AND / OR;
1 - AND;
2 - OR.
opcommand object 包含操作运行的命令的对象的对象。

下面详细描述操作命令对象.

远程命令操作需要。
opcommand_grp array 主机组运行远程命令。

每个对象具有以下属性:
opcommand_grpid - (string, 只读) 对象的ID;
operationid - (string) 操作的 ID;
groupid - (string) 主机组的ID。

如果opcommand_hst 未设置,则需要远程命令操作。
opcommand_hst array 主机运行远程命令。

每个对象具有以下属性:
opcommand_hstid - (string, 只读) 对象的ID;
operationid - (string) 操作的 ID;
hostid - (string) 主机的ID; 如果设置为0,则该命令将在当前主机上运行。

如果 opcommand_grp 未设置,则需要远程命令操作。
opconditions array 用于触发动作的操作条件。

操作对象条件 下面详细描述操作.
opgroup array 主机组添加主机。

每个对象具有以下属性:
operationid - (string) 操作的 ID;
groupid - (string) 主机组的ID。

需要“添加到主机组”和“从主机组删除”操作。
opmessage object 对象包含有关操作发送的消息的数据。

操作消息对象 下面详细描述操作.

需要消息操作。
opmessage_grp array 发送消息的用户组。

每个对象具有以下属性:
operationid - (string) 操作的 ID;
usrgrpid - (string) 用户组的ID。

如果 opmessage_usr 未设置,则为消息操作所必需。
opmessage_usr array 发送消息到用户。

每个对象具有以下属性:
operationid - (string) 操作的 ID;
userid - (string) 用户的ID。

如果 opmessage_grp 未设置,则为消息操作必需。
optemplate array 将主机链接到的模板。

每个对象具有以下属性:
operationid - (string) 操作的 ID;
templateid - (string) 模板的ID。

需要“链接到模板”和“取消与模板的链接”操作。
opinventory object 库存模式设置主机。

对象具有以下属性:
operationid - (string) 操作的 ID;
inventory_mode - (string) 库存模式。

需要设置主机库存模式”操作。

操作指令

操作命令对象包含有关操作将运行的命令的数据。

属性 类 说明
operationid string (只读)操作的ID。
command string 命令运行。输入IN(0,1,2,3) 时需要
type (必填) int ger 操作类 命令。
可能的值:
0 - 自定义脚本;
1 - IPMI;
2 - SSH;
3 - Telnet
4 - 全局脚本。
authtype integer 用于SSH命令的身份验证方法。
可能的值:
0 - 密码;
1 - 公钥。
对于SSH命令是必需的。
execute_on integer 将执行自定义脚本操作命令的目标。
可能的值:
0 - Zabbix代理;
1 - Zabbix服务器。
自定义脚本命令必需。
password string 用于具有密码认证和Telnet命令的SSH命令的密码。
port string 用于SSH和Telnet命令的端口号。
privatekey string 用于具有公钥认证的SSH命令的私钥文件的名称。
对于使用公钥身份验证的SSH命令,必需。
publickey string 用于具有公钥认证的SSH命令的公钥文件名。
对于使用公钥身份验证的SSH命令,必需。
scriptid string 用于全局脚本命令的脚本的ID。
全局脚本命令必需。
username string 用于认证的用户名。
需要SSH和Telnet命令。

操作信息

操作消息对象包含有关操作将发送的消息的数据。

属性 类 说明
operationid string (只读)操作操作的ID。
default_msg integer 是否使用默认动作消息文本和主题。
可能的值:
0 - (默认)使用操作中的数据;
1 - 使用动作中的数据。
mediatypeid string 将用于发送消息的媒体类型的ID。
integer string 操作消息文本。
subject string 操作信息主题。

动作操作条件

动作操作条件对象定义了执行当前操作必须满足的条件。 它具有以下属性。

属性 类 说明
opconditionid string (readonly)动作操作条件的ID
** conditiontype ** \\(必填) int ger 条件类 可能的值:
14 - 确认事件。
value \\(必填) str ng 价值比
operationid string (readonly)操作的ID。
operator integer 条件运算符。 可能的值:
0 - (默认) =。

每个操作条件类型都支持以下运算符和值。

条件 条 名称 支持的运算 预期值
14 Event acknowledged = 是否确认事件。 可能的值:
0 - 未确认;
1 - 确认。

Action recovery operation

The action recovery operation object defines an operation that will be performed when a problem is resolved. Recovery operations are possible for trigger actions and internal actions. It has the following properties.

Property Type Description
operationid string (readonly) ID of the action operation.
operationtype
(required)
integer Type of operation.

Possible values for trigger actions:
0 - send message;
1 - remote command;
11 - send recovery message.

Possible values for internal actions:
0 - send message;
11 - send recovery message.
actionid string ID of the action that the recovery operation belongs to.
opcommand object Object containing the data about the command run by the recovery operation.

The operation command object is described in detail below.

Required for remote command operations.
opcommand_grp array Host groups to run remote commands on.

Each object has the following properties:
opcommand_grpid - (string, readonly) ID of the object;
operationid - (string) ID of the operation;
groupid - (string) ID of the host group.

Required for remote command operations if opcommand_hst is not set.
opcommand_hst array Host to run remote commands on.

Each object has the following properties:
opcommand_hstid - (string, readonly) ID of the object;
operationid - (string) ID of the operation;
hostid - (string) ID of the host; if set to 0 the command will be run on the current host.

Required for remote command operations if opcommand_grp is not set.
opmessage object Object containing the data about the message sent by the recovery operation.

The operation message object is described in detail below.

Required for message operations.
opmessage_grp array User groups to send messages to.

Each object has the following properties:
operationid - (string) ID of the operation;
usrgrpid - (string) ID of the user group.

Required for message operations if opmessage_usr is not set.
opmessage_usr array Users to send messages to.

Each object has the following properties:
operationid - (string) ID of the operation;
userid - (string) ID of the user.

Required for message operations if opmessage_grp is not set.

Action filter

The action filter object defines a set of conditions that must be met to perform the configured action operations. It has the following properties.

Property Type Description
conditions
(required)
array Set of filter conditions to use for filtering results.
evaltype
(required)
integer Filter condition evaluation method.

Possible values:
0 - and/or;
1 - and;
2 - or;
3 - custom expression.
eval_formula string (readonly) Generated expression that will be used for evaluating filter conditions. The expression contains IDs that reference specific filter conditions by its formulaid. The value of eval_formula is equal to the value of formula for filters with a custom expression.
formula string User-defined expression to be used for evaluating conditions of filters with a custom expression. The expression must contain IDs that reference specific filter conditions by its formulaid. The IDs used in the expression must exactly match the ones defined in the filter conditions: no condition can remain unused or omitted.

Required for custom expression filters.

Action filter condition

The action filter condition object defines a specific condition that must be checked before running the action operations.

Property Type Description
conditionid string (readonly) ID of the action condition.
conditiontype
(required)
integer Type of condition.

Possible values for trigger actions:
0 - host group;
1 - host;
2 - trigger;
3 - trigger name;
4 - trigger severity;
6 - time period;
13 - host template;
15 - application;
16 - maintenance status;
25 - event tag;
26 - event tag value.

Possible values for discovery actions:
7 - host IP;
8 - discovered service type;
9 - discovered service port;
10 - discovery status;
11 - uptime or downtime duration;
12 - received value;
18 - discovery rule;
19 - discovery check;
20 - proxy;
21 - discovery object.

Possible values for auto-registration actions:
20 - proxy;
22 - host name;
24 - host metadata.

Possible values for internal actions:
0 - host group;
1 - host;
13 - host template;
15 - application;
23 - event type.
value
(required)
string Value to compare with.
value2
string Secondary value to compare with. Requried for trigger actions when condition type is 26.
actionid string (readonly) ID of the action that the condition belongs to.
formulaid string Arbitrary unique ID that is used to reference the condition from a custom expression. Can only contain capital-case letters. The ID must be defined by the user when modifying filter conditions, but will be generated anew when requesting them afterward.
operator integer Condition operator.

Possible values:
0 - (default) =;
1 - <>;
2 - like;
3 - not like;
4 - in;
5 - >=;
6 - <=;
7 - not in.

To better understand how to use filters with various types of expressions, see examples on the action.get and action.create method pages.

The following operators and values are supported for each condition type.

Condition Condition name Supported operators Expected value
0 Host group =, <> Host group ID.
1 Host =, <> Host ID.
2 Trigger =, <> Trigger ID.
3 Trigger name like, not like Trigger name.
4 Trigger severity =, <>, >=, <= Trigger severity. Refer to the trigger "severity" property for a list of supported trigger severities.
5 Trigger value = Trigger value. Refer to the trigger "value" property for a list of supported trigger values.
6 Time period in, not in Time when the event was triggered as a time period.
7 Host IP =, <> One or several IP ranges to check separated by commas. Refer to the network discovery configuration section for more information on supported formats of IP ranges.
8 Discovered service type =, <> Type of discovered service. The type of service matches the type of the discovery check used to detect the service. Refer to the discovery check "type" property for a list of supported types.
9 Discovered service port =, <> One or several port ranges separated by commas.
10 Discovery status = Status of a discovered object.

Possible values:
0 - host or service up;
1 - host or service down;
2 - host or service discovered;
3 - host or service lost.
11 Uptime or downtime duration >=, <= Time indicating how long has the discovered object been in the current status in seconds.
12 Received values =, <>, >=, <=, like, not like Value returned when performing a Zabbix agent, SNMPv1, SNMPv2 or SNMPv3 discovery check.
13 Host template =, <> Linked template ID.
15 Application =, like, not like Name of the application.
16 Maintenance status in, not in No value required: using the "in" operator means that the host must be in maintenance, "not in" - not in maintenance.
18 Discovery rule =, <> ID of the discovery rule.
19 Discovery check =, <> ID of the discovery check.
20 Proxy =, <> ID of the proxy.
21 Discovery object = Type of object that triggered the discovery event.

Possible values:
1 - discovered host;
2 - discovered service.
22 Host name like, not like Host name.
23 Event type = Specific internal event.

Possible values:
0 - item in "not supported" state;
1 - item in "normal" state;
2 - LLD rule in "not supported" state;
3 - LLD rule in "normal" state;
4 - trigger in "unknown" state;
5 - trigger in "normal" state.
24 Host metadata like, not like Metadata of the auto-registered host.
25 Tag =, <>, like, not like Event tag.
26 Tag value =, <>, like, not like Event tag value.