In the last column, we saw how triggers can be used to distinguish between normal states and problem states based on item values. Now let’s look at how to define actions that perform tasks when they receive events generated by triggers.
Action functions
In Zabbix, an action function is a function that performs a process (called an action) based on event information generated by a trigger.
An action has the following elements:
- Conditions
Conditions under which problem notification will occur - Operations
How the notification will be sent, and the contents of this notification - Operations performed when restoring
Contents of the notification sent when a problem is restored - Operations performed when updating
Contents of the notification sent when commenting on a problem, and when updating its severity level
Action
In the action settings, you can specify an action’s name, its conditional expression, and whether it is valid or invalid.
The important thing is the Conditions under which the action is performed.Conditions include the following items.
Application
Indicates conditions with a specified application name
- equals
- contains
- does not contain
Tag
Indicates conditions with the tag name of a problem
- equals
- does not equal
- contains
- does not contain
Tag value
Indicates the value of a problem’s tag
- equals
- does not equal
Host group/host/template
Indicates conditions based on the host group/host/template to which the monitored item belongs
- equals
- does not equal
Trigger
Set trigger name and specify its conditions
- equals
- does not equal
Trigger severity
Set trigger severity and specify its conditions
- equals
- does not equal
- is greater than or equals
- is less than or equals
Duratpon
Specify conditions by indicating a day of the week and time
- in (within the specified period)
- not in (outside the specified period)
Existing items can be specified for these conditions in the Zabbix Web UI. Multiple conditions can be specified by using the following logical operators.
- And
- Or
- And/OR
Automatically combines And and Or - Host in which a problem has occurred
- Any host
- Any host group
- IPMI
Use the target IPMI device to reset equipment, or to turn it on or off - Custom script
Executes specific commands from a Zabbix process on the following host
Note that these commands are executed by the `zabbix` user, and may require the use of utilities such as `sudo` to request additional permissions - Zabbix agent
- Zabbix server
- Zabbix server/Zabbix proxy
- ssh/telnet
Specify the credentials used to authenticate the connection: user name, password, public key/private key, key passphrase - Global script
- IPMI specifies an IPMI command
- Custom script/ssh/telnet specifies the command to be executed on the OS of a monitored target
- A global script specifies any command set in a global script
- Zabbix server
- Zabbix server (via Zabbix proxy)
- Zabbix agent
- Name
If you are using multiple mail servers, specify a unique name - SMTP server
The host name or IP address of the mail server - SMTP server port
The LISTEN port of the mail server (usually port 25) - When the port assignment is changed on the server
- When using smtps over SSL (port 465)
- When using the SMTP AUTH submission port (587)
- SMTP helo
The host name to use in the SMTP `helo` command. Normally this should specify the name of the Zabbix server. - SMTP email
The email address of the sender - Connection security
Regular SMTP traffic is sent in plain text, but can be encrypted in transit by using SSL. - none
Do not use SSL - STARTTLS
The SMTP connection uses port 25, but switches to SSL once a connection has been made - SSL/TLS
Use port 465 exclusively for SSL connections - SSL verify peer/SSL verify host
Check that a valid SSL certificate is used for SSL connection - Authentication
Use SMTP AUTH - Username/password
Specify the username and password for use with SMTP AUTH - Enabled
Check this item to enable this media - Concurrent sessions
Set the number of parallel sessions for this media - Once
Run only one session - Unlimited
Run unlimited sessions - Custom
Set any value - Attempts
Number of retries to attempt when transmission fails - Attempt interval
Retry frequency
Assumed to be a number of seconds if no unit is specified, but a time suffix such as 5 s or 1 m can also be used. - Although it says script, you can also specify an executable command
- The requirement is that the Zabbix Server can connect with and transmit to the target server
- Any exit code other than 0 is deemed to indicate a command execution error
- The specified command is placed under the directory specified by **AlertScriptsPath** in the Zabbix Server settings
- Name
The name of the Media Type (must be unique) - Type
Choose *Script* - Script Name
Name of the script - Script parameters
The arguments passed to the script
May include macros such as ${ALERT. SENDTO}/{ALERT.SUBJECT}/{ALERT. MESSAGE}
It is also possible to specify free conditional expressions such as A or (B and C).
Operations
When executing an action, you can choose whether to send a message or execute a command.It is possible to specify multiple actions of this sort.
Specify the message contents/operations/operation details.
Message contents
The contents of a message that are used when performing an action.
It is possible to specify the transmitted content, title, and transmitted content. In the contents of a message, you are free to include information such as the Zabbix macro host name, trigger name and time of occurrence.
Message transmission
For the transmission of messages, functions are provided for transmission to email, Jabber, SMS and EZ Texting services. In Japan, there are no services that use media other than email. An action can involve launching an alert script placed on the Zabbix server. You can use this function to provide notifications via social networking sites or telephone services, which are not supported as standard.
The destinations of these notification messages must be specified in advance by creating a user group or by specifying users and media. The method used to transmit messages is set for each user group/user.
Command execution
In addition to executing commands with a Zabbix server/agent, it is also possible to execute commands on a remote host.
To execute a command, specify the following items.
Target host
Execution type
A global script is a command that can be set from the Zabbix Web UI
Command
Specify the command to be executed.
Execution location
Specify where to run the command.
Recovery/Update operations
Specify what to do when a fault is recovered, or when the status of a fault is changed. The specified contents are the same as for command execution.
Media
In order to send a message, you must specify the media with which to do so. Media can be allocated to individual Zabbix users, and to user groups.
Media type
As mentioned earlier under *Message transmission*, the available media type settings are email, SMS, Jabber, EZ Text, and custom alert scripts. Of these, SMS and EZ Text cannot be used. To use Jabber, you must prepare a chat server called a Jabber server.
Email is the most commonly used message delivery tool.
! [Email]
In the email **Media type** tab, you can specify the following items.
May be changed to a different port in some circumstances
In the **Media Options** tab, you can enter the following information.
! [Media Options] (Media_Options.png)
Custom alert script
If an existing media type cannot be satisfied, it can be resolved by creating a custom alert script.
Please note that if an error occurs, the command will be repeated
In the **Media type** tab, you can enter the following information:
The **Media Options** tab is the same as for Mail.
Conclusion
In this column, we looked at the action and media functions of Zabbix. Actions allow Zabbix to send emails or social network notifications to administrators and execute commands for automatic recovery.
In the next column, I’ll show how service discovery helps you set up multiple hosts.