Fix: Update Zabbix API connector to handle versioning for 'with_hosts' parameter (#2049)
This changes the version number for `with_hosts` to return `real_hosts` when version is 6.0.0 or below. In 6.2 `real_hosts` is deprecated. https://www.zabbix.com/documentation/6.2/en/manual/api/reference/hostgroup/get In 6.0 it isn't. https://www.zabbix.com/documentation/6.0/en/manual/api/reference/hostgroup/get Fixes https://github.com/grafana/grafana-zabbix/issues/2048
This commit is contained in:
5
.changeset/gentle-suits-invite.md
Normal file
5
.changeset/gentle-suits-invite.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'grafana-zabbix': patch
|
||||
---
|
||||
|
||||
Fix: `real_hosts` deprecated in version 6.2 and 6.4
|
||||
@@ -37,9 +37,9 @@ describe('Zabbix API connector', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should send the real_hosts parameter when version is <7.0', () => {
|
||||
it('should send the real_hosts parameter when version is <=6.0', () => {
|
||||
const zabbixAPIConnector = new ZabbixAPIConnector(true, true, 123);
|
||||
zabbixAPIConnector.version = '6.5.0';
|
||||
zabbixAPIConnector.version = '6.0.0';
|
||||
zabbixAPIConnector.request = jest.fn();
|
||||
|
||||
zabbixAPIConnector.getGroups();
|
||||
@@ -49,6 +49,19 @@ describe('Zabbix API connector', () => {
|
||||
real_hosts: true,
|
||||
});
|
||||
});
|
||||
|
||||
it('should send the with_hosts parameter when version is >=6.2', () => {
|
||||
const zabbixAPIConnector = new ZabbixAPIConnector(true, true, 123);
|
||||
zabbixAPIConnector.version = '6.2.0';
|
||||
zabbixAPIConnector.request = jest.fn();
|
||||
|
||||
zabbixAPIConnector.getGroups();
|
||||
expect(zabbixAPIConnector.request).toHaveBeenCalledWith('hostgroup.get', {
|
||||
output: ['name', 'groupid'],
|
||||
sortfield: 'name',
|
||||
with_hosts: true,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('getHostAlerts function', () => {
|
||||
|
||||
@@ -1029,7 +1029,7 @@ function getParamsKeyByVersion(
|
||||
case 'selectAcknowledges':
|
||||
return semver.gte(version, '7.0.0') ? 'selectAcknowledges' : 'select_acknowledges';
|
||||
case 'with_hosts':
|
||||
return semver.gte(version, '7.0.0') ? 'with_hosts' : 'real_hosts';
|
||||
return semver.gte(version, '6.2.0') ? 'with_hosts' : 'real_hosts';
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user