From 62a034c0db85be5a876a8f4674357ecc2875ec1d Mon Sep 17 00:00:00 2001 From: Hosteroid Date: Thu, 12 Mar 2026 22:37:24 +0200 Subject: [PATCH] Limit Mattermost rich attachments to certain alerts Add a guard ($isRichAlert) so rich (green-bar) Mattermost attachments are only created for domain expiration/SSL/status alerts (days_left, expiration_date, new_status, or hostname != domain). DNS-change alerts remain plain text. Remove the attachment text property and adjust field handling accordingly to keep formatting consistent and avoid creating attachments for irrelevant events. --- app/Services/Channels/MattermostChannel.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/app/Services/Channels/MattermostChannel.php b/app/Services/Channels/MattermostChannel.php index 1d2f596..a0eb94b 100644 --- a/app/Services/Channels/MattermostChannel.php +++ b/app/Services/Channels/MattermostChannel.php @@ -28,8 +28,13 @@ class MattermostChannel implements NotificationChannelInterface 'text' => $message ]; - // Add attachments for richer formatting if domain data is available - if (isset($data['domain'])) { + // Add green-bar attachment only for expiration/SSL/status alerts, not for DNS change (plain text only) + $isRichAlert = isset($data['domain']) + && (array_key_exists('days_left', $data) + || array_key_exists('expiration_date', $data) + || isset($data['new_status']) + || (isset($data['hostname']) && $data['hostname'] !== $data['domain'])); + if ($isRichAlert) { $color = $this->getColorByDaysLeft($data['days_left'] ?? null); $title = $data['subject'] ?? '🔔 Domain Monitor Alert'; @@ -37,7 +42,6 @@ class MattermostChannel implements NotificationChannelInterface ['short' => true, 'title' => 'Domain', 'value' => $data['domain']] ]; - // Only add expiration fields for domain expiration alerts if (array_key_exists('days_left', $data) || array_key_exists('expiration_date', $data)) { $fields[] = ['short' => true, 'title' => 'Days Left', 'value' => (string) ($data['days_left'] ?? 'N/A')]; $fields[] = ['short' => true, 'title' => 'Expiration Date', 'value' => $data['expiration_date'] ?? 'N/A']; @@ -53,7 +57,6 @@ class MattermostChannel implements NotificationChannelInterface [ 'color' => $color, 'title' => $title, - 'text' => $message, 'fields' => $fields, 'footer' => 'Domain Monitor', 'ts' => time()