Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix event severity change #872

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/panel-triggers/components/AlertList/AlertCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import classNames from 'classnames';
import _ from 'lodash';
import moment from 'moment';
import { isNewProblem, formatLastChange } from '../../utils';
import { ProblemsPanelOptions, ZBXTrigger, ZBXTag } from '../../types';
import { ProblemsPanelOptions, ZBXTrigger, TriggerSeverity, ZBXTag } from '../../types';
import { AckProblemData, Modal } from '.././Modal';
import EventTag from '../EventTag';
import Tooltip from '.././Tooltip/Tooltip';
Expand Down Expand Up @@ -59,7 +59,13 @@ export default class AlertCard extends PureComponent<AlertCardProps, AlertCardSt
const showDatasourceName = panelOptions.targets && panelOptions.targets.length > 1;
const cardClass = classNames('alert-rule-item', 'zbx-trigger-card', { 'zbx-trigger-highlighted': panelOptions.highlightBackground });
const descriptionClass = classNames('alert-rule-item__text', { 'zbx-description--newline': panelOptions.descriptionAtNewLine });
const severityDesc = _.find(panelOptions.triggerSeverity, s => s.priority === Number(problem.priority));

let severityDesc: TriggerSeverity;
severityDesc = _.find(panelOptions.triggerSeverity, s => s.priority === Number(problem.priority));
if (problem.lastEvent && problem.lastEvent.severity) {
severityDesc = _.find(panelOptions.triggerSeverity, s => s.priority === Number(problem.lastEvent.severity));
}

const lastchange = formatLastChange(problem.lastchangeUnix, panelOptions.customLastChangeFormat && panelOptions.lastChangeFormat);
const age = moment.unix(problem.lastchangeUnix).fromNow(true);

Expand Down
8 changes: 7 additions & 1 deletion src/panel-triggers/components/Problems/Problems.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,13 @@ export default class ProblemList extends PureComponent<ProblemListProps, Problem
function SeverityCell(props: RTCell<ZBXTrigger>, problemSeverityDesc: TriggerSeverity[], markAckEvents?: boolean, ackEventColor?: string) {
const problem = props.original;
let color: string;
const severityDesc = _.find(problemSeverityDesc, s => s.priority === Number(props.original.priority));

let severityDesc: TriggerSeverity;
severityDesc = _.find(problemSeverityDesc, s => s.priority === Number(props.original.priority));
if (problem.lastEvent && problem.lastEvent.severity) {
severityDesc = _.find(problemSeverityDesc, s => s.priority === Number(problem.lastEvent.severity));
}

color = severityDesc.color;

// Mark acknowledged triggers with different color
Expand Down
6 changes: 5 additions & 1 deletion src/panel-triggers/triggers_panel_ctrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,11 @@ export class TriggerPanelCtrl extends PanelCtrl {

// Filter triggers by severity
triggerList = _.filter(triggerList, trigger => {
return this.panel.triggerSeverity[trigger.priority].show;
if (trigger.lastEvent && trigger.lastEvent.severity) {
return this.panel.triggerSeverity[trigger.lastEvent.severity].show;
} else {
return this.panel.triggerSeverity[trigger.priority].show;
}
});

return triggerList;
Expand Down
1 change: 1 addition & 0 deletions src/panel-triggers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ export interface ZBXEvent {
object?: string;
objectid?: string;
acknowledged?: string;
severity?: string;
hosts?: ZBXHost[];
acknowledges?: ZBXAcknowledge[];
}
Expand Down