feat(notification): add Pushover

This commit is contained in:
Zao Soula
2024-12-11 15:54:11 +01:00
parent 1908d8a180
commit ef35429533
31 changed files with 815 additions and 4 deletions

View File

@@ -62,6 +62,7 @@ class NotifyDemo extends Command
<li>slack</li>
<li>discord</li>
<li>telegram</li>
<li>pushover</li>
</ul>
</div>
</div>
@@ -72,6 +73,6 @@ class NotifyDemo extends Command
<div class="mr-1">
In which manner you wish a <strong class="text-coolify">coolified</strong> notification?
</div>
HTML, ['email', 'slack', 'discord', 'telegram']);
HTML, ['email', 'slack', 'discord', 'telegram', 'pushover']);
}
}

View File

@@ -0,0 +1,50 @@
<?php
namespace App\Jobs;
use App\Notifications\Dto\PushoverMessage;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeEncrypted;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Http;
class SendMessageToPushoverJob implements ShouldBeEncrypted, ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
* The number of times the job may be attempted.
*
* @var int
*/
public $tries = 5;
public $backoff = 10;
/**
* The maximum number of unhandled exceptions to allow before failing.
*/
public int $maxExceptions = 5;
public function __construct(
public PushoverMessage $message,
public string $token,
public string $user,
) {
$this->onQueue('high');
}
/**
* Execute the job.
*/
public function handle(): void
{
$response = Http::post('https://api.pushover.net/1/messages.json', $this->message->toPayload($this->token, $this->user));
if ($response->failed()) {
throw new \RuntimeException('Pushover notification failed with ' . $response->status() . ' status code.' . $response->body());
}
}
}

View File

