Move zone:check to debug namespace, add address:check command
This commit is contained in:
32
app/Console/Commands/Debug/AddressCheck.php
Normal file
32
app/Console/Commands/Debug/AddressCheck.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\Debug;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
use App\Models\Address;
|
||||
|
||||
class AddressCheck extends Command
|
||||
{
|
||||
protected $signature = 'debug:address:check'
|
||||
.' {ftn : FTN}';
|
||||
|
||||
protected $description = 'Check the addresses we use for a node';
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$o = Address::findFTN($this->argument('ftn'));
|
||||
|
||||
if (! $o) {
|
||||
$this->error(sprintf('Address: %s doesnt exist?',$this->argument('ftn')));
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
$this->info(sprintf('Address: %s',$o->ftn));
|
||||
$this->info(sprintf('Uplink: %s',$o->parent()?->ftn));
|
||||
$this->info(sprintf('Our Address: %s',our_address($o)?->ftn));
|
||||
$this->info(sprintf('Domain Addresses: %s',our_address($o->zone->domain)->pluck('ftn4d')->join(',')));
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
101
app/Console/Commands/Debug/ZoneCheck.php
Normal file
101
app/Console/Commands/Debug/ZoneCheck.php
Normal file
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\Debug;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
use App\Models\{Address,Domain};
|
||||
|
||||
class ZoneCheck extends Command
|
||||
{
|
||||
protected $signature = 'debug:zone:check'
|
||||
.' {domain : Domain Name}'
|
||||
.' {--Z|zone= : Zone}';
|
||||
|
||||
protected $description = 'Check that the addresses in a zone are configured correctly';
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$do = Domain::where('name',$this->argument('domain'))->singleOrFail();
|
||||
|
||||
foreach ($do->zones->sortby('zone_id') as $zo) {
|
||||
if ($this->option('zone') && ($this->option('zone') != $zo->zone_id))
|
||||
continue;
|
||||
|
||||
$this->warn('Zone: '.$zo->zone_id);
|
||||
$this->info(sprintf('- Our address(es): %s',our_address($do)->pluck('ftn4d')->join(',')));
|
||||
|
||||
$this->table(['id','ftn','role','parent','our_address','region_id','host_id','hub_id','system','notes'],$zo->addresses()->FTNorder()->active()->with(['system'])->get()->transform(function($item) {
|
||||
return [
|
||||
'id'=>$item->id,
|
||||
'ftn'=>$item->ftn4d,
|
||||
'role'=>$item->role_name,
|
||||
'parent'=>($x=$item->parent())?->ftn4d,
|
||||
'our_address'=>$x ? our_address($item->parent())->ftn4d : '',
|
||||
'region_id'=>$item->region_id,
|
||||
'host_id'=>$item->host_id,
|
||||
'hub_id'=>$item->hub_id,
|
||||
'system'=>$item->system->name,
|
||||
'notes'=>$this->check($item),
|
||||
];
|
||||
}));
|
||||
}
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that an address is defined correctly
|
||||
*
|
||||
* @param Address $ao
|
||||
* @return string
|
||||
*/
|
||||
private function check(Address $ao): string
|
||||
{
|
||||
// ZC address
|
||||
if ($ao->role === Address::NODE_ZC) {
|
||||
if (($ao->region_id === 0) && ($ao->host_id === 0) && ($ao->node_id === 0) && is_null($ao->hub_id) && ($ao->point_id === 0))
|
||||
return 'OK';
|
||||
|
||||
else
|
||||
return 'INVALID ZC address';
|
||||
}
|
||||
|
||||
// RC address
|
||||
if ($ao->role === Address::NODE_RC) {
|
||||
if ($ao->region_id && ($ao->region_id === $ao->host_id) && ($ao->node_id === 0) && is_null($ao->hub_id) && ($ao->point_id === 0))
|
||||
return 'OK';
|
||||
else
|
||||
return 'INVALID RC address';
|
||||
}
|
||||
|
||||
// NC address
|
||||
if ($ao->role === Address::NODE_NC) {
|
||||
if (($ao->node_id === 0) && is_null($ao->hub_id) && ($ao->point_id === 0))
|
||||
return 'OK';
|
||||
else
|
||||
return 'INVALID NC address';
|
||||
}
|
||||
|
||||
// HUB address
|
||||
if ($ao->role === Address::NODE_HC) {
|
||||
if (($ao->node_id !== 0) && is_null($ao->hub_id) && ($ao->point_id === 0))
|
||||
return 'OK';
|
||||
else
|
||||
return 'INVALID HUB address';
|
||||
}
|
||||
|
||||
// POINT address
|
||||
if ($ao->role === Address::NODE_POINT) {
|
||||
if ($ao->point_id !== 0)
|
||||
return 'OK';
|
||||
else
|
||||
return 'INVALID POINT address';
|
||||
}
|
||||
|
||||
if ($ao->region_id && ($ao->host_id === 0))
|
||||
return 'INVALID REGION NODE';
|
||||
|
||||
return '';
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user