-
Notifications
You must be signed in to change notification settings - Fork 463
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix querying and authentication for Zabbix v7.0+ (#1931)
* Fix querying for Zabbix v7.2+ * Update check from 7.2 to 7.0 * Fix also select acknowledges key * Remove unsused methods * release commit 4.6.0 --------- Co-authored-by: yesoreyeram <153843+yesoreyeram@users.noreply.github.com>
- Loading branch information
1 parent
0225320
commit dbcc008
Showing
15 changed files
with
1,226 additions
and
84 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
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:3.12-slim-bullseye | ||
|
||
ENV ZBX_API_URL=http://zabbix-web:8080 | ||
ENV ZBX_API_USER="Admin" | ||
ENV ZBX_API_PASSWORD="zabbix" | ||
ENV ZBX_CONFIG="zbx_export_hosts.json" | ||
ENV ZBX_BOOTSTRAP_SCRIPT="bootstrap_config.py" | ||
|
||
RUN pip install zabbix_utils | ||
|
||
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,75 @@ | ||
import os | ||
from zabbix_utils import ZabbixAPI | ||
|
||
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) | ||
|
||
for i in range(10): | ||
try: | ||
zapi.login(user=zabbix_user, password=zabbix_password) | ||
print("Connected to Zabbix API Version %s" % zapi.api_version()) | ||
break | ||
except Exception as e: | ||
print(e) | ||
|
||
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: | ||
import_result = zapi.configuration.import_(source=config, format="json", rules=import_rules) | ||
if import_result == True: | ||
print("Zabbix config imported successfully") | ||
else: | ||
print("Failed to import Zabbix config") | ||
except Exception as e: | ||
print(e) | ||
|
||
for h in zapi.host.get(output="extend"): | ||
print(h['name']) |
Oops, something went wrong.