@@ -0,0 +1,176 @@
<?php
namespace App\Livewire\Notifications;
use App\Models\PushoverNotificationSettings;
use App\Models\Team;
use App\Notifications\Test;
use Livewire\Attributes\Validate;
use Livewire\Component;
class Pushover extends Component
{
public Team $team;
public PushoverNotificationSettings $settings;
#[Validate(['boolean'])]
public bool $pushoverEnabled = false;
#[Validate(['string', 'nullable'])]
public ?string $pushoverToken = null;
#[Validate(['string', 'nullable'])]
public ?string $pushoverUser = null;
#[Validate(['boolean'])]
public bool $deploymentSuccessPushoverNotifications = false;
#[Validate(['boolean'])]
public bool $deploymentFailurePushoverNotifications = true;
#[Validate(['boolean'])]
public bool $statusChangePushoverNotifications = false;
#[Validate(['boolean'])]
public bool $backupSuccessPushoverNotifications = false;
#[Validate(['boolean'])]
public bool $backupFailurePushoverNotifications = true;
#[Validate(['boolean'])]
public bool $scheduledTaskSuccessPushoverNotifications = false;
#[Validate(['boolean'])]
public bool $scheduledTaskFailurePushoverNotifications = true;
#[Validate(['boolean'])]
public bool $dockerCleanupSuccessPushoverNotifications = false;
#[Validate(['boolean'])]
public bool $dockerCleanupFailurePushoverNotifications = true;
#[Validate(['boolean'])]
public bool $serverDiskUsagePushoverNotifications = true;
#[Validate(['boolean'])]
public bool $serverReachablePushoverNotifications = false;
#[Validate(['boolean'])]
public bool $serverUnreachablePushoverNotifications = true;
public function mount()
{
try {
$this->team = auth()->user()->currentTeam();
$this->settings = $this->team->pushoverNotificationSettings;
$this->syncData();
} catch (\Throwable $e) {
return handleError($e, $this);
}
}
public function syncData(bool $toModel = false)
{
if ($toModel) {
$this->validate();
$this->settings->pushover_enabled = $this->pushoverEnabled;
$this->settings->pushover_user = $this->pushoverUser;
$this->settings->pushover_token = $this->pushoverToken;
$this->settings->deployment_success_pushover_notifications = $this->deploymentSuccessPushoverNotifications;
$this->settings->deployment_failure_pushover_notifications = $this->deploymentFailurePushoverNotifications;
$this->settings->status_change_pushover_notifications = $this->statusChangePushoverNotifications;
$this->settings->backup_success_pushover_notifications = $this->backupSuccessPushoverNotifications;
$this->settings->backup_failure_pushover_notifications = $this->backupFailurePushoverNotifications;
$this->settings->scheduled_task_success_pushover_notifications = $this->scheduledTaskSuccessPushoverNotifications;
$this->settings->scheduled_task_failure_pushover_notifications = $this->scheduledTaskFailurePushoverNotifications;
$this->settings->docker_cleanup_success_pushover_notifications = $this->dockerCleanupSuccessPushoverNotifications;
$this->settings->docker_cleanup_failure_pushover_notifications = $this->dockerCleanupFailurePushoverNotifications;
$this->settings->server_disk_usage_pushover_notifications = $this->serverDiskUsagePushoverNotifications;
$this->settings->server_reachable_pushover_notifications = $this->serverReachablePushoverNotifications;
$this->settings->server_unreachable_pushover_notifications = $this->serverUnreachablePushoverNotifications;
$this->settings->save();
refreshSession();
} else {
$this->pushoverEnabled = $this->settings->pushover_enabled;
$this->pushoverUser = $this->settings->pushover_user;
$this->pushoverToken = $this->settings->pushover_token;
$this->deploymentSuccessPushoverNotifications = $this->settings->deployment_success_pushover_notifications;
$this->deploymentFailurePushoverNotifications = $this->settings->deployment_failure_pushover_notifications;
$this->statusChangePushoverNotifications = $this->settings->status_change_pushover_notifications;
$this->backupSuccessPushoverNotifications = $this->settings->backup_success_pushover_notifications;
$this->backupFailurePushoverNotifications = $this->settings->backup_failure_pushover_notifications;
$this->scheduledTaskSuccessPushoverNotifications = $this->settings->scheduled_task_success_pushover_notifications;
$this->scheduledTaskFailurePushoverNotifications = $this->settings->scheduled_task_failure_pushover_notifications;
$this->dockerCleanupSuccessPushoverNotifications = $this->settings->docker_cleanup_success_pushover_notifications;
$this->dockerCleanupFailurePushoverNotifications = $this->settings->docker_cleanup_failure_pushover_notifications;
$this->serverDiskUsagePushoverNotifications = $this->settings->server_disk_usage_pushover_notifications;
$this->serverReachablePushoverNotifications = $this->settings->server_reachable_pushover_notifications;
$this->serverUnreachablePushoverNotifications = $this->settings->server_unreachable_pushover_notifications;
}
}
public function instantSavePushoverEnabled()
{
try {
$this->validate([
'pushoverUser' => 'required',
'pushoverToken' => 'required',
], [
'pushoverUser.required' => 'Pushover User is required.',
'pushoverToken.required' => 'Pushover Token is required.',
]);
$this->saveModel();
} catch (\Throwable $e) {
$this->pushoverEnabled = false;
return handleError($e, $this);
}
}
public function instantSave()
{
try {
$this->syncData(true);
} catch (\Throwable $e) {
return handleError($e, $this);
}
}
public function submit()
{
try {
$this->resetErrorBag();
$this->syncData(true);
$this->saveModel();
} catch (\Throwable $e) {
return handleError($e, $this);
}
}
public function saveModel()
{
$this->syncData(true);
refreshSession();
$this->dispatch('success', 'Settings saved.');
}
public function sendTestNotification()
{
try {
$this->team->notify(new Test(channel: 'pushover'));
$this->dispatch('success', 'Test notification sent.');
} catch (\Throwable $e) {
return handleError($e, $this);
}
}
public function render()
{
return view('livewire.notifications.pushover');
}
}

View File

@@ -0,0 +1,61 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Notifiable;
class PushoverNotificationSettings extends Model
{
use Notifiable;
public $timestamps = false;
protected $fillable = [
'team_id',
'pushover_enabled',
'pushover_user',
'pushover_token',
'deployment_success_pushover_notifications',
'deployment_failure_pushover_notifications',
'status_change_pushover_notifications',
'backup_success_pushover_notifications',
'backup_failure_pushover_notifications',
'scheduled_task_success_pushover_notifications',
'scheduled_task_failure_pushover_notifications',
'docker_cleanup_pushover_notifications',
'server_disk_usage_pushover_notifications',
'server_reachable_pushover_notifications',
'server_unreachable_pushover_notifications',
];
protected $casts = [
'pushover_enabled' => 'boolean',
'pushover_user' => 'encrypted',
'pushover_token' => 'encrypted',
'deployment_success_pushover_notifications' => 'boolean',
'deployment_failure_pushover_notifications' => 'boolean',
'status_change_pushover_notifications' => 'boolean',
'backup_success_pushover_notifications' => 'boolean',
'backup_failure_pushover_notifications' => 'boolean',
'scheduled_task_success_pushover_notifications' => 'boolean',
'scheduled_task_failure_pushover_notifications' => 'boolean',
'docker_cleanup_pushover_notifications' => 'boolean',
'server_disk_usage_pushover_notifications' => 'boolean',
'server_reachable_pushover_notifications' => 'boolean',
'server_unreachable_pushover_notifications' => 'boolean',
];
public function team()
{
return $this->belongsTo(Team::class);
}
public function isEnabled()
{
return $this->pushover_enabled;
}
}

