Auto restart Linux service using zabbix

Configuration

Those remote commands that are executed on Zabbix agent (custom scripts) must be first enabled in the respective zabbix_agentd.conf.
Make sure that the EnableRemoteCommands parameter is set to 1 and uncommented. Restart agent daemon if changing this parameter.

Remote commands do not work with active Zabbix agents.

Then, when configuring a new action in Configuration→Actions:
  • In the Operations tab, select the Remote command operation type
  • Select the remote command type (IPMI, Custom script, SSH, Telnet, Global script)
  • Enter the remote command
For example:
sudo /etc/init.d/apache restart

In this case, Zabbix will try to restart an Apache process. With this 
command, make sure that the command is executed on Zabbix agent (mark 
the respective radio 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.

Zabbix does not check if a command has been executed successfully.

Remote commands on Zabbix agent are executed without timeout by the system.run[,nowait] key. On Zabbix server remote commands are executed with timeout as set in the TrapperTimeout parameter of zabbix_server.conf file.
  • In the Conditions tab, define the appropriate conditions. In this example, set that the action is activated upon any disaster problems with one of Apache applications.

Access permissions

Make sure that the 'zabbix' user has execute permissions for configured commands. One may be interested in using sudo to give access to privileged commands. To configure access, execute as root:
# visudo
Example lines that could be used in sudoers file:
# allows 'zabbix' user to run all commands without password.
zabbix ALL=NOPASSWD: ALL
# allows 'zabbix' user to restart apache without password.
zabbix ALL=NOPASSWD: /etc/init.d/apache restart

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.

Examples
Example 1
Restart of Windows on certain condition.
In order to automatically restart Windows upon a problem detected by Zabbix, define the following actions:
PARAMETER Description
Operation type'Remote command'
Type 'Custom script'
Command c:\windows\system32\shutdown.exe -r -f
Example 2
Restart the host by using IPMI control.
PARAMETER Description
Operation type'Remote command'
Type 'IPMI'
Command reset on
Example 3
Power off the host by using IPMI control.
PARAMETER Description
Operation type'Remote command'
Type 'IPMI'
Command power off

Nhận xét

Bài đăng phổ biến từ blog này

CLEANING UP THE ZABBIX DATABASE

Configuring DHCP Relay service on the FortiGate unit

Stuxnet Trojan - Memory Forensics with Volatility | Part I