With Zabbix review and export (backup)/import you can create review mechanism and save/restore zabbix configuration as code (Monitoring as Code)
You can export (backup) all hosts templates and other object with zabbix-export.py
script.
You can also import (restore) many types of zabbix objects from YAML dump with zabbix-import.py
script (note that order of import is
matters, i.e., you cant add user if there is no mediatype for them, etc...). Already existed objects will be skipped. Object type is
autodetected, but may be pointed manually (it is much faster for single-file import operations)/
- Requirements
- Make export and backup
- Restore from YAML dump
- Make review
- Supported objects
- Known issues
- Screenshots
- Installed Python >=3.4
If you want use review (or Monitoring as Code:
It's simple to start use this script as backup mechanism:
# git clone THIS_REPO or download and unpack archive
python -mpip install -r requirements.txt
# smoke test :)
python ./zabbix-export.py --help
# backup to current folder, save XML and JSON
python ./zabbix-export.py --zabbix-url https://zabbix.example.com --zabbix-username user --zabbix-password password
# backup only hosts in YAML format
python ./zabbix-export.py --save-yaml --zabbix-url https://zabbix.example.com --zabbix-username user --zabbix-password password --only hosts
# backup to custom folder in YAML format
python ./zabbix-export.py --save-yaml --directory /home/username/path/to/zabbix-yaml --zabbix-url https://zabbix.example.com --zabbix-username user --zabbix-password password
Few examples:
export ZABBIX_URL="https://zabbix.instan.ce"
export ZABBIX_USERNAME="user.name"
export ZABBIX_PASSWORD="secret"
./zabbix-import.py /path/to/file.yaml
./zabbix-import.py --type host /path/fo/repo/hosts/*
You want to make review (Moniroting as Code). Read more on habr.com: RU, EN translated
- Fork this repository to you GitLab account or instance (e.g.
groupname/zabbix-review-export
) - Create repository where will be saved XML and YAML (e.g. two repositories
groupname/zabbix-xml
andgroupname/zabbix-yaml
. Do first (init) commit (create emptyREADME.md
). - Create two branches in this repos:
master
anddevelop
. In repositorygroupname/zabbix-xml
setdevelop
as a default branch. - Specify Project Variables for all variables, specified on top of .gitlab-ci.yml
- Change jobs in
.gitlab-ci.yml
and leave the ones you need job in.gitlab-ci.yml
and change to you environment (see commented examples block). - Try to run manual job
YAML zabbix
- Create merge request
develop=>master
inzabbix-yaml
. For first time you can merge without review, it's too hard :) - Configure Schedule (eg. every week)
- Change some host, template or other supported objects in zabbix, run manual job and create merge request again. Enjoy!
Use two repositories for XML+JSON (raw-format) and readable YAML format:
XML
+JSON
will be useful if you want restore some object after remove or a large number of changes.YAML
format is more suitable for people to read and review changes. The script removes all empty values.
Create empty merge request develop=>master
after merge and receive notifications at changes (schedule or manual jobs run) on your email.
To answer for the question "Who make this changes?" you need use Zabbix Audit. It's difficult but possible.
Use standard zabbix export functional:
- hosts
- templates
- screen
Representing objects as JSON using the API:
- mediatypes
- actions
- ZBX-15175: Zabbix export - host's xml does not contain overrides or diff to templates (e.g. item's storage period, trigger.priority, trigger.status=disables\enabled)
- ZBXNEXT-4862: The implementation of functionality in Zabbix. Zabbix configuration as code - save XML in git repository
YAML change trigger expression:
XML change templates (but we recommend use YAML for review and XML only for backup):