Skip to content

Commit 5239fc0

Browse files
author
Ilya Ableev
committed
#149, fixed for Zabbix 3.x and Zabbix 4.x. Now you need to set 'zbx_server_version' variable in zbxtg_settings.py config file
1 parent 924f167 commit 5239fc0

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

zbxtg.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ def login(self):
301301

302302
self.cookie = cookie
303303

304-
def graph_get(self, itemid, period, title, width, height):
304+
def graph_get(self, itemid, period, title, width, height, version=3):
305305
file_img = self.tmp_dir + "/{0}.png".format("".join(itemid))
306306

307307
title = requests.utils.quote(title)
@@ -325,8 +325,12 @@ def graph_get(self, itemid, period, title, width, height):
325325
"items[{0}][drawtype]={3}&items[{0}][color]={2}".format(i, itemid[i], colors[i], drawtype)
326326
zbx_img_url_itemids.append(itemid_url)
327327

328-
zbx_img_url = self.server + "/chart3.php?period={0}&name={1}" \
329-
"&width={2}&height={3}&graphtype=0&legend=1".format(period, title, width, height)
328+
zbx_img_url = self.server + "/chart3.php?"
329+
if version < 4:
330+
zbx_img_url += "period={0}".format(period)
331+
else:
332+
zbx_img_url += "from=now-{0}&to=now".format(period)
333+
zbx_img_url += "&name={0}&width={1}&height={2}&graphtype=0&legend=1".format(title, width, height)
330334
zbx_img_url += "".join(zbx_img_url_itemids)
331335

332336
if self.debug:
@@ -597,6 +601,14 @@ def main():
597601

598602
zbx.tmp_dir = tmp_dir
599603

604+
# workaround for Zabbix 4.x
605+
zbx_version = 3
606+
607+
try:
608+
zbx_version = zbxtg_settings.zbx_server_version
609+
except:
610+
pass
611+
600612
if zbxtg_settings.proxy_to_zbx:
601613
zbx.proxies = {
602614
"http": "http://{0}/".format(zbxtg_settings.proxy_to_zbx),
@@ -639,7 +651,7 @@ def main():
639651
key = setting[0].replace(zbxtg_settings.zbx_tg_prefix + ";", "")
640652
if key not in settings_description:
641653
if "--debug" in args:
642-
print_message("[ERROR] There is no '{0}' method, use --features to get help")
654+
print_message("[ERROR] There is no '{0}' method, use --features to get help".format(key))
643655
continue
644656
if settings_description[key]["type"] == "list":
645657
value = setting[1].split(",")
@@ -861,7 +873,7 @@ def main():
861873
if not settings["extimg"]:
862874
zbxtg_file_img = zbx.graph_get(settings["zbxtg_itemid"], settings["zbxtg_image_period"],
863875
settings["zbxtg_title"], settings["zbxtg_image_width"],
864-
settings["zbxtg_image_height"])
876+
settings["zbxtg_image_height"], version=zbx_version)
865877
else:
866878
zbxtg_file_img = external_image_get(settings["extimg"], tmp_dir=zbx.tmp_dir)
867879
zbxtg_body_text, is_modified = list_cut(zbxtg_body_text, 200)

0 commit comments

Comments
 (0)