Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Problems panel failing for versions before 7.0.0 #1840

Merged
merged 3 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { ZabbixAPIConnector } from './zabbixAPIConnector';

describe('Zabbix API connector', () => {
describe('getProxies function', () => {
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, '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, '6.0.0');
zabbixAPIConnector.request = jest.fn();

zabbixAPIConnector.getProxies();
expect(zabbixAPIConnector.request).toHaveBeenCalledWith('proxy.get', { output: ['proxyid', 'host'] });
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class ZabbixAPIConnector {
getVersionPromise: Promise<string>;
datasourceId: number;

constructor(basicAuth: any, withCredentials: boolean, datasourceId: number) {
constructor(basicAuth: any, withCredentials: boolean, datasourceId: number, zabbixVersion?: string) {
this.datasourceId = datasourceId;
this.backendAPIUrl = `/api/datasources/${this.datasourceId}/resources/zabbix-api`;

Expand All @@ -37,6 +37,8 @@ export class ZabbixAPIConnector {
withCredentials: withCredentials,
};

this.version = zabbixVersion || null;

this.getTrend = this.getTrend_ZBXNEXT1193;
//getTrend = getTrend_30;

Expand Down Expand Up @@ -548,7 +550,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');
Expand Down Expand Up @@ -582,7 +584,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');
Expand Down Expand Up @@ -877,10 +879,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);
Expand Down
Loading