community.zabbix.zabbix_action 模块 – 创建/删除/更新 Zabbix 动作
注意
此模块是 community.zabbix 集合 (版本 3.2.0) 的一部分。
如果您使用的是 ansible
包,则可能已经安装了此集合。它不包含在 ansible-core
中。要检查它是否已安装,请运行 ansible-galaxy collection list
。
要安装它,请使用:ansible-galaxy collection install community.zabbix
。您需要其他要求才能使用此模块,有关详细信息,请参阅 要求。
要在剧本中使用它,请指定:community.zabbix.zabbix_action
。
概要
此模块允许您创建、修改和删除 Zabbix 动作。
要求
执行此模块的主机需要以下要求。
python >= 3.9
参数
参数 |
注释 |
---|---|
确认操作列表。 从 Zabbix 4.0 开始,操作确认操作被称为更新操作。
默认值: |
|
要运行的命令。 |
|
操作命令的类型。 选项
|
|
将执行自定义脚本操作命令的目标。 选项
|
|
将用于发送消息的媒体类型。 可在 *acknowledge_operations* 内与 *type=send_message* 或 *type=notify_all_involved* 一起使用。 对于所有媒体类型,设置为 默认值: |
|
操作消息文本。 如果未定义 *op_message* 和 *subject*,则将使用媒体类型的“默认消息”。 |
|
用于身份验证的密码。 当 *ssh_auth_type=password* 或 *command_type=telnet* 时必填。 可在 *type=remote_command* 时使用。 |
|
用于身份验证的端口号。 可在 *command_type in [ssh, telnet]* 和 *type=remote_command* 时使用。 |
|
要在其上运行远程命令的主机组。 当 *type=remote_command* 且未设置 *run_on_hosts* 时必填。 |
|
要在其上运行远程命令的主机。 当 *type=remote_command* 且未设置 *run_on_groups* 时必填。 如果设置为 0,则命令将在当前主机上运行。 |
|
用于全局脚本命令的脚本名称。 当 *command_type=global_script* 时必填。 可在 *type=remote_command* 时使用。 |
|
要向其发送消息的用户组。 |
|
要向其发送消息的用户(用户名或别名)。 |
|
用于 SSH 命令的身份验证方法。 当 *type=remote_command* 和 *command_type=ssh* 时必填。 选项
|
|
用于使用公钥身份验证的 SSH 命令的私钥文件名。 当 *ssh_auth_type=public_key* 时必填。 可在 *type=remote_command* 时使用。 |
|
用于使用公钥身份验证的 SSH 命令的公钥文件名。 当 *ssh_auth_type=public_key* 时必填。 可在 *type=remote_command* 时使用。 |
|
操作消息主题。 如果未定义 *op_message* 和 *subject*,则将使用媒体类型的“默认消息”。 |
|
操作类型。 选项
|
|
用于身份验证的用户名。 当 *ssh_auth_type in [public_key, password]* 或 *command_type=telnet* 时必填。 可在 *type=remote_command* 时使用。 |
|
用于过滤结果的条件列表。 有关此选项子选项的更多信息,请查看 Zabbix API 文档 https://www.zabbix.com/documentation/5.0/manual/api/reference/action/object#action_filter_condition 默认值: |
|
用于从自定义表达式引用条件的任意唯一 ID。 只能包含大写字母。 仅在自定义表达式过滤器中需要,否则忽略。 |
|
条件运算符。 当type设置为 选项
|
|
条件的类型(标签)。 当event_source=trigger时的可能值
当event_source=discovery时的可能值
当event_source=auto_registration时的可能值
当event_source=internal时的可能值
|
|
用于比较的值。 当type=discovery_status时,可选值为
当type=discovery_object时,可选值为
当type=event_type时,可选值为
当type=trigger_severity时,可选值为(不区分大小写)
无论Zabbix中用户可见的名称是否更改。如果省略,则默认为 除了以上选项外,这通常是对象的名称或要比较的字符串。 |
|
用于比较的第二个值。 当条件type=event_tag_value时,触发器操作需要此参数。 |
|
默认操作步骤持续时间。必须大于60秒。 接受秒、带后缀的时间单位和用户宏(自Zabbix 3.4起)。 当 |
|
筛选条件评估方法。 如果条件少于2个或未指定formula,则默认为 当指定formula时,默认为 选项
|
|
操作将处理的事件类型。 当 选项
|
|
用于使用自定义表达式评估条件的用户定义表达式。 表达式必须包含引用每个条件的formulaid的ID。 表达式中使用的ID必须与conditions中定义的ID完全匹配。任何条件都不能未使用或省略。 当eval_type=custom_expression时需要。 使用从“A”开始的连续ID。如果使用非连续ID,Zabbix将重新索引它们。这使得每个模块运行都会注意到ID的差异并更新操作。 |
|
基本认证密码 |
|
基本认证用户名 |
|
操作的名称 |
|
是否在取消升级时发出通知。 可在event_source=trigger时使用。 选项
|
|
操作列表 默认值: |
|
要运行的命令。 当type=remote_command且command_type!=global_script时需要。 |
|
操作命令的类型。 当type=remote_command时需要。 选项
|
|
升级步骤持续时间(秒)。 必须大于60秒。 接受秒、带后缀的时间单位和用户宏。 如果设置为0或0s,将使用默认操作升级周期。 默认: |
|
开始升级的步骤。 默认: |
|
结束升级的步骤。 指定0表示无限。 默认: |
|
将执行自定义脚本操作命令的目标。 当type=remote_command且command_type=custom_script时需要。 选项
|
|
主机应添加到的主机组列表。 当type=add_to_host_group或type=remove_from_host_group时需要。 |
|
主机清单模式。 当type=set_host_inventory_mode时需要。 选项
|
|
将用于发送消息的媒体类型。 可在 *acknowledge_operations* 内与 *type=send_message* 或 *type=notify_all_involved* 一起使用。 对于所有媒体类型,设置为 默认值: |
|
操作消息文本。 如果未定义 *op_message* 和 *subject*,则将使用媒体类型的“默认消息”。 |
|
操作条件对象定义必须满足才能执行当前操作的条件。 选项
|
|
用于身份验证的密码。 当 *ssh_auth_type=password* 或 *command_type=telnet* 时必填。 可在 *type=remote_command* 时使用。 |
|
用于身份验证的端口号。 可在 *command_type in [ssh, telnet]* 和 *type=remote_command* 时使用。 |
|
要在其上运行远程命令的主机组。 当 *type=remote_command* 且未设置 *run_on_hosts* 时必填。 |
|
要在其上运行远程命令的主机。 当 *type=remote_command* 且未设置 *run_on_groups* 时必填。 如果设置为 0,则命令将在当前主机上运行。 |
|
用于全局脚本命令的脚本名称。 当 *command_type=global_script* 时必填。 可在 *type=remote_command* 时使用。 |
|
要向其发送消息的用户组。 |
|
要向其发送消息的用户(用户名或别名)。 |
|
用于 SSH 命令的身份验证方法。 当 *type=remote_command* 和 *command_type=ssh* 时必填。 选项
|
|
用于使用公钥身份验证的 SSH 命令的私钥文件名。 当 *ssh_auth_type=public_key* 时必填。 可在 *type=remote_command* 时使用。 |
|
用于使用公钥身份验证的 SSH 命令的公钥文件名。 当 *ssh_auth_type=public_key* 时必填。 可在 *type=remote_command* 时使用。 |
|
操作消息主题。 如果未定义 *op_message* 和 *subject*,则将使用媒体类型的“默认消息”。 |
|
主机应链接到的模板列表。 当type=link_to_template或type=unlink_from_template时需要。 |
|
操作类型。 设置recovery_operations和acknowledge_operations类型的有效选择
选择 选项
|
|
用于身份验证的用户名。 当 *ssh_auth_type in [public_key, password]* 或 *command_type=telnet* 时必填。 可在 *type=remote_command* 时使用。 |
|
是否在维护期间暂停升级。 可在event_source=trigger时使用。 选项
|
|
如果事件是症状事件,是否暂停升级。 如果 仅适用于Zabbix 6.4及以上版本 选项
|
|
恢复操作列表。
默认值: |
|
要运行的命令。 |
|
操作命令的类型。 选项
|
|
将执行自定义脚本操作命令的目标。 选项
|
|
将用于发送消息的媒体类型。 可在 *acknowledge_operations* 内与 *type=send_message* 或 *type=notify_all_involved* 一起使用。 对于所有媒体类型,设置为 默认值: |
|
操作消息文本。 如果未定义 *op_message* 和 *subject*,则将使用媒体类型的“默认消息”。 |
|
用于身份验证的密码。 当 *ssh_auth_type=password* 或 *command_type=telnet* 时必填。 可在 *type=remote_command* 时使用。 |
|
用于身份验证的端口号。 可在 *command_type in [ssh, telnet]* 和 *type=remote_command* 时使用。 |
|
要在其上运行远程命令的主机组。 当 *type=remote_command* 且未设置 *run_on_hosts* 时必填。 |
|
要在其上运行远程命令的主机。 当 *type=remote_command* 且未设置 *run_on_groups* 时必填。 如果设置为 0,则命令将在当前主机上运行。 |
|
用于全局脚本命令的脚本名称。 当 *command_type=global_script* 时必填。 可在 *type=remote_command* 时使用。 |
|
要向其发送消息的用户组。 |
|
要向其发送消息的用户(用户名或别名)。 |
|
用于 SSH 命令的身份验证方法。 当 *type=remote_command* 和 *command_type=ssh* 时必填。 选项
|
|
用于使用公钥身份验证的 SSH 命令的私钥文件名。 当 *ssh_auth_type=public_key* 时必填。 可在 *type=remote_command* 时使用。 |
|
用于使用公钥身份验证的 SSH 命令的公钥文件名。 当 *ssh_auth_type=public_key* 时必填。 可在 *type=remote_command* 时使用。 |
|
操作消息主题。 如果未定义 *op_message* 和 *subject*,则将使用媒体类型的“默认消息”。 |
|
操作类型。 选项
|
|
用于身份验证的用户名。 当 *ssh_auth_type in [public_key, password]* 或 *command_type=telnet* 时必填。 可在 *type=remote_command* 时使用。 |
|
操作的状态。 对于 对于 选项
|
|
操作的状态。 选项
|
示例
# If you want to use Username and Password to be authenticated by Zabbix Server
- name: Set credentials to access Zabbix Server API
ansible.builtin.set_fact:
ansible_user: Admin
ansible_httpapi_pass: zabbix
# If you want to use API token to be authenticated by Zabbix Server
# https://www.zabbix.com/documentation/current/en/manual/web_interface/frontend_sections/administration/general#api-tokens
- name: Set API token
ansible.builtin.set_fact:
ansible_zabbix_auth_key: 8ec0d52432c15c91fcafe9888500cf9a607f44091ab554dbee860f6b44fac895
# Trigger action with only one condition
- name: Deploy trigger action
# set task level variables as we change ansible_connection plugin here
vars:
ansible_network_os: community.zabbix.zabbix
ansible_connection: httpapi
ansible_httpapi_port: 443
ansible_httpapi_use_ssl: true
ansible_httpapi_validate_certs: false
ansible_zabbix_url_path: "zabbixeu" # If Zabbix WebUI runs on non-default (zabbix) path ,e.g. http://<FQDN>/zabbixeu
ansible_host: zabbix-example-fqdn.org
community.zabbix.zabbix_action:
name: "Send alerts to Admin"
event_source: "trigger"
state: present
status: enabled
esc_period: 60
conditions:
- type: "trigger_severity"
operator: ">="
value: "Information"
operations:
- type: send_message
subject: "Something bad is happening"
op_message: "Come on, guys do something"
media_type: "Email"
send_to_users:
- "Admin"
# Trigger action with multiple conditions and operations
- name: Deploy trigger action
# set task level variables as we change ansible_connection plugin here
vars:
ansible_network_os: community.zabbix.zabbix
ansible_connection: httpapi
ansible_httpapi_port: 443
ansible_httpapi_use_ssl: true
ansible_httpapi_validate_certs: false
ansible_zabbix_url_path: "zabbixeu" # If Zabbix WebUI runs on non-default (zabbix) path ,e.g. http://<FQDN>/zabbixeu
ansible_host: zabbix-example-fqdn.org
community.zabbix.zabbix_action:
name: "Send alerts to Admin"
event_source: "trigger"
state: present
status: enabled
esc_period: 1m
conditions:
- type: "trigger_name"
operator: "like"
value: "Zabbix agent is unreachable"
formulaid: A
- type: "trigger_severity"
operator: ">="
value: "disaster"
formulaid: B
formula: A or B
operations:
- type: send_message
media_type: "Email"
send_to_users:
- "Admin"
- type: remote_command
command: "systemctl restart zabbix-agent"
command_type: custom_script
execute_on: server
run_on_hosts:
- 0
# Trigger action with recovery and acknowledge operations
- name: Deploy trigger action
# set task level variables as we change ansible_connection plugin here
vars:
ansible_network_os: community.zabbix.zabbix
ansible_connection: httpapi
ansible_httpapi_port: 443
ansible_httpapi_use_ssl: true
ansible_httpapi_validate_certs: false
ansible_zabbix_url_path: "zabbixeu" # If Zabbix WebUI runs on non-default (zabbix) path ,e.g. http://<FQDN>/zabbixeu
ansible_host: zabbix-example-fqdn.org
community.zabbix.zabbix_action:
name: "Send alerts to Admin"
event_source: "trigger"
state: present
status: enabled
esc_period: 1h
conditions:
- type: "trigger_severity"
operator: ">="
value: "Information"
operations:
- type: send_message
subject: "Something bad is happening"
op_message: "Come on, guys do something"
media_type: "Email"
send_to_users:
- "Admin"
recovery_operations:
- type: send_message
subject: "Host is down"
op_message: "Come on, guys do something"
media_type: "Email"
send_to_users:
- "Admin"
acknowledge_operations:
- type: send_message
media_type: "Email"
send_to_users:
- "Admin"
返回值
常见的返回值已在此处记录,以下是此模块特有的字段
键 |
描述 |
---|---|
操作的结果 返回:成功 示例: |