2727use Icinga \Module \Icingadb \Model \DependencyNode ;
2828use Icinga \Module \Icingadb \Model \Service ;
2929use Icinga \Module \Icingadb \Model \UnreachableParent ;
30+ use Icinga \Module \Icingadb \Notifications \IncidentFinder ;
3031use Icinga \Module \Icingadb \Redis \VolatileStateResults ;
3132use Icinga \Module \Icingadb \Web \Navigation \Action ;
3233use Icinga \Module \Icingadb \Widget \ItemList \ObjectList ;
@@ -381,7 +382,7 @@ protected function createNotes()
381382 return $ content ;
382383 }
383384
384- protected function createNotifications (): array
385+ protected function createConfiguredContacts (): array
385386 {
386387 [$ users , $ usergroups ] = $ this ->getUsersAndUsergroups ();
387388
@@ -399,8 +400,16 @@ protected function createNotifications(): array
399400 );
400401 }
401402
403+ if (
404+ Icinga::app ()->getModuleManager ()->hasEnabled ('notifications ' )
405+ && ! $ userList ->hasContent ()
406+ && ! $ usergroupList ->hasContent ()
407+ ) {
408+ return [];
409+ }
410+
402411 return [
403- Html::tag ('h2 ' , t ('Notifications ' )),
412+ Html::tag ('h2 ' , t ('Configured Contacts ' )),
404413 new HorizontalKeyValue (
405414 t ('Contacts ' ),
406415 $ userList ->hasContent () ? $ userList : new EmptyState (t ('No contacts configured. ' ))
@@ -414,6 +423,94 @@ protected function createNotifications(): array
414423 ];
415424 }
416425
426+ protected function createNotificationRecipients (): array
427+ {
428+ if (! Icinga::app ()->getModuleManager ()->hasEnabled ('notifications ' )) {
429+ return [];
430+ }
431+
432+ $ incidents = IncidentFinder::forObject ($ this ->object );
433+ if (! $ incidents ->hasIncident ()) {
434+ return [];
435+ }
436+
437+ $ recipientIcons = [
438+ 'contact ' => Icons::USER ,
439+ 'contactgroup ' => Icons::USERGROUP ,
440+ 'schedule ' => 'calendar ' ,
441+ ];
442+
443+ $ translatedTypes = [
444+ 'contact ' => t ('Contact ' ),
445+ 'contactgroup ' => t ('Contact Group ' ),
446+ 'schedule ' => t ('Schedule ' ),
447+ ];
448+
449+ $ subscribers = [];
450+ $ recipients = [];
451+ foreach ($ incidents as $ incident ) {
452+ foreach ($ incident ->getSubscribers () as $ subscriber ) {
453+ $ isManager = $ subscriber ['role ' ] === 'manager ' ;
454+ $ changedAt = DateFormatter::formatDateTime ($ subscriber ['roleChangedAt ' ]->getTimestamp ());
455+
456+ $ subscriberItem = Html::tag ('li ' , [
457+ 'title ' => $ isManager
458+ ? sprintf (t ('%s acknowledged on %s ' ), $ subscriber ['full_name ' ], $ changedAt )
459+ : sprintf (t ('%s subscribed on %s ' ), $ subscriber ['full_name ' ], $ changedAt )
460+ ], Text::create ($ subscriber ['full_name ' ]));
461+
462+ if ($ isManager ) {
463+ $ subscriberItem ->addHtml (
464+ Html::tag (
465+ 'span ' ,
466+ ['class ' => ['ack-badge ' ]],
467+ [
468+ new Icon ('check-circle ' ),
469+ Text::create ('ack ' )
470+ ]
471+ )
472+ );
473+ }
474+
475+ $ subscribers [] = $ subscriberItem ;
476+ }
477+
478+ foreach ($ incident ->getRecipients () as $ recipient ) {
479+ $ icon = new Icon ($ recipientIcons [$ recipient ['type ' ]]);
480+ $ name = $ recipient ['full_name ' ] ?? $ recipient ['name ' ];
481+ $ recipients [] = Html::tag (
482+ 'li ' ,
483+ [
484+ 'title ' => sprintf (
485+ '[%s] %s ' ,
486+ $ translatedTypes [$ recipient ['type ' ]],
487+ $ name
488+ )
489+ ],
490+ Html::tag (
491+ 'span ' ,
492+ ['class ' => 'recipient ' ],
493+ [$ icon , Text::create ($ name )]
494+ )
495+ );
496+ }
497+ }
498+
499+ $ subscribersValue = empty ($ subscribers )
500+ ? new EmptyState (t ('No subscribers. ' ))
501+ : Html::tag ('div ' , ['class ' => 'subscriber-list ' ], $ subscribers );
502+
503+ $ recipientsValue = empty ($ recipients )
504+ ? new EmptyState (t ('No recipients. ' ))
505+ : Html::tag ('div ' , ['class ' => 'recipient-list ' ], $ recipients );
506+
507+ return [
508+ Html::tag ('h2 ' , t ('Notification Recipients ' )),
509+ new HorizontalKeyValue (t ('Subscribers ' ), $ subscribersValue ),
510+ new HorizontalKeyValue (t ('Recipients ' ), $ recipientsValue ),
511+ ];
512+ }
513+
417514 protected function createPerformanceData (): array
418515 {
419516 $ content [] = Html::tag ('h2 ' , t ('Performance Data ' ));
0 commit comments