Skip to content

Commit

Permalink
triggers mode: filter results by group, fix #709
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderzobnin committed Apr 23, 2019
1 parent f76cff2 commit c545304
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
12 changes: 8 additions & 4 deletions src/datasource-zabbix/datasource.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ export class ZabbixDatasource {
queryTriggersData(target, timeRange) {
let [timeFrom, timeTo] = timeRange;
return this.zabbix.getHostsFromTarget(target)
.then((results) => {
.then(results => {
let [hosts, apps] = results;
if (hosts.length) {
let hostids = _.map(hosts, 'hostid');
Expand All @@ -342,9 +342,13 @@ export class ZabbixDatasource {
timeFrom: timeFrom,
timeTo: timeTo
};
return this.zabbix.getHostAlerts(hostids, appids, options)
.then((triggers) => {
return responseHandler.handleTriggersResponse(triggers, timeRange);
const groupFilter = target.group.filter;
return Promise.all([
this.zabbix.getHostAlerts(hostids, appids, options),
this.zabbix.getGroups(groupFilter)
])
.then(([triggers, groups]) => {
return responseHandler.handleTriggersResponse(triggers, groups, timeRange);
});
} else {
return Promise.resolve([]);
Expand Down
13 changes: 8 additions & 5 deletions src/datasource-zabbix/responseHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ function handleSLAResponse(itservice, slaProperty, slaObject) {
}
}

function handleTriggersResponse(triggers, timeRange) {
function handleTriggersResponse(triggers, groups, timeRange) {
if (_.isNumber(triggers)) {
return {
target: "triggers count",
Expand All @@ -152,16 +152,19 @@ function handleTriggersResponse(triggers, timeRange) {
]
};
} else {
let stats = getTriggerStats(triggers);
const stats = getTriggerStats(triggers);
const groupNames = _.map(groups, 'name');
let table = new TableModel();
table.addColumn({text: 'Host group'});
_.each(_.orderBy(c.TRIGGER_SEVERITY, ['val'], ['desc']), (severity) => {
table.addColumn({text: severity.text});
});
_.each(stats, (severity_stats, group) => {
let row = _.map(_.orderBy(_.toPairs(severity_stats), (s) => s[0], ['desc']), (s) => s[1]);
row = _.concat([group], ...row);
table.rows.push(row);
if (_.includes(groupNames, group)) {
let row = _.map(_.orderBy(_.toPairs(severity_stats), (s) => s[0], ['desc']), (s) => s[1]);
row = _.concat([group], ...row);
table.rows.push(row);
}
});
return table;
}
Expand Down

0 comments on commit c545304

Please sign in to comment.