From 95b9b731823c38f770007882b4b4dac26b4427e9 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 4 Jul 2024 16:16:18 +0200 Subject: [PATCH] incidents: Support notification suppression --- library/Notifications/Model/IncidentHistory.php | 2 ++ library/Notifications/Model/Objects.php | 4 +++- .../Widget/ItemList/IncidentHistoryListItem.php | 16 ++++++++++++++++ .../Widget/ItemList/IncidentListItem.php | 4 ++++ public/css/common.less | 5 ++--- public/css/detail/incident-detail.less | 4 ++++ 6 files changed, 31 insertions(+), 4 deletions(-) diff --git a/library/Notifications/Model/IncidentHistory.php b/library/Notifications/Model/IncidentHistory.php index 8cb4e0d6..320eb7cd 100644 --- a/library/Notifications/Model/IncidentHistory.php +++ b/library/Notifications/Model/IncidentHistory.php @@ -150,6 +150,8 @@ public static function translateNotificationState(string $state): string return t('failed', 'notifications.transmission.state'); case 'pending': return t('pending', 'notifications.transmission.state'); + case 'suppressed': + return t('suppressed', 'notifications.transmission.state'); default: return t('unknown', 'notifications.transmission.state'); } diff --git a/library/Notifications/Model/Objects.php b/library/Notifications/Model/Objects.php index 006a82e1..68d43e3b 100644 --- a/library/Notifications/Model/Objects.php +++ b/library/Notifications/Model/Objects.php @@ -22,6 +22,7 @@ * @property string $host * @property ?string $service * @property ?string $url + * @property ?string $mute_reason * * @property Query | Event $event * @property Query | Incident $incident @@ -48,7 +49,8 @@ public function getColumns() return [ 'source_id', 'name', - 'url' + 'url', + 'mute_reason' ]; } diff --git a/library/Notifications/Widget/ItemList/IncidentHistoryListItem.php b/library/Notifications/Widget/ItemList/IncidentHistoryListItem.php index 344cb373..ad98a90c 100644 --- a/library/Notifications/Widget/ItemList/IncidentHistoryListItem.php +++ b/library/Notifications/Widget/ItemList/IncidentHistoryListItem.php @@ -58,6 +58,10 @@ protected function getIncidentEventIcon(): string switch ($this->item->type) { case 'opened': return Icons::OPENED; + case 'muted': + return Icons::MUTE; + case 'unmuted': + return Icons::UNMUTE; case 'incident_severity_changed': return $this->getSeverityIcon(); case 'recipient_role_changed': @@ -180,6 +184,10 @@ protected function buildMessage(): string ); } + if ($this->item->notification_state === 'suppressed') { + $this->getAttributes()->add('class', 'notification-suppressed'); + } + break; case 'incident_severity_changed': $message = sprintf( @@ -251,6 +259,14 @@ protected function buildMessage(): string $this->item->rule_escalation->name ); + break; + case 'muted': + $message = t('Notifications for this incident have been muted'); + + break; + case 'unmuted': + $message = t('Notifications for this incident have been unmuted'); + break; default: $message = ''; diff --git a/library/Notifications/Widget/ItemList/IncidentListItem.php b/library/Notifications/Widget/ItemList/IncidentListItem.php index acf1bc9a..d4f010b2 100644 --- a/library/Notifications/Widget/ItemList/IncidentListItem.php +++ b/library/Notifications/Widget/ItemList/IncidentListItem.php @@ -79,6 +79,10 @@ protected function assembleHeader(BaseHtmlElement $header): void $header->add($this->createTitle()); $meta = new HtmlElement('span', Attributes::create(['class' => 'meta'])); + if ($this->item->severity !== 'ok' && $this->item->object->mute_reason !== null) { + $meta->addHtml(new Icon(Icons::MUTE, ['title' => $this->item->object->mute_reason])); + } + /** @var Source $source */ $source = $this->item->object->source; $meta->addHtml((new SourceIcon(SourceIcon::SIZE_BIG))->addHtml($source->getIcon())); diff --git a/public/css/common.less b/public/css/common.less index 10d6302c..db1959c8 100644 --- a/public/css/common.less +++ b/public/css/common.less @@ -99,8 +99,7 @@ .event-list .list-item, .incident-list .list-item { - .meta .source-icon { - margin-left: auto; + .meta > :not(:last-child) { margin-right: 0.5em; } -} \ No newline at end of file +} diff --git a/public/css/detail/incident-detail.less b/public/css/detail/incident-detail.less index db48aa8e..653911db 100644 --- a/public/css/detail/incident-detail.less +++ b/public/css/detail/incident-detail.less @@ -26,4 +26,8 @@ } } } + + .list-item.notification-suppressed { + opacity: .75; + } }