2023-07-26 12:46:28 +00:00
|
|
|
<?php
|
|
|
|
|
|
2023-07-28 08:55:26 +00:00
|
|
|
namespace App\Notifications\Application;
|
2023-07-26 12:46:28 +00:00
|
|
|
|
2023-09-15 13:34:25 +00:00
|
|
|
use App\Models\Application;
|
2024-11-26 09:19:05 +00:00
|
|
|
use App\Notifications\CustomEmailNotification;
|
2024-10-01 20:07:24 +00:00
|
|
|
use App\Notifications\Dto\DiscordMessage;
|
2024-12-11 14:54:11 +00:00
|
|
|
use App\Notifications\Dto\PushoverMessage;
|
2024-11-12 21:37:55 +00:00
|
|
|
use App\Notifications\Dto\SlackMessage;
|
2023-07-26 12:46:28 +00:00
|
|
|
use Illuminate\Notifications\Messages\MailMessage;
|
|
|
|
|
|
2024-11-26 09:19:05 +00:00
|
|
|
class StatusChanged extends CustomEmailNotification
|
2023-07-26 12:46:28 +00:00
|
|
|
{
|
2023-10-14 12:22:07 +00:00
|
|
|
public string $resource_name;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-07-26 12:46:28 +00:00
|
|
|
public string $project_uuid;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-11-22 15:05:24 +00:00
|
|
|
public string $environment_uuid;
|
|
|
|
|
|
2024-12-17 12:42:16 +00:00
|
|
|
public string $environment_name;
|
|
|
|
|
|
2023-10-14 12:22:07 +00:00
|
|
|
public ?string $resource_url = null;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-09-15 13:34:25 +00:00
|
|
|
public ?string $fqdn;
|
2023-07-26 12:46:28 +00:00
|
|
|
|
2025-01-07 14:31:43 +00:00
|
|
|
public function __construct(public Application $resource)
|
2023-07-26 12:46:28 +00:00
|
|
|
{
|
2024-11-22 10:16:01 +00:00
|
|
|
$this->onQueue('high');
|
2025-01-07 14:31:43 +00:00
|
|
|
$this->resource_name = data_get($resource, 'name');
|
|
|
|
|
$this->project_uuid = data_get($resource, 'environment.project.uuid');
|
|
|
|
|
$this->environment_uuid = data_get($resource, 'environment.uuid');
|
|
|
|
|
$this->environment_name = data_get($resource, 'environment.name');
|
|
|
|
|
$this->fqdn = data_get($resource, 'fqdn', null);
|
2024-06-25 08:37:10 +00:00
|
|
|
if (str($this->fqdn)->explode(',')->count() > 1) {
|
|
|
|
|
$this->fqdn = str($this->fqdn)->explode(',')->first();
|
2023-07-26 12:46:28 +00:00
|
|
|
}
|
2025-02-27 10:56:39 +00:00
|
|
|
$this->resource_url = base_url()."/project/{$this->project_uuid}/environment/{$this->environment_uuid}/application/{$this->resource->uuid}";
|
2023-07-26 12:46:28 +00:00
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2023-07-26 12:46:28 +00:00
|
|
|
public function via(object $notifiable): array
|
|
|
|
|
{
|
2024-12-09 15:57:15 +00:00
|
|
|
return $notifiable->getEnabledChannels('status_change');
|
2023-07-26 12:46:28 +00:00
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2023-07-26 12:46:28 +00:00
|
|
|
public function toMail(): MailMessage
|
|
|
|
|
{
|
2025-01-07 14:31:43 +00:00
|
|
|
$mail = new MailMessage;
|
2023-07-26 13:20:04 +00:00
|
|
|
$fqdn = $this->fqdn;
|
2025-01-07 14:31:43 +00:00
|
|
|
$mail->subject("Coolify: {$this->resource_name} has been stopped");
|
|
|
|
|
$mail->view('emails.application-status-changes', [
|
2023-10-14 12:22:07 +00:00
|
|
|
'name' => $this->resource_name,
|
2023-07-26 13:20:04 +00:00
|
|
|
'fqdn' => $fqdn,
|
2023-10-14 12:22:07 +00:00
|
|
|
'resource_url' => $this->resource_url,
|
2023-07-26 13:20:04 +00:00
|
|
|
]);
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2025-01-07 14:31:43 +00:00
|
|
|
return $mail;
|
2023-07-26 12:46:28 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-01 20:07:24 +00:00
|
|
|
public function toDiscord(): DiscordMessage
|
2023-07-26 12:46:28 +00:00
|
|
|
{
|
2024-10-31 17:20:11 +00:00
|
|
|
return new DiscordMessage(
|
2024-10-21 20:40:43 +00:00
|
|
|
title: ':cross_mark: Application stopped',
|
|
|
|
|
description: '[Open Application in Coolify]('.$this->resource_url.')',
|
2024-10-01 20:07:24 +00:00
|
|
|
color: DiscordMessage::errorColor(),
|
|
|
|
|
isCritical: true,
|
|
|
|
|
);
|
2023-07-26 12:46:28 +00:00
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-09-06 12:31:38 +00:00
|
|
|
public function toTelegram(): array
|
|
|
|
|
{
|
2024-06-10 20:43:34 +00:00
|
|
|
$message = 'Coolify: '.$this->resource_name.' has been stopped.';
|
|
|
|
|
|
2023-09-06 12:31:38 +00:00
|
|
|
return [
|
2024-06-10 20:43:34 +00:00
|
|
|
'message' => $message,
|
|
|
|
|
'buttons' => [
|
2023-09-06 12:31:38 +00:00
|
|
|
[
|
2024-06-10 20:43:34 +00:00
|
|
|
'text' => 'Open Application in Coolify',
|
|
|
|
|
'url' => $this->resource_url,
|
|
|
|
|
],
|
2023-09-06 12:31:38 +00:00
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
}
|
2024-11-12 21:37:55 +00:00
|
|
|
|
2024-12-11 14:54:11 +00:00
|
|
|
public function toPushover(): PushoverMessage
|
|
|
|
|
{
|
2024-12-17 12:42:16 +00:00
|
|
|
$message = $this->resource_name.' has been stopped.';
|
2024-12-11 14:54:11 +00:00
|
|
|
|
|
|
|
|
return new PushoverMessage(
|
|
|
|
|
title: 'Application stopped',
|
|
|
|
|
level: 'error',
|
|
|
|
|
message: $message,
|
|
|
|
|
buttons: [
|
|
|
|
|
[
|
|
|
|
|
'text' => 'Open Application in Coolify',
|
|
|
|
|
'url' => $this->resource_url,
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-12 21:37:55 +00:00
|
|
|
public function toSlack(): SlackMessage
|
|
|
|
|
{
|
2024-12-09 15:57:15 +00:00
|
|
|
$title = 'Application stopped';
|
2024-11-12 21:37:55 +00:00
|
|
|
$description = "{$this->resource_name} has been stopped";
|
|
|
|
|
|
2025-02-04 11:40:04 +00:00
|
|
|
$description .= "\n\n*Project:* ".data_get($this->resource, 'environment.project.name');
|
|
|
|
|
$description .= "\n*Environment:* {$this->environment_name}";
|
|
|
|
|
$description .= "\n*Application URL:* {$this->resource_url}";
|
2024-11-12 21:37:55 +00:00
|
|
|
|
|
|
|
|
return new SlackMessage(
|
|
|
|
|
title: $title,
|
|
|
|
|
description: $description,
|
|
|
|
|
color: SlackMessage::errorColor()
|
|
|
|
|
);
|
|
|
|
|
}
|
2025-10-10 16:41:46 +00:00
|
|
|
|
|
|
|
|
public function toWebhook(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
'success' => false,
|
|
|
|
|
'message' => 'Application stopped',
|
|
|
|
|
'event' => 'status_changed',
|
|
|
|
|
'application_name' => $this->resource_name,
|
|
|
|
|
'application_uuid' => $this->resource->uuid,
|
|
|
|
|
'url' => $this->resource_url,
|
|
|
|
|
'project' => data_get($this->resource, 'environment.project.name'),
|
|
|
|
|
'environment' => $this->environment_name,
|
|
|
|
|
'fqdn' => $this->fqdn,
|
|
|
|
|
];
|
|
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
}
|