View File

@@ -5,6 +5,7 @@ namespace App\Models;
use App\Notifications\Channels\SendsDiscord;
use App\Notifications\Channels\SendsEmail;
use App\Notifications\Channels\SendsSlack;
use App\Notifications\Channels\SendsPushover;
use App\Traits\HasNotificationSettings;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Model;
@@ -32,7 +33,7 @@ use OpenApi\Attributes as OA;
]
)]
class Team extends Model implements SendsDiscord, SendsEmail, SendsSlack
class Team extends Model implements SendsDiscord, SendsEmail, SendsSlack, SendsPushover
{
use HasNotificationSettings, Notifiable;
@@ -49,6 +50,7 @@ class Team extends Model implements SendsDiscord, SendsEmail, SendsSlack
$team->discordNotificationSettings()->create();
$team->slackNotificationSettings()->create();
$team->telegramNotificationSettings()->create();
$team->pushoverNotificationSettings()->create();
});
static::saving(function ($team) {
@@ -155,6 +157,14 @@ class Team extends Model implements SendsDiscord, SendsEmail, SendsSlack
return data_get($this, 'slack_webhook_url', null);
}
public function routeNotificationForPushover()
{
return [
'user' => data_get($this, 'pushover_user', null),
'token' => data_get($this, 'pushover_token', null),
];
}
public function getRecipients($notification)
{
$recipients = data_get($notification, 'emails', null);
@@ -174,7 +184,8 @@ class Team extends Model implements SendsDiscord, SendsEmail, SendsSlack
return $this->getNotificationSettings('email')?->isEnabled() ||
$this->getNotificationSettings('discord')?->isEnabled() ||
$this->getNotificationSettings('slack')?->isEnabled() ||
$this->getNotificationSettings('telegram')?->isEnabled();
$this->getNotificationSettings('telegram')?->isEnabled() ||
$this->getNotificationSettings('pushover')?->isEnabled();
}
public function subscriptionEnded()
@@ -276,4 +287,9 @@ class Team extends Model implements SendsDiscord, SendsEmail, SendsSlack
{
return $this->hasOne(SlackNotificationSettings::class);
}
public function pushoverNotificationSettings()
{
return $this->hasOne(PushoverNotificationSettings::class);
}
}

View File

