From 7e0178d183537a484a74a9db28cc4ee9d4dbdc34 Mon Sep 17 00:00:00 2001 From: Deon George Date: Sun, 26 May 2024 20:53:59 +1000 Subject: [PATCH] Fix routed netmails being packed for the hub, not the destination. Added some logging for idle netmails/emails --- app/Jobs/AddressIdle.php | 18 ++++++------------ app/Models/System.php | 13 +++++++++++++ app/Notifications/Emails/NodeDelisted.php | 5 +++++ app/Notifications/Emails/NodeMarkedDown.php | 5 +++++ app/Notifications/Emails/NodeMarkedHold.php | 5 +++++ app/Notifications/Netmails/NodeDelisted.php | 3 +-- app/Notifications/Netmails/NodeMarkedDown.php | 5 ++--- app/Notifications/Netmails/NodeMarkedHold.php | 3 +-- app/Traits/MessageAttributes.php | 3 --- 9 files changed, 38 insertions(+), 22 deletions(-) diff --git a/app/Jobs/AddressIdle.php b/app/Jobs/AddressIdle.php index 9ac3ecd..25b1230 100644 --- a/app/Jobs/AddressIdle.php +++ b/app/Jobs/AddressIdle.php @@ -68,10 +68,8 @@ class AddressIdle implements ShouldQueue } // Netmail Alert (to othernet network address) - // Uncommon addresses - $uncommon = $ao->system->addresses->map(fn($item)=>$item->parent())->diff(our_address())->first(); - if ($uncommon) { - Notification::route('netmail',$uncommon->withoutRelations())->notify(new NodeDelistedNetmail($ao->withoutRelations())); + if ($ao->system->uncommon()->count()) { + Notification::route('netmail',$ao->system->uncommon()->first()->withoutRelations())->notify(new NodeDelistedNetmail($ao->withoutRelations())); $contact = TRUE; } @@ -91,10 +89,8 @@ class AddressIdle implements ShouldQueue } // Netmail Alert (to othernet network address) - // Uncommon addresses - $uncommon = $ao->system->addresses->map(fn($item)=>$item->parent())->diff(our_address())->first(); - if ($uncommon) { - Notification::route('netmail',$uncommon->withoutRelations())->notify(new NodeMarkedDownNetmail($ao->withoutRelations())); + if ($ao->system->uncommon()->count()) { + Notification::route('netmail',$ao->system->uncommon()->first()->withoutRelations())->notify(new NodeMarkedDownNetmail($ao->withoutRelations())); $contact = TRUE; } @@ -124,10 +120,8 @@ class AddressIdle implements ShouldQueue } // Netmail Alert (to othernet network address) - // Uncommon addresses - $uncommon = $ao->system->addresses->map(fn($item)=>$item->parent())->diff(our_address())->first(); - if ($uncommon) { - Notification::route('netmail',$uncommon->withoutRelations())->notify(new NodeMarkedHoldNetmail($ao->withoutRelations())); + if ($ao->system->uncommon()->count()) { + Notification::route('netmail',$ao->system->uncommon()->first()->withoutRelations())->notify(new NodeMarkedHoldNetmail($ao->withoutRelations())); $contact = TRUE; } diff --git a/app/Models/System.php b/app/Models/System.php index 6c76d45..c292cf8 100644 --- a/app/Models/System.php +++ b/app/Models/System.php @@ -275,4 +275,17 @@ class System extends Model return $this->akas->pluck('id')->search($item->command->address->id) !== FALSE; }) ->last(); } + + /** + * Return other addresses that are no collected here, but are on the same network as us. + * + * @return \Illuminate\Database\Eloquent\Collection + * @throws \Exception + */ + public function uncommon(): Collection + { + $our = our_address(); + + return $this->akas->filter(fn($item)=>($item->parent() && (! $our->contains($item->parent())))); + } } \ No newline at end of file diff --git a/app/Notifications/Emails/NodeDelisted.php b/app/Notifications/Emails/NodeDelisted.php index 216c765..bac5491 100644 --- a/app/Notifications/Emails/NodeDelisted.php +++ b/app/Notifications/Emails/NodeDelisted.php @@ -7,6 +7,7 @@ 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; @@ -14,6 +15,8 @@ class NodeDelisted extends Notification //implements ShouldQueue { use Queueable; + private const LOGKEY = 'NED'; + /** * Create a new notification instance. */ @@ -36,6 +39,8 @@ class NodeDelisted extends Notification //implements ShouldQueue */ public function toMail(object $notifiable): MailMessage { + Log::info(sprintf('%s:+ Sending a NODE DELISTED EMAIL for address [%s]',self::LOGKEY,$this->ao->ftn)); + $now = Carbon::now(); return (new MailMessage) diff --git a/app/Notifications/Emails/NodeMarkedDown.php b/app/Notifications/Emails/NodeMarkedDown.php index 2686628..5050f6f 100644 --- a/app/Notifications/Emails/NodeMarkedDown.php +++ b/app/Notifications/Emails/NodeMarkedDown.php @@ -7,6 +7,7 @@ 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; @@ -14,6 +15,8 @@ class NodeMarkedDown extends Notification //implements ShouldQueue { use Queueable; + private const LOGKEY = 'NEM'; + /** * Create a new notification instance. */ @@ -36,6 +39,8 @@ class NodeMarkedDown extends Notification //implements ShouldQueue */ 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) diff --git a/app/Notifications/Emails/NodeMarkedHold.php b/app/Notifications/Emails/NodeMarkedHold.php index eeffbee..7d69176 100644 --- a/app/Notifications/Emails/NodeMarkedHold.php +++ b/app/Notifications/Emails/NodeMarkedHold.php @@ -7,6 +7,7 @@ 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; @@ -14,6 +15,8 @@ class NodeMarkedHold extends Notification //implements ShouldQueue { use Queueable; + private const LOGKEY = 'NEH'; + /** * Create a new notification instance. */ @@ -36,6 +39,8 @@ class NodeMarkedHold extends Notification //implements ShouldQueue */ public function toMail(object $notifiable): MailMessage { + Log::info(sprintf('%s:+ Sending a NODE MARKED HOLD EMAIL for address [%s]',self::LOGKEY,$this->ao->ftn)); + $now = Carbon::now(); return (new MailMessage) diff --git a/app/Notifications/Netmails/NodeDelisted.php b/app/Notifications/Netmails/NodeDelisted.php index af4b548..6590ca4 100644 --- a/app/Notifications/Netmails/NodeDelisted.php +++ b/app/Notifications/Netmails/NodeDelisted.php @@ -4,7 +4,6 @@ namespace App\Notifications\Netmails; use Carbon\Carbon; use Illuminate\Bus\Queueable; -use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Support\Facades\Log; use App\Classes\FTN\Message; @@ -16,7 +15,7 @@ class NodeDelisted extends Netmails //implements ShouldQueue { use Queueable,PageTemplate; - private const LOGKEY = 'NMD'; + private const LOGKEY = 'NND'; /** * Create a new notification instance. diff --git a/app/Notifications/Netmails/NodeMarkedDown.php b/app/Notifications/Netmails/NodeMarkedDown.php index f7b3f8c..58f5a04 100644 --- a/app/Notifications/Netmails/NodeMarkedDown.php +++ b/app/Notifications/Netmails/NodeMarkedDown.php @@ -4,7 +4,6 @@ namespace App\Notifications\Netmails; use Carbon\Carbon; use Illuminate\Bus\Queueable; -use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Support\Facades\Log; use App\Classes\FTN\Message; @@ -16,7 +15,7 @@ class NodeMarkedDown extends Netmails //implements ShouldQueue { use Queueable,PageTemplate; - private const LOGKEY = 'NMD'; + private const LOGKEY = 'NNM'; /** * Create a new notification instance. @@ -36,7 +35,7 @@ class NodeMarkedDown extends Netmails //implements ShouldQueue $o = $this->setupNetmail($notifiable); $ao = $notifiable->routeNotificationFor(static::via); - Log::info(sprintf('%s:+ Sending a NODE MARKED DOWN for address [%s]',self::LOGKEY,$ao->ftn)); + Log::info(sprintf('%s:+ Sending a NODE MARKED DOWN NETMAIL for address [%s]',self::LOGKEY,$ao->ftn)); $o->subject = sprintf('ACTION REQUIRED: Your system will be delisted on %s',$now->format('Y-m-d')); $o->flags = (Message::FLAG_LOCAL|Message::FLAG_PRIVATE|Message::FLAG_CRASH); diff --git a/app/Notifications/Netmails/NodeMarkedHold.php b/app/Notifications/Netmails/NodeMarkedHold.php index 27e37db..565f2bc 100644 --- a/app/Notifications/Netmails/NodeMarkedHold.php +++ b/app/Notifications/Netmails/NodeMarkedHold.php @@ -4,7 +4,6 @@ namespace App\Notifications\Netmails; use Carbon\Carbon; use Illuminate\Bus\Queueable; -use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Support\Facades\Log; use App\Classes\FTN\Message; @@ -16,7 +15,7 @@ class NodeMarkedHold extends Netmails //implements ShouldQueue { use Queueable,PageTemplate; - private const LOGKEY = 'NMD'; + private const LOGKEY = 'NNH'; /** * Create a new notification instance. diff --git a/app/Traits/MessageAttributes.php b/app/Traits/MessageAttributes.php index b3c97e8..588ca58 100644 --- a/app/Traits/MessageAttributes.php +++ b/app/Traits/MessageAttributes.php @@ -169,9 +169,6 @@ trait MessageAttributes { Log::debug(sprintf('%s:+ Bundling [%s] for [%s]',self::LOGKEY,$this->id,$ao->ftn),['type'=>get_class($this)]); - // For netmails, our tftn is the next hop - $this->tftn = $ao; - // @todo Dont bundle mail to nodes that have been disabled, or addresses that have been deleted return Message::packMessage($this); }