triggers: able to filter by proxy, #418
This commit is contained in:
@@ -243,7 +243,7 @@ export class Zabbix {
|
||||
/**
|
||||
* Build query - convert target filters to array of Zabbix items
|
||||
*/
|
||||
getTriggers(groupFilter, hostFilter, appFilter, options) {
|
||||
getTriggers(groupFilter, hostFilter, appFilter, options, proxyFilter) {
|
||||
let promises = [
|
||||
this.getGroups(groupFilter),
|
||||
this.getHosts(groupFilter, hostFilter),
|
||||
@@ -252,9 +252,7 @@ export class Zabbix {
|
||||
|
||||
return Promise.all(promises)
|
||||
.then(results => {
|
||||
let filteredGroups = results[0];
|
||||
let filteredHosts = results[1];
|
||||
let filteredApps = results[2];
|
||||
let [filteredGroups, filteredHosts, filteredApps] = results;
|
||||
let query = {};
|
||||
|
||||
if (appFilter) {
|
||||
@@ -268,8 +266,36 @@ export class Zabbix {
|
||||
}
|
||||
|
||||
return query;
|
||||
}).then(query => {
|
||||
return this.zabbixAPI.getTriggers(query.groupids, query.hostids, query.applicationids, options);
|
||||
})
|
||||
.then(query => this.zabbixAPI.getTriggers(query.groupids, query.hostids, query.applicationids, options))
|
||||
.then(triggers => this.filterTriggersByProxy(triggers, proxyFilter));
|
||||
}
|
||||
|
||||
filterTriggersByProxy(triggers, proxyFilter) {
|
||||
return this.getFilteredProxies(proxyFilter)
|
||||
.then(proxies => {
|
||||
if (proxyFilter && proxyFilter !== '/.*/' && triggers) {
|
||||
const proxy_ids = proxies.map(proxy => proxy.proxyid);
|
||||
triggers = triggers.filter(trigger => {
|
||||
let filtered = false;
|
||||
for(let i = 0; i < trigger.hosts.length; i++) {
|
||||
const host = trigger.hosts[i];
|
||||
if (proxy_ids.includes(host.proxy_hostid)) {
|
||||
filtered = true;
|
||||
}
|
||||
}
|
||||
return filtered;
|
||||
});
|
||||
}
|
||||
return triggers;
|
||||
});
|
||||
}
|
||||
|
||||
getFilteredProxies(proxyFilter) {
|
||||
return this.zabbixAPI.getProxies()
|
||||
.then(proxies => {
|
||||
proxies.forEach(proxy => proxy.name = proxy.host);
|
||||
return findByFilter(proxies, proxyFilter);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import _ from 'lodash';
|
||||
import {DEFAULT_TARGET} from './triggers_panel_ctrl';
|
||||
|
||||
// Actual schema version
|
||||
export const CURRENT_SCHEMA_VERSION = 4;
|
||||
export const CURRENT_SCHEMA_VERSION = 5;
|
||||
|
||||
export function migratePanelSchema(panel) {
|
||||
if (isEmptyPanel(panel)) {
|
||||
@@ -31,7 +31,7 @@ export function migratePanelSchema(panel) {
|
||||
delete panel.hideHostsInMaintenance;
|
||||
}
|
||||
|
||||
if (schemaVersion < 4) {
|
||||
if (schemaVersion < 5) {
|
||||
if (panel.targets && !_.isEmpty(panel.targets)) {
|
||||
_.each(panel.targets, (target) => {
|
||||
_.defaultsDeep(target, DEFAULT_TARGET);
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
<div class="section gf-form-group">
|
||||
<h5 class="section-heading">{{ ds }}</h5>
|
||||
<div class="gf-form-inline">
|
||||
<div class="gf-form max-width-20">
|
||||
<div class="gf-form">
|
||||
<label class="gf-form-label query-keyword width-7">Group</label>
|
||||
<input type="text"
|
||||
ng-model="ctrl.panel.targets[ds].group.filter"
|
||||
@@ -27,7 +27,7 @@
|
||||
ng-blur="editor.parseTarget()"
|
||||
data-min-length=0
|
||||
data-items=100
|
||||
class="gf-form-input"
|
||||
class="gf-form-input width-14"
|
||||
ng-class="{
|
||||
'zbx-variable': editor.isVariable(ctrl.panel.targets[ds].group.filter),
|
||||
'zbx-regex': editor.isRegex(ctrl.panel.targets[ds].group.filter)
|
||||
@@ -41,16 +41,30 @@
|
||||
ng-blur="editor.parseTarget()"
|
||||
data-min-length=0
|
||||
data-items=100
|
||||
class="gf-form-input"
|
||||
class="gf-form-input width-14"
|
||||
ng-class="{
|
||||
'zbx-variable': editor.isVariable(ctrl.panel.targets[ds].host.filter),
|
||||
'zbx-regex': editor.isRegex(ctrl.panel.targets[ds].host.filter)
|
||||
}">
|
||||
</div>
|
||||
<div class="gf-form">
|
||||
<label class="gf-form-label query-keyword width-7">Proxy</label>
|
||||
<input type="text"
|
||||
ng-model="ctrl.panel.targets[ds].proxy.filter"
|
||||
bs-typeahead="editor.getHostNames[ds]"
|
||||
ng-blur="editor.parseTarget()"
|
||||
data-min-length=0
|
||||
data-items=100
|
||||
class="gf-form-input width-14"
|
||||
ng-class="{
|
||||
'zbx-variable': editor.isVariable(ctrl.panel.targets[ds].proxy.filter),
|
||||
'zbx-regex': editor.isRegex(ctrl.panel.targets[ds].proxy.filter)
|
||||
}">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="gf-form-inline">
|
||||
<div class="gf-form max-width-20">
|
||||
<div class="gf-form">
|
||||
<label class="gf-form-label query-keyword width-7">Application</label>
|
||||
<input type="text"
|
||||
ng-model="ctrl.panel.targets[ds].application.filter"
|
||||
@@ -58,7 +72,7 @@
|
||||
ng-blur="editor.parseTarget()"
|
||||
data-min-length=0
|
||||
data-items=100
|
||||
class="gf-form-input"
|
||||
class="gf-form-input width-14"
|
||||
ng-class="{
|
||||
'zbx-variable': editor.isVariable(ctrl.panel.targets[ds].application.filter),
|
||||
'zbx-regex': editor.isRegex(ctrl.panel.targets[ds].application.filter)
|
||||
@@ -70,7 +84,7 @@
|
||||
ng-model="ctrl.panel.targets[ds].trigger.filter"
|
||||
ng-blur="editor.parseTarget()"
|
||||
placeholder="trigger name"
|
||||
class="gf-form-input"
|
||||
class="gf-form-input width-14"
|
||||
ng-style="ctrl.panel.targets[ds].trigger.style"
|
||||
ng-class="{
|
||||
'zbx-variable': editor.isVariable(ctrl.panel.targets[ds].trigger.filter),
|
||||
@@ -80,7 +94,7 @@
|
||||
</div>
|
||||
<div class="gf-form">
|
||||
<label class="gf-form-label query-keyword width-7">Tags</label>
|
||||
<input type="text" class="gf-form-input"
|
||||
<input type="text" class="gf-form-input width-14"
|
||||
ng-model="ctrl.panel.targets[ds].tags.filter"
|
||||
ng-blur="editor.parseTarget()"
|
||||
placeholder="tag1:value1, tag2:value2">
|
||||
|
||||
@@ -15,6 +15,7 @@ export const DEFAULT_TARGET = {
|
||||
application: {filter: ""},
|
||||
trigger: {filter: ""},
|
||||
tags: {filter: ""},
|
||||
proxy: {filter: ""},
|
||||
};
|
||||
|
||||
export const DEFAULT_SEVERITY = [
|
||||
@@ -204,7 +205,7 @@ export class TriggerPanelCtrl extends PanelCtrl {
|
||||
|
||||
getTriggers() {
|
||||
let promises = _.map(this.panel.datasources, (ds) => {
|
||||
let proxies = [];
|
||||
let proxies;
|
||||
return this.datasourceSrv.get(ds)
|
||||
.then(datasource => {
|
||||
const zabbix = datasource.zabbix;
|
||||
@@ -217,27 +218,24 @@ export class TriggerPanelCtrl extends PanelCtrl {
|
||||
const groupFilter = datasource.replaceTemplateVars(triggerFilter.group.filter);
|
||||
const hostFilter = datasource.replaceTemplateVars(triggerFilter.host.filter);
|
||||
const appFilter = datasource.replaceTemplateVars(triggerFilter.application.filter);
|
||||
const proxyFilter = datasource.replaceTemplateVars(triggerFilter.proxy.filter);
|
||||
|
||||
let triggersOptions = {
|
||||
showTriggers: showEvents
|
||||
};
|
||||
|
||||
return Promise.all([
|
||||
zabbix.getTriggers(groupFilter, hostFilter, appFilter, triggersOptions),
|
||||
zabbix.getTriggers(groupFilter, hostFilter, appFilter, triggersOptions, proxyFilter),
|
||||
getProxiesPromise
|
||||
]);
|
||||
}).then(([triggers, sourceProxies]) => {
|
||||
proxies = _.keyBy(sourceProxies, 'proxyid');
|
||||
return this.getAcknowledges(triggers, ds);
|
||||
}).then((triggers) => {
|
||||
return this.setMaintenanceStatus(triggers);
|
||||
}).then((triggers) => {
|
||||
return this.filterTriggersPre(triggers, ds);
|
||||
}).then((triggers) => {
|
||||
return this.addTriggerDataSource(triggers, ds);
|
||||
}).then((triggers) => {
|
||||
return this.addTriggerHostProxy(triggers, proxies);
|
||||
});
|
||||
})
|
||||
.then(triggers => this.setMaintenanceStatus(triggers))
|
||||
.then(triggers => this.filterTriggersPre(triggers, ds))
|
||||
.then(triggers => this.addTriggerDataSource(triggers, ds))
|
||||
.then(triggers => this.addTriggerHostProxy(triggers, proxies));
|
||||
});
|
||||
|
||||
return Promise.all(promises)
|
||||
|
||||
Reference in New Issue
Block a user