community.zabbix.zabbix_action module – Create/Delete/Update Zabbix actions
Note
This module is part of the community.zabbix collection (version 1.9.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_action
.
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.
python >= 2.6
Parameters
Parameter |
Comments |
---|---|
Update operation (known as “Acknowledge operation” before Zabbix 4.0) message text. With >= Zabbix 5.0 this field is removed from the API and is dropped silently by module. Works only with >= Zabbix 3.4 and < Zabbix 5.0 |
|
Update operation (known as “Acknowledge operation” before Zabbix 4.0) message subject. With >= Zabbix 5.0 this field is removed from the API and is dropped silently by module. Works only with >= Zabbix 3.4 and < Zabbix 5.0 |
|
List of acknowledge operations. Action acknowledge operations are known as update operations since Zabbix 4.0.
Works only with >= Zabbix 3.4 |
|
List of conditions to use for filtering results. For more information about suboptions of this option please check out Zabbix API documentation https://www.zabbix.com/documentation/5.0/manual/api/reference/action/object#action_filter_condition |
|
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. |
|
Condition operator. When type is set to
When type is set to Choices:
|
|
Type (label) of the condition.
Possible values when event_source=trigger:
Possible values when event_source=discovery:
Possible values when event_source=auto_registration:
Possible values when event_source=internal:
|
|
Value to compare with. When type=discovery_status, the choices are:
When type=discovery_object, the choices are:
When type=event_type, the choices are:
When type=trigger_severity, the choices are (case-insensitive):
Irrespective of user-visible names being changed in Zabbix. Defaults to Besides the above options, this is usually either the name of the object or a string to compare with. |
|
Secondary value to compare with. Required for trigger actions when condition type=event_tag_value. |
|
Problem message default text. With >= Zabbix 5.0 this field is removed from the API and is dropped silently by module. Works only with < Zabbix 5.0 |
|
Problem message default subject. With >= Zabbix 5.0 this field is removed from the API and is dropped silently by module. Works only with < Zabbix 5.0 |
|
Default operation step duration. Must be greater than 60 seconds. Accepts only seconds in int for <= Zabbix 3.2 Accepts seconds, time unit with suffix and user macro since => Zabbix 3.4 Required when |
|
Filter condition evaluation method. Defaults to Defaults to Choices:
|
|
Type of events that the action will handle. Required when Choices:
|
|
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 conditions. No condition can remain unused or omitted. Required when 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. |
|
Zabbix user password. If not set the environment variable This option is deprecated with the move to httpapi connection and will be removed in the next release |
|
Zabbix user name. If not set the environment variable This option is deprecated with the move to httpapi connection and will be removed in the next release |
|
Name of the action |
|
List of action operations |
|
Command to run. Required when type=remote_command and command_type!=global_script. |
|
Type of operation command. Required when type=remote_command. Choices:
|
|
Duration of an escalation step in seconds. Must be greater than 60 seconds. Accepts only seconds in int for <= Zabbix 3.2 Accepts seconds, time unit with suffix and user macro since => Zabbix 3.4 If set to 0 or 0s, the default action escalation period will be used. Default: |
|
Step to start escalation from. Default: |
|
Step to end escalation at. Specify 0 for infinitely. Default: |
|
Target on which the custom script operation command will be executed. Required when type=remote_command and command_type=custom_script. Choices:
|
|
List of host groups host should be added to. Required when type=add_to_host_group or type=remove_from_host_group. |
|
Host inventory mode. Required when type=set_host_inventory_mode. Choices:
|
|
Media type that will be used to send the message. Can be used with type=send_message or type=notify_all_involved inside acknowledge_operations. Set to Default: |
|
Operation message text. Will check the ‘default message’ and use the text from default_message if this and default_subject are not specified |
|
The action operation condition object defines a condition that must be met to perform the current operation. Choices:
|
|
Password used for authentication. Required when ssh_auth_type=password or command_type=telnet. Can be used when type=remote_command. |
|
Port number used for authentication. Can be used when command_type in [ssh, telnet] and type=remote_command. |
|
Host groups to run remote commands on. Required when type=remote_command and run_on_hosts is not set. |
|
Hosts to run remote commands on. Required when type=remote_command and run_on_groups is not set. If set to 0 the command will be run on the current host. |
|
The name of script used for global script commands. Required when command_type=global_script. Can be used when type=remote_command. |
|
User groups to send messages to. |
|
Users (usernames or aliases) to send messages to. |
|
Authentication method used for SSH commands. Required when type=remote_command and command_type=ssh. Choices:
|
|
Name of the private key file used for SSH commands with public key authentication. Required when ssh_auth_type=public_key. Can be used when type=remote_command. |
|
Name of the public key file used for SSH commands with public key authentication. Required when ssh_auth_type=public_key. Can be used when type=remote_command. |
|
Operation message subject. Will check the ‘default message’ and use the text from default_subject if this and default_subject are not specified |
|
List of templates host should be linked to. Required when type=link_to_template or type=unlink_from_template. |
|
Type of operation. Valid choices when setting type for recovery_operations and acknowledge_operations:
Choice Choices:
|
|
User name used for authentication. Required when ssh_auth_type in [public_key, password] or command_type=telnet. Can be used when type=remote_command. |
|
Whether to pause escalation during maintenance periods or not. Can be used when event_source=trigger. Choices:
|
|
Recovery message text. With >= Zabbix 5.0 this field is removed from the API and is dropped silently by module. Works only with >= Zabbix 3.2 and < Zabbix 5.0 |
|
Recovery message subject. With >= Zabbix 5.0 this field is removed from the API and is dropped silently by module. Works only with >= Zabbix 3.2 and < Zabbix 5.0 |
|
List of recovery operations.
Works only with >= Zabbix 3.2 |
|
URL of Zabbix server, with protocol (http or https). If not set the environment variable This option is deprecated with the move to httpapi connection and will be removed in the next release |
|
State of the action. On On Choices:
|
|
Status of the action. Choices:
|
|
The timeout of API request (seconds). This option is deprecated with the move to httpapi connection and will be removed in the next release Default: |
|
If set to False, SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates. If not set the environment variable This option is deprecated with the move to httpapi connection and will be removed in the next release Choices:
|
Notes
Note
Only Zabbix >= 3.0 is supported.
If you use login_password=zabbix, the word “zabbix” is replaced by “********” in all module output, because login_password uses
no_log
. See this FAQ for more information.
Examples
# Set following variables for Zabbix Server host in play or inventory
- name: Set connection specific variables
set_fact:
ansible_network_os: community.zabbix.zabbix
ansible_connection: httpapi
ansible_httpapi_port: 80
ansible_httpapi_use_ssl: false
ansible_httpapi_validate_certs: false
ansible_zabbix_url_path: 'zabbixeu' # If Zabbix WebUI runs on non-default (zabbix) path ,e.g. http://<FQDN>/zabbixeu
# If you want to use Username and Password to be authenticated by Zabbix Server
- name: Set credentials to access Zabbix Server API
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
set_fact:
ansible_zabbix_auth_key: 8ec0d52432c15c91fcafe9888500cf9a607f44091ab554dbee860f6b44fac895
# Trigger action with only one condition
- name: Deploy trigger action
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"
message: "Come on, guys do something"
media_type: 'Email'
send_to_users:
- 'Admin'
# Trigger action with multiple conditions and operations
- name: Deploy trigger action
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
# Trigger action with recovery and acknowledge operations
- name: Deploy trigger action
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"
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 |
Description |
---|---|
The result of the operation Returned: success Sample: |