2023-09-14 10:45:50 +00:00
< ? php
namespace App\Notifications\Server ;
use App\Models\Server ;
2024-11-26 09:19:05 +00:00
use App\Notifications\CustomEmailNotification ;
2024-10-01 19:38:12 +00:00
use App\Notifications\Dto\DiscordMessage ;
2024-12-11 14:54:11 +00:00
use App\Notifications\Dto\PushoverMessage ;
2024-12-09 15:57:15 +00:00
use App\Notifications\Dto\SlackMessage ;
2023-09-14 10:45:50 +00:00
use Illuminate\Notifications\Messages\MailMessage ;
2024-11-26 09:19:05 +00:00
class Unreachable extends CustomEmailNotification
2023-09-14 10:45:50 +00:00
{
2024-10-25 13:13:23 +00:00
protected bool $isRateLimited = false ;
public function __construct ( public Server $server )
{
2024-11-22 10:16:01 +00:00
$this -> onQueue ( 'high' );
2024-10-25 13:13:23 +00:00
$this -> isRateLimited = isEmailRateLimited (
2024-12-09 15:57:15 +00:00
limiterKey : 'server-unreachable:' . $this -> server -> id ,
2024-10-25 13:13:23 +00:00
);
}
2023-09-14 10:45:50 +00:00
public function via ( object $notifiable ) : array
{
2024-10-25 13:13:23 +00:00
if ( $this -> isRateLimited ) {
return [];
}
2024-12-09 15:57:15 +00:00
return $notifiable -> getEnabledChannels ( 'server_unreachable' );
2023-09-14 10:45:50 +00:00
}
2024-10-25 13:13:23 +00:00
public function toMail () : ? MailMessage
2023-09-14 10:45:50 +00:00
{
2024-07-24 19:11:12 +00:00
$mail = new MailMessage ;
2023-12-15 09:01:14 +00:00
$mail -> subject ( " Coolify: Your server ( { $this -> server -> name } ) is unreachable. " );
2023-09-14 10:45:50 +00:00
$mail -> view ( 'emails.server-lost-connection' , [
'name' => $this -> server -> name ,
]);
2024-06-10 20:43:34 +00:00
2023-09-14 10:45:50 +00:00
return $mail ;
}
2024-10-25 13:13:23 +00:00
public function toDiscord () : ? DiscordMessage
2023-09-14 10:45:50 +00:00
{
2024-10-01 19:38:12 +00:00
$message = new DiscordMessage (
2024-10-21 20:40:43 +00:00
title : ':cross_mark: Server unreachable' ,
description : " Your server ' { $this -> server -> name } ' is unreachable. " ,
2024-10-01 19:38:12 +00:00
color : DiscordMessage :: errorColor (),
);
$message -> addField ( 'IMPORTANT' , 'We automatically try to revive your server and turn on all automations & integrations.' );
2024-06-10 20:43:34 +00:00
2023-09-14 10:45:50 +00:00
return $message ;
}
2024-06-10 20:43:34 +00:00
2024-10-25 13:13:23 +00:00
public function toTelegram () : ? array
2023-09-14 10:45:50 +00:00
{
return [
2024-06-10 20:43:34 +00:00
'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. " ,
2023-09-14 10:45:50 +00:00
];
}
2024-11-12 21:37:55 +00:00
2024-12-11 14:54:11 +00:00
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. " ,
);
}
2024-11-12 21:37:55 +00:00
public function toSlack () : SlackMessage
{
$description = " Your server ' { $this -> server -> name } ' is unreachable. \n " ;
$description .= " All automations & integrations are turned off! \n \n " ;
2024-12-09 15:57:15 +00:00
$description .= '*IMPORTANT:* We automatically try to revive your server and turn on all automations & integrations.' ;
2024-11-12 21:37:55 +00:00
return new SlackMessage (
title : 'Server unreachable' ,
description : $description ,
color : SlackMessage :: errorColor ()
);
}
2025-10-10 16:41:46 +00:00
public function toWebhook () : array
{
$url = base_url () . '/server/' . $this -> server -> uuid ;
return [
'success' => false ,
'message' => 'Server unreachable' ,
'event' => 'server_unreachable' ,
'server_name' => $this -> server -> name ,
'server_uuid' => $this -> server -> uuid ,
'url' => $url ,
];
}
2023-09-14 10:45:50 +00:00
}