community.zabbix.zabbix_action (2.3.1) — module

Create/Delete/Update Zabbix actions

Authors: Ruben Tsirunyan (@rubentsirunyan), Ruben Harutyunov (@K-DOT)

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 create, modify and delete Zabbix actions.


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.
# 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"
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# 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"

Inputs

    
name:
    description:
    - Name of the action
    required: true
    type: str

state:
    choices:
    - present
    - absent
    default: present
    description:
    - State of the action.
    - On C(present), it will create an action if it does not exist or update the action
      if the associated data is different.
    - On C(absent), it will remove the action if it exists.
    type: str

status:
    choices:
    - enabled
    - disabled
    default: enabled
    description:
    - Status of the action.
    type: str

formula:
    description:
    - User-defined expression to be used for evaluating conditions with a custom expression.
    - The expression must contain IDs that reference each condition by its formulaid.
    - The IDs used in the expression must exactly match the ones defined in the I(conditions).
      No condition can remain unused or omitted.
    - Required when I(eval_type=custom_expression).
    - Use sequential IDs that start at "A". If non-sequential IDs are used, Zabbix re-indexes
      them. This makes each module run notice the difference in IDs and update the action.
    type: str

eval_type:
    choices:
    - andor
    - and
    - or
    - custom_expression
    description:
    - Filter condition evaluation method.
    - Defaults to C(andor) if conditions are less then 2 or if I(formula) is not specified.
    - Defaults to C(custom_expression) when formula is specified.
    type: str

