Skip to content

Commit

Permalink
Fix querying and authentication for Zabbix v7.0+ (#1931)
Browse files Browse the repository at this point in the history
* 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
ivanahuckova and yesoreyeram authored Dec 17, 2024
1 parent 0225320 commit dbcc008
Show file tree
Hide file tree
Showing 15 changed files with 1,226 additions and 84 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Change Log

## [4.6.0] - 2024-12-16

- Feature: Added support for Zabbix 7. ( Fixes [#1914](https://github.com/grafana/grafana-zabbix/issues/1914) )
- Feature: Host ID alias function `$__zbx_host_id` ([#1913](https://github.com/grafana/grafana-zabbix/pull/1913))
- Bug Fix: Fixed a bug where mixed datasource with variable ref were not working #1909
- Bug Fix: Fixed a bug where multiple SLA queries not handled correctly #1910
- Chore: Updated grafana plugin SDK

## [4.5.7] - 2024-10-30

- Chore: Bump uplot to 1.6.31
Expand Down
17 changes: 17 additions & 0 deletions devenv/zabbix72/bootstrap/Dockerfile
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"]
75 changes: 75 additions & 0 deletions devenv/zabbix72/bootstrap/bootstrap_config.py
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'])
Loading

0 comments on commit dbcc008

Please sign in to comment.