always return array from problems requests

This commit is contained in:
Alexander Zobnin
2020-05-27 09:55:57 +03:00
parent 938b3cdc05
commit d2a1a7797b
4 changed files with 14 additions and 6 deletions

View File

@@ -5,6 +5,7 @@ import { ZBXProblem, ZBXTrigger, ProblemDTO, ZBXEvent } from './types';
export function joinTriggersWithProblems(problems: ZBXProblem[], triggers: ZBXTrigger[]): ProblemDTO[] {
const problemDTOList: ProblemDTO[] = [];
for (let i = 0; i < problems.length; i++) {
const p = problems[i];
const triggerId = Number(p.objectid);
@@ -52,8 +53,8 @@ interface JoinOptions {
export function joinTriggersWithEvents(events: ZBXEvent[], triggers: ZBXTrigger[], options?: JoinOptions): ProblemDTO[] {
const { valueFromEvent } = options;
const problemDTOList: ProblemDTO[] = [];
for (let i = 0; i < events.length; i++) {
const e = events[i];
const triggerId = Number(e.objectid);

View File

@@ -380,3 +380,7 @@ export function parseTags(tagStr: string): any[] {
});
return tags;
}
export function mustArray(result: any): any[] {
return result || [];
}

View File

@@ -425,7 +425,7 @@ export class ZabbixAPIConnector {
params.time_till = timeTo;
}
return this.request('problem.get', params);
return this.request('problem.get', params).then(utils.mustArray);
}
getTriggersByIds(triggerids: string[]) {
@@ -445,7 +445,7 @@ export class ZabbixAPIConnector {
preservekeys: '1',
};
return this.request('trigger.get', params);
return this.request('trigger.get', params).then(utils.mustArray);
}
getTriggers(groupids, hostids, applicationids, options) {
@@ -507,7 +507,7 @@ export class ZabbixAPIConnector {
params.sortorder = 'DESC';
}
return this.request('event.get', params);
return this.request('event.get', params).then(utils.mustArray);
}
getEventsHistory(groupids, hostids, applicationids, options) {
@@ -543,7 +543,7 @@ export class ZabbixAPIConnector {
params.value = value;
}
return this.request('event.get', params);
return this.request('event.get', params).then(utils.mustArray);
}
getExtendedEventData(eventids) {

View File

@@ -340,7 +340,10 @@ export class Zabbix implements ZabbixConnector {
.then(query => this.zabbixAPI.getProblems(query.groupids, query.hostids, query.applicationids, options))
.then(problems => {
const triggerids = problems?.map(problem => problem.objectid);
return Promise.all([Promise.resolve(problems), this.zabbixAPI.getTriggersByIds(triggerids)]);
return Promise.all([
Promise.resolve(problems),
this.zabbixAPI.getTriggersByIds(triggerids)
]);
})
.then(([problems, triggers]) => joinTriggersWithProblems(problems, triggers))
.then(triggers => this.filterTriggersByProxy(triggers, proxyFilter))