*/ 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 */ 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, ]; } }