From a6a616a48798f50d4420100d9e7e33c8d585f2d2 Mon Sep 17 00:00:00 2001 From: christosku Date: Mon, 23 Oct 2023 16:20:10 +0200 Subject: [PATCH 1/7] Add Microsoft Teams notification channel --- config/health.php | 4 ++++ src/Notifications/CheckFailedNotification.php | 14 ++++++++++++++ src/Notifications/Notifiable.php | 5 +++++ 3 files changed, 23 insertions(+) diff --git a/config/health.php b/config/health.php index b6fc9873..5d43394c 100644 --- a/config/health.php +++ b/config/health.php @@ -78,6 +78,10 @@ 'icon' => null, ], + + 'microsoft_teams' => [ + 'webhook_url' => env('HEALTH_TEAMS_WEBHOOK_URL', ''), + ], ], /* diff --git a/src/Notifications/CheckFailedNotification.php b/src/Notifications/CheckFailedNotification.php index 0ac0c269..330f3155 100644 --- a/src/Notifications/CheckFailedNotification.php +++ b/src/Notifications/CheckFailedNotification.php @@ -90,6 +90,20 @@ public function toSlack(): SlackMessage return $slackMessage; } + public function toMicrosoftTeams(): MicrosoftTeamsMessage + { + $teamsMessage = (new MicrosoftTeamsMessage()) + ->type('error') + ->content(trans('health::notifications.check_failed_slack_message', $this->transParameters())); + + foreach ($this->results as $result) { + $teamsMessage->addStartGroupToSection(); + $teamsMessage->fact($result->check->getLabel(), $result->getNotificationMessage()); + } + + return $teamsMessage; + } + /** * @return array */ diff --git a/src/Notifications/Notifiable.php b/src/Notifications/Notifiable.php index 457c8a22..6a87a13c 100644 --- a/src/Notifications/Notifiable.php +++ b/src/Notifications/Notifiable.php @@ -19,6 +19,11 @@ public function routeNotificationForSlack(): string return config('health.notifications.slack.webhook_url'); } + public function routeNotificationForMicrosoftTeams(): string + { + return config('health.notifications.microsoft_teams.webhook_url'); + } + public function getKey(): int { return 1; From bc1be5ad118bf8d86bdf731beab896a7935e4e08 Mon Sep 17 00:00:00 2001 From: christosku Date: Mon, 23 Oct 2023 16:25:04 +0200 Subject: [PATCH 2/7] Rename the notification message key --- resources/lang/ar/notifications.php | 2 +- resources/lang/bg/notifications.php | 2 +- resources/lang/bn/notifications.php | 2 +- resources/lang/da/notifications.php | 2 +- resources/lang/de/notifications.php | 2 +- resources/lang/en/notifications.php | 2 +- resources/lang/es/notifications.php | 2 +- resources/lang/fa/notifications.php | 2 +- resources/lang/fr/notifications.php | 2 +- resources/lang/hi/notifications.php | 2 +- resources/lang/it/notifications.php | 2 +- resources/lang/nl/notifications.php | 2 +- resources/lang/pt/notifications.php | 2 +- resources/lang/ru/notifications.php | 2 +- resources/lang/sk/notifications.php | 2 +- resources/lang/tr/notifications.php | 2 +- src/Notifications/CheckFailedNotification.php | 4 ++-- 17 files changed, 18 insertions(+), 18 deletions(-) diff --git a/resources/lang/ar/notifications.php b/resources/lang/ar/notifications.php index 63999977..6a5a49c5 100644 --- a/resources/lang/ar/notifications.php +++ b/resources/lang/ar/notifications.php @@ -7,7 +7,7 @@ 'check_failed_mail_body' => 'التشخيصات التالية أبلغت عن تحذيرات و أخطاء', - 'check_failed_slack_message' => 'بعض التشخيصات في :application_name فشلت', + 'check_failed_notification_message' => 'بعض التشخيصات في :application_name فشلت', 'health_results' => 'نتائج التشخيص', diff --git a/resources/lang/bg/notifications.php b/resources/lang/bg/notifications.php index 401150ba..53889a2a 100644 --- a/resources/lang/bg/notifications.php +++ b/resources/lang/bg/notifications.php @@ -7,7 +7,7 @@ 'check_failed_mail_body' => 'Следните проверки съобщават за предупреждения и грешки:', - 'check_failed_slack_message' => 'Някои от проверките на здравето на :application_name са неуспешни.', + 'check_failed_notification_message' => 'Някои от проверките на здравето на :application_name са неуспешни.', 'health_results' => 'Резултати за проверка на здравето', diff --git a/resources/lang/bn/notifications.php b/resources/lang/bn/notifications.php index 1780f005..4e6300b1 100644 --- a/resources/lang/bn/notifications.php +++ b/resources/lang/bn/notifications.php @@ -7,7 +7,7 @@ 'check_failed_mail_body' => 'নিম্নলিখিত যাচাইকৃত সতর্কতা এবং ত্রুটি রিপোর্ট করা হয়েছে:', - 'check_failed_slack_message' => ':application_name এর কিছু স্বাস্থ্য পরীক্ষা ব্যর্থ হয়েছে।', + 'check_failed_notification_message' => ':application_name এর কিছু স্বাস্থ্য পরীক্ষা ব্যর্থ হয়েছে।', 'health_results' => 'স্বাস্থ্য পরীক্ষা ফলাফল', diff --git a/resources/lang/da/notifications.php b/resources/lang/da/notifications.php index da60731c..cf525167 100644 --- a/resources/lang/da/notifications.php +++ b/resources/lang/da/notifications.php @@ -7,7 +7,7 @@ 'check_failed_mail_body' => 'Følgende tjeks rapporterede advarsler og fejl:', - 'check_failed_slack_message' => 'Nogle tjeks på :application_name mislykkedes.', + 'check_failed_notification_message' => 'Nogle tjeks på :application_name mislykkedes.', 'health_results' => 'Health resultater', diff --git a/resources/lang/de/notifications.php b/resources/lang/de/notifications.php index dc76e60b..bda4822a 100644 --- a/resources/lang/de/notifications.php +++ b/resources/lang/de/notifications.php @@ -7,7 +7,7 @@ 'check_failed_mail_body' => 'Folgende Kontrollen haben Warnungen und Fehler gemeldet:', - 'check_failed_slack_message' => 'Einige Kontrollen für :application_name sind fehlgeschlagen.', + 'check_failed_notification_message' => 'Einige Kontrollen für :application_name sind fehlgeschlagen.', 'health_results' => 'Gesundheitsergebnisse', diff --git a/resources/lang/en/notifications.php b/resources/lang/en/notifications.php index c68a346c..e9d23743 100644 --- a/resources/lang/en/notifications.php +++ b/resources/lang/en/notifications.php @@ -7,7 +7,7 @@ 'check_failed_mail_body' => 'The following checks reported warnings and errors:', - 'check_failed_slack_message' => 'Some of the health checks on :application_name have failed.', + 'check_failed_notification_message' => 'Some of the health checks on :application_name have failed.', 'health_results' => 'Health Results', diff --git a/resources/lang/es/notifications.php b/resources/lang/es/notifications.php index 7f75108b..b6953d13 100644 --- a/resources/lang/es/notifications.php +++ b/resources/lang/es/notifications.php @@ -7,7 +7,7 @@ 'check_failed_mail_body' => 'Las siguientes validaciones reportaron warnings y errors:', - 'check_failed_slack_message' => 'Algunos de los chequeos en :application_name han fallado.', + 'check_failed_notification_message' => 'Algunos de los chequeos en :application_name han fallado.', 'health_results' => 'Resultados del chequeo', diff --git a/resources/lang/fa/notifications.php b/resources/lang/fa/notifications.php index 52599c51..d3abbeda 100644 --- a/resources/lang/fa/notifications.php +++ b/resources/lang/fa/notifications.php @@ -7,7 +7,7 @@ 'check_failed_mail_body' => 'موارد ذکر شده دارای خطا می باشد:', - 'check_failed_slack_message' => 'بررسی برخی موارد امنیتی در برنامه :application_name از نظر سلامت ناموفق بود', + 'check_failed_notification_message' => 'بررسی برخی موارد امنیتی در برنامه :application_name از نظر سلامت ناموفق بود', 'health_results' => 'گزارش وضعیت سلامت', diff --git a/resources/lang/fr/notifications.php b/resources/lang/fr/notifications.php index f987fc81..74b1c9c8 100644 --- a/resources/lang/fr/notifications.php +++ b/resources/lang/fr/notifications.php @@ -7,7 +7,7 @@ 'check_failed_mail_body' => 'Les tests suivants comportent des avertissements et des erreurs:', - 'check_failed_slack_message' => 'Certains tests de :application_name ont échoué.', + 'check_failed_notification_message' => 'Certains tests de :application_name ont échoué.', 'health_results' => 'Bilan de santé', diff --git a/resources/lang/hi/notifications.php b/resources/lang/hi/notifications.php index 55868635..63f1a65b 100644 --- a/resources/lang/hi/notifications.php +++ b/resources/lang/hi/notifications.php @@ -7,7 +7,7 @@ 'check_failed_mail_body' => 'निम्नलिखित जाँचों ने चेतावनी और त्रुटियों की सूचना दी:', - 'check_failed_slack_message' => ':application_name पर कुछ स्वास्थ्य जाँच विफल हो गई हैं।', + 'check_failed_notification_message' => ':application_name पर कुछ स्वास्थ्य जाँच विफल हो गई हैं।', 'health_results' => 'स्वास्थ्य जाँच के परिणाम', diff --git a/resources/lang/it/notifications.php b/resources/lang/it/notifications.php index 2616f5e6..7570d848 100644 --- a/resources/lang/it/notifications.php +++ b/resources/lang/it/notifications.php @@ -7,7 +7,7 @@ 'check_failed_mail_body' => 'I seguenti check hanno riportato warning o errori:', - 'check_failed_slack_message' => 'Alcuni check sulla saluta di :application_name sono falliti.', + 'check_failed_notification_message' => 'Alcuni check sulla saluta di :application_name sono falliti.', 'health_results' => 'Risultati check sulla salute', diff --git a/resources/lang/nl/notifications.php b/resources/lang/nl/notifications.php index 48680bc5..44c2be96 100644 --- a/resources/lang/nl/notifications.php +++ b/resources/lang/nl/notifications.php @@ -7,7 +7,7 @@ 'check_failed_mail_body' => 'De volgende health checks resulteerden in een warning of error:', - 'check_failed_slack_message' => 'Enkele van de health checks op :application_name faalden.', + 'check_failed_notification_message' => 'Enkele van de health checks op :application_name faalden.', 'health_results' => 'Health Results', diff --git a/resources/lang/pt/notifications.php b/resources/lang/pt/notifications.php index e2533c8a..2c61f4cb 100644 --- a/resources/lang/pt/notifications.php +++ b/resources/lang/pt/notifications.php @@ -7,7 +7,7 @@ 'check_failed_mail_body' => 'As seguintes verificações reportaram avisos e erros:', - 'check_failed_slack_message' => 'Falharam algumas verificações de saúde em :application_name .', + 'check_failed_notification_message' => 'Falharam algumas verificações de saúde em :application_name .', 'health_results' => 'Resultados da saúde', diff --git a/resources/lang/ru/notifications.php b/resources/lang/ru/notifications.php index e29681b2..72b83ba2 100644 --- a/resources/lang/ru/notifications.php +++ b/resources/lang/ru/notifications.php @@ -7,7 +7,7 @@ 'check_failed_mail_body' => 'Обнаружены следующие ошибки и предупреждения:', - 'check_failed_slack_message' => 'Во время проверки :application_name обнаружены ошибки.', + 'check_failed_notification_message' => 'Во время проверки :application_name обнаружены ошибки.', 'health_results' => 'Результаты проверки', diff --git a/resources/lang/sk/notifications.php b/resources/lang/sk/notifications.php index ecc1312e..39331199 100644 --- a/resources/lang/sk/notifications.php +++ b/resources/lang/sk/notifications.php @@ -7,7 +7,7 @@ 'check_failed_mail_body' => 'Nasledovné kontroly hlásených upozornení a chýb:', - 'check_failed_slack_message' => 'Niektoré kontroly stavu :application_name zlyhali.', + 'check_failed_notification_message' => 'Niektoré kontroly stavu :application_name zlyhali.', 'health_results' => 'Výsledky', diff --git a/resources/lang/tr/notifications.php b/resources/lang/tr/notifications.php index 9251193b..90609b0a 100644 --- a/resources/lang/tr/notifications.php +++ b/resources/lang/tr/notifications.php @@ -7,7 +7,7 @@ 'check_failed_mail_body' => 'Aşağıda belirtilen sağlik kontrolleri uyari veya hata verdi:', - 'check_failed_slack_message' => ':application_name isimli Uygulamada sağlık kontrolleri başarısız oldu.', + 'check_failed_notification_message' => ':application_name isimli Uygulamada sağlık kontrolleri başarısız oldu.', 'health_results' => 'Sağlık Durumu Raporu', diff --git a/src/Notifications/CheckFailedNotification.php b/src/Notifications/CheckFailedNotification.php index 330f3155..40909286 100644 --- a/src/Notifications/CheckFailedNotification.php +++ b/src/Notifications/CheckFailedNotification.php @@ -76,7 +76,7 @@ public function toSlack(): SlackMessage ->error() ->from(config('health.notifications.slack.username'), config('health.notifications.slack.icon')) ->to(config('health.notifications.slack.channel')) - ->content(trans('health::notifications.check_failed_slack_message', $this->transParameters())); + ->content(trans('health::notifications.check_failed_notification_message', $this->transParameters())); foreach ($this->results as $result) { $slackMessage->attachment(function (SlackAttachment $attachment) use ($result) { @@ -94,7 +94,7 @@ public function toMicrosoftTeams(): MicrosoftTeamsMessage { $teamsMessage = (new MicrosoftTeamsMessage()) ->type('error') - ->content(trans('health::notifications.check_failed_slack_message', $this->transParameters())); + ->content(trans('health::notifications.check_failed_notification_message', $this->transParameters())); foreach ($this->results as $result) { $teamsMessage->addStartGroupToSection(); From c4564b8942549c1fbdb4f8f89d32da1a08acde95 Mon Sep 17 00:00:00 2001 From: christosku Date: Tue, 24 Oct 2023 10:18:43 +0200 Subject: [PATCH 3/7] Add and modify documentation for Microsoft Teams --- README.md | 2 +- config/health.php | 3 +- docs/configuring-notifications/general.md | 1 + .../via-microsoft-teams.md | 32 +++++++++++++++++++ docs/installation-setup.md | 3 +- docs/introduction.md | 2 +- 6 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 docs/configuring-notifications/via-microsoft-teams.md diff --git a/README.md b/README.md index a1f57dc2..3c93fafa 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ Health::checks([ ]); ``` -When the used disk space is over 70%, then a notification with a warning will be sent. If it's above 90%, you'll get an error notification. Out of the box, the package can notify you via mail and Slack. +When the used disk space is over 70%, then a notification with a warning will be sent. If it's above 90%, you'll get an error notification. Out of the box, the package can notify you via mail, Slack and Microsoft Teams. ## Support us diff --git a/config/health.php b/config/health.php index 5d43394c..b5cafa0c 100644 --- a/config/health.php +++ b/config/health.php @@ -28,8 +28,9 @@ ], /* - * You can get notified when specific events occur. Out of the box you can use 'mail' and 'slack'. + * You can get notified when specific events occur. Out of the box you can use 'mail', 'slack' and 'microsoftTeams. * For Slack you need to install laravel/slack-notification-channel. + * For Microsoft Teams you need to install laravel-notification-channels/microsoft-teams. */ 'notifications' => [ /* diff --git a/docs/configuring-notifications/general.md b/docs/configuring-notifications/general.md index 4ceedadd..db05344c 100644 --- a/docs/configuring-notifications/general.md +++ b/docs/configuring-notifications/general.md @@ -9,6 +9,7 @@ Out of the box, the notification can be sent: - via [mail](/docs/laravel-health/v1/configuring-notifications/via-mail), - via [Slack](/docs/laravel-health/v1/configuring-notifications/via-slack) +- via [Microsoft Teams](/docs/laravel-health/v1/configuring-notifications/via-microsoft-teams) - via [Oh Dear](/docs/laravel-health/v1/configuring-notifications/via-oh-dear) (enables snoozing notifications, and delivery via Telegram, Discord, MS Teams, webhooks, ...) ## Throttling notifications diff --git a/docs/configuring-notifications/via-microsoft-teams.md b/docs/configuring-notifications/via-microsoft-teams.md new file mode 100644 index 00000000..a5c7ed9d --- /dev/null +++ b/docs/configuring-notifications/via-microsoft-teams.md @@ -0,0 +1,32 @@ +--- +title: Via Microsoft Teams +weight: 2 +--- + +When a check starts returning warnings or failures, you can get notified via Microsoft Teams. + +To use this channel, you must install the Microsoft Teams notification channel. + +```bash +composer require laravel-notification-channels/microsoft-teams +``` + +To do this you must set the `CheckFailedNotification` to use the `microsoftTeams` channel. This can be done in the config file. + +```php +// in config/health.php + +'notifications' => [ + Spatie\Health\Notifications\CheckFailedNotification::class => ['microsoftTeams'], +], +``` + +In the `microsoft_teams` key of the `health` config file, you can configure the webhook url for Teams. Set `HEALTH_TEAMS_WEBHOOK_URL` env variable with a valid Microsoft Teams webhook URL. You can learn how to get a webhook URL in the [Microsoft Teams Developer documentation](https://learn.microsoft.com/en-gb/microsoftteams/platform/webhooks-and-connectors/how-to/add-incoming-webhook). + +```php +// in config/health.php + +'microsoft_teams' => [ + 'webhook_url' => env('HEALTH_TEAMS_WEBHOOK_URL', ''), +], +``` diff --git a/docs/installation-setup.md b/docs/installation-setup.md index 34613c65..aaeabe92 100644 --- a/docs/installation-setup.md +++ b/docs/installation-setup.md @@ -48,8 +48,9 @@ return [ ], /* - * You can get notified when specific events occur. Out of the box you can use 'mail' and 'slack'. + * You can get notified when specific events occur. Out of the box you can use 'mail', 'slack' and 'microsoftTeams'. * For Slack you need to install laravel/slack-notification-channel. + * For Microsoft Teams you need to install laravel-notification-channels/microsoft-teams. */ 'notifications' => [ /* diff --git a/docs/introduction.md b/docs/introduction.md index 8035c7a9..082a3268 100644 --- a/docs/introduction.md +++ b/docs/introduction.md @@ -20,7 +20,7 @@ Health::checks([ ]); ``` -When the used disk space is over 70%, then a notification with a warning will be sent. If it's above 90%, you'll get an error notification. Out of the box, the package can notify you via mail and Slack. +When the used disk space is over 70%, then a notification with a warning will be sent. If it's above 90%, you'll get an error notification. Out of the box, the package can notify you via mail, Slack and Microsoft Teams. You'll find a [list of available checks](/docs/laravel-health/v1/available-checks/overview) here. Need a custom check? No problem, you [can create your own check](/docs/laravel-health/v1/basic-usage/creating-custom-checks) in no time. From de2393a57eec01bf2799ddf1e4c23e569254c70d Mon Sep 17 00:00:00 2001 From: christosku Date: Tue, 24 Oct 2023 10:20:24 +0200 Subject: [PATCH 4/7] Add laravel-notification-channels/microsoft-teams to composer.json --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index 2e208860..e774c590 100644 --- a/composer.json +++ b/composer.json @@ -33,6 +33,7 @@ "require-dev": { "laravel/horizon": "^5.9.10", "laravel/slack-notification-channel": "^2.4", + "laravel-notification-channels/microsoft-teams": "^1.1", "nunomaduro/collision": "^5.10|^6.2.1|^6.1", "nunomaduro/larastan": "^1.0.3|^2.4", "orchestra/testbench": "^6.23|^7.6|^8.0", From 456ed7b7f17289ba173611289d6bbebddfff08ff Mon Sep 17 00:00:00 2001 From: christosku Date: Tue, 24 Oct 2023 10:31:45 +0200 Subject: [PATCH 5/7] Add MicrosoftTeamsMessage recipient --- src/Notifications/CheckFailedNotification.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Notifications/CheckFailedNotification.php b/src/Notifications/CheckFailedNotification.php index 40909286..634483bc 100644 --- a/src/Notifications/CheckFailedNotification.php +++ b/src/Notifications/CheckFailedNotification.php @@ -94,6 +94,7 @@ public function toMicrosoftTeams(): MicrosoftTeamsMessage { $teamsMessage = (new MicrosoftTeamsMessage()) ->type('error') + ->to(config('health.notifications.microsoft_teams.webhook_url')) ->content(trans('health::notifications.check_failed_notification_message', $this->transParameters())); foreach ($this->results as $result) { From cbebbdbb2ebee7d04d675b1140624c678a6a80b8 Mon Sep 17 00:00:00 2001 From: christosku Date: Tue, 24 Oct 2023 10:34:07 +0200 Subject: [PATCH 6/7] Remove unnecessary addStartGroupToSection from MicrosoftTeamsMessage building --- src/Notifications/CheckFailedNotification.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Notifications/CheckFailedNotification.php b/src/Notifications/CheckFailedNotification.php index 634483bc..60640d83 100644 --- a/src/Notifications/CheckFailedNotification.php +++ b/src/Notifications/CheckFailedNotification.php @@ -98,7 +98,6 @@ public function toMicrosoftTeams(): MicrosoftTeamsMessage ->content(trans('health::notifications.check_failed_notification_message', $this->transParameters())); foreach ($this->results as $result) { - $teamsMessage->addStartGroupToSection(); $teamsMessage->fact($result->check->getLabel(), $result->getNotificationMessage()); } From 2449852df5c19e9f5007b0959dbe602c49c03976 Mon Sep 17 00:00:00 2001 From: christosku Date: Wed, 25 Oct 2023 09:40:59 +0200 Subject: [PATCH 7/7] Add missing import --- src/Notifications/CheckFailedNotification.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Notifications/CheckFailedNotification.php b/src/Notifications/CheckFailedNotification.php index 60640d83..9eb577b2 100644 --- a/src/Notifications/CheckFailedNotification.php +++ b/src/Notifications/CheckFailedNotification.php @@ -7,6 +7,7 @@ use Illuminate\Notifications\Messages\SlackAttachment; use Illuminate\Notifications\Messages\SlackMessage; use Illuminate\Notifications\Notification; +use NotificationChannels\MicrosoftTeams\MicrosoftTeamsMessage; use Spatie\Health\Checks\Result; use Spatie\Health\Enums\Status;