zabbix_action – Create/Delete/Update Zabbix actions

New in version 2.8.

Synopsis

  • This module allows you to create, modify and delete Zabbix actions.

Requirements

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

  • zabbix-api

Parameters

Parameter Choices/Defaults Comments
acknowledge_default_message
-
Update operation (known as "Acknowledge operation" before Zabbix 4.0) message text.
Works only with >= Zabbix 3.4
acknowledge_default_subject
-
Update operation (known as "Acknowledge operation" before Zabbix 4.0) message subject.
Works only with >= Zabbix 3.4
acknowledge_operations
list
List of acknowledge operations.
Suboptions are the same as for operations.
Works only with >= Zabbix 3.4
conditions
list
List of dictionaries of conditions to evaluate.
For more information about suboptions of this option please check out Zabbix API documentation https://www.zabbix.com/documentation/3.4/manual/api/reference/action/object#action_filter_condition
formulaid
-
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.
operator
-
    Choices:
  • =
  • <>
  • like
  • not like
  • in
  • >=
  • <=
  • not in
Condition operator.
When type is set to time_period, the choices are in, not in.
type
-
    Choices:
  • host_group
  • host
  • trigger
  • trigger_name
  • trigger_severity
  • time_period
  • host_template
  • application
  • maintenance_status
  • event_tag
  • event_tag_value
  • host_IP
  • discovered_service_type
  • discovered_service_port
  • discovery_status
  • uptime_or_downtime_duration
  • received_value
  • discovery_rule
  • discovery_check
  • proxy
  • discovery_object
  • proxy
  • host_name
  • host_metadata
  • host_group
  • host
  • host_template
  • application
  • event_type
Type (label) of the condition.
value
-
Value to compare with.
When type is set to discovery_status, the choices are up, down, discovered, lost.
When type is set to discovery_object, the choices are host, service.
When type is set to event_type, the choices are item in not supported state, item in normal state, LLD rule in not supported state, LLD rule in normal state, trigger in unknown state, trigger in normal state.
When type is set to trigger_severity, the choices are (case-insensitive) not classified, information, warning, average, high, disaster irrespective of user-visible names being changed in Zabbix. Defaults to not classified if omitted.
Besides the above options, this is usually either the name of the object or a string to compare with.
default_message
-
Problem message default text.
default_subject
-
Problem message default subject.
esc_period
-
Default:
"60"
Default operation step duration. Must be greater than 60 seconds. Accepts seconds, time unit with suffix and user macro.
eval_type
-
    Choices:
  • andor
  • and
  • or
  • custom_expression
Filter condition evaluation method.
Defaults to andor if conditions are less then 2 or if formula is not specified.
Defaults to custom_expression when formula is specified.
event_source
- / required
    Choices:
  • trigger
  • discovery
  • auto_registration
  • internal
Type of events that the action will handle.
formula
-
User-defined expression to be used for evaluating conditions of filters with a custom expression.
The expression must contain IDs that reference specific filter conditions by its formulaid.
The IDs used in the expression must exactly match the ones defined in the filter conditions. No condition can remain unused or omitted.
Required for custom expression filters.
http_login_password
string
added in 2.1
Basic Auth password
http_login_user
string / required
added in 2.1
Basic Auth login
login_password
string / required
Zabbix user password.
login_user
string / required
Zabbix user name.
name
- / required
Name of the action
operations
list
List of action operations
command
-
Command to run.
Required when type=remote_command and command_type!=global_script.
command_type
-
    Choices:
  • custom_script
  • ipmi
  • ssh
  • telnet
  • global_script
Type of operation command.
Required when type=remote_command.
esc_period
-
Default:
"0s"
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.
esc_step_from
-
Default:
1
Step to start escalation from.
esc_step_to
-
Default:
1
Step to end escalation at.
execute_on
-
    Choices:
  • agent
  • server
  • proxy
Target on which the custom script operation command will be executed.
Required when type=remote_command and command_type=custom_script.
host_groups
list
List of host groups host should be added to.
Required when type=add_to_host_group or type=remove_from_host_group.
inventory
-
Host inventory mode.
Required when type=set_host_inventory_mode.
media_type
-
Default:
"all"
Media type that will be used to send the message.
Set to all for all media types
message
-
Operation message text.
Will check the 'default message' and use the text from default_message if this and default_subject are not specified
operation_condition
string
    Choices:
  • acknowledged
  • not_acknowledged
