community.zabbix.zabbix_host_events_info (2.3.1) — module

Get all triggers about a Zabbix host

Authors: Stéphane Travassac (@stravassac)

Install collection

Install with ansible-galaxy collection install community.zabbix:==2.3.1


Add to requirements.yml

  collections:
    - name: community.zabbix
      version: 2.3.1

Description

This module allows you to see if a Zabbix host have no active alert to make actions on it. For this case use module Ansible "fail" to exclude host in trouble.

Length of "triggers_ok" allow if template's triggers exist for Zabbix Host


Requirements

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: exclude machine if alert active on it
  # 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_host_events_info:
      host_identifier: "{{inventory_hostname}}"
      host_id_type: "hostname"
  register: zbx_host
  delegate_to: localhost
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- fail:
    msg: "machine alert in zabbix"
  when: zbx_host["triggers_problem"]|length > 0

Inputs

    
host_id_type:
    choices:
    - hostname
    - visible_name
    - hostid
    default: hostname
    description:
    - Type of host_identifier
    required: false
    type: str

host_identifier:
    description:
    - Identifier of Zabbix Host
    required: true
    type: str

http_login_user:
    description:
    - Basic Auth login
    required: false
    type: str

trigger_severity:
    choices:
    - not_classified
    - information
    - warning
    - average
    - high
    - disaster
    default: average
    description:
    - Zabbix severity for search filter
    required: false
    type: str

http_login_password:
    description:
    - Basic Auth password
    required: false
    type: str

Outputs

triggers_ok:
  contains:
    comments:
      description: Additional description of the trigger
      type: str
    description:
      description: Name of the trigger
      type: str
    error:
      description: Error text if there have been any problems when updating the state
        of the trigger
      type: str
    expression:
      description: Reduced trigger expression
      type: str
    flags:
      description: Origin of the trigger
      type: int
    lastchange:
      description: Time when the trigger last changed its state (timestamp)
      type: int
    priority:
      description: Severity of the trigger
      type: int
    state:
      description: State of the trigger
      type: int
    status:
      description: Whether the trigger is enabled or disabled
      type: int
    templateid:
      description: ID of the parent template trigger
      type: int
    triggerid:
      description: ID of the trigger
      type: int
    type:
      description: Whether the trigger can generate multiple problem events
      type: int
    url:
      description: URL associated with the trigger
      type: str
    value:
      description: Whether the trigger is in OK or problem state
      type: int
  description: Host Zabbix Triggers in OK state
  returned: On success
  type: complex
triggers_problem:
  contains:
    comments:
      description: Additional description of the trigger
      type: str
    description:
      description: Name of the trigger
      type: str
    error:
      description: Error text if there have been any problems when updating the state
        of the trigger
      type: str
    expression:
      description: Reduced trigger expression
      type: str
    flags:
      description: Origin of the trigger
      type: int
    last_event:
      contains:
        acknowledged:
          description: If set to true return only acknowledged events
          type: int
        acknowledges:
          contains:
            alias:
              description: Account who acknowledge
              type: str
            clock:
              description: Time when the event was created (timestamp)
              type: int
            message:
              description: Text of the acknowledgement message
              type: str
          description: acknowledges informations
          type: complex
        clock:
          description: Time when the event was created (timestamp)
          type: int
        eventid:
          description: ID of the event
          type: int
        value:
          description: State of the related object
          type: int
      description: last event informations
      type: complex
    lastchange:
      description: Time when the trigger last changed its state (timestamp)
      type: int
    priority:
      description: Severity of the trigger
      type: int
    state:
      description: State of the trigger
      type: int
    status:
      description: Whether the trigger is enabled or disabled
      type: int
    templateid:
      description: ID of the parent template trigger
      type: int
    triggerid:
      description: ID of the trigger
      type: int
    type:
      description: Whether the trigger can generate multiple problem events
      type: int
    url:
      description: URL associated with the trigger
      type: str
    value:
      description: Whether the trigger is in OK or problem state
      type: int
  description: Host Zabbix Triggers in problem state. See trigger and event objects
    in API documentation of your zabbix version for more
  returned: On success
  type: complex