Zabbix Agent Over an ssh Tunnel

Today I set up Zabbix monitoring of a bunch of boxes. A couple have public IP addresses - the load-balancers - so they were pretty standard. However, most of them are sitting behind a NAT, so are a little trickier. I played around with Zabbix proxy for a while - whose purpose is to solve this exact problem. In the end though, just to be different/awkward, I opted to set up ssh tunnels and just pass the Zabbix traffic through the load-balancer boxes. The Zabbix agent config was fiddly and took a lot of trial and error to get right, so, maybe this will help someone else.

First of all, the ssh tunnels. This is the command I used, but you’ll probably want to set up ssh keys and use autossh or some such thing. This is run on the load-balancer box, as it’s acting as a bridge between the public network and the NAT’ed network.

  ssh -f user@10.0.0.25 -L0.0.0.0:14050:10.0.0.25:10050 -N

Breaking this down:

So, we’re tunnelling from 14050 on the load-balancer to 10050 on the client.

Now the tricky bit - the Zabbix config. First of all the client. Open up the config file - /etc/zabbix/zabbix_agentd.conf and add the config bits below:

  Server=10.0.0.25
  Hostname=my-awesome-client-1
  DisableActive=1

First of all, we’re setting ‘Server’ to the IP of the actual client itself. This one took me ages to get right. As we’re tunnelling through, the Zabbix requests appear to come from the client itself. If we don’t set this right, the Zabbix agent will just send back a ‘not authorised’ message to the server.

Next, you need to set ‘Hostname’ to the hostname of the box itself which should also be the same as the hostname you’ll give it in the Zabbix server-side config.

Lastly, with this setup, we don’t seem to be able to use active checks. I.e., checks initiated by the client and sent to the server. With this setup, the client is passive and just sits there waiting for the server to ask it to execute checks.

Now for the Zabbix server-side config. All of the ‘Items’ for your client have to be of the type ‘Zabbix agent’, not ‘Zabbix agent (active)’. As I was just saying, they all need to be server-initiated. To do this, I cloned an existing template and used ‘Mass update’ to set the ‘Type’ to ‘Zabbix agent’.

Next, create a host; Configuration > Hosts > Create Host. Link your template created above and set name and group as you normally would. Then set the following:

And, in theory, that’s it. If you look at Monitoring > Overview, you should start seeing data trickle in.