From 803dbf512cf84b968738519f16980f6d435b9ccc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Bedi?= Date: Thu, 13 Jun 2024 16:38:31 +0200 Subject: [PATCH 1/3] Fix: Problems panel failing for versions before 7.0.0 (#1840) * Fix: Problems panel failing for versions before 7.0.0 * Add tests * Use spy instead of new argument --- .../zabbix_api/zabbixAPIConnector.test.ts | 27 +++++++++++++++++++ .../zabbix_api/zabbixAPIConnector.ts | 11 ++++---- 2 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 src/datasource/zabbix/connectors/zabbix_api/zabbixAPIConnector.test.ts diff --git a/src/datasource/zabbix/connectors/zabbix_api/zabbixAPIConnector.test.ts b/src/datasource/zabbix/connectors/zabbix_api/zabbixAPIConnector.test.ts new file mode 100644 index 0000000..d2ff32e --- /dev/null +++ b/src/datasource/zabbix/connectors/zabbix_api/zabbixAPIConnector.test.ts @@ -0,0 +1,27 @@ +import { ZabbixAPIConnector } from './zabbixAPIConnector'; + +describe('Zabbix API connector', () => { + describe('getProxies function', () => { + beforeAll(() => { + jest.spyOn(ZabbixAPIConnector.prototype, 'initVersion').mockResolvedValue(''); + }); + + it('should send the name parameter to the request when version is 7 or greater for the getProxies', async () => { + const zabbixAPIConnector = new ZabbixAPIConnector(true, true, 123); + zabbixAPIConnector.version = '7.0.0'; + zabbixAPIConnector.request = jest.fn(); + + await zabbixAPIConnector.getProxies(); + expect(zabbixAPIConnector.request).toHaveBeenCalledWith('proxy.get', { output: ['proxyid', 'name'] }); + }); + + it('should send the host parameter when version is less than 7.0.0', () => { + const zabbixAPIConnector = new ZabbixAPIConnector(true, true, 123); + zabbixAPIConnector.version = '6.0.0'; + zabbixAPIConnector.request = jest.fn(); + + zabbixAPIConnector.getProxies(); + expect(zabbixAPIConnector.request).toHaveBeenCalledWith('proxy.get', { output: ['proxyid', 'host'] }); + }); + }); +}); diff --git a/src/datasource/zabbix/connectors/zabbix_api/zabbixAPIConnector.ts b/src/datasource/zabbix/connectors/zabbix_api/zabbixAPIConnector.ts index 89ef220..845e08a 100644 --- a/src/datasource/zabbix/connectors/zabbix_api/zabbixAPIConnector.ts +++ b/src/datasource/zabbix/connectors/zabbix_api/zabbixAPIConnector.ts @@ -548,7 +548,7 @@ export class ZabbixAPIConnector { }; // Before version 7.0.0 proxy_hostid was used, after - proxyid - if (semver.lte(this.version, '7.0.0')) { + if (semver.lt(this.version, '7.0.0')) { params.selectHosts.push('proxy_hostid'); } else { params.selectHosts.push('proxyid'); @@ -582,7 +582,7 @@ export class ZabbixAPIConnector { }; // Before version 7.0.0 proxy_hostid was used, after - proxyid - if (semver.lte(this.version, '7.0.0')) { + if (semver.lt(this.version, '7.0.0')) { params.selectHosts.push('proxy_hostid'); } else { params.selectHosts.push('proxyid'); @@ -877,10 +877,11 @@ export class ZabbixAPIConnector { const params = { output: ['proxyid'], }; - if (semver.lte(this.version, '7.0.0')) { - params.output.push('name'); - } else { + // Before version 7.0.0 host was used, after - name + if (semver.lt(this.version, '7.0.0')) { params.output.push('host'); + } else { + params.output.push('name'); } return this.request('proxy.get', params); From 0782a0c82dc8675593ead91640f2aecc7502029a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Bedi?= Date: Fri, 14 Jun 2024 17:07:01 +0200 Subject: [PATCH 2/3] Chore: Release prep 4.5.1 --- CHANGELOG.md | 4 ++++ package.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ff80c77..8496710 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Change Log +## [4.5.1] - 2024-06-14 + +- Fix: Problems queries not working before zabbix version 7 + ## [4.5.0] - 2024-06-10 - Add support for Zabbix version 7 diff --git a/package.json b/package.json index 307e082..45941b1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "grafana-zabbix", - "version": "4.5.0", + "version": "4.5.1", "description": "Zabbix plugin for Grafana", "homepage": "http://grafana-zabbix.org", "bugs": { From ae495f4b947c341b1717153244def52e5207683a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 14 Jun 2024 15:16:09 +0000 Subject: [PATCH 3/3] Bump braces from 3.0.2 to 3.0.3 Bumps [braces](https://github.com/micromatch/braces) from 3.0.2 to 3.0.3. - [Changelog](https://github.com/micromatch/braces/blob/master/CHANGELOG.md) - [Commits](https://github.com/micromatch/braces/compare/3.0.2...3.0.3) --- updated-dependencies: - dependency-name: braces dependency-type: indirect ... Signed-off-by: dependabot[bot] --- yarn.lock | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/yarn.lock b/yarn.lock index 5476564..b9a980b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3091,11 +3091,11 @@ brace-expansion@^2.0.1: balanced-match "^1.0.0" braces@^3.0.2, braces@~3.0.2: - version "3.0.2" - resolved "https://registry.yarnpkg.com/braces/-/braces-3.0.2.tgz#3454e1a462ee8d599e236df336cd9ea4f8afe107" - integrity sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A== + version "3.0.3" + resolved "https://registry.yarnpkg.com/braces/-/braces-3.0.3.tgz#490332f40919452272d55a8480adc0c441358789" + integrity sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA== dependencies: - fill-range "^7.0.1" + fill-range "^7.1.1" browserslist@^4.14.5, browserslist@^4.20.3, browserslist@^4.21.9: version "4.21.11" @@ -4762,10 +4762,10 @@ file-selector@^0.6.0: dependencies: tslib "^2.4.0" -fill-range@^7.0.1: - version "7.0.1" - resolved "https://registry.yarnpkg.com/fill-range/-/fill-range-7.0.1.tgz#1919a6a7c75fe38b2c7c77e5198535da9acdda40" - integrity sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ== +fill-range@^7.1.1: + version "7.1.1" + resolved "https://registry.yarnpkg.com/fill-range/-/fill-range-7.1.1.tgz#44265d3cac07e3ea7dc247516380643754a05292" + integrity sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg== dependencies: to-regex-range "^5.0.1"