For those reading my blog posts regularly, you know I am an fan of automation. Declaring each host in Zabbix configuration manually is not an idea I like very much. Moreover, in dynamic environments which are moving a lot, manual registration is not sustainable.

I sought for the best way to automate that, and I found several:

In this blog post, I will focus on autoregistration.

Active vs Passive Agent

A Zabbix Agent can run in two modes: Active or Passive.

Active means that metrics are pushed to Zabbix server with the requirement that it should know what to push. Passive means Zabbix server polls the agents. As you might have guessed, this also implies a change in connection direction.

  • Active: Agent to Server
  • Passive: Server to Agent

I will not go deeper on the difference as everything is very well explained in this blog post by Zabbix.

Until now, I used only passive mode. In case where you want to use autoregistration, agent must also use active mode to register itself to Zabbix server. The only configuration change is to add (or modify) this line with the Zabbix server hostname/IP:

ServerActive=ZabbixServerHostName

Actions

For the host to register, we need to setup an autoregistration action on server side. This will allow us to apply several operations to the new host like associating a template, sending a notification to administrator, etc. So, let’s do that now. Go in Alerts, Actions, Autoregistration actions menu:

I will create a new action. As you can have different types of servers, which can have different operations, you must find the condition used to match the host trying to register. Condition (ie. filter) can be based on multiple type like hostname, host meta data or Zabbix proxy. As far as I am concerned, I want to apply Linux by Zabbix agent and Zabbix agent (passive mode) template when host is linux server.

Luckily, server hostname contains linux, thus the condition is easy:

Once I clicked Add, I go to Operations tab to link both templates. I am adding an operation and select Link to template and both templates:

Then, click Add button to confirm new operation and Add again to create action.

I am also adding another operation to assign middleware_webserver hostgroup to the host.

Autoregistration

Initially, my hosts list shows only Zabbix server itself:

Few seconds after agent starts (systemctl start zabbix-agent2.service), new hosts will appear in Hosts list, and I can check its settings:

If you look carefully, you can see there is no templates applied and I also noticed that ZBX interface never goes green. So, I investigated into Zabbix server log (ie. /var/log/zabbix/zabbix_server.log) and found the following error:

  3241:20230622:085808.278 cannot link template(s) "Linux by Zabbix agent", "Zabbix agent" to host "srv-linux-wls-ols-1": conflicting item key "agent.version" found

This is because both templates contain the same key definition. I can reproduce this by trying to add both template to the host manually:

The solution is to remove Zabbix agent template for autoregistration action operation and here we are:

Note that you must delete host for registration process to happen again.

Next Steps

With this method, new hosts are only assigned the Agent interface. It is missing JMX interface as setup on this blog post. and as required by WildFly Server by JMX template. If I try to link that template, I will face that error:

An enhancement exists for that feature, but it does not seem to be coming anytime soon.