Skip to content

Commit

Permalink
Add support for v7 (#1835)
Browse files Browse the repository at this point in the history
* Add support for v7

* Bump version
  • Loading branch information
zoltanbedi authored Jun 10, 2024
1 parent 7664a75 commit aecdb4b
Show file tree
Hide file tree
Showing 8 changed files with 478 additions and 29 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## [4.5.0] - 2024-06-10

- Add support for Zabbix version 7

## [4.4.9] - 2024-04-30

- Fix: Improve compatibility with the scenes framework (#1822)
Expand Down
6 changes: 3 additions & 3 deletions devenv/zabbix70/bootstrap/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
FROM python:2.7
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.xml"
ENV ZBX_CONFIG="zbx_export_hosts.json"
ENV ZBX_BOOTSTRAP_SCRIPT="bootstrap_config.py"

RUN pip install pyzabbix
RUN pip install zabbix_utils

ADD ./bootstrap_config.py /bootstrap_config.py
ADD ${ZBX_CONFIG} /${ZBX_CONFIG}
Expand Down
29 changes: 12 additions & 17 deletions devenv/zabbix70/bootstrap/bootstrap_config.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,20 @@
import os
from time import sleep
from pyzabbix import ZabbixAPI, ZabbixAPIException
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, timeout=5)
zapi = ZabbixAPI(zabbix_url)

for i in range(10):
print("Trying to connected to Zabbix API %s" % zabbix_url)
try:
zapi.login(zabbix_user, zabbix_password)
zapi.login(user=zabbix_user, password=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)

except Exception as e:
print(e)

config_path = os.environ['ZBX_CONFIG']
import_rules = {
Expand Down Expand Up @@ -70,11 +63,13 @@
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
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'])
Loading

0 comments on commit aecdb4b

Please sign in to comment.