More work on finding idle nodes
All checks were successful
Create Docker Image / Build Docker Image (x86_64) (push) Successful in 46s
Create Docker Image / Build Docker Image (arm64) (push) Successful in 1m53s
Create Docker Image / Final Docker Image Manifest (push) Successful in 10s

This commit is contained in:
Deon George 2024-09-22 17:33:08 +10:00
parent 4501443a43
commit 333e7e773d

View File

@ -49,12 +49,19 @@ class AddressIdle implements ShouldQueue
$result = collect(); $result = collect();
// Delist DOWN nodes // Delist DOWN nodes
if (config('fido.idle.delist')) {
$age = Carbon::now()->subDays(config('fido.idle.delist'));
foreach ($this->old($this->do,config('fido.idle.delist'),Address::NODE_DOWN,$this->ao) as $ao) { foreach ($this->old($this->do,config('fido.idle.delist'),Address::NODE_DOWN,$this->ao) as $ao) {
// Only delist system that has been marked down // Only delist system that has been marked down
// Only delist them if its been 14 days since they were marked DOWN // Only delist them if its been 14 days since they were marked DOWN
if ((! $ao->is_down) || ($ao->updated_at->greaterThan(Carbon::now()->subWeeks(2)))) if ((! $ao->is_down) || ($ao->updated_at->greaterThan(Carbon::now()->subWeeks(2))))
continue; continue;
// Validate that the last seen was infact that long ago
if ($ao->system->last_seen->greaterThan($age))
continue;
Log::info(sprintf('%s:- Delisting [%s], not seen for [%d] days',self::LOGKEY,$ao->ftn,config('fido.idle.delist'))); Log::info(sprintf('%s:- Delisting [%s], not seen for [%d] days',self::LOGKEY,$ao->ftn,config('fido.idle.delist')));
$contact = FALSE; $contact = FALSE;
@ -103,14 +110,22 @@ class AddressIdle implements ShouldQueue
$ao->contacted = $contact; $ao->contacted = $contact;
$result->push($ao); $result->push($ao);
} }
}
// Mark nodes DOWN // Mark nodes DOWN
if (config('fido.idle.down')) {
$age = Carbon::now()->subDays(config('fido.idle.down'));
foreach ($this->old($this->do,config('fido.idle.down'),Address::NODE_HOLD,$this->ao) as $ao) { foreach ($this->old($this->do,config('fido.idle.down'),Address::NODE_HOLD,$this->ao) as $ao) {
// Only mark down system that has been marked down // Only mark down system that has been marked down
// Only mark down them if its been 14 days since they were marked HOLD // Only mark down them if its been 14 days since they were marked HOLD
if ((! $ao->is_hold) || ($ao->updated_at->greaterThan(Carbon::now()->subWeeks(2)))) if ((! $ao->is_hold) || ($ao->updated_at->greaterThan(Carbon::now()->subWeeks(2))))
continue; continue;
// Validate that the last seen was infact that long ago
if ($ao->system->last_seen->greaterThan($age))
continue;
Log::info(sprintf('%s:- Marking [%s] as DOWN, not seen for [%d] days',self::LOGKEY,$ao->ftn,config('fido.idle.down'))); Log::info(sprintf('%s:- Marking [%s] as DOWN, not seen for [%d] days',self::LOGKEY,$ao->ftn,config('fido.idle.down')));
$contact = FALSE; $contact = FALSE;
@ -134,9 +149,13 @@ class AddressIdle implements ShouldQueue
$ao->contacted = $contact; $ao->contacted = $contact;
$result->push($ao); $result->push($ao);
} }
}
// @todo Make sure we only process addresses that we are responsible for, eg: 1/999 shouldnt have been processed even though 3/999 as eligible (and they are were connected to the same system) // @todo Make sure we only process addresses that we are responsible for, eg: 1/999 shouldnt have been processed even though 3/999 as eligible (and they are were connected to the same system)
// Mark nodes as HOLD // Mark nodes as HOLD
if (config('fido.idle.hold')) {
$age = Carbon::now()->subDays(config('fido.idle.hold'));
foreach ($this->old($this->do,config('fido.idle.hold'),Address::NODE_ALL,$this->ao) as $ao) { foreach ($this->old($this->do,config('fido.idle.hold'),Address::NODE_ALL,$this->ao) as $ao) {
// Ignore any systems that are a Discoverd System // Ignore any systems that are a Discoverd System
if ($ao->system->name === System::default) { if ($ao->system->name === System::default) {
@ -148,6 +167,10 @@ class AddressIdle implements ShouldQueue
if ($ao->role & (Address::NODE_DOWN|Address::NODE_HOLD)) if ($ao->role & (Address::NODE_DOWN|Address::NODE_HOLD))
continue; continue;
// Validate that the last seen was infact that long ago
if ($ao->system->last_seen->greaterThan($age))
continue;
$contact = FALSE; $contact = FALSE;
Log::info(sprintf('%s:- Marking [%s] as HOLD, not seen for [%d] days',self::LOGKEY,$ao->ftn,config('fido.idle.hold'))); Log::info(sprintf('%s:- Marking [%s] as HOLD, not seen for [%d] days',self::LOGKEY,$ao->ftn,config('fido.idle.hold')));
@ -171,6 +194,7 @@ class AddressIdle implements ShouldQueue
$ao->contacted = $contact; $ao->contacted = $contact;
$result->push($ao); $result->push($ao);
} }
}
if ($result->count()) if ($result->count())
Notification::route('echomail',$this->do->nodestatusarea)->notify(new AbsentNodes($result)); Notification::route('echomail',$this->do->nodestatusarea)->notify(new AbsentNodes($result));
@ -178,6 +202,10 @@ class AddressIdle implements ShouldQueue
private function old(Domain $do,int $days,int $flags=0,Address $ao=NULL): Collection private function old(Domain $do,int $days,int $flags=0,Address $ao=NULL): Collection
{ {
// Ignore dates that are zero
if (! $days)
return collect();
$age = Carbon::now()->subDays($days)->endOfDay(); $age = Carbon::now()->subDays($days)->endOfDay();
return Address::select([ return Address::select([