Zabbix - service restart

I have zabbix monitoring multiple servers (Linux and Windows). Is it possible to have zabbix automate services that they are down to automatically restart?


Solution 1:

It is possible. First thing you will have to do is enable remote actions on zabbix agents, by setting the following in zabbix_agentd.conf:

EnableRemoteCommands=1

You will also need to grant sudo privileges to your zabbix user, so create a file /etc/sudoers.d/zabbix_nopasswd with the following content:

zabbix ALL=NOPASSWD: ALL

For better security concerns, you'd better only allow zabbix to run specific shell commands, e,g:

# allows 'zabbix' user to restart apache without password.
zabbix ALL=NOPASSWD: /etc/init.d/apache restart

After that, restart zabbix agent(s).

Now, on the Zabbix server, log in as an user that has admin privileges to Zabbix web gui, and create new action: Configuration -> Actions -> New Action. Name the new action someething like 'Restart Apache'.

Set Action Type to "Remote Command". Set Remote Command to:

{HOSTNAME}:/usr/bin/sudo service apache2 restart

After that, create a Trigger on an item that counts number of apache processes running, in a way that if the number is 0 that the action "Restart Apache" is run, and that's it.