脚本 object

以下 objects 直接与 script API 相关。

脚本

脚本对象具有以下属性。

Property Type Description
scriptid ID 脚本的 ID。

属性行为
- 只读
- 更新操作时必需
name string 脚本名称。

属性行为
- 创建操作时必需
type integer 脚本类型。

scope 设置为 "action operation" 时的可能值:
0 - 脚本;
1 - IPMI;
2 - SSH;
3 - TELNET;
5 - webhook。

scope 设置为 "manual host action" 或 "manual event action" 时的可能值:
6 - URL。

属性行为
- 创建操作时必需
command string 要运行的命令。

属性行为
- 当 type 设置为 "Script"、"IPMI"、"SSH"、"TELNET" 或 "Webhook" 时必需
scope integer 脚本范围。

可能值:
1 - action operation;
2 - manual host action;
4 - manual event action。

属性行为
- 创建操作时必需
execute_on integer 运行脚本的位置。

可能值:
0 - 在 Zabbix agent 上运行;
1 - 在 Zabbix 服务器上运行。仅当 Zabbix 服务器启用了全局脚本执行时才支持
2 - (默认) 在 Zabbix 服务器或 proxy 上运行。

属性行为
- 当 type 设置为 "Script" 时支持
menu_path string 由斜杠分隔的文件夹。单击主机或事件时,这些文件夹会在前端中形成类似菜单的导航。

属性行为
- 当 scope 设置为 "manual host action" 或 "manual event action" 时支持
authtype integer SSH 脚本类型使用的身份验证方法。

可能值:
0 - 密码;
1 - 公钥。

属性行为
- 当 type 设置为 "SSH" 时支持
username string 用于身份验证的用户名。

属性行为
- 当 type 设置为 "SSH" 或 "TELNET" 时必需
password string 使用密码身份验证的 SSH 脚本和 TELNET 脚本所使用的密码。

属性行为
- 当 type 设置为 "SSH" 且 authtype 设置为 "password",或 type 设置为 "TELNET" 时支持
publickey string 使用公钥身份验证的 SSH 脚本所使用的公钥文件名称。

属性行为
- 当 type 设置为 "SSH" 且 authtype 设置为 "public key" 时必需
privatekey string 使用公钥身份验证的 SSH 脚本所使用的私钥文件名称。

属性行为
- 当 type 设置为 "SSH" 且 authtype 设置为 "public key" 时必需
port string SSH 和 TELNET 脚本使用的端口号。

属性行为
- 当 type 设置为 "SSH" 或 "TELNET" 时支持
groupid ID 脚本可以运行的主机组的 ID。

如果设置为 "0",则所有主机组都可以使用该脚本。

默认值:0。
usrgrpid ID 允许运行该脚本的用户组的 ID。

如果设置为 "0",则所有用户组都可以使用该脚本。

默认值:0。

属性行为
- 当 scope 设置为 "manual host action" 或 "manual event action" 时支持
host_access integer 运行脚本所需的主机权限。

可能值:
2 - (默认) 读取;
3 - 写入。

属性行为
- 当 scope 设置为 "manual host action" 或 "manual event action" 时支持
confirmation string 确认弹窗文本。
尝试从 Zabbix 前端运行脚本时,将显示该弹窗。

属性行为
- 当 scope 设置为 "manual host action" 或 "manual event action" 时支持
timeout string webhook 脚本执行超时时间,单位为秒。支持时间后缀(例如 30s1m)。

可能值:1-60s。

默认值:30s。

属性行为
- 当 type 设置为 "Webhook" 时必需
parameters array webhook 输入参数数组。

属性行为
- 当 type 设置为 "Webhook" 时支持
description string 脚本描述。
url string 用户定义的 URL。

属性行为
- 当 type 设置为 "URL" 时必需
new_window integer 在新窗口中打开 URL。

可能值:
0 - 否;
1 - (默认) 是。

属性行为
- 当 type 设置为 "URL" 时支持
manualinput integer 指示脚本是否接受用户提供的输入。

可能值:
0 - (默认) 禁用;
1 - 启用;

属性行为
- 当 scope 设置为 "manual host action" 或 "manual event action" 时支持
manualinput_prompt string 手动输入提示文本。

属性行为
- 当 manualinput 设置为 "Enabled" 时必需
manualinput_validator string 用于验证用户提供输入的字符串字段。该字符串由正则表达式或以逗号分隔的一组值组成。

属性行为
- 当 manualinput 设置为 "Enabled" 时必需
manualinput_validator_type integer 确定所需的用户输入类型。

可能值:
0 - (默认) 字符串。表示将 manualinput_validator 视为正则表达式;
1 - 列表。表示将 manualinput_validator 视为以逗号分隔的可能输入值列表。

属性行为
- 当 manualinput 设置为 "Enabled" 时支持
manualinput_default_value string 用于自动填充用户输入的默认值。

属性行为
- 当 manualinput_validator_type 设置为 "String" 时支持

webhook 参数

调用 webhook 脚本时传递的参数具有以下属性。

Property Type Description
name string 参数名称。

属性行为:
- required
value string 参数值。支持

调试

已执行 webhook 脚本的调试信息。调试对象具有以下属性。

Property Type Description
logs array 日志条目数组。
ms string 脚本执行持续时间,单位为毫秒。

日志条目

日志条目对象具有以下属性。

Property Type Description
level integer 日志级别。
ms string 自脚本运行以来到添加日志条目之前经过的毫秒数。
message string 日志消息。