55
66namespace Icinga \Module \Notifications \View ;
77
8+ use Icinga \Module \Notifications \Common \EscalationConditionDescriber ;
89use Icinga \Module \Notifications \Common \Icons ;
10+ use Icinga \Module \Notifications \Common \IncidentHistoryType ;
911use Icinga \Module \Notifications \Model \IncidentHistory ;
1012use Icinga \Module \Notifications \Widget \IconBall ;
1113use ipl \Html \Attributes ;
@@ -26,7 +28,7 @@ class IncidentHistoryRenderer implements ItemRenderer
2628 public function assembleAttributes ($ item , Attributes $ attributes , string $ layout ): void
2729 {
2830 $ classes = ['incident-history ' ];
29- if ($ item ->type === ' notified ' ) {
31+ if ($ item ->type === IncidentHistoryType:: NOTIFIED ) {
3032 $ classes [] = 'notification-state ' ;
3133 if ($ item ->notification_state === 'suppressed ' ) {
3234 $ classes [] = 'suppressed ' ;
@@ -40,20 +42,21 @@ public function assembleAttributes($item, Attributes $attributes, string $layout
4042
4143 public function assembleVisual ($ item , HtmlDocument $ visual , string $ layout ): void
4244 {
43- if ($ item ->type === ' incident_severity_changed ' ) {
45+ if ($ item ->type === IncidentHistoryType:: INCIDENT_SEVERITY_CHANGED ) {
4446 $ content = $ item ->new_severity ->getIcon ();
4547 } else {
46- $ content = new IconBall (match ($ item ->type ) {
47- 'opened ' => Icons::OPENED ,
48- 'muted ' => Icons::MUTE ,
49- 'unmuted ' => Icons::UNMUTE ,
50- 'recipient_role_changed ' => $ this ->getRoleIcon ($ item ),
51- 'closed ' => Icons::CLOSED ,
52- 'rule_matched ' => Icons::RULE_MATCHED ,
53- 'escalation_triggered ' => Icons::TRIGGERED ,
54- 'notified ' => Icons::NOTIFIED ,
55- default => Icons::UNDEFINED
56- });
48+ $ content = new IconBall (
49+ match ($ item ->type ) {
50+ IncidentHistoryType::OPENED => Icons::OPENED ,
51+ IncidentHistoryType::MUTED => Icons::MUTE ,
52+ IncidentHistoryType::UNMUTED => Icons::UNMUTE ,
53+ IncidentHistoryType::RECIPIENT_ROLE_CHANGED => $ this ->getRoleIcon ($ item ),
54+ IncidentHistoryType::CLOSED => Icons::CLOSED ,
55+ IncidentHistoryType::RULE_MATCHED => Icons::RULE_MATCHED ,
56+ IncidentHistoryType::ESCALATION_TRIGGERED => Icons::TRIGGERED ,
57+ IncidentHistoryType::NOTIFIED => Icons::NOTIFIED
58+ }
59+ );
5760 }
5861
5962 $ visual ->addHtml ($ content );
@@ -119,18 +122,18 @@ protected function getRoleIcon(IncidentHistory $item): string
119122 protected function buildMessage (IncidentHistory $ item ): ValidHtml
120123 {
121124 switch ($ item ->type ) {
122- case ' opened ' :
125+ case IncidentHistoryType:: OPENED :
123126 $ message = sprintf (
124127 $ this ->translate ('Incident opened at severity %s ' ),
125128 $ item ->new_severity ->getLabel ()
126129 );
127130
128131 break ;
129- case ' closed ' :
132+ case IncidentHistoryType:: CLOSED :
130133 $ message = $ this ->translate ('Incident closed ' );
131134
132135 break ;
133- case " notified " :
136+ case IncidentHistoryType:: NOTIFIED :
134137 if (isset ($ item ->contactgroup ->name ) && isset ($ item ->contact ->full_name )) {
135138 if (isset ($ item ->channel ->type )) {
136139 $ message = sprintf (
@@ -200,15 +203,15 @@ protected function buildMessage(IncidentHistory $item): ValidHtml
200203 }
201204
202205 break ;
203- case ' incident_severity_changed ' :
206+ case IncidentHistoryType:: INCIDENT_SEVERITY_CHANGED :
204207 $ message = sprintf (
205208 $ this ->translate ('Incident severity changed from %s to %s ' ),
206209 $ item ->old_severity ->getLabel (),
207210 $ item ->new_severity ->getLabel ()
208211 );
209212
210213 break ;
211- case ' recipient_role_changed ' :
214+ case IncidentHistoryType:: RECIPIENT_ROLE_CHANGED :
212215 $ newRole = $ item ->new_recipient_role ;
213216 $ message = '' ;
214217 if ($ newRole === 'manager ' || (! $ newRole && $ item ->old_recipient_role === 'manager ' )) {
@@ -251,21 +254,23 @@ protected function buildMessage(IncidentHistory $item): ValidHtml
251254 }
252255
253256 break ;
254- case ' rule_matched ' :
257+ case IncidentHistoryType:: RULE_MATCHED :
255258 if (isset ($ item ->rule ->name )) {
256259 $ message = sprintf ($ this ->translate ('Rule %s matched on this incident ' ), $ item ->rule ->name );
257260 } else {
258261 $ message = $ this ->translate ('Unknown rule matched on this incident ' );
259262 }
260263
261264 break ;
262- case ' escalation_triggered ' :
265+ case IncidentHistoryType:: ESCALATION_TRIGGERED :
263266 if (isset ($ item ->rule ->name )) {
264- if (isset ($ item ->rule_escalation ->name )) {
267+ if (isset ($ item ->rule_escalation ->id )) {
265268 $ message = sprintf (
266269 $ this ->translate ('Rule %s reached escalation %s ' ),
267270 $ item ->rule ->name ,
271+ // An escalation is only named optionally, its condition describes it otherwise
268272 $ item ->rule_escalation ->name
273+ ?? EscalationConditionDescriber::describe ($ item ->rule_escalation ->condition )
269274 );
270275 } else {
271276 $ message = sprintf (
@@ -278,16 +283,14 @@ protected function buildMessage(IncidentHistory $item): ValidHtml
278283 }
279284
280285 break ;
281- case ' muted ' :
286+ case IncidentHistoryType:: MUTED :
282287 $ message = $ this ->translate ('Notifications for this incident have been muted ' );
283288
284289 break ;
285- case ' unmuted ' :
290+ case IncidentHistoryType:: UNMUTED :
286291 $ message = $ this ->translate ('Notifications for this incident have been unmuted ' );
287292
288293 break ;
289- default :
290- $ message = '' ;
291294 }
292295
293296 $ messageFromDb = $ item ->message ? ': ' . $ item ->message : '' ;
0 commit comments