📜 ⬆️ ⬇️

Mass add / remove hosts in Zabbix using API

On one of the projects, new nodes were often deployed / deleted in the cloud, respectively, the task of adding / deleting new hosts in Zabbix appeared to monitor the availability and removal of statistics. For self-development, it was decided to use the zabbix API library on python. This was the first experience of writing scripts, so I will be grateful for the feedback and comments on the code.

We use zabbix 1.8.5 - as practice has shown, sometimes in different versions of 1.8. * Data can be returned by different types of data, so inconsistencies are possible when working with scripts with other versions of zabbix, however, they are easily fixed.

To add a new host, we need to know the following parameters:

Briefly on the above points: if with the first five everything is pretty simple and clear, then the rest for a person who has little experience with zabbiks can cause questions. More detailed information, of course, is more correct and better to look on the website with documentation zabbix.

Host groups are pretty convenient. For example, when setting up notification scripts, you can create different conditions and types of notifications for different groups, for example, for some groups, send E-Mail and SMS notifications, for others, only E-Mail and so on.
')
Templates are, roughly speaking, a set of parameters by which data is taken as well as triggers that respond to events. For web servers, for example, we will take data from apache or nginx, while for the database we will need completely different parameters. Accordingly, we will connect different templates to different hosts.

Finally, macros are variables that we pass to the host. For example, we have an item (in the Russian version - “Data Elements”), which removes HDD utilization statistics. Since we may have several disks, macros allow us to convey that $ DISK1 = / dev / sda, $ DISK2 = / dev / sdb, etc., thus removing statistics from different disks with one item using macros.

What needs to be changed in the script configuration?
The necessary parameters are stored in the file zabbix_credentials.py

Adding a host is as follows: zabbix_host_add.py <useip 1 or 0. if 0 - DNS will be used> <groupid1,...,groupidN> <templateid,...,templateidN> <macro1...macroN>


- zabbix_host_del.py

, readme - github.com/gnetsman/zabbix_api

Source: https://habr.com/ru/post/146455/


All Articles