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:
Zoltán Bedi
2025-07-10 17:28:04 +02:00
committed by GitHub
parent 30c0b0e982
commit bb6ade69c8
3 changed files with 21 additions and 3 deletions

View File

@@ -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', () => {

View File

@@ -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 '';
}