some progress

This commit is contained in:
Doar Mihai
2026-01-17 16:42:43 +02:00
parent 030a105992
commit 3665a1d5a3
57 changed files with 5804 additions and 3 deletions
+99
View File
@@ -0,0 +1,99 @@
<?php
namespace App\Notifications;
use App\Models\DnsRecord;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
class DnsRecordAlert extends Notification implements ShouldQueue
{
use Queueable;
/**
* Create a new notification instance.
*/
public function __construct(
public DnsRecord $dnsRecord,
public string $status,
public ?array $actualValue = null,
public ?string $errorMessage = null
) {}
/**
* Get the notification's delivery channels.
*
* @return array<int, string>
*/
public function via(object $notifiable): array
{
return ['mail', 'database'];
}
/**
* Get the mail representation of the notification.
*/
public function toMail(object $notifiable): MailMessage
{
$subject = $this->status === 'invalid'
? "DNS Record Invalid: {$this->dnsRecord->domain}"
: "DNS Record Restored: {$this->dnsRecord->domain}";
$message = (new MailMessage)
->subject($subject);
if ($this->status === 'invalid') {
$message->error()
->line("DNS record validation failed for {$this->dnsRecord->record_type} record of {$this->dnsRecord->domain}")
->line("This could indicate a DNS configuration issue or propagation delay.");
if ($this->errorMessage) {
$message->line("Error: {$this->errorMessage}");
} elseif ($this->actualValue && $this->dnsRecord->expected_value) {
$actualFormatted = is_array($this->actualValue) ? implode(', ', $this->actualValue) : $this->actualValue;
$message->line("Expected: {$this->dnsRecord->expected_value}")
->line("Actual: {$actualFormatted}");
}
} else {
$message->success()
->line("DNS record for {$this->dnsRecord->record_type} of {$this->dnsRecord->domain} is now valid.")
->line("The DNS configuration has been restored.");
if ($this->actualValue) {
$actualFormatted = is_array($this->actualValue) ? implode(', ', $this->actualValue) : $this->actualValue;
$message->line("Current value: {$actualFormatted}");
}
}
return $message
->line("Domain: {$this->dnsRecord->domain}")
->line("Record Type: {$this->dnsRecord->record_type}")
->line("Checked at: {$this->dnsRecord->last_checked_at->format('Y-m-d H:i:s')}")
->action('View Details', url("/sites/{$this->dnsRecord->site_id}/dns-records/{$this->dnsRecord->id}"));
}
/**
* Get the array representation of the notification.
*
* @return array<string, mixed>
*/
public function toArray(object $notifiable): array
{
return [
'type' => 'dns_record',
'dns_record_id' => $this->dnsRecord->id,
'site_id' => $this->dnsRecord->site_id,
'site_name' => $this->dnsRecord->site->name,
'domain' => $this->dnsRecord->domain,
'record_type' => $this->dnsRecord->record_type,
'status' => $this->status,
'is_valid' => $this->dnsRecord->is_valid,
'expected_value' => $this->dnsRecord->expected_value,
'actual_value' => $this->actualValue,
'error_message' => $this->errorMessage,
'checked_at' => $this->dnsRecord->last_checked_at,
];
}
}
+97
View File
@@ -0,0 +1,97 @@
<?php
namespace App\Notifications;
use App\Models\HealthCheck;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
class HealthCheckAlert extends Notification implements ShouldQueue
{
use Queueable;
/**
* Create a new notification instance.
*/
public function __construct(
public HealthCheck $healthCheck,
public string $status,
public ?int $statusCode = null,
public ?int $responseTime = null
) {}
/**
* Get the notification's delivery channels.
*
* @return array<int, string>
*/
public function via(object $notifiable): array
{
return ['mail', 'database'];
}
/**
* Get the mail representation of the notification.
*/
public function toMail(object $notifiable): MailMessage
{
$subject = $this->status === 'unhealthy'
? "Health Check Failed: {$this->healthCheck->endpoint}"
: "Health Check Restored: {$this->healthCheck->endpoint}";
$message = (new MailMessage)
->subject($subject)
->line("Health check alert for {$this->healthCheck->site->name}");
if ($this->status === 'unhealthy') {
$message->error()
->line("The health endpoint {$this->healthCheck->endpoint} is reporting as unhealthy.")
->line("This could indicate an application issue or service degradation.");
if ($this->statusCode) {
$message->line("HTTP Status Code: {$this->statusCode}");
}
} else {
$message->success()
->line("The health endpoint {$this->healthCheck->endpoint} is now healthy.")
->line("The service has been restored.");
if ($this->statusCode) {
$message->line("HTTP Status Code: {$this->statusCode}");
}
if ($this->responseTime) {
$message->line("Response Time: {$this->responseTime}ms");
}
}
return $message
->line("Endpoint: {$this->healthCheck->full_url}")
->line("Checked at: {$this->healthCheck->last_checked_at->format('Y-m-d H:i:s')}")
->action('View Details', url("/sites/{$this->healthCheck->site_id}"));
}
/**
* Get the array representation of the notification.
*
* @return array<string, mixed>
*/
public function toArray(object $notifiable): array
{
return [
'type' => 'health_check',
'health_check_id' => $this->healthCheck->id,
'site_id' => $this->healthCheck->site_id,
'site_name' => $this->healthCheck->site->name,
'endpoint' => $this->healthCheck->endpoint,
'full_url' => $this->healthCheck->full_url,
'status' => $this->status,
'is_healthy' => $this->healthCheck->is_healthy,
'status_code' => $this->statusCode,
'response_time_ms' => $this->responseTime,
'checked_at' => $this->healthCheck->last_checked_at,
];
}
}
+90
View File
@@ -0,0 +1,90 @@
<?php
namespace App\Notifications;
use App\Models\HealthCheck;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
class PerformanceAlert extends Notification implements ShouldQueue
{
use Queueable;
/**
* Create a new notification instance.
*/
public function __construct(
public string $resourceType,
public string $resourceName,
public int $responseTime,
public int $threshold,
public ?string $url = null,
public ?int $resourceId = null
) {}
/**
* Get the notification's delivery channels.
*
* @return array<int, string>
*/
public function via(object $notifiable): array
{
return ['mail', 'database'];
}
/**
* Get the mail representation of the notification.
*/
public function toMail(object $notifiable): MailMessage
{
$subject = "Performance Alert: {$this->resourceName}";
$percentageOver = round((($this->responseTime - $this->threshold) / $this->threshold) * 100);
$message = (new MailMessage)
->subject($subject)
->warning()
->line("Performance threshold exceeded for {$this->resourceType}: {$this->resourceName}")
->line("Response time ({$this->responseTime}ms) exceeded the threshold of {$this->threshold}ms by {$percentageOver}%.")
->line("This could indicate a performance degradation or resource constraint.");
$message->line("Response Time: {$this->responseTime}ms")
->line("Threshold: {$this->threshold}ms")
->line("Difference: " . ($this->responseTime - $this->threshold) . "ms");
if ($this->url) {
$message->line("URL: {$this->url}");
}
if ($this->resourceId) {
$actionUrl = match($this->resourceType) {
'Health Check' => url("/sites/{$this->resourceId}"),
default => url('/dashboard'),
};
$message->action('View Details', $actionUrl);
}
return $message;
}
/**
* Get the array representation of the notification.
*
* @return array<string, mixed>
*/
public function toArray(object $notifiable): array
{
return [
'type' => 'performance_alert',
'resource_type' => $this->resourceType,
'resource_name' => $this->resourceName,
'resource_id' => $this->resourceId,
'response_time_ms' => $this->responseTime,
'threshold_ms' => $this->threshold,
'difference_ms' => $this->responseTime - $this->threshold,
'percentage_over' => round((($this->responseTime - $this->threshold) / $this->threshold) * 100, 2),
'url' => $this->url,
];
}
}
+81
View File
@@ -0,0 +1,81 @@
<?php
namespace App\Notifications;
use App\Models\TcpPort;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
class TcpPortAlert extends Notification implements ShouldQueue
{
use Queueable;
/**
* Create a new notification instance.
*/
public function __construct(
public TcpPort $tcpPort,
public string $status
) {}
/**
* Get the notification's delivery channels.
*
* @return array<int, string>
*/
public function via(object $notifiable): array
{
return ['mail', 'database'];
}
/**
* Get the mail representation of the notification.
*/
public function toMail(object $notifiable): MailMessage
{
$subject = $this->status === 'closed'
? "TCP Port {$this->tcpPort->port} is Closed"
: "TCP Port {$this->tcpPort->port} is Now Open";
$message = (new MailMessage)
->subject($subject)
->line("Port monitoring alert for {$this->tcpPort->site->name}");
if ($this->status === 'closed') {
$message->error()
->line("Port {$this->tcpPort->display_name} ({$this->tcpPort->port}) is currently closed.")
->line("This could indicate a service outage or firewall issue.");
} else {
$message->success()
->line("Port {$this->tcpPort->display_name} ({$this->tcpPort->port}) is now accessible.")
->line("The service has been restored.");
}
return $message
->line("Site: {$this->tcpPort->site->url}")
->line("Checked at: {$this->tcpPort->last_checked_at->format('Y-m-d H:i:s')}")
->action('View Details', url("/sites/{$this->tcpPort->site_id}"));
}
/**
* Get the array representation of the notification.
*
* @return array<string, mixed>
*/
public function toArray(object $notifiable): array
{
return [
'type' => 'tcp_port',
'tcp_port_id' => $this->tcpPort->id,
'site_id' => $this->tcpPort->site_id,
'site_name' => $this->tcpPort->site->name,
'port' => $this->tcpPort->port,
'port_name' => $this->tcpPort->display_name,
'status' => $this->status,
'is_open' => $this->tcpPort->is_open,
'checked_at' => $this->tcpPort->last_checked_at,
];
}
}