triggers panel: fix undefined username in acknowledges #393
This commit is contained in:
20
dist/panel-triggers/specs/panel_ctrl.spec.js
vendored
20
dist/panel-triggers/specs/panel_ctrl.spec.js
vendored
@@ -187,6 +187,26 @@ describe('TriggerPanelCtrl', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('When formatting acknowledges', () => {
|
||||
beforeEach(() => {
|
||||
ctx.panelCtrl = createPanelCtrl();
|
||||
});
|
||||
|
||||
it('should build proper user name', () => {
|
||||
const ack = {
|
||||
alias: 'alias', name: 'name', surname: 'surname'
|
||||
};
|
||||
|
||||
const formatted = ctx.panelCtrl.formatAcknowledge(ack);
|
||||
expect(formatted.user).toBe('alias (name surname)');
|
||||
});
|
||||
|
||||
it('should return empty name if it is not defined', () => {
|
||||
const formatted = ctx.panelCtrl.formatAcknowledge({});
|
||||
expect(formatted.user).toBe('');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
const defaultTrigger = {
|
||||
|
||||
27
dist/panel-triggers/triggers_panel_ctrl.js
vendored
27
dist/panel-triggers/triggers_panel_ctrl.js
vendored
@@ -367,16 +367,7 @@ System.register(['lodash', 'jquery', 'moment', '../datasource-zabbix/utils', 'ap
|
||||
});
|
||||
|
||||
if (event) {
|
||||
trigger.acknowledges = _.map(event.acknowledges, function (ack) {
|
||||
var timestamp = moment.unix(ack.clock);
|
||||
if (_this6.panel.customLastChangeFormat) {
|
||||
ack.time = timestamp.format(_this6.panel.lastChangeFormat);
|
||||
} else {
|
||||
ack.time = timestamp.format(_this6.defaultTimeFormat);
|
||||
}
|
||||
ack.user = ack.alias + ' (' + ack.name + ' ' + ack.surname + ')';
|
||||
return ack;
|
||||
});
|
||||
trigger.acknowledges = _.map(event.acknowledges, _this6.formatAcknowledge.bind(_this6));
|
||||
}
|
||||
|
||||
if (!trigger.lastEvent.eventid) {
|
||||
@@ -387,6 +378,22 @@ System.register(['lodash', 'jquery', 'moment', '../datasource-zabbix/utils', 'ap
|
||||
return triggerList;
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: 'formatAcknowledge',
|
||||
value: function formatAcknowledge(ack) {
|
||||
var timestamp = moment.unix(ack.clock);
|
||||
if (this.panel.customLastChangeFormat) {
|
||||
ack.time = timestamp.format(this.panel.lastChangeFormat);
|
||||
} else {
|
||||
ack.time = timestamp.format(this.defaultTimeFormat);
|
||||
}
|
||||
ack.user = ack.alias || '';
|
||||
if (ack.name || ack.surname) {
|
||||
var fullName = (ack.name || '') + ' ' + (ack.surname || '');
|
||||
ack.user += ' (' + fullName + ')';
|
||||
}
|
||||
return ack;
|
||||
}
|
||||
}, {
|
||||
key: 'filterTriggersPre',
|
||||
value: function filterTriggersPre(triggerList, ds) {
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -187,6 +187,26 @@ describe('TriggerPanelCtrl', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('When formatting acknowledges', () => {
|
||||
beforeEach(() => {
|
||||
ctx.panelCtrl = createPanelCtrl();
|
||||
});
|
||||
|
||||
it('should build proper user name', () => {
|
||||
const ack = {
|
||||
alias: 'alias', name: 'name', surname: 'surname'
|
||||
};
|
||||
|
||||
const formatted = ctx.panelCtrl.formatAcknowledge(ack);
|
||||
expect(formatted.user).toBe('alias (name surname)');
|
||||
});
|
||||
|
||||
it('should return empty name if it is not defined', () => {
|
||||
const formatted = ctx.panelCtrl.formatAcknowledge({});
|
||||
expect(formatted.user).toBe('');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
const defaultTrigger = {
|
||||
|
||||
@@ -243,16 +243,7 @@ export class TriggerPanelCtrl extends PanelCtrl {
|
||||
});
|
||||
|
||||
if (event) {
|
||||
trigger.acknowledges = _.map(event.acknowledges, ack => {
|
||||
let timestamp = moment.unix(ack.clock);
|
||||
if (this.panel.customLastChangeFormat) {
|
||||
ack.time = timestamp.format(this.panel.lastChangeFormat);
|
||||
} else {
|
||||
ack.time = timestamp.format(this.defaultTimeFormat);
|
||||
}
|
||||
ack.user = ack.alias + ' (' + ack.name + ' ' + ack.surname + ')';
|
||||
return ack;
|
||||
});
|
||||
trigger.acknowledges = _.map(event.acknowledges, this.formatAcknowledge.bind(this));
|
||||
}
|
||||
|
||||
if (!trigger.lastEvent.eventid) {
|
||||
@@ -264,6 +255,21 @@ export class TriggerPanelCtrl extends PanelCtrl {
|
||||
});
|
||||
}
|
||||
|
||||
formatAcknowledge(ack) {
|
||||
let timestamp = moment.unix(ack.clock);
|
||||
if (this.panel.customLastChangeFormat) {
|
||||
ack.time = timestamp.format(this.panel.lastChangeFormat);
|
||||
} else {
|
||||
ack.time = timestamp.format(this.defaultTimeFormat);
|
||||
}
|
||||
ack.user = ack.alias || '';
|
||||
if (ack.name || ack.surname) {
|
||||
const fullName = `${ack.name || ''} ${ack.surname || ''}`;
|
||||
ack.user += ` (${fullName})`;
|
||||
}
|
||||
return ack;
|
||||
}
|
||||
|
||||
filterTriggersPre(triggerList, ds) {
|
||||
// Filter triggers by description
|
||||
let triggerFilter = this.panel.targets[ds].trigger.filter;
|
||||
|
||||
Reference in New Issue
Block a user