Skip to content

Commit

Permalink
Update readme + requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
syphernl committed Mar 11, 2020
1 parent 5263cfe commit 04e93ae
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
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 Frank Klaassen
Copyright (c) 2018-2020 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
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Zabbix Template Exporter

This tool connects to the Zabbix API.
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
Expand All @@ -13,7 +13,8 @@ $ pip3 install -r requirements.txt
You can provide your credentials on the commandline:
```bash
usage: export.py [-h] [--server ZABBIX_HOST] [--username ZABBIX_USER]
[--password ZABBIX_PASSWORD]
[--password ZABBIX_PASSWORD] [--format EXPORT_FORMAT]
[--type EXPORT_TYPE] [--debug]

optional arguments:
-h, --help show this help message and exit
Expand All @@ -23,6 +24,11 @@ optional arguments:
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
Export the templates as XML or JSON
--type EXPORT_TYPE, -t EXPORT_TYPE
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:
Expand All @@ -33,9 +39,9 @@ export ZABBIX_USER=youruser
export ZABBIX_PASS=yourpass
```

Both `ZABBIX_USER` and `ZABBIX_PASS` can be provided as a string or a base64 string to prevent the passwords from being visible easily.
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.


## License
The MIT License (MIT). Please see the [license file](https://github.com/syphernl/zabbix-template-exporter/blob/master/LICENSE) for more information.
13 changes: 6 additions & 7 deletions export.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# The MIT License (MIT)
#
# Copyright (c) 2018 Frank Klaassen
# Copyright (c) 2018-2020 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 All @@ -28,6 +28,8 @@
import base64
import sys
import logging
from xml.dom import minidom
import simplejson


def is_base64(sb):
Expand Down Expand Up @@ -71,13 +73,13 @@ def set_arguments():
)
parser.add_argument('--type', '-t',
dest='export_type',
help='Export this type of',
help='Export this type of entities',
default='templates',
)
parser.add_argument('--debug', '-d',
dest='debug',
help='Enable debug mode',
default=False,
help='Enable debugging output',
action='store_true'
)

args = parser.parse_args()
Expand Down Expand Up @@ -174,13 +176,11 @@ def export_templates(args):
def write_export(name, config, export_format='xml'):
if config is not None:
if export_format == 'xml':
from xml.dom import minidom
xmlstr = minidom.parseString(config).toprettyxml(indent=" ")
print('Writing %s.xml' % name)
with open("%s.xml" % name, "w") as f:
f.write(xmlstr)
elif export_format == 'json':
import simplejson
print('Writing %s.json' % name)
with open("%s.json" % name, "w") as f:
f.write(simplejson.dumps(simplejson.loads(config), indent=4, sort_keys=True))
Expand All @@ -196,4 +196,3 @@ def normalize(input):
if __name__ == "__main__":
args = set_arguments()
export_templates(args)

3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pyzabbix==0.7.5
pyzabbix==0.7.5
simplejson==3.17.0

0 comments on commit 04e93ae

Please sign in to comment.