community.zabbix.zabbix_trigger 模块 – 创建/删除 Zabbix 触发器

注意

此模块是 community.zabbix 集合(版本 3.2.0)的一部分。

如果您正在使用 ansible 包,您可能已经安装了此集合。它不包含在 ansible-core 中。要检查是否已安装,请运行 ansible-galaxy collection list

要安装它,请使用:ansible-galaxy collection install community.zabbix。您需要其他要求才能使用此模块,请参阅 要求 了解详细信息。

要在剧本中使用它,请指定:community.zabbix.zabbix_trigger

概要

  • 如果触发器不存在,则创建它们。

  • 如果现有触发器存在,则删除它们。

要求

执行此模块的主机需要满足以下要求。

  • python >= 2.6

参数

参数

注释

dependencies

列表 / 元素=字典

此触发器所依赖的触发器列表

host_name

字符串

包含依赖触发器的主机名称。

当未使用 template_name 时为必需。

template_name 互斥。

name

字符串 / 必需

依赖触发器的名称。

template_name

字符串

包含依赖触发器的模板名称。

当未使用 host_name 时为必需。

host_name 互斥。

desc

别名:description

字符串

触发器的其他描述。

覆盖 API 文档中的“comments”。

host_name

字符串

要向其中添加触发器的主机名称。

当未使用 template_name 时为必需。

template_name 互斥。

http_login_password

字符串

基本身份验证密码

http_login_user

字符串

基本身份验证登录名

name

字符串 / 必需

要创建或删除的触发器的名称。

覆盖 API 文档中的“description”。

无法更改。如果需要更改触发器的名称,则需要删除并重新创建它

params

字典

用于创建/更新触发器的参数。

如果 state 为“present”,则为必需。

参数定义于 https://www.zabbix.com/documentation/current/en/manual/api/reference/trigger/object

此外,还支持以下参数。

correlation_mode

字符串

OK 事件关闭。

覆盖 API 文档中的“correlation_mode”。

选择

  • "all"

  • "tag"

enabled

布尔值

触发器的状态。

覆盖 API 文档中的“status”。

选择

  • false

  • true

generate_multiple_events

布尔值

触发器是否可以生成多个问题事件。

API 文档中“type”的别名。

选择

  • false

  • true

manual_close

布尔值

允许手动关闭。

覆盖 API 文档中的“manual_close”。

选择

  • false

  • true

recovery_mode

字符串

OK 事件生成模式。

覆盖 API 文档中的“recovery_mode”。

选择

  • "expression"

  • "recovery_expression"

  • "none"

severity

别名:priority

字符串

触发器的严重性。

API 文档中“priority”的别名。

选择

  • "not_classified"

  • "information"

  • "warning"

  • "average"

  • "high"

  • "disaster"

status

字符串

触发器的状态。

选择

  • "enabled"

  • "disabled"

state

字符串

创建或删除触发器。

选择

  • "present" ← (默认)

  • "absent"

template_name

字符串

要向其中添加触发器的模板名称。

当未使用 host_name 时为必需。

host_name 互斥。

示例

# 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

# Create ping trigger on example_host
- name: create ping trigger
  # 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_trigger:
    name: agent_ping
    host_name: example_host
    params:
        severity: high
        expression: 'nodata(/example_host/agent.ping,1m)=1'
        manual_close: True
        enabled: True
    state: present

# Create ping trigger on example_template
- name: create ping trigger
  # 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_trigger:
    name: agent_ping
    host_name: example_template
    params:
        severity: high
        expression: 'nodata(/example_template/agent.ping,1m)=1'
        manual_close: True
        enabled: True
    state: present

# Add tags to the existing Zabbix trigger
- name: update ping trigger
  # 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_trigger:
    name: agent_ping
    host_name: example_template
    params:
        severity: high
        expression: 'nodata(/example_template/agent.ping,1m)=1'
        manual_close: True
        enabled: True
        tags:
          - tag: class
            value: application
    state: present

# delete Zabbix trigger
- name: delete ping trigger
  # 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_trigger:
    name: agent_ping
    host_name: example_template
    state: absent

作者

  • Andrew Lathrop (@aplathrop)