clrghouz/app/Notifications/Echomails/AbsentNodes.php
Deon George 8fb3a21fcd
All checks were successful
Create Docker Image / Build Docker Image (x86_64) (push) Successful in 39s
Create Docker Image / Build Docker Image (arm64) (push) Successful in 1m51s
Create Docker Image / Final Docker Image Manifest (push) Successful in 10s
Normalise tagline/tearline/origin
2024-06-03 19:09:09 +10:00

104 lines
3.1 KiB
PHP

<?php
namespace App\Notifications\Echomails;
use Carbon\Carbon;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Log;
use App\Classes\{Fonts\Thick,Page};
use App\Models\{Address,Echomail,Setup};
use App\Notifications\Echomails;
use App\Traits\MessagePath;
class AbsentNodes extends Echomails
{
use MessagePath;
private const LOGKEY = 'NNP';
private Echomail $mo;
/**
* Reply to a netmail ping request.
*
* @param Echomail $mo
*/
public function __construct(private Collection $aos)
{
parent::__construct();
}
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return Echomail
* @throws \Exception
*/
public function toEchomail(object $notifiable): Echomail
{
$echoarea = $notifiable->routeNotificationFor(static::via);
$o = $this->setupEchomail($echoarea);
$now = Carbon::now();
Log::info(sprintf('%s:+ Creating NODE ABSENT echomail in [%s]',self::LOGKEY,$echoarea->name));
$o->to = 'All';
$o->subject = 'Status changes for nodes';
$o->fftn_id = ($x=our_address($echoarea->domain)->last())->id;
$o->kludges->put('CHRS:','CP437 2');
// Message
$msg = new Page;
$header = new Thick;
$header->addText('Clearing Houz');
$msg->addHeader($header,'FTN Mailer and Tosser',TRUE,0xc4);
$msg->addText("The following nodes have had their status changed, because they are absent from the network.\r\r");
// Nodes marked HOLD - will be marked down ...
if (($x=$this->aos->filter(fn($item)=>$item->role & Address::NODE_HOLD))->count()) {
$msg->addText("The following nodes have been marked HOLD:\r");
foreach ($x as $ao)
$msg->addText(sprintf('* %s (%s), last seen %d days ago',$ao->ftn4d,$ao->system->name,$ao->system->last_session->diffInDays($now)).($ao->contacted ? '': ' ^')."\r");
$msg->addText("\r");
}
// Nodes marked DOWN - will be delisted on...
if (($x=$this->aos->filter(fn($item)=>$item->role & Address::NODE_DOWN))->count()) {
$msg->addText("The following nodes have been marked DOWN:\r");
foreach ($x as $ao)
$msg->addText(sprintf('* %s (%s), last seen %d days ago',$ao->ftn4d,$ao->system->name,$ao->system->last_session->diffInDays($now)).($ao->contacted ? '': ' ^')."\r");
$msg->addText("\r");
}
// Nodes DELISTED
if (($x=$this->aos->filter(fn($item)=>! $item->active))->count()) {
$msg->addText("The following nodes have been DE-LISTED:\r");
foreach ($x as $ao)
$msg->addText(sprintf('* %s (%s), last seen %d days ago',$ao->ftn4d,$ao->system->name,$ao->system->last_session->diffInDays($now)).($ao->contacted ? '': ' ^')."\r");
$msg->addText("\r");
}
if ($this->aos->filter(fn($item)=>(! $item->contacted))->count())
$msg->addText("^ Unable to contact these nodes.\r");
$msg->addText("\rEmails and/or Netmails have been sent to these nodes. If you can help let them know that they have outstanding mail on the Hub, that would be helpful :)");
$o->msg = $msg->render();
$o->set_tagline = 'When life gives you lemons, freeze them and throw them back.';
$o->set_origin = sprintf('%s (%s)',Setup::PRODUCT_NAME,$x->ftn4d);
$o->save();
return $o;
}
}