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.
One approach would be to use a nodata()
trigger on some JMX item, same as you would do with agent.ping
or any other item to check that the data is coming.
Another would be to use internal item zabbix[host,jmx,available]
(see internal item documentation). If the value of this item is 1, then the JMX icon in the frontend is green. Otherwise, if the value is 0, then the JMX icon is red. Value 2 corresponds to the icon being grey.
If you are interested in monitoring the availability of the Java gateway itself, rather the JMX agent, a good idea would be to use internal item zabbix[java,,ping]
. Unfortunately, according to ZBX-8049, it does not really work currently.
Best Answer
HostMetadataItem is an item key that will be evaluated and the result sent as HostMetadata, for example, system.uname
HostMetadata is just user defined string. Write there, what do you need. Example of Zabbix agent HostMetadataItem setting:
Example Zabbix autoregistration with condition&operation for HostMetadataItem example above:
If your autoregistration rules are complete, then you can delete your hosts from the Zabbix UI anytime. They will be autoregistered back in a few minutes with the right templates/group.