conditions:
    default: []
    description:
    - List of conditions to use for filtering results.
    - For more information about suboptions of this option please check out Zabbix API
      documentation U(https://www.zabbix.com/documentation/5.0/manual/api/reference/action/object#action_filter_condition)
    elements: dict
    suboptions:
      formulaid:
        description:
        - Arbitrary unique ID that is used to reference the condition from a custom expression.
        - Can only contain upper-case letters.
        - Required for custom expression filters and ignored otherwise.
        type: str
      operator:
        choices:
        - equals
        - '='
        - does not equal
        - <>
        - contains
        - like
        - does not contain
        - not like
        - in
        - is greater than or equals
        - '>='
        - is less than or equals
        - <=
        - not in
        - matches
        - does not match
        - 'Yes'
        - 'No'
        description:
        - Condition operator.
        - When I(type) is set to C(time_period), the choices are C(in), C(not in).
        required: true
        type: str
      type:
        description:
        - Type (label) of the condition.
        - 'Possible values when I(event_source=trigger):'
        - ' - C(host_group)'
        - ' - C(host)'
        - ' - C(trigger)'
        - ' - C(trigger_name)'
        - ' - C(trigger_severity)'
        - ' - C(time_period)'
        - ' - C(host_template)'
        - ' - C(maintenance_status) known in Zabbix 4.0 and above as ''Problem is suppressed'''
        - ' - C(event_tag)'
        - ' - C(event_tag_value)'
        - 'Possible values when I(event_source=discovery):'
        - ' - C(host_IP)'
        - ' - C(discovered_service_type)'
        - ' - C(discovered_service_port)'
        - ' - C(discovery_status)'
        - ' - C(uptime_or_downtime_duration)'
        - ' - C(received_value)'
        - ' - C(discovery_rule)'
        - ' - C(discovery_check)'
        - ' - C(proxy)'
        - ' - C(discovery_object)'
        - 'Possible values when I(event_source=auto_registration):'
        - ' - C(proxy)'
        - ' - C(host_name)'
        - ' - C(host_metadata)'
        - 'Possible values when I(event_source=internal):'
        - ' - C(host_group)'
        - ' - C(host)'
        - ' - C(host_template)'
        - ' - C(event_type)'
        required: true
        type: str
      value:
        description:
        - Value to compare with.
        - 'When I(type=discovery_status), the choices are:'
        - ' - C(up)'
        - ' - C(down)'
        - ' - C(discovered)'
        - ' - C(lost)'
        - 'When I(type=discovery_object), the choices are:'
        - ' - C(host)'
        - ' - C(service)'
        - 'When I(type=event_type), the choices are:'
        - ' - C(item in not supported state)'
        - ' - C(item in normal state)'
        - ' - C(LLD rule in not supported state)'
        - ' - C(LLD rule in normal state)'
        - ' - C(trigger in unknown state)'
        - ' - C(trigger in normal state)'
        - 'When I(type=trigger_severity), the choices are (case-insensitive):'
        - ' - C(not classified)'
        - ' - C(information)'
        - ' - C(warning)'
        - ' - C(average)'
        - ' - C(high)'
        - ' - C(disaster)'
        - Irrespective of user-visible names being changed in Zabbix. Defaults to C(not
          classified) if omitted.
        - Besides the above options, this is usually either the name of the object or
          a string to compare with.
        type: str
      value2:
        description:
        - Secondary value to compare with.
        - Required for trigger actions when condition I(type=event_tag_value).
        type: str
    type: list

esc_period:
    description:
    - Default operation step duration. Must be greater than 60 seconds.
    - Accepts seconds, time unit with suffix and user macro since => Zabbix 3.4
    - Required when C(state=present).
    required: false
    type: str

operations:
    default: []
    description:
    - List of action operations
    elements: dict
    suboptions:
      command:
        description:
        - Command to run.
        - Required when I(type=remote_command) and I(command_type!=global_script).
        type: str
      command_type:
        choices:
        - custom_script
        - ipmi
        - ssh
        - telnet
        - global_script
        description:
        - Type of operation command.
        - Required when I(type=remote_command).
        type: str
      esc_period:
        default: 0s
        description:
        - Duration of an escalation step in seconds.
        - Must be greater than 60 seconds.
        - Accepts seconds, time unit with suffix and user macro.
        - If set to 0 or 0s, the default action escalation period will be used.
        type: str
      esc_step_from:
        default: 1
        description:
        - Step to start escalation from.
        type: int
      esc_step_to:
        default: 1
        description:
        - Step to end escalation at.
        - Specify 0 for infinitely.
        type: int
      execute_on:
        choices:
        - agent
        - server
        - proxy
        description:
        - Target on which the custom script operation command will be executed.
        - Required when I(type=remote_command) and I(command_type=custom_script).
        type: str
      host_groups:
        description:
        - List of host groups host should be added to.
        - Required when I(type=add_to_host_group) or I(type=remove_from_host_group).
        elements: str
        type: list
      inventory:
        choices:
        - manual
        - automatic
        description:
        - Host inventory mode.
        - Required when I(type=set_host_inventory_mode).
        type: str
      media_type:
        default: all
        description:
        - Media type that will be used to send the message.
        - Can be used with I(type=send_message) or I(type=notify_all_involved) inside
          I(acknowledge_operations).
        - Set to C(all) for all media types
        type: str
      op_message:
        description:
        - Operation message text.
        - If I(op_message) and I(subject) not defined then "default message" from media
          type will be used
        type: str
      operation_condition:
        choices:
        - acknowledged
        - not_acknowledged
        description:
        - The action operation condition object defines a condition that must be met to
          perform the current operation.
        type: str
      password:
        description:
        - Password used for authentication.
        - Required when I(ssh_auth_type=password) or I(command_type=telnet).
        - Can be used when I(type=remote_command).
        type: str
      port:
        description:
        - Port number used for authentication.
        - Can be used when I(command_type in [ssh, telnet]) and I(type=remote_command).
        type: int
      run_on_groups:
        description:
        - Host groups to run remote commands on.
        - Required when I(type=remote_command) and I(run_on_hosts) is not set.
        elements: str
        type: list
      run_on_hosts:
        description:
        - Hosts to run remote commands on.
        - Required when I(type=remote_command) and I(run_on_groups) is not set.
        - If set to 0 the command will be run on the current host.
        elements: str
        type: list
      script_name:
        description:
        - The name of script used for global script commands.
        - Required when I(command_type=global_script).
        - Can be used when I(type=remote_command).
        type: str
      send_to_groups:
        description:
        - User groups to send messages to.
        elements: str
        type: list
      send_to_users:
        description:
        - Users (usernames or aliases) to send messages to.
        elements: str
        type: list
      ssh_auth_type:
        choices:
        - password
        - public_key
        description:
        - Authentication method used for SSH commands.
        - Required when I(type=remote_command) and I(command_type=ssh).
        type: str
      ssh_privatekey_file:
        description:
        - Name of the private key file used for SSH commands with public key authentication.
        - Required when I(ssh_auth_type=public_key).
        - Can be used when I(type=remote_command).
        type: str
      ssh_publickey_file:
        description:
        - Name of the public key file used for SSH commands with public key authentication.
        - Required when I(ssh_auth_type=public_key).
        - Can be used when I(type=remote_command).
        type: str
      subject:
        description:
        - Operation message subject.
        - If I(op_message) and I(subject) not defined then "default message" from media
          type will be used
        type: str
      templates:
        description:
        - List of templates host should be linked to.
        - Required when I(type=link_to_template) or I(type=unlink_from_template).
        elements: str
        type: list
      type:
        choices:
        - send_message
        - remote_command
        - add_host
        - remove_host
        - add_to_host_group
        - remove_from_host_group
        - link_to_template
        - unlink_from_template
        - enable_host
        - disable_host
        - set_host_inventory_mode
        - notify_all_involved
        description:
        - Type of operation.
        - 'Valid choices when setting type for I(recovery_operations) and I(acknowledge_operations):'
        - ' - C(send_message)'
        - ' - C(remote_command)'
        - ' - C(notify_all_involved)'
        - Choice C(notify_all_involved) only supported in I(recovery_operations) and I(acknowledge_operations).
        required: true
        type: str
      username:
        description:
        - User name used for authentication.
        - Required when I(ssh_auth_type in [public_key, password]) or I(command_type=telnet).
        - Can be used when I(type=remote_command).
        type: str
    type: list

event_source:
    choices:
    - trigger
    - discovery
    - auto_registration
    - internal
    description:
    - Type of events that the action will handle.
    - Required when C(state=present).
    required: false
    type: str

pause_symptoms:
    default: true
    description:
    - Whether to pause escalation if event is a symptom event.
    - I(supported) if C(event_source) is set to C(trigger)
    - Works only with >= Zabbix 6.4
    type: bool

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

notify_if_canceled:
    default: true
    description:
    - Weather to notify when escalation is canceled.
    - Can be used when I(event_source=trigger).
    type: bool

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

recovery_operations:
    default: []
    description:
    - List of recovery operations.
    - C(Suboptions) are the same as for I(operations).
    elements: dict
    suboptions:
      command:
        description:
        - Command to run.
        required: false
        type: str
      command_type:
        choices:
        - custom_script
        - ipmi
        - ssh
        - telnet
        - global_script
        description:
        - Type of operation command.
        required: false
        type: str
      execute_on:
        choices:
        - agent
        - server
        - proxy
        description:
        - Target on which the custom script operation command will be executed.
        required: false
        type: str
      media_type:
        default: all
        description:
        - Media type that will be used to send the message.
        - Can be used with I(type=send_message) or I(type=notify_all_involved) inside
          I(acknowledge_operations).
        - Set to C(all) for all media types
        type: str
      op_message:
        description:
        - Operation message text.
        - If I(op_message) and I(subject) not defined then "default message" from media
          type will be used
        type: str
      password:
        description:
        - Password used for authentication.
        - Required when I(ssh_auth_type=password) or I(command_type=telnet).
        - Can be used when I(type=remote_command).
        type: str
      port:
        description:
        - Port number used for authentication.
        - Can be used when I(command_type in [ssh, telnet]) and I(type=remote_command).
        type: int
      run_on_groups:
        description:
        - Host groups to run remote commands on.
        - Required when I(type=remote_command) and I(run_on_hosts) is not set.
        elements: str
        type: list
      run_on_hosts:
        description:
        - Hosts to run remote commands on.
        - Required when I(type=remote_command) and I(run_on_groups) is not set.
        - If set to 0 the command will be run on the current host.
        elements: str
        type: list
      script_name:
        description:
        - The name of script used for global script commands.
        - Required when I(command_type=global_script).
        - Can be used when I(type=remote_command).
        type: str
      send_to_groups:
        description:
        - User groups to send messages to.
        elements: str
        type: list
      send_to_users:
        description:
        - Users (usernames or aliases) to send messages to.
        elements: str
        type: list
      ssh_auth_type:
        choices:
        - password
        - public_key
        description:
        - Authentication method used for SSH commands.
        - Required when I(type=remote_command) and I(command_type=ssh).
        type: str
      ssh_privatekey_file:
        description:
        - Name of the private key file used for SSH commands with public key authentication.
        - Required when I(ssh_auth_type=public_key).
        - Can be used when I(type=remote_command).
        type: str
      ssh_publickey_file:
        description:
        - Name of the public key file used for SSH commands with public key authentication.
        - Required when I(ssh_auth_type=public_key).
        - Can be used when I(type=remote_command).
        type: str
      subject:
        description:
        - Operation message subject.
        - If I(op_message) and I(subject) not defined then "default message" from media
          type will be used
        type: str
      type:
        choices:
        - send_message
        - remote_command
        - notify_all_involved
        description:
        - Type of operation.
        required: true
        type: str
      username:
        description:
        - User name used for authentication.
        - Required when I(ssh_auth_type in [public_key, password]) or I(command_type=telnet).
        - Can be used when I(type=remote_command).
        type: str
    type: list

pause_in_maintenance:
    default: true
    description:
    - Whether to pause escalation during maintenance periods or not.
    - Can be used when I(event_source=trigger).
    type: bool

acknowledge_operations:
    aliases:
    - update_operations
    default: []
    description:
    - List of acknowledge operations.
    - Action acknowledge operations are known as update operations since Zabbix 4.0.
    - C(Suboptions) are the same as for I(operations).
    elements: dict
    suboptions:
      command:
        description:
        - Command to run.
        required: false
        type: str
      command_type:
        choices:
        - custom_script
        - ipmi
        - ssh
        - telnet
        - global_script
        description:
        - Type of operation command.
        required: false
        type: str
      execute_on:
        choices:
        - agent
        - server
        - proxy
        description:
        - Target on which the custom script operation command will be executed.
        required: false
        type: str
      media_type:
        default: all
        description:
        - Media type that will be used to send the message.
        - Can be used with I(type=send_message) or I(type=notify_all_involved) inside
          I(acknowledge_operations).
        - Set to C(all) for all media types
        type: str
      op_message:
        description:
        - Operation message text.
        - If I(op_message) and I(subject) not defined then "default message" from media
          type will be used
        type: str
      password:
        description:
        - Password used for authentication.
        - Required when I(ssh_auth_type=password) or I(command_type=telnet).
        - Can be used when I(type=remote_command).
        type: str
      port:
        description:
        - Port number used for authentication.
        - Can be used when I(command_type in [ssh, telnet]) and I(type=remote_command).
        type: int
      run_on_groups:
        description:
        - Host groups to run remote commands on.
        - Required when I(type=remote_command) and I(run_on_hosts) is not set.
        elements: str
        type: list
      run_on_hosts:
        description:
        - Hosts to run remote commands on.
        - Required when I(type=remote_command) and I(run_on_groups) is not set.
        - If set to 0 the command will be run on the current host.
        elements: str
        type: list
      script_name:
        description:
        - The name of script used for global script commands.
        - Required when I(command_type=global_script).
        - Can be used when I(type=remote_command).
        type: str
      send_to_groups:
        description:
        - User groups to send messages to.
        elements: str
        type: list
      send_to_users:
        description:
        - Users (usernames or aliases) to send messages to.
        elements: str
        type: list
      ssh_auth_type:
        choices:
        - password
        - public_key
        description:
        - Authentication method used for SSH commands.
        - Required when I(type=remote_command) and I(command_type=ssh).
        type: str
      ssh_privatekey_file:
        description:
        - Name of the private key file used for SSH commands with public key authentication.
        - Required when I(ssh_auth_type=public_key).
        - Can be used when I(type=remote_command).
        type: str
      ssh_publickey_file:
        description:
        - Name of the public key file used for SSH commands with public key authentication.
        - Required when I(ssh_auth_type=public_key).
        - Can be used when I(type=remote_command).
        type: str
      subject:
        description:
        - Operation message subject.
        - If I(op_message) and I(subject) not defined then "default message" from media
          type will be used
        type: str
      type:
        choices:
        - send_message
        - remote_command
        - notify_all_involved
        description:
        - Type of operation.
        required: true
        type: str
      username:
        description:
        - User name used for authentication.
        - Required when I(ssh_auth_type in [public_key, password]) or I(command_type=telnet).
        - Can be used when I(type=remote_command).
        type: str
    type: list

Outputs

msg:
  description: The result of the operation
  returned: success
  sample: 'Action Deleted: Register webservers, ID: 0001'
  type: str