From b60d44783f3b3bdaf2ef18ed060244195ea5e975 Mon Sep 17 00:00:00 2001 From: Zao Soula Date: Thu, 18 Apr 2024 21:53:25 +0200 Subject: [PATCH] feat: add pushover notifications --- app/Console/Commands/NotifyDemo.php | 3 +- app/Jobs/SendMessageToPushoverJob.php | 65 ++++++++++++++++++ app/Livewire/Notifications/Pushover.php | 66 +++++++++++++++++++ app/Models/Team.php | 16 ++++- .../Application/DeploymentFailed.php | 19 ++++++ .../Application/DeploymentSuccess.php | 31 +++++++++ .../Application/StatusChanged.php | 14 ++++ .../Channels/PushoverChannel.php | 24 +++++++ app/Notifications/Channels/SendsPushover.php | 8 +++ .../Container/ContainerRestarted.php | 19 ++++++ .../Container/ContainerStopped.php | 19 ++++++ app/Notifications/Database/BackupFailed.php | 10 ++- app/Notifications/Database/BackupSuccess.php | 7 ++ app/Notifications/Database/DailyBackup.php | 10 ++- .../Internal/GeneralNotification.php | 12 ++++ app/Notifications/Server/DockerCleanup.php | 12 ++++ app/Notifications/Server/ForceDisabled.php | 12 ++++ app/Notifications/Server/ForceEnabled.php | 12 ++++ app/Notifications/Server/HighDiskUsage.php | 12 ++++ app/Notifications/Server/Revived.php | 12 ++++ app/Notifications/Server/Unreachable.php | 12 ++++ app/Notifications/Test.php | 14 ++++ bootstrap/helpers/shared.php | 7 ++ ...825_add_pushover_notifications_to_team.php | 34 ++++++++++ .../components/notification/navbar.blade.php | 4 ++ .../livewire/notifications/pushover.blade.php | 39 +++++++++++ routes/web.php | 2 + 27 files changed, 489 insertions(+), 6 deletions(-) create mode 100644 app/Jobs/SendMessageToPushoverJob.php create mode 100644 app/Livewire/Notifications/Pushover.php create mode 100644 app/Notifications/Channels/PushoverChannel.php create mode 100644 app/Notifications/Channels/SendsPushover.php create mode 100644 database/migrations/2024_04_18_183825_add_pushover_notifications_to_team.php create mode 100644 resources/views/livewire/notifications/pushover.blade.php diff --git a/app/Console/Commands/NotifyDemo.php b/app/Console/Commands/NotifyDemo.php index 72e4a37e68..45b269ad73 100644 --- a/app/Console/Commands/NotifyDemo.php +++ b/app/Console/Commands/NotifyDemo.php @@ -62,6 +62,7 @@ private function showHelp()
  • slack
  • discord
  • telegram
  • +
  • pushover
  • @@ -72,6 +73,6 @@ private function showHelp()
    In which manner you wish a coolified notification?
    - HTML, ['email', 'slack', 'discord', 'telegram']); + HTML, ['email', 'slack', 'discord', 'telegram', 'pushover']); } } diff --git a/app/Jobs/SendMessageToPushoverJob.php b/app/Jobs/SendMessageToPushoverJob.php new file mode 100644 index 0000000000..9f887637f2 --- /dev/null +++ b/app/Jobs/SendMessageToPushoverJob.php @@ -0,0 +1,65 @@ +".$this->text."

    "; + + if (!empty($this->buttons)) { + foreach ($this->buttons as $button) { + $buttonUrl = data_get($button, 'url'); + $text = data_get($button, 'text', 'Click here'); + if ($buttonUrl && Str::contains($buttonUrl, 'http://localhost')) { + $buttonUrl = str_replace('http://localhost', config('app.url'), $buttonUrl); + } + $message .= " ".$text.""; + } + } + + $payload = [ + 'token' => $this->token, + 'user' => $this->user, + 'message' => $message, + 'html' => 1 + ]; + ray($payload); + Http::post("https://api.pushover.net/1/messages.json", $payload); + } +} diff --git a/app/Livewire/Notifications/Pushover.php b/app/Livewire/Notifications/Pushover.php new file mode 100644 index 0000000000..df683f80b4 --- /dev/null +++ b/app/Livewire/Notifications/Pushover.php @@ -0,0 +1,66 @@ + 'nullable|boolean', + 'team.pushover_token' => 'required|string', + 'team.pushover_user' => 'required|string', + 'team.pushover_notifications_test' => 'nullable|boolean', + 'team.pushover_notifications_deployments' => 'nullable|boolean', + 'team.pushover_notifications_status_changes' => 'nullable|boolean', + 'team.pushover_notifications_database_backups' => 'nullable|boolean', + ]; + protected $validationAttributes = [ + 'team.pushover_token' => 'Token', + 'team.pushover_user' => 'User Key', + ]; + + public function mount() + { + $this->team = auth()->user()->currentTeam(); + } + public function instantSave() + { + try { + $this->submit(); + } catch (\Throwable $e) { + ray($e->getMessage()); + $this->team->pushover_enabled = false; + $this->validate(); + } + } + + public function submit() + { + $this->resetErrorBag(); + $this->validate(); + $this->saveModel(); + } + + public function saveModel() + { + $this->team->save(); + refreshSession(); + $this->dispatch('success', 'Settings saved.'); + } + + public function sendTestNotification() + { + $this->team?->notify(new Test()); + $this->dispatch('success', 'Test notification sent.'); + } + public function render() + { + return view('livewire.notifications.pushover'); + } +} diff --git a/app/Models/Team.php b/app/Models/Team.php index 29e434a5d2..a707022529 100644 --- a/app/Models/Team.php +++ b/app/Models/Team.php @@ -4,11 +4,12 @@ use App\Notifications\Channels\SendsDiscord; use App\Notifications\Channels\SendsEmail; +use App\Notifications\Channels\SendsPushover; use Illuminate\Database\Eloquent\Casts\Attribute; use Illuminate\Database\Eloquent\Model; use Illuminate\Notifications\Notifiable; -class Team extends Model implements SendsDiscord, SendsEmail +class Team extends Model implements SendsDiscord, SendsEmail, SendsPushover { use Notifiable; @@ -37,7 +38,15 @@ public function routeNotificationForTelegram() { return [ "token" => data_get($this, 'telegram_token', null), - "chat_id" => data_get($this, 'telegram_chat_id', null), + "user_key" => data_get($this, 'telegram_user_key', null), + ]; + } + + public function routeNotificationForPushover() + { + return [ + "token" => data_get($this, 'pushover_token', null), + "user" => data_get($this, 'pushover_user', null), ]; } @@ -179,7 +188,8 @@ public function isAnyNotificationEnabled() if (isCloud()) { return true; } - if ($this->smtp_enabled || $this->resend_enabled || $this->discord_enabled || $this->telegram_enabled || $this->use_instance_email_settings) { + + if ($this->smtp_enabled || $this->resend_enabled || $this->discord_enabled || $this->telegram_enabled || $this->pushover_enabled || $this->use_instance_email_settings) { return true; } return false; diff --git a/app/Notifications/Application/DeploymentFailed.php b/app/Notifications/Application/DeploymentFailed.php index 1705deda18..84e14cd0d4 100644 --- a/app/Notifications/Application/DeploymentFailed.php +++ b/app/Notifications/Application/DeploymentFailed.php @@ -95,4 +95,23 @@ public function toTelegram(): array ], ]; } + + public function toPushover(): array + { + if ($this->preview) { + $message = 'Coolify: Pull request #' . $this->preview->pull_request_id . ' of **' . $this->application_name . '** (' . $this->preview->fqdn . ') deployment failed: '; + } else { + $message = 'Coolify: Deployment failed of **' . $this->application_name . '** (' . $this->fqdn . '): '; + } + $buttons[] = [ + "text" => "Deployment logs", + "url" => $this->deployment_url + ]; + return [ + "message" => $message, + "buttons" => [ + ...$buttons + ], + ]; + } } diff --git a/app/Notifications/Application/DeploymentSuccess.php b/app/Notifications/Application/DeploymentSuccess.php index 322df5cec1..6d3a87f80c 100644 --- a/app/Notifications/Application/DeploymentSuccess.php +++ b/app/Notifications/Application/DeploymentSuccess.php @@ -123,4 +123,35 @@ public function toTelegram(): array ], ]; } + + public function toPushover(): array + { + if ($this->preview) { + $message = 'Coolify: New PR' . $this->preview->pull_request_id . ' version successfully deployed of ' . $this->application_name . ''; + if ($this->preview->fqdn) { + $buttons[] = [ + "text" => "Open Application", + "url" => $this->preview->fqdn + ]; + } + } else { + $message = '✅ New version successfully deployed of ' . $this->application_name . ''; + if ($this->fqdn) { + $buttons[] = [ + "text" => "Open Application", + "url" => $this->fqdn + ]; + } + } + $buttons[] = [ + "text" => "Deployment logs", + "url" => $this->deployment_url + ]; + return [ + "message" => $message, + "buttons" => [ + ...$buttons + ], + ]; + } } diff --git a/app/Notifications/Application/StatusChanged.php b/app/Notifications/Application/StatusChanged.php index 3d3b042ddd..1eab0638f7 100644 --- a/app/Notifications/Application/StatusChanged.php +++ b/app/Notifications/Application/StatusChanged.php @@ -73,4 +73,18 @@ public function toTelegram(): array ], ]; } + + public function toPushover(): array + { + $message = 'Coolify: ' . $this->resource_name . ' has been stopped.'; + return [ + "message" => $message, + "buttons" => [ + [ + "text" => "Open Application in Coolify", + "url" => $this->resource_url + ] + ], + ]; + } } diff --git a/app/Notifications/Channels/PushoverChannel.php b/app/Notifications/Channels/PushoverChannel.php new file mode 100644 index 0000000000..9a6df9a862 --- /dev/null +++ b/app/Notifications/Channels/PushoverChannel.php @@ -0,0 +1,24 @@ +toPushover($notifiable); + $pushoverData = $notifiable->routeNotificationForPushover(); + $message = data_get($data, 'message'); + $buttons = data_get($data, 'buttons', []); + $pushoverToken = data_get($pushoverData, 'token'); + $pushoverUser = data_get($pushoverData, 'user'); + + if (!$pushoverToken || !$pushoverUser || !$message) { + return; + } + dispatch(new SendMessageToPushoverJob($message, $buttons, $pushoverToken, $pushoverUser)); + } +} diff --git a/app/Notifications/Channels/SendsPushover.php b/app/Notifications/Channels/SendsPushover.php new file mode 100644 index 0000000000..7922eefb44 --- /dev/null +++ b/app/Notifications/Channels/SendsPushover.php @@ -0,0 +1,8 @@ +name}) has been restarted automatically on {$this->server->name}"; + $payload = [ + "message" => $message, + ]; + if ($this->url) { + $payload['buttons'] = [ + [ + [ + "text" => "Check Proxy in Coolify", + "url" => $this->url + ] + ] + ]; + }; + return $payload; + } } diff --git a/app/Notifications/Container/ContainerStopped.php b/app/Notifications/Container/ContainerStopped.php index 7bab749346..498741539e 100644 --- a/app/Notifications/Container/ContainerStopped.php +++ b/app/Notifications/Container/ContainerStopped.php @@ -58,4 +58,23 @@ public function toTelegram(): array } return $payload; } + + public function toPushover(): array + { + $message = "Coolify: A resource ($this->name) has been stopped unexpectedly on {$this->server->name}"; + $payload = [ + "message" => $message, + ]; + if ($this->url) { + $payload['buttons'] = [ + [ + [ + "text" => "Open Application in Coolify", + "url" => $this->url + ] + ] + ]; + } + return $payload; + } } diff --git a/app/Notifications/Database/BackupFailed.php b/app/Notifications/Database/BackupFailed.php index 3aa63ffd95..ce2518eecf 100644 --- a/app/Notifications/Database/BackupFailed.php +++ b/app/Notifications/Database/BackupFailed.php @@ -4,6 +4,7 @@ use App\Models\ScheduledDatabaseBackup; use App\Notifications\Channels\DiscordChannel; +use App\Notifications\Channels\PushoverChannel; use App\Notifications\Channels\TelegramChannel; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; @@ -29,7 +30,7 @@ public function __construct(ScheduledDatabaseBackup $backup, public $database, p public function via(object $notifiable): array { - return [DiscordChannel::class, TelegramChannel::class, MailChannel::class]; + return [DiscordChannel::class, TelegramChannel::class, MailChannel::class, PushoverChannel::class]; } public function toMail(): MailMessage @@ -56,4 +57,11 @@ public function toTelegram(): array "message" => $message, ]; } + + public function toPushover(): array + { + return [ + "message" => "Coolify: Database backup for {$this->name} with frequency of {$this->frequency} was FAILED.\n\nReason: {$this->output}", + ]; + } } diff --git a/app/Notifications/Database/BackupSuccess.php b/app/Notifications/Database/BackupSuccess.php index 9ca3234e1a..757e901685 100644 --- a/app/Notifications/Database/BackupSuccess.php +++ b/app/Notifications/Database/BackupSuccess.php @@ -52,4 +52,11 @@ public function toTelegram(): array "message" => $message, ]; } + + public function toPushover(): array + { + return [ + "message" => "Coolify: Database backup for {$this->name} with frequency of {$this->frequency} was successful.", + ]; + } } diff --git a/app/Notifications/Database/DailyBackup.php b/app/Notifications/Database/DailyBackup.php index dfa508fbd9..25218ea844 100644 --- a/app/Notifications/Database/DailyBackup.php +++ b/app/Notifications/Database/DailyBackup.php @@ -4,6 +4,7 @@ use App\Models\ScheduledDatabaseBackup; use App\Notifications\Channels\DiscordChannel; +use App\Notifications\Channels\PushoverChannel; use App\Notifications\Channels\TelegramChannel; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; @@ -23,7 +24,7 @@ public function __construct(public $databases) public function via(object $notifiable): array { - return [DiscordChannel::class, TelegramChannel::class, MailChannel::class]; + return [DiscordChannel::class, TelegramChannel::class, MailChannel::class, PushoverChannel::class]; } public function toMail(): MailMessage @@ -47,4 +48,11 @@ public function toTelegram(): array "message" => $message, ]; } + + public function toPushover(): array + { + return [ + "message" => "Coolify: Daily backup statuses", + ]; + } } diff --git a/app/Notifications/Internal/GeneralNotification.php b/app/Notifications/Internal/GeneralNotification.php index ddb5a553d3..e02454c4e1 100644 --- a/app/Notifications/Internal/GeneralNotification.php +++ b/app/Notifications/Internal/GeneralNotification.php @@ -3,6 +3,7 @@ namespace App\Notifications\Internal; use App\Notifications\Channels\DiscordChannel; +use App\Notifications\Channels\PushoverChannel; use App\Notifications\Channels\TelegramChannel; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; @@ -22,6 +23,7 @@ public function via(object $notifiable): array $channels = []; $isDiscordEnabled = data_get($notifiable, 'discord_enabled'); $isTelegramEnabled = data_get($notifiable, 'telegram_enabled'); + $isPushoverEnabled = data_get($notifiable, 'pushover_enabled'); if ($isDiscordEnabled) { $channels[] = DiscordChannel::class; @@ -29,6 +31,9 @@ public function via(object $notifiable): array if ($isTelegramEnabled) { $channels[] = TelegramChannel::class; } + if ($isPushoverEnabled) { + $channels[] = PushoverChannel::class; + } return $channels; } @@ -42,4 +47,11 @@ public function toTelegram(): array "message" => $this->message, ]; } + + public function toPushover(): array + { + return [ + "message" => $this->message, + ]; + } } diff --git a/app/Notifications/Server/DockerCleanup.php b/app/Notifications/Server/DockerCleanup.php index 754287fa18..f45e4f8b5d 100644 --- a/app/Notifications/Server/DockerCleanup.php +++ b/app/Notifications/Server/DockerCleanup.php @@ -3,6 +3,7 @@ namespace App\Notifications\Server; use App\Models\Server; +use App\Notifications\Channels\PushoverChannel; use Illuminate\Bus\Queueable; use App\Notifications\Channels\DiscordChannel; use App\Notifications\Channels\TelegramChannel; @@ -24,6 +25,7 @@ public function via(object $notifiable): array // $isEmailEnabled = isEmailEnabled($notifiable); $isDiscordEnabled = data_get($notifiable, 'discord_enabled'); $isTelegramEnabled = data_get($notifiable, 'telegram_enabled'); + $isPushoverEnabled = data_get($notifiable, 'pushover_enabled'); if ($isDiscordEnabled) { $channels[] = DiscordChannel::class; @@ -34,6 +36,9 @@ public function via(object $notifiable): array if ($isTelegramEnabled) { $channels[] = TelegramChannel::class; } + if ($isPushoverEnabled) { + $channels[] = PushoverChannel::class; + } return $channels; } @@ -60,4 +65,11 @@ public function toTelegram(): array "message" => "Coolify: Server '{$this->server->name}' cleanup job done!\n\n{$this->message}" ]; } + + public function toPushover(): array + { + return [ + "message" => "Coolify: Server '{$this->server->name}' cleanup job done!\n\n{$this->message}" + ]; + } } diff --git a/app/Notifications/Server/ForceDisabled.php b/app/Notifications/Server/ForceDisabled.php index 4bce44e466..6ad21abf83 100644 --- a/app/Notifications/Server/ForceDisabled.php +++ b/app/Notifications/Server/ForceDisabled.php @@ -3,6 +3,7 @@ namespace App\Notifications\Server; use App\Models\Server; +use App\Notifications\Channels\PushoverChannel; use Illuminate\Bus\Queueable; use App\Notifications\Channels\DiscordChannel; use App\Notifications\Channels\EmailChannel; @@ -26,6 +27,7 @@ public function via(object $notifiable): array $isEmailEnabled = isEmailEnabled($notifiable); $isDiscordEnabled = data_get($notifiable, 'discord_enabled'); $isTelegramEnabled = data_get($notifiable, 'telegram_enabled'); + $isPushoverEnabled = data_get($notifiable, 'pushover_enabled'); if ($isDiscordEnabled) { $channels[] = DiscordChannel::class; @@ -36,6 +38,9 @@ public function via(object $notifiable): array if ($isTelegramEnabled) { $channels[] = TelegramChannel::class; } + if ($isPushoverEnabled) { + $channels[] = PushoverChannel::class; + } return $channels; } @@ -60,4 +65,11 @@ public function toTelegram(): array "message" => "Coolify: Server ({$this->server->name}) disabled because it is not paid!\n All automations and integrations are stopped.\nPlease update your subscription to enable the server again [here](https://app.coolify.io/subsciprtions)." ]; } + + public function toPushover(): array + { + return [ + "message" => "Coolify: Server ({$this->server->name}) disabled because it is not paid!\n All automations and integrations are stopped.\nPlease update your subscription to enable the server again [here](https://app.coolify.io/subsciprtions)." + ]; + } } diff --git a/app/Notifications/Server/ForceEnabled.php b/app/Notifications/Server/ForceEnabled.php index c29a086440..bb77772707 100644 --- a/app/Notifications/Server/ForceEnabled.php +++ b/app/Notifications/Server/ForceEnabled.php @@ -3,6 +3,7 @@ namespace App\Notifications\Server; use App\Models\Server; +use App\Notifications\Channels\PushoverChannel; use Illuminate\Bus\Queueable; use App\Notifications\Channels\DiscordChannel; use App\Notifications\Channels\EmailChannel; @@ -26,6 +27,7 @@ public function via(object $notifiable): array $isEmailEnabled = isEmailEnabled($notifiable); $isDiscordEnabled = data_get($notifiable, 'discord_enabled'); $isTelegramEnabled = data_get($notifiable, 'telegram_enabled'); + $isPushoverEnabled = data_get($notifiable, 'pushover_enabled'); if ($isDiscordEnabled) { $channels[] = DiscordChannel::class; @@ -36,6 +38,9 @@ public function via(object $notifiable): array if ($isTelegramEnabled) { $channels[] = TelegramChannel::class; } + if ($isPushoverEnabled) { + $channels[] = PushoverChannel::class; + } return $channels; } @@ -60,4 +65,11 @@ public function toTelegram(): array "message" => "Coolify: Server ({$this->server->name}) enabled again!" ]; } + + public function toPushover(): array + { + return [ + "message" => "Coolify: Server ({$this->server->name}) enabled again!" + ]; + } } diff --git a/app/Notifications/Server/HighDiskUsage.php b/app/Notifications/Server/HighDiskUsage.php index 33e49387e0..a78f47265f 100644 --- a/app/Notifications/Server/HighDiskUsage.php +++ b/app/Notifications/Server/HighDiskUsage.php @@ -3,6 +3,7 @@ namespace App\Notifications\Server; use App\Models\Server; +use App\Notifications\Channels\PushoverChannel; use Illuminate\Bus\Queueable; use App\Notifications\Channels\DiscordChannel; use App\Notifications\Channels\EmailChannel; @@ -26,6 +27,7 @@ public function via(object $notifiable): array $isEmailEnabled = isEmailEnabled($notifiable); $isDiscordEnabled = data_get($notifiable, 'discord_enabled'); $isTelegramEnabled = data_get($notifiable, 'telegram_enabled'); + $isPushoverEnabled = data_get($notifiable, 'pushover_enabled'); if ($isDiscordEnabled) { $channels[] = DiscordChannel::class; @@ -36,6 +38,9 @@ public function via(object $notifiable): array if ($isTelegramEnabled) { $channels[] = TelegramChannel::class; } + if ($isPushoverEnabled) { + $channels[] = PushoverChannel::class; + } return $channels; } @@ -62,4 +67,11 @@ public function toTelegram(): array "message" => "Coolify: Server '{$this->server->name}' high disk usage detected!\nDisk usage: {$this->disk_usage}%. Threshold: {$this->cleanup_after_percentage}%.\nPlease cleanup your disk to prevent data-loss.\nHere are some tips: https://coolify.io/docs/knowledge-base/server/automated-cleanup." ]; } + + public function toPushover(): array + { + return [ + "message" => "Coolify: Server '{$this->server->name}' high disk usage detected!\nDisk usage: {$this->disk_usage}%. Threshold: {$this->cleanup_after_percentage}%.\nPlease cleanup your disk to prevent data-loss.\nHere are some tips: https://coolify.io/docs/knowledge-base/server/automated-cleanup." + ]; + } } diff --git a/app/Notifications/Server/Revived.php b/app/Notifications/Server/Revived.php index c670ded9a2..74dedfd2a1 100644 --- a/app/Notifications/Server/Revived.php +++ b/app/Notifications/Server/Revived.php @@ -4,6 +4,7 @@ use App\Jobs\ContainerStatusJob; use App\Models\Server; +use App\Notifications\Channels\PushoverChannel; use Illuminate\Bus\Queueable; use App\Notifications\Channels\DiscordChannel; use App\Notifications\Channels\EmailChannel; @@ -31,6 +32,7 @@ public function via(object $notifiable): array $isEmailEnabled = isEmailEnabled($notifiable); $isDiscordEnabled = data_get($notifiable, 'discord_enabled'); $isTelegramEnabled = data_get($notifiable, 'telegram_enabled'); + $isPushoverEnabled = data_get($notifiable, 'pushover_enabled'); if ($isDiscordEnabled) { $channels[] = DiscordChannel::class; @@ -41,6 +43,9 @@ public function via(object $notifiable): array if ($isTelegramEnabled) { $channels[] = TelegramChannel::class; } + if ($isPushoverEnabled) { + $channels[] = PushoverChannel::class; + } return $channels; } @@ -65,4 +70,11 @@ public function toTelegram(): array "message" => "Coolify: Server '{$this->server->name}' revived. All automations & integrations are turned on again!" ]; } + + public function toPushover(): array + { + return [ + "message" => "Coolify: Server '{$this->server->name}' revived. All automations & integrations are turned on again!" + ]; + } } diff --git a/app/Notifications/Server/Unreachable.php b/app/Notifications/Server/Unreachable.php index bfd862993b..999e0ad825 100644 --- a/app/Notifications/Server/Unreachable.php +++ b/app/Notifications/Server/Unreachable.php @@ -5,6 +5,7 @@ use App\Models\Server; use App\Notifications\Channels\DiscordChannel; use App\Notifications\Channels\EmailChannel; +use App\Notifications\Channels\PushoverChannel; use App\Notifications\Channels\TelegramChannel; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; @@ -27,6 +28,7 @@ public function via(object $notifiable): array $isEmailEnabled = isEmailEnabled($notifiable); $isDiscordEnabled = data_get($notifiable, 'discord_enabled'); $isTelegramEnabled = data_get($notifiable, 'telegram_enabled'); + $isPushoverEnabled = data_get($notifiable, 'pushover_enabled'); if ($isDiscordEnabled) { $channels[] = DiscordChannel::class; @@ -37,6 +39,9 @@ public function via(object $notifiable): array if ($isTelegramEnabled) { $channels[] = TelegramChannel::class; } + if ($isPushoverEnabled) { + $channels[] = PushoverChannel::class; + } return $channels; } @@ -61,4 +66,11 @@ public function toTelegram(): array "message" => "Coolify: Your server '{$this->server->name}' is unreachable. All automations & integrations are turned off! Please check your server! IMPORTANT: We automatically try to revive your server and turn on all automations & integrations." ]; } + + public function toPushover(): array + { + return [ + "message" => "Coolify: Your server '{$this->server->name}' is unreachable. All automations & integrations are turned off! Please check your server! IMPORTANT: We automatically try to revive your server and turn on all automations & integrations." + ]; + } } diff --git a/app/Notifications/Test.php b/app/Notifications/Test.php index 06e3adbaa8..eccbc5f151 100644 --- a/app/Notifications/Test.php +++ b/app/Notifications/Test.php @@ -6,6 +6,7 @@ use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Notifications\Notification; +use Illuminate\Support\Facades\Log; class Test extends Notification implements ShouldQueue { @@ -48,4 +49,17 @@ public function toTelegram(): array ], ]; } + + public function toPushover(): array + { + return [ + "message" => 'Coolify: This is a test Pushover notification from Coolify.', + "buttons" => [ + [ + "text" => "Go to your dashboard", + "url" => base_url() + ] + ], + ]; + } } diff --git a/bootstrap/helpers/shared.php b/bootstrap/helpers/shared.php index b2c34900e4..67aadc5632 100644 --- a/bootstrap/helpers/shared.php +++ b/bootstrap/helpers/shared.php @@ -23,6 +23,7 @@ use App\Models\User; use App\Notifications\Channels\DiscordChannel; use App\Notifications\Channels\EmailChannel; +use App\Notifications\Channels\PushoverChannel; use App\Notifications\Channels\TelegramChannel; use App\Notifications\Internal\GeneralNotification; use DanHarrin\LivewireRateLimiting\Exceptions\TooManyRequestsException; @@ -378,9 +379,11 @@ function setNotificationChannels($notifiable, $event) $isEmailEnabled = isEmailEnabled($notifiable); $isDiscordEnabled = data_get($notifiable, 'discord_enabled'); $isTelegramEnabled = data_get($notifiable, 'telegram_enabled'); + $isPushoverEnabled = data_get($notifiable, 'pushover_enabled'); $isSubscribedToEmailEvent = data_get($notifiable, "smtp_notifications_$event"); $isSubscribedToDiscordEvent = data_get($notifiable, "discord_notifications_$event"); $isSubscribedToTelegramEvent = data_get($notifiable, "telegram_notifications_$event"); + $isSubscribedToPushoverEvent = data_get($notifiable, "pushover_notifications_$event"); if ($isDiscordEnabled && $isSubscribedToDiscordEvent) { $channels[] = DiscordChannel::class; @@ -391,6 +394,10 @@ function setNotificationChannels($notifiable, $event) if ($isTelegramEnabled && $isSubscribedToTelegramEvent) { $channels[] = TelegramChannel::class; } + + if ($isPushoverEnabled && $isSubscribedToPushoverEvent) { + $channels[] = PushoverChannel::class; + } return $channels; } function parseEnvFormatToArray($env_file_contents) diff --git a/database/migrations/2024_04_18_183825_add_pushover_notifications_to_team.php b/database/migrations/2024_04_18_183825_add_pushover_notifications_to_team.php new file mode 100644 index 0000000000..0213a5ff83 --- /dev/null +++ b/database/migrations/2024_04_18_183825_add_pushover_notifications_to_team.php @@ -0,0 +1,34 @@ +boolean('pushover_enabled')->default(false); + $table->text('pushover_token')->nullable(); + $table->text('pushover_user')->nullable(); + $table->boolean('pushover_notifications_test')->default(true); + $table->boolean('pushover_notifications_deployments')->default(true); + $table->boolean('pushover_notifications_status_changes')->default(true); + $table->boolean('pushover_notifications_database_backups')->default(true); + }); + } + + public function down(): void + { + Schema::table('teams', function (Blueprint $table) { + $table->dropColumn('pushover_enabled'); + $table->dropColumn('pushover_token'); + $table->dropColumn('pushover_user'); + $table->dropColumn('pushover_notifications_test'); + $table->dropColumn('pushover_notifications_deployments'); + $table->dropColumn('pushover_notifications_status_changes'); + $table->dropColumn('pushover_notifications_database_backups'); + }); + } +}; diff --git a/resources/views/components/notification/navbar.blade.php b/resources/views/components/notification/navbar.blade.php index 24b4fecfd0..1fa6e3ddce 100644 --- a/resources/views/components/notification/navbar.blade.php +++ b/resources/views/components/notification/navbar.blade.php @@ -14,5 +14,9 @@ href="{{ route('notifications.discord') }}"> + + + diff --git a/resources/views/livewire/notifications/pushover.blade.php b/resources/views/livewire/notifications/pushover.blade.php new file mode 100644 index 0000000000..488e2e78e7 --- /dev/null +++ b/resources/views/livewire/notifications/pushover.blade.php @@ -0,0 +1,39 @@ +
    + +
    +
    +

    Pushover

    + + Save + + @if ($team->pushover_enabled) + + Send Test Notifications + + @endif +
    +
    + +
    + + + + + @if (data_get($team, 'pushover_enabled')) +

    Subscribe to events

    +
    + @if (isDev()) + + @endif + + + +
    + @endif +
    diff --git a/routes/web.php b/routes/web.php index bd85ecdd14..a5c3782fbd 100644 --- a/routes/web.php +++ b/routes/web.php @@ -25,6 +25,7 @@ use App\Livewire\Notifications\Email as NotificationEmail; use App\Livewire\Notifications\Telegram as NotificationTelegram; use App\Livewire\Notifications\Discord as NotificationDiscord; +use App\Livewire\Notifications\Pushover as NotificationPushover; use App\Livewire\Team\Index as TeamIndex; use App\Livewire\Team\Member\Index as TeamMemberIndex; @@ -142,6 +143,7 @@ Route::get('/email', NotificationEmail::class)->name('notifications.email'); Route::get('/telegram', NotificationTelegram::class)->name('notifications.telegram'); Route::get('/discord', NotificationDiscord::class)->name('notifications.discord'); + Route::get('/pushover', NotificationPushover::class)->name('notifications.pushover'); }); Route::prefix('storages')->group(function () {