lots of progress

This commit is contained in:
Doar Mihai
2026-01-17 13:46:20 +02:00
parent ab5d3cae98
commit 030a105992
77 changed files with 8507 additions and 20 deletions
+85
View File
@@ -0,0 +1,85 @@
<?php
namespace App\Notifications;
use App\Models\Site;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
class BrokenLinkAlert extends Notification implements ShouldQueue
{
use Queueable;
/**
* Create a new notification instance.
*/
public function __construct(
public Site $site,
public array $brokenLinks
) {
}
/**
* Get the notification's delivery channels.
*
* @return array<int, string>
*/
public function via(object $notifiable): array
{
$preferences = $notifiable->notification_preferences ?? [];
$channels = $preferences['broken_links'] ?? ['mail'];
return $channels;
}
/**
* Get the mail representation of the notification.
*/
public function toMail(object $notifiable): MailMessage
{
$brokenLinkCount = count($this->brokenLinks);
$message = (new MailMessage)
->warning()
->subject("⚠️ Broken Links Detected: {$this->site->name}")
->line("We detected **{$brokenLinkCount}** broken link(s) on **{$this->site->name}**.")
->line("Site URL: {$this->site->url}")
->line('')
->line('**Broken Links:**');
// Add up to 10 broken links to the email
$displayLimit = min(10, $brokenLinkCount);
foreach (array_slice($this->brokenLinks, 0, $displayLimit) as $link) {
$message->line("• {$link['url']} (HTTP {$link['status_code']})");
}
if ($brokenLinkCount > $displayLimit) {
$remaining = $brokenLinkCount - $displayLimit;
$message->line("... and {$remaining} more");
}
$message->line('')
->action('View All Broken Links', url("/sites/{$this->site->id}/broken-links"))
->line('Please fix these broken links to improve user experience and SEO.');
return $message;
}
/**
* Get the array representation of the notification.
*
* @return array<string, mixed>
*/
public function toArray(object $notifiable): array
{
return [
'site_id' => $this->site->id,
'site_name' => $this->site->name,
'site_url' => $this->site->url,
'broken_link_count' => count($this->brokenLinks),
'broken_links' => $this->brokenLinks,
];
}
}
+118
View File
@@ -0,0 +1,118 @@
<?php
namespace App\Notifications;
use App\Models\Site;
use Carbon\Carbon;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Messages\SlackMessage;
use Illuminate\Notifications\Notification;
class SslExpiryAlert extends Notification implements ShouldQueue
{
use Queueable;
/**
* Create a new notification instance.
*/
public function __construct(
public Site $site,
public string $issuer,
public Carbon $expiresAt,
public int $daysRemaining,
public bool $isExpired = false
) {
}
/**
* Get the notification's delivery channels.
*
* @return array<int, string>
*/
public function via(object $notifiable): array
{
$preferences = $notifiable->notification_preferences ?? [];
$channels = $preferences['ssl'] ?? ['mail'];
return $channels;
}
/**
* Get the mail representation of the notification.
*/
public function toMail(object $notifiable): MailMessage
{
$message = (new MailMessage)
->subject($this->isExpired
? "🔴 SSL Certificate Expired: {$this->site->name}"
: "⚠️ SSL Certificate Expiring Soon: {$this->site->name}")
->line($this->isExpired
? "The SSL certificate for **{$this->site->name}** has **expired**."
: "The SSL certificate for **{$this->site->name}** is expiring soon.")
->line("URL: {$this->site->url}")
->line("Issuer: {$this->issuer}")
->line($this->isExpired
? "Expired on: {$this->expiresAt->format('Y-m-d')}"
: "Expires on: {$this->expiresAt->format('Y-m-d')} ({$this->daysRemaining} days remaining)")
->action('View Site Details', url("/sites/{$this->site->id}"));
if ($this->isExpired) {
$message->error();
$message->line('⚠️ Your site visitors may see security warnings. Please renew the certificate immediately.');
} else {
$message->warning();
$message->line('Please renew the certificate before it expires to avoid service disruption.');
}
return $message;
}
/**
* Get the Slack representation of the notification.
*/
public function toSlack(object $notifiable): SlackMessage
{
$color = $this->isExpired ? 'danger' : 'warning';
$emoji = $this->isExpired ? '🔴' : '⚠️';
return (new SlackMessage)
->from('Site Monitor')
->to(config('services.slack.channel'))
->content($this->isExpired
? "{$emoji} SSL Certificate Expired!"
: "{$emoji} SSL Certificate Expiring Soon!")
->attachment(function ($attachment) use ($color) {
$attachment
->color($color)
->title($this->site->name, url("/sites/{$this->site->id}"))
->fields([
'URL' => $this->site->url,
'Issuer' => $this->issuer,
'Expires' => $this->expiresAt->format('Y-m-d'),
'Status' => $this->isExpired
? 'EXPIRED'
: "{$this->daysRemaining} days remaining",
]);
});
}
/**
* Get the array representation of the notification.
*
* @return array<string, mixed>
*/
public function toArray(object $notifiable): array
{
return [
'site_id' => $this->site->id,
'site_name' => $this->site->name,
'site_url' => $this->site->url,
'issuer' => $this->issuer,
'expires_at' => $this->expiresAt->toDateTimeString(),
'days_remaining' => $this->daysRemaining,
'is_expired' => $this->isExpired,
];
}
}
+72
View File
@@ -0,0 +1,72 @@
<?php
namespace App\Notifications;
use App\Models\Site;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
class UptimeAlert extends Notification implements ShouldQueue
{
use Queueable;
/**
* Create a new notification instance.
*/
public function __construct(
public Site $site,
public ?int $statusCode,
public ?int $responseTime
) {
}
/**
* Get the notification's delivery channels.
*
* @return array<int, string>
*/
public function via(object $notifiable): array
{
$preferences = $notifiable->notification_preferences ?? [];
$channels = $preferences['uptime'] ?? ['mail'];
return $channels;
}
/**
* Get the mail representation of the notification.
*/
public function toMail(object $notifiable): MailMessage
{
$status = $this->statusCode ? "returned HTTP {$this->statusCode}" : "is unreachable";
return (new MailMessage)
->error()
->subject("⚠️ Site Down Alert: {$this->site->name}")
->line("Your site **{$this->site->name}** is experiencing downtime.")
->line("URL: {$this->site->url}")
->line("Status: {$status}")
->line("Response Time: " . ($this->responseTime ? "{$this->responseTime}ms" : "N/A"))
->line("Detected at: " . now()->format('Y-m-d H:i:s'))
->action('View Site Details', url("/sites/{$this->site->id}"))
->line('Please investigate the issue as soon as possible.');
}
/**
* Get the array representation of the notification.
*
* @return array<string, mixed>
*/
public function toArray(object $notifiable): array
{
return [
'site_id' => $this->site->id,
'site_name' => $this->site->name,
'site_url' => $this->site->url,
'status_code' => $this->statusCode,
'response_time' => $this->responseTime,
];
}
}