Fallback for SLA in Zabbix 6.0, fixes #1408
This commit is contained in:
@@ -385,6 +385,65 @@ export class ZabbixAPIConnector {
|
|||||||
return this.request('service.getsla', params);
|
return this.request('service.getsla', params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getSLA60(serviceids, timeRange, options) {
|
||||||
|
const [timeFrom, timeTo] = timeRange;
|
||||||
|
let intervals = [{ from: timeFrom, to: timeTo }];
|
||||||
|
if (options.slaInterval === 'auto') {
|
||||||
|
const interval = getSLAInterval(options.intervalMs);
|
||||||
|
intervals = buildSLAIntervals(timeRange, interval);
|
||||||
|
} else if (options.slaInterval !== 'none') {
|
||||||
|
const interval = utils.parseInterval(options.slaInterval) / 1000;
|
||||||
|
intervals = buildSLAIntervals(timeRange, interval);
|
||||||
|
}
|
||||||
|
|
||||||
|
const params: any = {
|
||||||
|
output: 'extend',
|
||||||
|
serviceids,
|
||||||
|
};
|
||||||
|
|
||||||
|
const slaObjects = await this.request('sla.get', params);
|
||||||
|
if (slaObjects.length === 0) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
const sla = slaObjects[0];
|
||||||
|
|
||||||
|
const periods = intervals.map(interval => ({
|
||||||
|
period_from: interval.from,
|
||||||
|
period_to: interval.to,
|
||||||
|
}));
|
||||||
|
const sliParams: any = {
|
||||||
|
slaid: sla.slaid,
|
||||||
|
serviceids,
|
||||||
|
period_from: timeFrom,
|
||||||
|
period_to: timeTo,
|
||||||
|
periods: Math.min(intervals.length, 100),
|
||||||
|
};
|
||||||
|
|
||||||
|
const sliResponse = await this.request('sla.getsli', sliParams);
|
||||||
|
if (sliResponse.length === 0) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
const slaLikeResponse: any = {};
|
||||||
|
sliResponse.serviceids.forEach((serviceid) => {
|
||||||
|
slaLikeResponse[serviceid] = {
|
||||||
|
sla: []
|
||||||
|
};
|
||||||
|
});
|
||||||
|
sliResponse.sli.forEach((sliItem, i) => {
|
||||||
|
sliItem.forEach((sli, j) => {
|
||||||
|
slaLikeResponse[sliResponse.serviceids[j]].sla.push({
|
||||||
|
downtimeTime: sli.downtime,
|
||||||
|
okTime: sli.uptime,
|
||||||
|
sla: sli.sli,
|
||||||
|
from: sliResponse.periods[i].period_from,
|
||||||
|
to: sliResponse.periods[i].period_to
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return slaLikeResponse;
|
||||||
|
}
|
||||||
|
|
||||||
getProblems(groupids, hostids, applicationids, options): Promise<ZBXProblem[]> {
|
getProblems(groupids, hostids, applicationids, options): Promise<ZBXProblem[]> {
|
||||||
const { timeFrom, timeTo, recent, severities, limit, acknowledged, tags } = options;
|
const { timeFrom, timeTo, recent, severities, limit, acknowledged, tags } = options;
|
||||||
|
|
||||||
|
|||||||
@@ -184,6 +184,11 @@ export class Zabbix implements ZabbixConnector {
|
|||||||
return version ? semver.lt(version, '5.4.0') : true;
|
return version ? semver.lt(version, '5.4.0') : true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
supportSLA() {
|
||||||
|
const version = this.version || this.zabbixAPI.version;
|
||||||
|
return version ? semver.gte(version, '6.0.0') : true;
|
||||||
|
}
|
||||||
|
|
||||||
isZabbix54OrHigher() {
|
isZabbix54OrHigher() {
|
||||||
const version = this.version || this.zabbixAPI.version;
|
const version = this.version || this.zabbixAPI.version;
|
||||||
return version ? semver.gte(version, '5.4.0') : false;
|
return version ? semver.gte(version, '5.4.0') : false;
|
||||||
@@ -496,14 +501,19 @@ export class Zabbix implements ZabbixConnector {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getSLA(itservices, timeRange, target, options) {
|
async getSLA(itservices, timeRange, target, options) {
|
||||||
const itServiceIds = _.map(itservices, 'serviceid');
|
const itServiceIds = _.map(itservices, 'serviceid');
|
||||||
return this.zabbixAPI.getSLA(itServiceIds, timeRange, options)
|
if (this.supportSLA()) {
|
||||||
.then(slaResponse => {
|
const slaResponse = await this.zabbixAPI.getSLA60(itServiceIds, timeRange, options);
|
||||||
return _.map(itServiceIds, serviceid => {
|
return _.map(itServiceIds, serviceid => {
|
||||||
const itservice = _.find(itservices, { 'serviceid': serviceid });
|
const itservice = _.find(itservices, { 'serviceid': serviceid });
|
||||||
return responseHandler.handleSLAResponse(itservice, target.slaProperty, slaResponse);
|
return responseHandler.handleSLAResponse(itservice, target.slaProperty, slaResponse);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
const slaResponse = await this.zabbixAPI.getSLA(itServiceIds, timeRange, options);
|
||||||
|
return _.map(itServiceIds, serviceid => {
|
||||||
|
const itservice = _.find(itservices, { 'serviceid': serviceid });
|
||||||
|
return responseHandler.handleSLAResponse(itservice, target.slaProperty, slaResponse);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user