Another way to do some automation in Zabbix is to automate the registration of active clients. It is possible to register an active Zabbix client automatically in the Zabbix server once it is detected.
For this recipe to work, we need our Zabbix server with administrator rights and of course a Zabbix agent that is configured to be an active agent. Make sure that the agent is set up and not added to the Zabbix server yet, as this is what we will automate in this recipe. In production, this will be an added value as we can automate in Zabbix the discovery and configuration of new hosts in our environment. For instance, when an administrator installs new servers with a golden image or with some configuration management tools, the server will automatically be detected by the Zabbix server and / or added to a group and linked with a template.
HostMetadata
or HostMetadataItem
from the agents
configuration file but this is optional.Add host
.The automatic agent registration works only with active agents, so we need to make sure that in the zabbix_agentd.conf
file the option ServerActive=
is filled in with the address of our Zabbix server (or proxy).
We have to create an action just as we do with the network discovery; however it is not needed to do any network discovery in this case.
In the Action we have defined a new name for our action and we could add a subject and a message to inform us, for example by email, once an agent has been registered.
In the Conditions tab, we have not added anything but it would be possible to filter for only certain hostnames, host metadata, or proxies.
In the Operations tab we told Zabbix to add the host to Zabbix once conditions were met. Here we have many more options. We could also send a message, add the host to a group, link it with a template, launch a remote command, and so on.
To get information for the host metadata we have to configure this data in the zabbix_agentd.conf
file. There are two lines in the agent
configuration file HostMetadata
and HostMetadataItem
that can be used for this. This can be useful if you would like to define certain servers as, for example, web servers, database servers, and so on.
It's in general a good practice not to add and remove clients when discovered or when not discovered anymore, as a host may be unreachable or an agent can be installed on a temporary machine. It's probably wise to use a certain delay before an action is taken.
Zabbix states that an auto-registration attempt happens every time an active agent sends a request to refresh the active checks to the server. The delay between requests is specified in the RefreshActiveChecks
parameter of the Zabbix agent. The first request will be sent immediately after the agent is restarted.