-
Notifications
You must be signed in to change notification settings - Fork 462
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Chore: Add devenv for Zabbix 7 (#1730)
- Loading branch information
1 parent
06835a2
commit e0bfe1f
Showing
4 changed files
with
648 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
FROM python:2.7 | ||
|
||
ENV ZBX_API_URL=http://zabbix-web:8080 | ||
ENV ZBX_API_USER="Admin" | ||
ENV ZBX_API_PASSWORD="zabbix" | ||
ENV ZBX_CONFIG="zbx_export_hosts.xml" | ||
ENV ZBX_BOOTSTRAP_SCRIPT="bootstrap_config.py" | ||
|
||
RUN pip install pyzabbix | ||
|
||
ADD ./bootstrap_config.py /bootstrap_config.py | ||
ADD ${ZBX_CONFIG} /${ZBX_CONFIG} | ||
|
||
WORKDIR / | ||
|
||
# Run bootstrap_config.py when the container launches | ||
CMD ["python", "/bootstrap_config.py"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import os | ||
from time import sleep | ||
from pyzabbix import ZabbixAPI, ZabbixAPIException | ||
|
||
zabbix_url = os.environ['ZBX_API_URL'] | ||
zabbix_user = os.environ['ZBX_API_USER'] | ||
zabbix_password = os.environ['ZBX_API_PASSWORD'] | ||
print(zabbix_url, zabbix_user, zabbix_password) | ||
|
||
zapi = ZabbixAPI(zabbix_url, timeout=5) | ||
|
||
for i in range(10): | ||
print("Trying to connected to Zabbix API %s" % zabbix_url) | ||
try: | ||
zapi.login(zabbix_user, zabbix_password) | ||
print("Connected to Zabbix API Version %s" % zapi.api_version()) | ||
break | ||
except ZabbixAPIException as e: | ||
print e | ||
sleep(5) | ||
except: | ||
print("Waiting") | ||
sleep(5) | ||
|
||
|
||
config_path = os.environ['ZBX_CONFIG'] | ||
import_rules = { | ||
'discoveryRules': { | ||
'createMissing': True, | ||
'updateExisting': True | ||
}, | ||
'graphs': { | ||
'createMissing': True, | ||
'updateExisting': True | ||
}, | ||
'host_groups': { | ||
'createMissing': True | ||
}, | ||
'hosts': { | ||
'createMissing': True, | ||
'updateExisting': True | ||
}, | ||
'images': { | ||
'createMissing': True, | ||
'updateExisting': True | ||
}, | ||
'items': { | ||
'createMissing': True, | ||
'updateExisting': True | ||
}, | ||
'maps': { | ||
'createMissing': True, | ||
'updateExisting': True | ||
}, | ||
'templateLinkage': { | ||
'createMissing': True, | ||
}, | ||
'templates': { | ||
'createMissing': True, | ||
'updateExisting': True | ||
}, | ||
'triggers': { | ||
'createMissing': True, | ||
'updateExisting': True | ||
}, | ||
} | ||
|
||
print("Importing Zabbix config from %s" % config_path) | ||
with open(config_path, 'r') as f: | ||
config = f.read() | ||
|
||
try: | ||
# https://github.com/lukecyca/pyzabbix/issues/62 | ||
import_result = zapi.confimport("xml", config, import_rules) | ||
print(import_result) | ||
except ZabbixAPIException as e: | ||
print e | ||
|
||
for h in zapi.host.get(output="extend"): | ||
print(h['name']) |
Oops, something went wrong.