@@ -6,6 +6,7 @@ use App\Models\Application;
use App\Models\ApplicationPreview;
use App\Notifications\CustomEmailNotification;
use App\Notifications\Dto\DiscordMessage;
use App\Notifications\Dto\PushoverMessage;
use App\Notifications\Dto\SlackMessage;
use Illuminate\Notifications\Messages\MailMessage;
@@ -130,6 +131,31 @@ class DeploymentFailed extends CustomEmailNotification
];
}
public function toPushover(): PushoverMessage
{
if ($this->preview) {
$title = "Pull request #{$this->preview->pull_request_id} deployment failed";
$message = "Pull request deployment failed for {$this->application_name}";
} else {
$title = 'Deployment failed';
$message = "Deployment failed for {$this->application_name}";
}
$buttons[] = [
'text' => 'Deployment logs',
'url' => $this->deployment_url,
];
return new PushoverMessage(
title: $title,
level: 'error',
message: $message,
buttons: [
...$buttons,
],
);
}
public function toSlack(): SlackMessage
{
if ($this->preview) {

View File

@@ -6,6 +6,7 @@ use App\Models\Application;
use App\Models\ApplicationPreview;
use App\Notifications\CustomEmailNotification;
use App\Notifications\Dto\DiscordMessage;
use App\Notifications\Dto\PushoverMessage;
use App\Notifications\Dto\SlackMessage;
use Illuminate\Notifications\Messages\MailMessage;
@@ -139,6 +140,42 @@ class DeploymentSuccess extends CustomEmailNotification
];
}
public function toPushover(): PushoverMessage
{
if ($this->preview) {
$title = "Pull request #{$this->preview->pull_request_id} successfully deployed";
$message = '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 {
$title = 'New version successfully deployed';
$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 new PushoverMessage(
title: $title,
level: 'success',
message: $message,
buttons: [
...$buttons,
],
);
}
public function toSlack(): SlackMessage
{
if ($this->preview) {

View File

@@ -5,6 +5,7 @@ namespace App\Notifications\Application;
use App\Models\Application;
use App\Notifications\CustomEmailNotification;
use App\Notifications\Dto\DiscordMessage;
use App\Notifications\Dto\PushoverMessage;
use App\Notifications\Dto\SlackMessage;
use Illuminate\Notifications\Messages\MailMessage;
@@ -77,6 +78,23 @@ class StatusChanged extends CustomEmailNotification
];
}
public function toPushover(): PushoverMessage
{
$message = $this->resource_name . ' has been stopped.';
return new PushoverMessage(
title: 'Application stopped',
level: 'error',
message: $message,
buttons: [
[
'text' => 'Open Application in Coolify',
'url' => $this->resource_url,
],
],
);
}
public function toSlack(): SlackMessage
{
$title = 'Application stopped';

View File

@@ -0,0 +1,21 @@
<?php
namespace App\Notifications\Channels;
use App\Jobs\SendMessageToPushoverJob;
use Illuminate\Notifications\Notification;
class PushoverChannel
{
public function send(SendsPushover $notifiable, Notification $notification): void
{
$message = $notification->toPushover();
$pushoverSettings = $notifiable->pushoverNotificationSettings;
if (! $pushoverSettings || ! $pushoverSettings->isEnabled() || ! $pushoverSettings->pushover_user || ! $pushoverSettings->pushover_token) {
return;
}
SendMessageToPushoverJob::dispatch($message, $pushoverSettings->pushover_token, $pushoverSettings->pushover_user);
}
}

View File

@@ -0,0 +1,8 @@
<?php
namespace App\Notifications\Channels;
interface SendsPushover
{
public function routeNotificationForPushover();
}

View File

@@ -5,6 +5,7 @@ namespace App\Notifications\Container;
use App\Models\Server;
use App\Notifications\CustomEmailNotification;
use App\Notifications\Dto\DiscordMessage;
use App\Notifications\Dto\PushoverMessage;
use App\Notifications\Dto\SlackMessage;
use Illuminate\Notifications\Messages\MailMessage;
@@ -68,6 +69,24 @@ class ContainerRestarted extends CustomEmailNotification
return $payload;
}
public function toPushover(): PushoverMessage
{
$buttons = [];
if ($this->url) {
$buttons[] = [
'text' => 'Check Proxy in Coolify',
'url' => $this->url,
];
}
return new PushoverMessage(
title: 'Resource restarted',
level: 'warning',
message: "A resource ({$this->name}) has been restarted automatically on {$this->server->name}",
buttons: $buttons,
);
}
public function toSlack(): SlackMessage
{
$title = 'Resource restarted';

View File

@@ -5,6 +5,7 @@ namespace App\Notifications\Container;
use App\Models\Server;
use App\Notifications\CustomEmailNotification;
use App\Notifications\Dto\DiscordMessage;
use App\Notifications\Dto\PushoverMessage;
use App\Notifications\Dto\SlackMessage;
use Illuminate\Notifications\Messages\MailMessage;
@@ -68,6 +69,25 @@ class ContainerStopped extends CustomEmailNotification
return $payload;
}
public function toPushover(): PushoverMessage
{
$buttons = [];
if ($this->url) {
$buttons[] = [
'text' => 'Open Application in Coolify',
'url' => $this->url,
];
}
return new PushoverMessage(
title: 'Resource stopped',
level: 'error',
message: "A resource ({$this->name}) has been stopped unexpectedly on {$this->server->name}",
buttons: $buttons,
);
}
public function toSlack(): SlackMessage
{
$title = 'Resource stopped';

View File

@@ -5,6 +5,7 @@ namespace App\Notifications\Database;
use App\Models\ScheduledDatabaseBackup;
use App\Notifications\CustomEmailNotification;
use App\Notifications\Dto\DiscordMessage;
use App\Notifications\Dto\PushoverMessage;
use App\Notifications\Dto\SlackMessage;
use Illuminate\Notifications\Messages\MailMessage;
@@ -64,6 +65,15 @@ class BackupFailed extends CustomEmailNotification
];
}
public function toPushover(): PushoverMessage
{
return new PushoverMessage(
title: 'Database backup failed',
level: 'error',
message: "Database backup for {$this->name} (db:{$this->database_name}) was FAILED<br/><br/><b>Frequency:</b> {$this->frequency} .<br/><b>Reason:</b> {$this->output}",
);
}
public function toSlack(): SlackMessage
{
$title = 'Database backup failed';

View File

@@ -5,6 +5,7 @@ namespace App\Notifications\Database;
use App\Models\ScheduledDatabaseBackup;
use App\Notifications\CustomEmailNotification;
use App\Notifications\Dto\DiscordMessage;
use App\Notifications\Dto\PushoverMessage;
use App\Notifications\Dto\SlackMessage;
use Illuminate\Notifications\Messages\MailMessage;
@@ -62,6 +63,17 @@ class BackupSuccess extends CustomEmailNotification
];
}
public function toPushover(): PushoverMessage
{
return new PushoverMessage(
title: 'Database backup successful',
level: 'success',
message: "Database backup for {$this->name} (db:{$this->database_name}) was successful.<br/><br/><b>Frequency:</b> {$this->frequency}.",
);
}
public function toSlack(): SlackMessage
{
$title = 'Database backup successful';

View File

@@ -0,0 +1,50 @@
<?php
namespace App\Notifications\Dto;
use Illuminate\Support\Facades\Log;
class PushoverMessage
{
public function __construct(
public string $title,
public string $message,
public array $buttons = [],
public string $level = 'info',
) {}
public function getLevelIcon(): string
{
return match ($this->level) {
'info' => '',
'error' => '🚨',
'success' => '🟢',
'warning' => '⚠️',
};
}
public function toPayload(string $token, string $user): array
{
$levelIcon = $this->getLevelIcon();
$payload = [
'token' => $token,
'user' => $user,
'title' => "{$levelIcon} {$this->title}",
'message' => $this->message,
'html' => 1,
];
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);
}
$payload['message'] .= "&nbsp;<a href='" . $buttonUrl . "'>" . $text . '</a>';
}
Log::info('Pushover message', $payload);
return $payload;
}
}