The action operation condition object defines a condition that must be met to perform the current operation.
password
-
Password used for authentication.
Required when type=remote_command and command_type in [ssh, telnet].
port
-
Port number used for authentication.
Required when type=remote_command and command_type in [ssh, telnet].
run_on_groups
-
Host groups to run remote commands on.
Required when type=remote_command if run_on_hosts is not set.
run_on_hosts
-
Hosts to run remote commands on.
Required when type=remote_command if run_on_groups is not set.
If set to 0 the command will be run on the current host.
script_name
-
The name of script used for global script commands.
Required when type=remote_command and command_type=global_script.
send_to_groups
list
User groups to send messages to.
send_to_users
list
Users (usernames or aliases) to send messages to.
ssh_auth_type
-
    Choices:
  • password
  • public_key
Authentication method used for SSH commands.
Required when type=remote_command and command_type=ssh.
ssh_privatekey_file
-
Name of the private key file used for SSH commands with public key authentication.
Required when type=remote_command and command_type=ssh.
ssh_publickey_file
-
Name of the public key file used for SSH commands with public key authentication.
Required when type=remote_command and command_type=ssh.
subject
-
Operation message subject.
Will check the 'default message' and use the text from default_subject if this and default_subject are not specified
templates
list
List of templates host should be linked to.
Required when type=link_to_template or type=unlink_from_template.
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
Type of operation.
username
-
User name used for authentication.
Required when type=remote_command and command_type in [ssh, telnet].
pause_in_maintenance
boolean
    Choices:
  • no
  • yes
Whether to pause escalation during maintenance periods or not.
Can be used when event_source=trigger.
recovery_default_message
-
Recovery message text.
Works only with >= Zabbix 3.2
recovery_default_subject
-
Recovery message subject.
Works only with >= Zabbix 3.2
recovery_operations
list
List of recovery operations.
Suboptions are the same as for operations.
Works only with >= Zabbix 3.2
server_url
string / required
URL of Zabbix server, with protocol (http or https). url is an alias for server_url.

aliases: url
state
-
    Choices:
  • present
  • absent
State of the action.
On present, it will create an action if it does not exist or update the action if the associated data is different.
On absent, it will remove the action if it exists.
status
-
    Choices:
  • enabled
  • disabled
Status of the action.
timeout
integer
Default:
10
The timeout of API request (seconds).
validate_certs
boolean
added in 2.5
    Choices:
  • no
  • yes
If set to False, SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates.

Notes

Note

  • Only Zabbix >= 3.0 is supported.

Examples

# Trigger action with only one condition
- name: Deploy trigger action
  zabbix_action:
    server_url: "http://zabbix.example.com/zabbix/"
    login_user: Admin
    login_password: secret
    name: "Send alerts to Admin"
    event_source: 'trigger'
    state: present
    status: enabled
    conditions:
      - type: 'trigger_severity'
        operator: '>='
        value: 'Information'
    operations:
      - type: send_message
        subject: "Something bad is happening"
        message: "Come on, guys do something"
        media_type: 'Email'
        send_to_users:
          - 'Admin'

# Trigger action with multiple conditions and operations
- name: Deploy trigger action
  zabbix_action:
    server_url: "http://zabbix.example.com/zabbix/"
    login_user: Admin
    login_password: secret
    name: "Send alerts to Admin"
    event_source: 'trigger'
    state: present
    status: enabled
    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'
        run_on_hosts:
          - 0

# Trigger action with recovery and acknowledge operations
- name: Deploy trigger action
  zabbix_action:
    server_url: "http://zabbix.example.com/zabbix/"
    login_user: Admin
    login_password: secret
    name: "Send alerts to Admin"
    event_source: 'trigger'
    state: present
    status: enabled
    conditions:
      - type: 'trigger_severity'
        operator: '>='
        value: 'Information'
    operations:
      - type: send_message
        subject: "Something bad is happening"
        message: "Come on, guys do something"
        media_type: 'Email'
        send_to_users:
          - 'Admin'
    recovery_operations:
      - type: send_message
        subject: "Host is down"
        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'

Return Values

Common return values are documented here, the following are the fields unique to this module:

Key Returned Description
msg
string
success
The result of the operation

Sample:
Action Deleted: Register webservers, ID: 0001


Status

Authors

  • Ruben Tsirunyan (@rubentsirunyan)
  • Ruben Harutyunov (@K-DOT)

Hint

If you notice any issues in this documentation you can edit this document to improve it.

© 2012–2018 Michael DeHaan
© 2018–2019 Red Hat, Inc.
Licensed under the GNU General Public License version 3.
https://docs.ansible.com/ansible/2.8/modules/zabbix_action_module.html