2 Remote commands

    Overview

    Thus remote commands are a powerful mechanism for smart pro-active monitoring.

    In the most obvious uses of the feature you can try to:

    • Automatically restart some application (web server, middleware, CRM) if it does not respond
    • Use IPMI ‘reboot’ command to reboot some remote server if it does not answer requests
    • Automatically free disk space (removing older files, cleaning /tmp) if running out of disk space
    • Migrate a VM from one physical box to another depending on the CPU load
    • Add new nodes to a cloud environment upon insufficient CPU (disk, memory, whatever) resources

    Configuring an action for remote commands is similar to that for sending a message, the only difference being that Zabbix will execute a command instead of sending a message.

    Remote commands can be executed by Zabbix server, proxy or agent. Remote commands on Zabbix agent can be executed directly by Zabbix server or through Zabbix proxy. Both on Zabbix agent and Zabbix proxy remote commands are disabled by default. They can be enabled by:

    • adding an parameter in agent configuration;

    Remote commands executed by Zabbix server are run as described in including exit code checking.

    Remote commands are executed even if the target host is in maintenance.

    Remote command limit

    Remote command limit after resolving all macros depends on the type of database and character set (non- ASCII characters require more than one byte to be stored):

    The following tutorial provides step-by-step instructions on how to set up remote commands.

    Configuration

    Those remote commands that are executed on Zabbix agent (custom scripts) must be first enabled in the agent configuration.

    Make sure that the AllowKey=system.run[<command>,*] parameter is added for each allowed command in agent configuration to allow specific command with nowait mode. Restart agent daemon if changing this parameter.

    Then, when configuring a new action in Alerts → Actions → Trigger actions:

    1. Define the appropriate conditions, for example, set that the action is activated upon any disaster problems with one of Apache applications.

    1. In the tab, click on Add in the Operations, Recovery operations, or Update operations block.

    2 Remote commands - 图2

    1. Select one of the predefined scripts from the Operation dropdown list and set the Target list for the script.

    Predefined scripts

    Scripts that are available for action operations (webhook, script, SSH, Telnet, IPMI) are defined in .

    For example:

    In this case, Zabbix will try to restart an Apache process. With this command, make sure that the command is executed on Zabbix agent (click the Zabbix agent button against Execute on).

    Note the use of sudo - Zabbix user does not have permissions to restart system services by default. See below for hints on how to configure sudo.

    Zabbix agent should run on the remote host and accept incoming connections. Zabbix agent executes commands in background.

    Remote commands on Zabbix agent are executed without timeout by the system.run[,nowait] key and are not checked for execution results. On Zabbix server and Zabbix proxy, remote commands are executed with timeout as set in the TrapperTimeout parameter of zabbix_server.conf or zabbix_proxy.conf file and are checked for execution results.

    Access permissions

    Example lines that could be used in sudoers file:

    On some systems sudoers file will prevent non-local users from executing commands. To change this, comment out requiretty option in /etc/sudoers.

    Remote commands with multiple interfaces

    If the target system has multiple interfaces of the selected type (Zabbix agent or IPMI), remote commands will be executed on the default interface.

    It is possible to execute remote commands via SSH and Telnet using another interface than the Zabbix agent one. The available interface to use is selected in the following order:

    • Zabbix agent default interface
    • SNMP default interface
    • JMX default interface
    • IPMI default interface

    IPMI remote commands

    For IPMI remote commands the following syntax should be used:

    where

    • <command> - one of IPMI commands without spaces

    Examples

    Examples of that may be used as remote commands in action operations.

    Example 1

    Restart of Windows on certain condition.

    In order to automatically restart Windows upon a problem detected by Zabbix, define the following script:

    Example 2

    Restart the host by using IPMI control.

    Example 3