Skip to content

Recipes

Status: verified

Short jobs made from the parts the lab proved: a second machine to watch, a check of your own in a template, an action that tells a group instead of a person, and a one-pass health check of the whole installation. Where a recipe walks past the lab's one machine, it says so on its face.

Watch a second machine

The lab watched its own machine; a second machine is the same recipe with two addresses changed, and is therefore a recipe the lab points at rather than one it ran.

Install agent 2 on the new machine (the same repository, the same package). In its zabbix_agent2.conf set Server= to your Zabbix server's address, ServerActive= likewise, and Hostname= to the name you are about to create. Back at the server:

$ zapi.py host.create '{"host": "second-machine", "interfaces": [
  {"type": 1, "main": 1, "useip": 1, "ip": "192.0.2.20", "dns": "", "port": "10050"}],
  "groups": [{"groupid": "2"}], "templates": [{"templateid": "10001"}]}'

Wait a minute, then ask the agent directly: zabbix_get -s 192.0.2.20 -p 10050 -k agent.ping must answer 1, and host.get must show the 82 items filling with values. If the ping fails, it is almost always one of two things: the agent's Server= does not list your server, or a firewall between them has not met port 10050 yet.

Add a check of your own — to a template

Your gauge from chapter 6, made permanent, belongs in a template so every machine inherits it. Create one template (template.create with a name like Template Lab gauge and the Linux servers group), create the item in it (item.create with the template's hostid and no interface — template items carry no machine's interface), link the template to your hosts alongside the stock one, and put the UserParameter= line on each agent. Edit the template later and every linked host's copy of the item follows; edit a host's inherited copy and the next template change silently overwrites you. That asymmetry is the whole lesson of templates, and the recipe is written this way on purpose.

Tell a group instead of a person

Chapter 8's action sent its message to one user. To tell a team, change one line: the operation's recipient (opmessage_grp) names a user group instead of users (opmessage_usr), and everyone in that group with a media address on the action's media type gets the message, on the hours and severities their own records allow. Keep the group for on-call membership only — an action that tells twenty people tells nobody, and the alert record will list all twenty silences faithfully.

A one-pass health check

When "is Zabbix okay?" needs an answer in a minute, in this order:

$ zabbix_get -s 127.0.0.1 -p 10050 -k agent.ping          # the agent answers
$ zapi.py apiinfo.version                                  # the API answers
$ zapi.py problem.get '{"recent": true, "output": ["eventid", "name"]}'
$ zapi.py alert.get '{"output": ["alertid", "status", "error"], "sortfield": "clock",
                     "sortorder": "DESC", "limit": 5}'     # the alerts tell the truth
$ tail -20 /var/log/zabbix/zabbix_server.log               # and the log agrees

A current problem list you recognise, five alert rows whose statuses match what the mail system claims, and a log without a repeating error: that is an installation telling you it is healthy, in every voice it has.