Skip to content

Commit

Permalink
Merge pull request #1 from syphernl/feat/refactor
Browse files Browse the repository at this point in the history
refactor to support all configuration exports
  • Loading branch information
syphernl authored Oct 19, 2021
2 parents 04e93ae + d2d4158 commit 6115a61
Show file tree
Hide file tree
Showing 5 changed files with 238 additions and 155 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea
*.xml
*.json
*.json
*.yaml
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2018-2020 Frank Klaassen
Copyright (c) 2018-2021 Frank Klaassen

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
45 changes: 28 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,47 +1,58 @@
# Zabbix Template Exporter
# Zabbix Configuration Exporter

This tool connects to the Zabbix API and retrieves configuration and stores this in individual files, allowing you to re-use these templates and make backups of them (e.g. by adding them to version control).

It is capable of exporting the following:

* Templates
* Mediatypes
* Hosts
* Host Groups
* Maps
* Images

Tested with Zabbix 5.4.x


This tool connects to the Zabbix API.
It retrieves all templates and stores them in individual XML files allowing you to re-use these templates and make backups of them.

## Install
Install the requirements:

```bash
$ pip3 install -r requirements.txt
```

## Usage
You can provide your credentials on the commandline:

```bash
usage: export.py [-h] [--server ZABBIX_HOST] [--username ZABBIX_USER]
[--password ZABBIX_PASSWORD] [--format EXPORT_FORMAT]
[--type EXPORT_TYPE] [--debug]
usage: export.py [-h] [--server ZABBIX_HOST] [--token ZABBIX_API_TOKEN] [--format {xml,json,yaml}] [--type {templates,mediatypes,hosts,hostgroups,maps,images}] [--debug]

optional arguments:
-h, --help show this help message and exit
--server ZABBIX_HOST, -s ZABBIX_HOST
Zabbix URL
--username ZABBIX_USER, -u ZABBIX_USER
Zabbix user to connect with the API
--password ZABBIX_PASSWORD, -p ZABBIX_PASSWORD
Zabbix password for connecting to the API
--format EXPORT_FORMAT, -f EXPORT_FORMAT
--token ZABBIX_API_TOKEN
Zabbix API token
--format {xml,json,yaml}, -f {xml,json,yaml}
Export the templates as XML or JSON
--type EXPORT_TYPE, -t EXPORT_TYPE
--type {templates,mediatypes,hosts,hostgroups,maps,images}, -t {templates,mediatypes,hosts,hostgroups,maps,images}
Export this type of entities
--debug, -d Enable debugging output


```

You can also configure your credentials globally and export these (e.g. in `.bashrc` or `.zshrc`) like this:

```bash
export ZABBIX_HOST=https://zabbix.example.com
export ZABBIX_USER=youruser
export ZABBIX_PASS=yourpass
export ZABBIX_API_TOKEN=your-token
```

Both `ZABBIX_USER` and `ZABBIX_PASS` can be provided as a string or a base64 string to prevent the passwords from being visible easily.
The exporter automatically detects the content and will act accordingly.
## Limitations

* Exporting auto-discovered hosts results in an empty file, because the Zabbix API does not provide this information.

## License
The MIT License (MIT). Please see the [license file](https://github.com/syphernl/zabbix-template-exporter/blob/master/LICENSE) for more information.
The MIT License (MIT). Please see the [license file](./blob/master/LICENSE) for more information.
Loading

0 comments on commit 6115a61

Please sign in to comment.