Skip to content

Commit

Permalink
triggers: prepend proxy name to host name, #418
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderzobnin committed Nov 7, 2018
1 parent 85f320a commit b45eb5a
Showing 1 changed file with 35 additions and 9 deletions.
44 changes: 35 additions & 9 deletions src/panel-triggers/triggers_panel_ctrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ export class TriggerPanelCtrl extends PanelCtrl {

getTriggers() {
let promises = _.map(this.panel.datasources, (ds) => {
let proxies = [];
return this.datasourceSrv.get(ds)
.then(datasource => {
var zabbix = datasource.zabbix;
Expand All @@ -218,15 +219,21 @@ export class TriggerPanelCtrl extends PanelCtrl {
showTriggers: showEvents
};

return zabbix.getTriggers(groupFilter, hostFilter, appFilter, triggersOptions);
}).then((triggers) => {
return Promise.all([
zabbix.getTriggers(groupFilter, hostFilter, appFilter, triggersOptions),
zabbix.getProxies()
]);
}).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);
});
});

Expand Down Expand Up @@ -344,6 +351,19 @@ export class TriggerPanelCtrl extends PanelCtrl {
return triggers;
}

addTriggerHostProxy(triggers, proxies) {
triggers.forEach(trigger => {
if (trigger.hosts && trigger.hosts.length) {
let host = trigger.hosts[0];
if (host.proxy_hostid !== '0') {
const hostProxy = proxies[host.proxy_hostid];
host.proxy = hostProxy ? hostProxy.host : '';
}
}
});
return triggers;
}

sortTriggers(triggerList) {
if (this.panel.sortTriggersBy.value === 'priority') {
triggerList = _.orderBy(triggerList, ['priority', 'lastchangeUnix', 'triggerid'], ['desc', 'desc', 'desc']);
Expand All @@ -355,12 +375,15 @@ export class TriggerPanelCtrl extends PanelCtrl {

formatTrigger(zabbixTrigger) {
let trigger = _.cloneDeep(zabbixTrigger);
let triggerObj = trigger;

// Set host that the trigger belongs
// Set host and proxy that the trigger belongs
if (trigger.hosts && trigger.hosts.length) {
triggerObj.host = trigger.hosts[0].name;
triggerObj.hostTechName = trigger.hosts[0].host;
const host = trigger.hosts[0];
trigger.host = host.name;
trigger.hostTechName = host.host;
if (host.proxy) {
trigger.proxy = host.proxy;
}
}

// Set tags if present
Expand All @@ -375,9 +398,9 @@ export class TriggerPanelCtrl extends PanelCtrl {

// Format last change and age
trigger.lastchangeUnix = Number(trigger.lastchange);
triggerObj = this.setTriggerLastChange(triggerObj);
triggerObj = this.setTriggerSeverity(triggerObj);
return triggerObj;
trigger = this.setTriggerLastChange(trigger);
trigger = this.setTriggerSeverity(trigger);
return trigger;
}

updateTriggerFormat(trigger) {
Expand Down Expand Up @@ -491,6 +514,9 @@ export class TriggerPanelCtrl extends PanelCtrl {
} else if (this.panel.hostField || this.panel.hostTechNameField) {
host = this.panel.hostField ? trigger.host : trigger.hostTechName;
}
if (trigger.proxy) {
host = `${trigger.proxy}: ${host}`;
}

return host;
}
Expand Down

0 comments on commit b45eb5a

Please sign in to comment.