Macros in templates

If you have a lot of servers then you probably want to have your templates a bit more dynamic. There are probably also some cases where a certain value in your template is not fit for just one server in your park. For this, we can make use of macros in our templates.

Getting ready

For this recipe to work, we need a Zabbix server and a Zabbix host. We also need to make sure that we have a SSH session active on port 22 on our host as we will monitor the SSH service on our host. For this, we will make use of macros. We also need to make use of the super administrator account in Zabbix.

How to do it ...

  1. First thing that we need to do is to go to Administration | general | Macros in our Zabbix menu. (Macros can be selected from the dropdown menu on the right).
  2. In the Macros menu, add a new macro {$SSH_PORT} and give it the value 422 or something other than 22. It must be a port that is not in use by SSH.
    How to do it ...
  3. Now go to Configuration | Template and create a new template with the name Template SSH port.
  4. Link the template to your client and save it.
    How to do it ...
  5. Next go to the Items in your template and create a new item.
  6. Add a Name Check SSH port $3.
  7. Select Type as Simple check.
  8. Add the following Key: net.tcp.service[ssh,,{$SSH_PORT}]
  9. The Type of information should be Numeric.
  10. Data type should be Decimal.
  11. Give in New application, an application name example. ssh check.
  12. Save your item.
    How to do it ...
  13. Next we go to our host again from the menu Configuration | Hosts.
  14. We then go to the tab Macros in our host.
    How to do it ...
  15. Here we add the macro {$SSH_PORT} with value 22.
  16. We now save our work.
  17. Next when we go to Monitoring | Latest data, we will see that on our host for the SSH port the status is 1. This means that our service is up.

How it works

In the Administration panel under General | Macros, we can define global macros. Those global macros can be used in our templates. So by defining {$SSH_PORT} macro in our item to monitor the SSH port, we were telling our template to look to the global macro. This means that our template would always check, in this case, port 422. Because we defined a new macro on our host with the value 22, that specific macro was over written for only this particular host. So in our case the template would always look for a service on port 422, but only for our host it would look for a service on port 22.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.58.121.251