feat: slack notifications

This commit is contained in:
Marvin von Rappard
2024-11-12 22:37:55 +01:00
parent 9af3fe9c97
commit eb0686fe20
27 changed files with 822 additions and 181 deletions

View File

@@ -8,14 +8,16 @@ use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
use App\Notifications\Dto\SlackMessage;
class ContainerStopped extends Notification implements ShouldQueue
{
use Queueable;
public $tries = 1;
public function __construct(public string $name, public Server $server, public ?string $url = null) {}
public function __construct(public string $name, public Server $server, public ?string $url = null)
{
}
public function via(object $notifiable): array
{
@@ -44,7 +46,7 @@ class ContainerStopped extends Notification implements ShouldQueue
);
if ($this->url) {
$message->addField('Resource', '[Link]('.$this->url.')');
$message->addField('Resource', '[Link](' . $this->url . ')');
}
return $message;
@@ -69,4 +71,20 @@ class ContainerStopped extends Notification implements ShouldQueue
return $payload;
}
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()
);
}
}