community.zabbix.zabbix_trigger module – Create/delete Zabbix triggers

Note

This module is part of the community.zabbix collection (version 3.2.0).

You might already have this collection installed if you are using the ansible package. It is not included in ansible-core. To check whether it is installed, run ansible-galaxy collection list.

To install it, use: ansible-galaxy collection install community.zabbix. You need further requirements to be able to use this module, see Requirements for details.

To use it in a playbook, specify: community.zabbix.zabbix_trigger.

Synopsis

  • Create triggers if they do not exist.

  • Delete existing triggers if they exist.

Requirements

The below requirements are needed on the host that executes this module.

  • python >= 2.6

Parameters

Parameter

Comments

dependencies

list / elements=dictionary

list of triggers that this trigger is dependent on

host_name

string

Name of host containing dependent trigger.

Required when template_name is not used.

Mutually exclusive with template_name.

name

string / required

Name of dependent trigger.

template_name

string

Name of template containing dependent trigger.

Required when host_name is not used.

Mutually exclusive with host_name.

desc

aliases: description

string

Additional description of the trigger.

Overrides “comments” in API docs.

host_name

string

Name of host to add trigger to.

Required when template_name is not used.

Mutually exclusive with template_name.

http_login_password

string

Basic Auth password

http_login_user

string

Basic Auth login

name

string / required

Name of trigger to create or delete.

Overrides “description” in API docs.

Cannot be changed. If a trigger’s name needs to be changed, it needs to deleted and recreated

params

dictionary

Parameters to create/update trigger with.

Required if state is “present”.

Parameters as defined at https://www.zabbix.com/documentation/current/en/manual/api/reference/trigger/object

Additionally supported parameters are below.

correlation_mode

string

OK event closes.

Overrides “correlation_mode” in API docs.

Choices:

  • "all"

  • "tag"

enabled

boolean

Status of the trigger.

Overrides “status” in API docs.

Choices:

  • false

  • true

generate_multiple_events

boolean

Whether the trigger can generate multiple problem events.

Alias for “type” in API docs.

Choices:

  • false

  • true

manual_close

boolean

Allow manual close.

Overrides “manual_close” in API docs.

Choices:

  • false

  • true

recovery_mode

string

OK event generation mode.

Overrides “recovery_mode” in API docs.

Choices:

  • "expression"

  • "recovery_expression"

  • "none"

severity

aliases: priority

string

Severity of the trigger.

Alias for “priority” in API docs.

Choices:

  • "not_classified"

  • "information"

  • "warning"

  • "average"

  • "high"

  • "disaster"

status

string

Status of the trigger.

Choices:

  • "enabled"

  • "disabled"

state

string

Create or delete trigger.

Choices:

  • "present" ← (default)

  • "absent"

template_name

string

Name of template to add trigger to.

Required when host_name is not used.

Mutually exclusive with host_name.

Examples

# 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

Authors

  • Andrew Lathrop (@aplathrop)