Add notification-level deduplication keys and TTLs for deployment, backup, server, container, scheduled task, SSL, token, and transactional emails. Apply deduplication in email channels before sending rendered messages.
133 lines
3.6 KiB
PHP
133 lines
3.6 KiB
PHP
<?php
|
|
|
|
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;
|
|
|
|
class ContainerStopped extends CustomEmailNotification
|
|
{
|
|
public function __construct(public string $name, public Server $server, public ?string $url = null)
|
|
{
|
|
$this->onQueue('high');
|
|
}
|
|
|
|
public function via(object $notifiable): array
|
|
{
|
|
return $notifiable->getEnabledChannels('status_change');
|
|
}
|
|
|
|
public function deduplicationKey(object $notifiable, string $channel): ?string
|
|
{
|
|
return "container-stopped:server:{$this->server->uuid}:container:{$this->name}";
|
|
}
|
|
|
|
public function deduplicateFor(): int
|
|
{
|
|
return 3600;
|
|
}
|
|
|
|
public function toMail(): MailMessage
|
|
{
|
|
$mail = new MailMessage;
|
|
$mail->subject("Coolify: A resource has been stopped unexpectedly on {$this->server->name}");
|
|
$mail->view('emails.container-stopped', [
|
|
'containerName' => $this->name,
|
|
'serverName' => $this->server->name,
|
|
'url' => $this->url,
|
|
]);
|
|
|
|
return $mail;
|
|
}
|
|
|
|
public function toDiscord(): DiscordMessage
|
|
{
|
|
$message = new DiscordMessage(
|
|
title: ':cross_mark: Resource stopped',
|
|
description: "{$this->name} has been stopped unexpectedly on {$this->server->name}.",
|
|
color: DiscordMessage::errorColor(),
|
|
);
|
|
|
|
if ($this->url) {
|
|
$message->addField('Resource', '[Link]('.$this->url.')');
|
|
}
|
|
|
|
return $message;
|
|
}
|
|
|
|
public function toTelegram(): 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;
|
|
}
|
|
|
|
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';
|
|
$description = "A resource ({$this->name}) has been stopped unexpectedly on {$this->server->name}";
|
|
|
|
if ($this->url) {
|
|
$description .= "\n*Resource URL:* {$this->url}";
|
|
}
|
|
|
|
return new SlackMessage(
|
|
title: $title,
|
|
description: $description,
|
|
color: SlackMessage::errorColor()
|
|
);
|
|
}
|
|
|
|
public function toWebhook(): array
|
|
{
|
|
$data = [
|
|
'success' => false,
|
|
'message' => 'Resource stopped unexpectedly',
|
|
'event' => 'container_stopped',
|
|
'container_name' => $this->name,
|
|
'server_name' => $this->server->name,
|
|
'server_uuid' => $this->server->uuid,
|
|
];
|
|
|
|
if ($this->url) {
|
|
$data['url'] = $this->url;
|
|
}
|
|
|
|
return $data;
|
|
}
|
|
}
|