Skip to content

Commit

Permalink
Problems: support problems history
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderzobnin committed May 18, 2020
1 parent d7a96f0 commit 0df9023
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 14 deletions.
8 changes: 6 additions & 2 deletions src/datasource-zabbix/datasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -425,13 +425,17 @@ export class ZabbixDatasource {
problemsOptions.severities = severities;
}

if (showProblems !== ShowProblemTypes.Problems) {
if (showProblems === ShowProblemTypes.History) {
problemsOptions.timeFrom = timeFrom;
problemsOptions.timeTo = timeTo;
}

const getProblemsPromise = showProblems === ShowProblemTypes.History ?
this.zabbix.getProblemsHistory(groupFilter, hostFilter, appFilter, proxyFilter, problemsOptions) :
this.zabbix.getProblems(groupFilter, hostFilter, appFilter, proxyFilter, problemsOptions);

const problemsPromises = Promise.all([
this.zabbix.getProblems(groupFilter, hostFilter, appFilter, proxyFilter, problemsOptions),
getProblemsPromise,
getProxiesPromise
])
.then(([problems, sourceProxies]) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -485,20 +485,34 @@ export class ZabbixAPIConnector {
return this.request('event.get', params);
}

getAcknowledges(eventids) {
const params = {
getEventsHistory(groupids, hostids, applicationids, options) {
const { timeFrom, timeTo, severities, limit } = options;

const params: any = {
output: 'extend',
eventids: eventids,
preservekeys: true,
select_acknowledges: 'extend',
sortfield: 'clock',
sortorder: 'DESC'
time_from: timeFrom,
time_till: timeTo,
value: '1',
source: '0',
object: '0',
evaltype: '0',
sortfield: ['eventid'],
sortorder: 'DESC',
selectSuppressionData: ['maintenanceid', 'suppress_until'],
groupids,
hostids,
applicationids,
};

return this.request('event.get', params)
.then(events => {
return _.filter(events, (event) => event.acknowledges.length);
});
if (limit) {
params.limit = limit;
}

if (severities) {
params.severities = severities;
}

return this.request('event.get', params);
}

getExtendedEventData(eventids) {
Expand Down Expand Up @@ -530,6 +544,22 @@ export class ZabbixAPIConnector {
return this.request('alert.get', params);
}

getAcknowledges(eventids) {
const params = {
output: 'extend',
eventids: eventids,
preservekeys: true,
select_acknowledges: 'extend',
sortfield: 'clock',
sortorder: 'DESC'
};

return this.request('event.get', params)
.then(events => {
return _.filter(events, (event) => event.acknowledges.length);
});
}

getAlerts(itemids, timeFrom, timeTo) {
const params: any = {
output: 'extend',
Expand Down
35 changes: 34 additions & 1 deletion src/datasource-zabbix/zabbix/zabbix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,6 @@ export class Zabbix implements ZabbixConnector {

return query;
})
// .then(query => this.zabbixAPI.getTriggers(query.groupids, query.hostids, query.applicationids, options))
.then(query => this.zabbixAPI.getProblems(query.groupids, query.hostids, query.applicationids, options))
.then(problems => {
const triggerids = problems?.map(problem => problem.objectid);
Expand All @@ -327,6 +326,40 @@ export class Zabbix implements ZabbixConnector {
.then(triggers => this.expandUserMacro.bind(this)(triggers, true));
}

getProblemsHistory(groupFilter, hostFilter, appFilter, proxyFilter?, options?) {
const promises = [
this.getGroups(groupFilter),
this.getHosts(groupFilter, hostFilter),
this.getApps(groupFilter, hostFilter, appFilter)
];

return Promise.all(promises)
.then(results => {
const [filteredGroups, filteredHosts, filteredApps] = results;
const query: any = {};

if (appFilter) {
query.applicationids = _.flatten(_.map(filteredApps, 'applicationid'));
}
if (hostFilter) {
query.hostids = _.map(filteredHosts, 'hostid');
}
if (groupFilter) {
query.groupids = _.map(filteredGroups, 'groupid');
}

return query;
})
.then(query => this.zabbixAPI.getEventsHistory(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)]);
})
.then(([problems, triggers]) => joinTriggersWithProblems(problems, triggers))
.then(triggers => this.filterTriggersByProxy(triggers, proxyFilter))
.then(triggers => this.expandUserMacro.bind(this)(triggers, true));
}

filterTriggersByProxy(triggers, proxyFilter) {
return this.getFilteredProxies(proxyFilter)
.then(proxies => {
Expand Down

0 comments on commit 0df9023

Please sign in to comment.