Problems panel: clean up
This commit is contained in:
@@ -99,61 +99,6 @@ describe('TriggerPanelCtrl', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('When formatting triggers', () => {
|
|
||||||
beforeEach(() => {
|
|
||||||
ctx.panelCtrl = createPanelCtrl();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should handle new lines in trigger description', () => {
|
|
||||||
ctx.panelCtrl.setTriggerSeverity = jest.fn((trigger) => trigger);
|
|
||||||
const trigger = { comments: "this is\ndescription" };
|
|
||||||
const formattedTrigger = ctx.panelCtrl.formatTrigger(trigger);
|
|
||||||
expect(formattedTrigger.comments).toBe("this is<br>description");
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should format host name to display (default)', (done) => {
|
|
||||||
ctx.panelCtrl.onDataFramesReceived(ctx.dataFramesReceived).then(() => {
|
|
||||||
const trigger = getProblemById(1, ctx);
|
|
||||||
const hostname = ctx.panelCtrl.formatHostName(trigger);
|
|
||||||
expect(hostname).toBe('backend01');
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should format host name to display (tech name)', (done) => {
|
|
||||||
ctx.panelCtrl.panel.hostField = false;
|
|
||||||
ctx.panelCtrl.panel.hostTechNameField = true;
|
|
||||||
ctx.panelCtrl.onDataFramesReceived(ctx.dataFramesReceived).then(() => {
|
|
||||||
const trigger = getProblemById(1, ctx);
|
|
||||||
const hostname = ctx.panelCtrl.formatHostName(trigger);
|
|
||||||
expect(hostname).toBe('backend01_tech');
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should format host name to display (both tech and visible)', (done) => {
|
|
||||||
ctx.panelCtrl.panel.hostField = true;
|
|
||||||
ctx.panelCtrl.panel.hostTechNameField = true;
|
|
||||||
ctx.panelCtrl.onDataFramesReceived(ctx.dataFramesReceived).then(() => {
|
|
||||||
const trigger = getProblemById(1, ctx);
|
|
||||||
const hostname = ctx.panelCtrl.formatHostName(trigger);
|
|
||||||
expect(hostname).toBe('backend01 (backend01_tech)');
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should hide hostname if both visible and tech name checkboxes unset', (done) => {
|
|
||||||
ctx.panelCtrl.panel.hostField = false;
|
|
||||||
ctx.panelCtrl.panel.hostTechNameField = false;
|
|
||||||
ctx.panelCtrl.onDataFramesReceived(ctx.dataFramesReceived).then(() => {
|
|
||||||
const trigger = getProblemById(1, ctx);
|
|
||||||
const hostname = ctx.panelCtrl.formatHostName(trigger);
|
|
||||||
expect(hostname).toBe("");
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const defaultProblem: any = {
|
const defaultProblem: any = {
|
||||||
|
|||||||
@@ -319,54 +319,6 @@ export class TriggerPanelCtrl extends MetricsPanelCtrl {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
formatHostName(trigger) {
|
|
||||||
let host = "";
|
|
||||||
if (this.panel.hostField && this.panel.hostTechNameField) {
|
|
||||||
host = `${trigger.host} (${trigger.hostTechName})`;
|
|
||||||
} else if (this.panel.hostField || this.panel.hostTechNameField) {
|
|
||||||
host = this.panel.hostField ? trigger.host : trigger.hostTechName;
|
|
||||||
}
|
|
||||||
if (this.panel.hostProxy && trigger.proxy) {
|
|
||||||
host = `${trigger.proxy}: ${host}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
return host;
|
|
||||||
}
|
|
||||||
|
|
||||||
formatHostGroups(trigger) {
|
|
||||||
let groupNames = "";
|
|
||||||
if (this.panel.hostGroups) {
|
|
||||||
const groups = _.map(trigger.groups, 'name').join(', ');
|
|
||||||
groupNames += `[ ${groups} ]`;
|
|
||||||
}
|
|
||||||
|
|
||||||
return groupNames;
|
|
||||||
}
|
|
||||||
|
|
||||||
isNewTrigger(trigger) {
|
|
||||||
try {
|
|
||||||
const highlightIntervalMs = utils.parseInterval(this.panel.highlightNewerThan || PANEL_DEFAULTS.highlightNewerThan);
|
|
||||||
const durationSec = (Date.now() - trigger.lastchangeUnix * 1000);
|
|
||||||
return durationSec < highlightIntervalMs;
|
|
||||||
} catch (e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
getAlertIconClass(trigger) {
|
|
||||||
let iconClass = '';
|
|
||||||
if (trigger.value === '1' && trigger.priority >= 2) {
|
|
||||||
iconClass = 'icon-gf-critical';
|
|
||||||
} else {
|
|
||||||
iconClass = 'icon-gf-online';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.panel.highlightNewEvents && this.isNewTrigger(trigger)) {
|
|
||||||
iconClass += ' zabbix-trigger--blinked';
|
|
||||||
}
|
|
||||||
return iconClass;
|
|
||||||
}
|
|
||||||
|
|
||||||
getAlertIconClassBySeverity(triggerSeverity) {
|
getAlertIconClassBySeverity(triggerSeverity) {
|
||||||
let iconClass = 'icon-gf-online';
|
let iconClass = 'icon-gf-online';
|
||||||
if (triggerSeverity.priority >= 2) {
|
if (triggerSeverity.priority >= 2) {
|
||||||
@@ -375,22 +327,6 @@ export class TriggerPanelCtrl extends MetricsPanelCtrl {
|
|||||||
return iconClass;
|
return iconClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
getAlertStateClass(trigger) {
|
|
||||||
let statusClass = '';
|
|
||||||
|
|
||||||
if (trigger.value === '1') {
|
|
||||||
statusClass = 'alert-state-critical';
|
|
||||||
} else {
|
|
||||||
statusClass = 'alert-state-ok';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.panel.highlightNewEvents && this.isNewTrigger(trigger)) {
|
|
||||||
statusClass += ' zabbix-trigger--blinked';
|
|
||||||
}
|
|
||||||
|
|
||||||
return statusClass;
|
|
||||||
}
|
|
||||||
|
|
||||||
resetResizedColumns() {
|
resetResizedColumns() {
|
||||||
this.panel.resizedColumns = [];
|
this.panel.resizedColumns = [];
|
||||||
this.render();
|
this.render();
|
||||||
|
|||||||
Reference in New Issue
Block a user