Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Microsoft Teams notification functionality #199

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 6 additions & 1 deletion config/health.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => [
/*
Expand Down Expand Up @@ -78,6 +79,10 @@

'icon' => null,
],

'microsoft_teams' => [
'webhook_url' => env('HEALTH_TEAMS_WEBHOOK_URL', ''),
],
],

/*
Expand Down
1 change: 1 addition & 0 deletions docs/configuring-notifications/general.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 32 additions & 0 deletions docs/configuring-notifications/via-microsoft-teams.md
Original file line number Diff line number Diff line change
@@ -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', ''),
],
```
3 changes: 2 additions & 1 deletion docs/installation-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -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' => [
/*
Expand Down
2 changes: 1 addition & 1 deletion docs/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion resources/lang/ar/notifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

'check_failed_mail_body' => 'التشخيصات التالية أبلغت عن تحذيرات و أخطاء',

'check_failed_slack_message' => 'بعض التشخيصات في :application_name فشلت',
'check_failed_notification_message' => 'بعض التشخيصات في :application_name فشلت',

'health_results' => 'نتائج التشخيص',

Expand Down
2 changes: 1 addition & 1 deletion resources/lang/bg/notifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

'check_failed_mail_body' => 'Следните проверки съобщават за предупреждения и грешки:',

'check_failed_slack_message' => 'Някои от проверките на здравето на :application_name са неуспешни.',
'check_failed_notification_message' => 'Някои от проверките на здравето на :application_name са неуспешни.',

'health_results' => 'Резултати за проверка на здравето',

Expand Down
2 changes: 1 addition & 1 deletion resources/lang/bn/notifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

'check_failed_mail_body' => 'নিম্নলিখিত যাচাইকৃত সতর্কতা এবং ত্রুটি রিপোর্ট করা হয়েছে:',

'check_failed_slack_message' => ':application_name এর কিছু স্বাস্থ্য পরীক্ষা ব্যর্থ হয়েছে।',
'check_failed_notification_message' => ':application_name এর কিছু স্বাস্থ্য পরীক্ষা ব্যর্থ হয়েছে।',

'health_results' => 'স্বাস্থ্য পরীক্ষা ফলাফল',

Expand Down
2 changes: 1 addition & 1 deletion resources/lang/da/notifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',

Expand Down
2 changes: 1 addition & 1 deletion resources/lang/de/notifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',

Expand Down
2 changes: 1 addition & 1 deletion resources/lang/en/notifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',

Expand Down
2 changes: 1 addition & 1 deletion resources/lang/es/notifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',

Expand Down
2 changes: 1 addition & 1 deletion resources/lang/fa/notifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

'check_failed_mail_body' => 'موارد ذکر شده دارای خطا می باشد:',

'check_failed_slack_message' => 'بررسی برخی موارد امنیتی در برنامه :application_name از نظر سلامت ناموفق بود',
'check_failed_notification_message' => 'بررسی برخی موارد امنیتی در برنامه :application_name از نظر سلامت ناموفق بود',

'health_results' => 'گزارش وضعیت سلامت',

Expand Down
2 changes: 1 addition & 1 deletion resources/lang/fr/notifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -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é',

Expand Down
2 changes: 1 addition & 1 deletion resources/lang/hi/notifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

'check_failed_mail_body' => 'निम्नलिखित जाँचों ने चेतावनी और त्रुटियों की सूचना दी:',

'check_failed_slack_message' => ':application_name पर कुछ स्वास्थ्य जाँच विफल हो गई हैं।',
'check_failed_notification_message' => ':application_name पर कुछ स्वास्थ्य जाँच विफल हो गई हैं।',

'health_results' => 'स्वास्थ्य जाँच के परिणाम',

Expand Down
2 changes: 1 addition & 1 deletion resources/lang/it/notifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',

Expand Down
2 changes: 1 addition & 1 deletion resources/lang/nl/notifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',

Expand Down
2 changes: 1 addition & 1 deletion resources/lang/pt/notifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',

Expand Down
2 changes: 1 addition & 1 deletion resources/lang/ru/notifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

'check_failed_mail_body' => 'Обнаружены следующие ошибки и предупреждения:',

'check_failed_slack_message' => 'Во время проверки :application_name обнаружены ошибки.',
'check_failed_notification_message' => 'Во время проверки :application_name обнаружены ошибки.',

'health_results' => 'Результаты проверки',

Expand Down
2 changes: 1 addition & 1 deletion resources/lang/sk/notifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',

Expand Down
2 changes: 1 addition & 1 deletion resources/lang/tr/notifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',

Expand Down
17 changes: 16 additions & 1 deletion src/Notifications/CheckFailedNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -76,7 +77,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) {
Expand All @@ -90,6 +91,20 @@ public function toSlack(): SlackMessage
return $slackMessage;
}

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) {
$teamsMessage->fact($result->check->getLabel(), $result->getNotificationMessage());
}

return $teamsMessage;
}

/**
* @return array<string, string>
*/
Expand Down
5 changes: 5 additions & 0 deletions src/Notifications/Notifiable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down