clrghouz/app/Notifications/Emails/NodeMarkedDown.php
Deon George 4501443a43
All checks were successful
Create Docker Image / Build Docker Image (x86_64) (push) Successful in 47s
Create Docker Image / Build Docker Image (arm64) (push) Successful in 1m53s
Create Docker Image / Final Docker Image Manifest (push) Successful in 10s
Improvements to finding idle nodes, last_session actually only shows the last time the remote polled us
2024-09-15 22:37:35 +10:00

63 lines
2.0 KiB
PHP

<?php
namespace App\Notifications\Emails;
use Carbon\Carbon;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
use Illuminate\Support\Facades\Log;
use App\Models\Address;
class NodeMarkedDown extends Notification //implements ShouldQueue
{
use Queueable;
private const LOGKEY = 'NEM';
/**
* Create a new notification instance.
*/
public function __construct(private Address $ao)
{
}
/**
* Get the notification's delivery channels.
*
* @return array<int, string>
*/
public function via(object $notifiable): array
{
return ['mail'];
}
/**
* Get the mail representation of the notification.
*/
public function toMail(object $notifiable): MailMessage
{
Log::info(sprintf('%s:+ Sending a NODE MARKED DOWN EMAIL for address [%s]',self::LOGKEY,$this->ao->ftn));
$now = Carbon::now();
return (new MailMessage)
->cc(our_address($this->ao)->system->users->first()->email)
->subject(sprintf('ACTION REQUIRED: Your system will be delisted on %s',$now->format('Y-m-d')))
->line(sprintf('Your system has been marked **DOWN**, because it hasnt polled **%s** with address %s since **%s** (%d days).',
$this->ao->zone->domain->name,
$this->ao->ftn4d,
$this->ao->system->last_seen?->format('Y-m-d') ?: 'Not seen',
$this->ao->system->last_seen?->diffInDays($now)))
->line('')
->line('You have (waiting for collection):')
->line(sprintf('* %s Netmails',number_format($this->ao->uncollected_netmail)))
->line(sprintf('* %s Echomails',number_format($this->ao->uncollected_echomail)))
->line(sprintf('* %s Files',number_format($this->ao->uncollected_files)))
->line('')
->line(sprintf('Your system will automatically be **DE-LISTED** if your system hasnt polled to collected your mail/file(s) by **%s**',$now->addDays(7)->format('Y-m-d')))
->line('If you think you\'ve received this email by mistake or need help, please let me know.');
}
}