Skip to content

Commit d467e78

Browse files
Add Notification Recipients section
1 parent 6e2a092 commit d467e78

4 files changed

Lines changed: 130 additions & 4 deletions

File tree

library/Icingadb/Widget/Detail/HostDetail.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ protected function assemble()
5151
400 => $this->createComments(),
5252
401 => $this->createDowntimes(),
5353
500 => $this->createGroups(),
54-
501 => $this->createNotifications(),
54+
501 => $this->createNotificationRecipients(),
55+
502 => $this->createConfiguredContacts(),
5556
510 => $this->createAffectedObjects(),
5657
600 => $this->createCheckStatistics(),
5758
601 => $this->createPerformanceData(),

library/Icingadb/Widget/Detail/ObjectDetail.php

Lines changed: 99 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
use Icinga\Module\Icingadb\Model\DependencyNode;
2828
use Icinga\Module\Icingadb\Model\Service;
2929
use Icinga\Module\Icingadb\Model\UnreachableParent;
30+
use Icinga\Module\Icingadb\Notifications\IncidentFinder;
3031
use Icinga\Module\Icingadb\Redis\VolatileStateResults;
3132
use Icinga\Module\Icingadb\Web\Navigation\Action;
3233
use 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'));

library/Icingadb/Widget/Detail/ServiceDetail.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ protected function assemble()
2929
400 => $this->createComments(),
3030
401 => $this->createDowntimes(),
3131
500 => $this->createGroups(),
32-
501 => $this->createNotifications(),
32+
501 => $this->createNotificationRecipients(),
33+
502 => $this->createConfiguredContacts(),
3334
510 => $this->createAffectedObjects(),
3435
600 => $this->createCheckStatistics(),
3536
601 => $this->createPerformanceData(),
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// SPDX-FileCopyrightText: 2026 Icinga GmbH <https://icinga.com>
2+
// SPDX-License-Identifier: GPL-3.0-or-later
3+
4+
.recipient-list li, .subscriber-list li {
5+
display: inline-block;
6+
line-height: 2;
7+
8+
.ack-badge {
9+
margin-left: .25em;
10+
}
11+
12+
&:not(:last-child)::after {
13+
content: ',';
14+
margin-right: .25em;
15+
}
16+
}
17+
18+
.recipient-list .recipient {
19+
.rounded-corners(1em);
20+
padding: .25em .5em;
21+
background-color: @gray-lighter;
22+
white-space: nowrap;
23+
24+
i {
25+
color: @text-color-light;
26+
}
27+
}

0 commit comments

Comments
 (0)