View File

@@ -3,6 +3,7 @@
namespace App\Notifications\Internal;
use App\Notifications\Dto\DiscordMessage;
use App\Notifications\Dto\PushoverMessage;
use App\Notifications\Dto\SlackMessage;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
@@ -40,6 +41,15 @@ class GeneralNotification extends Notification implements ShouldQueue
];
}
public function toPushover(): PushoverMessage
{
return new PushoverMessage(
title: 'General Notification',
level: 'info',
message: $this->message,
);
}
public function toSlack(): SlackMessage
{
return new SlackMessage(

View File

@@ -5,6 +5,7 @@ namespace App\Notifications\ScheduledTask;
use App\Models\ScheduledTask;
use App\Notifications\CustomEmailNotification;
use App\Notifications\Dto\DiscordMessage;
use App\Notifications\Dto\PushoverMessage;
use App\Notifications\Dto\SlackMessage;
use Illuminate\Notifications\Messages\MailMessage;
@@ -70,6 +71,30 @@ class TaskFailed extends CustomEmailNotification
];
}
public function toPushover(): PushoverMessage
{
$message = "Scheduled task ({$this->task->name}) failed<br/>";
if ($this->output) {
$message .= "<br/><b>Error Output:</b>{$this->output}";
}
$buttons = [];
if ($this->url) {
$buttons[] = [
'text' => 'Open task in Coolify',
'url' => (string) $this->url,
];
}
return new PushoverMessage(
title: 'Scheduled task failed',
level: 'error',
message: $message,
buttons: $buttons,
);
}
public function toSlack(): SlackMessage
{
$title = 'Scheduled task failed';

View File

@@ -5,6 +5,7 @@ namespace App\Notifications\ScheduledTask;
use App\Models\ScheduledTask;
use App\Notifications\CustomEmailNotification;
use App\Notifications\Dto\DiscordMessage;
use App\Notifications\Dto\PushoverMessage;
use App\Notifications\Dto\SlackMessage;
use Illuminate\Notifications\Messages\MailMessage;
@@ -70,6 +71,25 @@ class TaskSuccess extends CustomEmailNotification
];
}
public function toPushover(): PushoverMessage
{
$message = "Coolify: Scheduled task ({$this->task->name}) succeeded.";
$buttons = [];
if ($this->url) {
$buttons[] = [
'text' => 'Open task in Coolify',
'url' => (string) $this->url,
];
}
return new PushoverMessage(
title: 'Scheduled task succeeded',
level: 'success',
message: $message,
buttons: $buttons,
);
}
public function toSlack(): SlackMessage
{
$title = 'Scheduled task succeeded';

View File

@@ -5,6 +5,7 @@ namespace App\Notifications\Server;
use App\Models\Server;
use App\Notifications\CustomEmailNotification;
use App\Notifications\Dto\DiscordMessage;
use App\Notifications\Dto\PushoverMessage;
use App\Notifications\Dto\SlackMessage;
use Illuminate\Notifications\Messages\MailMessage;
@@ -48,6 +49,15 @@ class DockerCleanupFailed extends CustomEmailNotification
];
}
public function toPushover(): PushoverMessage
{
return new PushoverMessage(
title: 'Docker cleanup job failed',
level: 'error',
message: "[ACTION REQUIRED] Docker cleanup job failed on {$this->server->name}!\n\n{$this->message}",
);
}
public function toSlack(): SlackMessage
{
return new SlackMessage(

View File

@@ -5,6 +5,7 @@ namespace App\Notifications\Server;
use App\Models\Server;
use App\Notifications\CustomEmailNotification;
use App\Notifications\Dto\DiscordMessage;
use App\Notifications\Dto\PushoverMessage;
use App\Notifications\Dto\SlackMessage;
use Illuminate\Notifications\Messages\MailMessage;
@@ -48,6 +49,15 @@ class DockerCleanupSuccess extends CustomEmailNotification
];
}
public function toPushover(): PushoverMessage
{
return new PushoverMessage(
title: 'Docker cleanup job succeeded',
level: 'success',
message: "Docker cleanup job succeeded on {$this->server->name}!\n\n{$this->message}",
);
}
public function toSlack(): SlackMessage
{
return new SlackMessage(

View File

@@ -5,6 +5,7 @@ namespace App\Notifications\Server;
use App\Models\Server;
use App\Notifications\CustomEmailNotification;
use App\Notifications\Dto\DiscordMessage;
use App\Notifications\Dto\PushoverMessage;
use App\Notifications\Dto\SlackMessage;
use Illuminate\Notifications\Messages\MailMessage;
@@ -51,6 +52,15 @@ class ForceDisabled extends CustomEmailNotification
];
}
public function toPushover(): PushoverMessage
{
return new PushoverMessage(
title: 'Server disabled',
level: 'error',
message: "Server ({$this->server->name}) disabled because it is not paid!\n All automations and integrations are stopped.<br/>Please update your subscription to enable the server again [here](https://app.coolify.io/subscriptions).",
);
}
public function toSlack(): SlackMessage
{
$title = 'Server disabled';

View File

@@ -5,6 +5,7 @@ namespace App\Notifications\Server;
use App\Models\Server;
use App\Notifications\CustomEmailNotification;
use App\Notifications\Dto\DiscordMessage;
use App\Notifications\Dto\PushoverMessage;
use App\Notifications\Dto\SlackMessage;
use Illuminate\Notifications\Messages\MailMessage;
@@ -47,6 +48,15 @@ class ForceEnabled extends CustomEmailNotification
];
}
public function toPushover(): PushoverMessage
{
return new PushoverMessage(
title: 'Server enabled',
level: 'success',
message: "Server ({$this->server->name}) enabled again!",
);
}
public function toSlack(): SlackMessage
{
return new SlackMessage(

View File

@@ -5,6 +5,7 @@ namespace App\Notifications\Server;
use App\Models\Server;
use App\Notifications\CustomEmailNotification;
use App\Notifications\Dto\DiscordMessage;
use App\Notifications\Dto\PushoverMessage;
use App\Notifications\Dto\SlackMessage;
use Illuminate\Notifications\Messages\MailMessage;
@@ -57,6 +58,19 @@ class HighDiskUsage extends CustomEmailNotification
];
}
public function toPushover(): PushoverMessage
{
return new PushoverMessage(
title: 'High disk usage detected',
level: 'warning',
message: "Server '{$this->server->name}' high disk usage detected!<br/><br/><b>Disk usage:</b> {$this->disk_usage}%.<br/><b>Threshold:</b> {$this->server_disk_usage_notification_threshold}%.<br/>Please cleanup your disk to prevent data-loss.",
buttons: [
'Change settings' => base_url().'/server/'.$this->server->uuid."#advanced",
'Tips for cleanup' => "https://coolify.io/docs/knowledge-base/server/automated-cleanup",
],
);
}
public function toSlack(): SlackMessage
{
$description = "Server '{$this->server->name}' high disk usage detected!\n";

View File

@@ -5,6 +5,7 @@ namespace App\Notifications\Server;
use App\Models\Server;
use App\Notifications\CustomEmailNotification;
use App\Notifications\Dto\DiscordMessage;
use App\Notifications\Dto\PushoverMessage;
use App\Notifications\Dto\SlackMessage;
use Illuminate\Notifications\Messages\MailMessage;
@@ -49,6 +50,15 @@ class Reachable extends CustomEmailNotification
);
}
public function toPushover(): PushoverMessage
{
return new PushoverMessage(
title: 'Server revived',
message: "Server '{$this->server->name}' revived. All automations & integrations are turned on again!",
level: 'success',
);
}
public function toTelegram(): array
{
return [

View File

@@ -5,6 +5,7 @@ namespace App\Notifications\Server;
use App\Models\Server;
use App\Notifications\CustomEmailNotification;
use App\Notifications\Dto\DiscordMessage;
use App\Notifications\Dto\PushoverMessage;
use App\Notifications\Dto\SlackMessage;
use Illuminate\Notifications\Messages\MailMessage;
@@ -60,6 +61,15 @@ class Unreachable extends CustomEmailNotification
];
}
public function toPushover(): PushoverMessage
{
return new PushoverMessage(
title: 'Server unreachable',
level: 'error',
message: "Your server '{$this->server->name}' is unreachable.<br/>All automations & integrations are turned off!<br/><br/><b>IMPORTANT:</b> We automatically try to revive your server and turn on all automations & integrations.",
);
}
public function toSlack(): SlackMessage
{
$description = "Your server '{$this->server->name}' is unreachable.\n";

View File

@@ -6,7 +6,9 @@ use App\Notifications\Channels\DiscordChannel;
use App\Notifications\Channels\EmailChannel;
use App\Notifications\Channels\SlackChannel;
use App\Notifications\Channels\TelegramChannel;
use App\Notifications\Channels\PushoverChannel;
use App\Notifications\Dto\DiscordMessage;
use App\Notifications\Dto\PushoverMessage;
use App\Notifications\Dto\SlackMessage;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
@@ -33,6 +35,7 @@ class Test extends Notification implements ShouldQueue
'discord' => [DiscordChannel::class],
'telegram' => [TelegramChannel::class],
'slack' => [SlackChannel::class],
'pushover' => [PushoverChannel::class],
default => [],
};
} else {
@@ -85,6 +88,20 @@ class Test extends Notification implements ShouldQueue
];
}
public function toPushover(): PushoverMessage
{
return new PushoverMessage(
title: 'Test Pushover Notification',
message: 'This is a test Pushover notification from Coolify.',
buttons: [
[
'text' => 'Go to your dashboard',
'url' => base_url(),
],
],
);
}
public function toSlack(): SlackMessage
{
return new SlackMessage(

View File

@@ -6,6 +6,7 @@ use App\Notifications\Channels\DiscordChannel;
use App\Notifications\Channels\EmailChannel;
use App\Notifications\Channels\SlackChannel;
use App\Notifications\Channels\TelegramChannel;
use App\Notifications\Channels\PushoverChannel;
use Illuminate\Database\Eloquent\Model;
trait HasNotificationSettings
@@ -27,6 +28,7 @@ trait HasNotificationSettings
'discord' => $this->discordNotificationSettings,
'telegram' => $this->telegramNotificationSettings,
'slack' => $this->slackNotificationSettings,
'pushover' => $this->pushoverNotificationSettings,
default => null,
};
}
@@ -73,6 +75,7 @@ trait HasNotificationSettings
'discord' => DiscordChannel::class,
'telegram' => TelegramChannel::class,
'slack' => SlackChannel::class,
'pushover' => PushoverChannel::class,
];
if ($event === 'general') {

View File

@@ -0,0 +1,47 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('pushover_notification_settings', function (Blueprint $table) {
$table->id();
$table->foreignId('team_id')->constrained()->cascadeOnDelete();
$table->boolean('pushover_enabled')->default(false);
$table->text('pushover_user')->nullable();
$table->text('pushover_token')->nullable();
$table->boolean('deployment_success_pushover_notifications')->default(false);
$table->boolean('deployment_failure_pushover_notifications')->default(true);
$table->boolean('status_change_pushover_notifications')->default(false);
$table->boolean('backup_success_pushover_notifications')->default(false);
$table->boolean('backup_failure_pushover_notifications')->default(true);
$table->boolean('scheduled_task_success_pushover_notifications')->default(false);
$table->boolean('scheduled_task_failure_pushover_notifications')->default(true);
$table->boolean('docker_cleanup_success_pushover_notifications')->default(false);
$table->boolean('docker_cleanup_failure_pushover_notifications')->default(true);
$table->boolean('server_disk_usage_pushover_notifications')->default(true);
$table->boolean('server_reachable_pushover_notifications')->default(false);
$table->boolean('server_unreachable_pushover_notifications')->default(true);
$table->unique(['team_id']);
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('pushover_notification_settings');
}
};

View File

@@ -19,6 +19,10 @@
href="{{ route('notifications.slack') }}">
<button>Slack</button>
</a>
<a class="{{ request()->routeIs('notifications.pushover') ? 'dark:text-white' : '' }}"
href="{{ route('notifications.pushover') }}">
<button>Pushover</button>
</a>
</nav>
</div>
</div>

View File

@@ -0,0 +1,84 @@
<div>
<x-slot:title>
Notifications | Coolify
</x-slot>
<x-notification.navbar />
<form wire:submit='submit' class="flex flex-col gap-4 pb-4">
<div class="flex items-center gap-2">
<h2>Pushover</h2>
<x-forms.button type="submit">
Save
</x-forms.button>
@if ($pushoverEnabled)
<x-forms.button class="normal-case dark:text-white btn btn-xs no-animation btn-primary"
wire:click="sendTestNotification">
Send Test Notification
</x-forms.button>
@else
<x-forms.button disabled class="normal-case dark:text-white btn btn-xs no-animation btn-primary">
Send Test Notification
</x-forms.button>
@endif
</div>
<div class="w-32">
<x-forms.checkbox instantSave="instantSavePushoverEnabled" id="pushoverEnabled" label="Enabled" />
</div>
<x-forms.input type="text"
helper="Get your user key in Pushover.<br><a href='https://pushover.net' target='_blank'>Pushover</a>" required
id="pushoverUser" label="User" />
<x-forms.input type="password"
helper="Generate a token in Pushover.<br>Example: https://pushover.net/apps/build/...." required
id="pushoverToken" label="Token" />
</form>
<h2 class="mt-4">Notification Settings</h2>
<p class="mb-4">
Select events for which you would like to receive Pushover notifications.
</p>
<div class="flex flex-col gap-4 max-w-2xl">
<div class="border dark:border-coolgray-300 p-4 rounded-lg">
<h3 class="font-medium mb-3">Deployments</h3>
<div class="flex flex-col gap-1.5 pl-1">
<x-forms.checkbox instantSave="saveModel" id="deploymentSuccessPushoverNotifications"
label="Deployment Success" />
<x-forms.checkbox instantSave="saveModel" id="deploymentFailurePushoverNotifications"
label="Deployment Failure" />
<x-forms.checkbox instantSave="saveModel"
helper="Send a notification when a container status changes. It will notify for Stopped and Restarted events of a container."
id="statusChangePushoverNotifications" label="Container Status Changes" />
</div>
</div>
<div class="border dark:border-coolgray-300 p-4 rounded-lg">
<h3 class="font-medium mb-3">Backups</h3>
<div class="flex flex-col gap-1.5 pl-1">
<x-forms.checkbox instantSave="saveModel" id="backupSuccessPushoverNotifications"
label="Backup Success" />
<x-forms.checkbox instantSave="saveModel" id="backupFailurePushoverNotifications"
label="Backup Failure" />
</div>
</div>
<div class="border dark:border-coolgray-300 p-4 rounded-lg">
<h3 class="font-medium mb-3">Scheduled Tasks</h3>
<div class="flex flex-col gap-1.5 pl-1">
<x-forms.checkbox instantSave="saveModel" id="scheduledTaskSuccessPushoverNotifications"
label="Scheduled Task Success" />
<x-forms.checkbox instantSave="saveModel" id="scheduledTaskFailurePushoverNotifications"
label="Scheduled Task Failure" />
</div>
</div>
<div class="border dark:border-coolgray-300 p-4 rounded-lg">
<h3 class="font-medium mb-3">Server</h3>
<div class="flex flex-col gap-1.5 pl-1">
<x-forms.checkbox instantSave="saveModel" id="dockerCleanupSuccessPushoverNotifications"
label="Docker Cleanup Success" />
<x-forms.checkbox instantSave="saveModel" id="dockerCleanupFailurePushoverNotifications"
label="Docker Cleanup Failure" />
<x-forms.checkbox instantSave="saveModel" id="serverDiskUsagePushoverNotifications"
label="Server Disk Usage" />
<x-forms.checkbox instantSave="saveModel" id="serverReachablePushoverNotifications"
label="Server Reachable" />
<x-forms.checkbox instantSave="saveModel" id="serverUnreachablePushoverNotifications"
label="Server Unreachable" />
</div>
</div>
</div>
</div>

View File

@@ -14,6 +14,7 @@ use App\Livewire\Notifications\Discord as NotificationDiscord;
use App\Livewire\Notifications\Email as NotificationEmail;
use App\Livewire\Notifications\Slack as NotificationSlack;
use App\Livewire\Notifications\Telegram as NotificationTelegram;
use App\Livewire\Notifications\Pushover as NotificationPushover;
use App\Livewire\Profile\Index as ProfileIndex;
use App\Livewire\Project\Application\Configuration as ApplicationConfiguration;
use App\Livewire\Project\Application\Deployment\Index as DeploymentIndex;
@@ -133,6 +134,7 @@ Route::middleware(['auth', 'verified'])->group(function () {
Route::get('/telegram', NotificationTelegram::class)->name('notifications.telegram');
Route::get('/discord', NotificationDiscord::class)->name('notifications.discord');
Route::get('/slack', NotificationSlack::class)->name('notifications.slack');
Route::get('/pushover', NotificationPushover::class)->name('notifications.pushover');
});
Route::prefix('storages')->group(function () {