unioslo / zabbix-cli

Command-line interface for Zabbix
https://unioslo.github.io/zabbix-cli/
GNU General Public License v3.0
205 stars 102 forks source link

Add support for Zabbix 5.4 #139

Closed AleksejsC closed 2 years ago

AleksejsC commented 3 years ago

Zabbix 5.4.4. tested zabbix-cli 2.2.1

$zabbix-cli -C "show_host *"

[ERROR]:'available

$zabbix-cli -C "show_usergroups"

[ERROR]:'alias'

show_hostgroups does work, for instance.

Pigi-102 commented 3 years ago

Hello. same configuration and same problem here.

paalbra commented 3 years ago

There seem to be a lot of incompatible changes in 5.4: https://www.zabbix.com/documentation/current/manual/api/changes_5.2_-_5.4#backward_incompatible_changes

The errors are key errors. "available" is removed from hosts. "alias" is removed from users.

Pigi-102 commented 3 years ago
--- ./zabbix-cli/zabbix_cli/cli.py      2021-09-29 13:50:58.933467683 +0200
+++ /usr/lib/python3.6/site-packages/zabbix_cli/cli.py  2021-10-13 19:31:29.860120126 +0200
@@ -861,6 +861,10 @@
             "selectApplications": [
                 "name"
             ],
+            "selectTags": [
+                "tag",
+                "value"
+            ],
             "sortfield": "host",
             "sortorder": "ASC",
             "searchWildcardsEnabled": True,
@@ -907,7 +911,6 @@
                                                       'host': host['host'],
                                                       'groups': host['groups'],
                                                       'templates': host['parentTemplates'],
-                                                      'zabbix_agent': zabbix_cli.utils.get_zabbix_agent_status(int(host['available'])),
                                                       'maintenance_status': zabbix_cli.utils.get_maintenance_status(int(host['maintenance_status'])),
                                                       'status': zabbix_cli.utils.get_monitoring_status(int(host['status'])),
                                                       'proxy': proxy_name}
@@ -915,11 +918,15 @@
             else:

                 hostgroup_list = []
+                tag_list = []
                 template_list = []

                 for hostgroup in host['groups']:
                     hostgroup_list.append(hostgroup['name'])

+                for tag in host['tags']:
+                    tag_list.append(tag['value'])
+
                 for template in host['parentTemplates']:
                     template_list.append(template['name'])

@@ -928,9 +935,9 @@

                 result_columns[result_columns_key] = {'1': host['hostid'],
                                                       '2': host['host'],
-                                                      '3': '\n'.join(hostgroup_list),
-                                                      '4': '\n'.join(template_list),
-                                                      '5': zabbix_cli.utils.get_zabbix_agent_status(int(host['available'])),
+                                                      '3': ','.join(hostgroup_list),
+                                                      '4': ','.join(template_list),
+                                                      '5': ','.join(tag_list),
                                                       '6': zabbix_cli.utils.get_maintenance_status(int(host['maintenance_status'])),
                                                       '7': zabbix_cli.utils.get_monitoring_status(int(host['status'])),
                                                       '8': proxy_name}

In case, this patch make it working on 5.4

greenaar commented 2 years ago

^^ The above fixes hosts from limited testing, users will still need to be fixed, with the switch from 'alias' to 'username'. I'm going to take a look at this as time permits, it should be relatively simple.

carlfugate commented 2 years ago

I'm having the same issue on 5.4.9. Outside of show_alarms nothing else really seems to work. Is there any roadmap on this?

AleksejsC commented 2 years ago

Version 6 of Zabbix brought even more changes to API.

mbakke commented 2 years ago

This should be fixed in the latest release, closing!