some progress
This commit is contained in:
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Jobs\CheckDnsRecord;
|
||||
use App\Models\DnsRecord;
|
||||
use App\Models\Site;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class MonitorDns extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'monitor:dns
|
||||
{--dns-record= : Specific DNS record ID to monitor}
|
||||
{--site= : Monitor all DNS records for a specific site ID}
|
||||
{--sync : Run checks synchronously instead of queuing}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Monitor DNS records for all sites';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
$this->info('Starting DNS monitoring...');
|
||||
|
||||
$query = DnsRecord::with('site')->where('is_active', true);
|
||||
|
||||
// Filter by specific DNS record
|
||||
if ($dnsRecordId = $this->option('dns-record')) {
|
||||
$query->where('id', $dnsRecordId);
|
||||
}
|
||||
|
||||
// Filter by site
|
||||
if ($siteId = $this->option('site')) {
|
||||
$query->where('site_id', $siteId);
|
||||
}
|
||||
|
||||
$dnsRecords = $query->get();
|
||||
|
||||
if ($dnsRecords->isEmpty()) {
|
||||
$this->warn('No active DNS records found.');
|
||||
return self::SUCCESS;
|
||||
}
|
||||
|
||||
$this->info("Found {$dnsRecords->count()} active DNS record(s).");
|
||||
|
||||
$bar = $this->output->createProgressBar($dnsRecords->count());
|
||||
$bar->start();
|
||||
|
||||
$dispatched = 0;
|
||||
$errors = 0;
|
||||
|
||||
foreach ($dnsRecords as $dnsRecord) {
|
||||
try {
|
||||
if ($this->option('sync')) {
|
||||
// Run synchronously
|
||||
CheckDnsRecord::dispatchSync($dnsRecord);
|
||||
$this->newLine();
|
||||
$this->line(" ✓ Checked: {$dnsRecord->site->name} - {$dnsRecord->record_type} {$dnsRecord->domain}");
|
||||
} else {
|
||||
// Queue the job
|
||||
CheckDnsRecord::dispatch($dnsRecord);
|
||||
}
|
||||
|
||||
$dispatched++;
|
||||
} catch (\Exception $e) {
|
||||
$errors++;
|
||||
$this->newLine();
|
||||
$this->error(" ✗ Error checking {$dnsRecord->domain}: {$e->getMessage()}");
|
||||
}
|
||||
|
||||
$bar->advance();
|
||||
}
|
||||
|
||||
$bar->finish();
|
||||
$this->newLine(2);
|
||||
|
||||
// Summary
|
||||
$this->info("DNS monitoring completed!");
|
||||
$this->table(
|
||||
['Metric', 'Count'],
|
||||
[
|
||||
['Total DNS Records', $dnsRecords->count()],
|
||||
['Successfully Dispatched', $dispatched],
|
||||
['Errors', $errors],
|
||||
]
|
||||
);
|
||||
|
||||
if (!$this->option('sync')) {
|
||||
$this->comment('Jobs have been queued. Run the queue worker to process them.');
|
||||
}
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Jobs\CheckHealthEndpoint;
|
||||
use App\Models\HealthCheck;
|
||||
use App\Models\Site;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class MonitorHealth extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'monitor:health
|
||||
{--health-check= : Specific health check ID to monitor}
|
||||
{--site= : Monitor all health checks for a specific site ID}
|
||||
{--sync : Run checks synchronously instead of queuing}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Monitor application health endpoints';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
$this->info('Starting health endpoint monitoring...');
|
||||
|
||||
$query = HealthCheck::with('site')->where('is_active', true);
|
||||
|
||||
// Filter by specific health check
|
||||
if ($healthCheckId = $this->option('health-check')) {
|
||||
$query->where('id', $healthCheckId);
|
||||
}
|
||||
|
||||
// Filter by site
|
||||
if ($siteId = $this->option('site')) {
|
||||
$query->where('site_id', $siteId);
|
||||
}
|
||||
|
||||
$healthChecks = $query->get();
|
||||
|
||||
if ($healthChecks->isEmpty()) {
|
||||
$this->warn('No active health checks found.');
|
||||
return self::SUCCESS;
|
||||
}
|
||||
|
||||
$this->info("Found {$healthChecks->count()} active health check(s).");
|
||||
|
||||
$bar = $this->output->createProgressBar($healthChecks->count());
|
||||
$bar->start();
|
||||
|
||||
$dispatched = 0;
|
||||
$errors = 0;
|
||||
|
||||
foreach ($healthChecks as $healthCheck) {
|
||||
try {
|
||||
if ($this->option('sync')) {
|
||||
// Run synchronously
|
||||
CheckHealthEndpoint::dispatchSync($healthCheck);
|
||||
$this->newLine();
|
||||
$this->line(" ✓ Checked: {$healthCheck->site->name} - {$healthCheck->endpoint}");
|
||||
} else {
|
||||
// Queue the job
|
||||
CheckHealthEndpoint::dispatch($healthCheck);
|
||||
}
|
||||
|
||||
$dispatched++;
|
||||
} catch (\Exception $e) {
|
||||
$errors++;
|
||||
$this->newLine();
|
||||
$this->error(" ✗ Error checking {$healthCheck->site->name} - {$healthCheck->endpoint}: {$e->getMessage()}");
|
||||
}
|
||||
|
||||
$bar->advance();
|
||||
}
|
||||
|
||||
$bar->finish();
|
||||
$this->newLine(2);
|
||||
|
||||
// Summary
|
||||
$this->info("Health monitoring completed!");
|
||||
$this->table(
|
||||
['Metric', 'Count'],
|
||||
[
|
||||
['Total Health Checks', $healthChecks->count()],
|
||||
['Successfully Dispatched', $dispatched],
|
||||
['Errors', $errors],
|
||||
]
|
||||
);
|
||||
|
||||
if (!$this->option('sync')) {
|
||||
$this->comment('Jobs have been queued. Run the queue worker to process them.');
|
||||
}
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Jobs\CheckSitePing;
|
||||
use App\Models\Site;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class MonitorPing extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'monitor:ping
|
||||
{--site= : Specific site ID to ping}
|
||||
{--sync : Run synchronously instead of dispatching jobs}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Ping all enabled sites to check their uptime status';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
$this->info('Starting site ping monitoring...');
|
||||
|
||||
$query = Site::where('monitoring_enabled', true);
|
||||
|
||||
if ($siteId = $this->option('site')) {
|
||||
$query->where('id', $siteId);
|
||||
}
|
||||
|
||||
$sites = $query->get();
|
||||
|
||||
if ($sites->isEmpty()) {
|
||||
$this->warn('No enabled sites found to monitor.');
|
||||
return self::SUCCESS;
|
||||
}
|
||||
|
||||
$this->info("Found {$sites->count()} site(s) to ping.");
|
||||
|
||||
$progressBar = $this->output->createProgressBar($sites->count());
|
||||
$progressBar->start();
|
||||
|
||||
$dispatched = 0;
|
||||
$failed = 0;
|
||||
|
||||
foreach ($sites as $site) {
|
||||
try {
|
||||
if ($this->option('sync')) {
|
||||
// Run synchronously for testing/debugging
|
||||
CheckSitePing::dispatchSync($site);
|
||||
} else {
|
||||
// Dispatch to queue
|
||||
CheckSitePing::dispatch($site);
|
||||
}
|
||||
|
||||
$dispatched++;
|
||||
} catch (\Exception $e) {
|
||||
$failed++;
|
||||
Log::error('MonitorPing: Failed to dispatch job', [
|
||||
'site_id' => $site->id,
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
}
|
||||
|
||||
$progressBar->advance();
|
||||
}
|
||||
|
||||
$progressBar->finish();
|
||||
$this->newLine(2);
|
||||
|
||||
$this->info("Successfully dispatched {$dispatched} ping job(s).");
|
||||
|
||||
if ($failed > 0) {
|
||||
$this->error("Failed to dispatch {$failed} job(s).");
|
||||
return self::FAILURE;
|
||||
}
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Jobs\CheckTcpPort;
|
||||
use App\Models\TcpPort;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class MonitorTcpPorts extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'monitor:tcp-ports
|
||||
{--tcp-port= : Specific TCP port ID to check}
|
||||
{--site= : Specific site ID to check all ports for}
|
||||
{--sync : Run synchronously instead of dispatching jobs}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Monitor all active TCP ports';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
$this->info('Starting TCP port monitoring...');
|
||||
|
||||
$query = TcpPort::with('site')->where('is_active', true);
|
||||
|
||||
if ($tcpPortId = $this->option('tcp-port')) {
|
||||
$query->where('id', $tcpPortId);
|
||||
}
|
||||
|
||||
if ($siteId = $this->option('site')) {
|
||||
$query->where('site_id', $siteId);
|
||||
}
|
||||
|
||||
$tcpPorts = $query->get();
|
||||
|
||||
if ($tcpPorts->isEmpty()) {
|
||||
$this->warn('No active TCP ports found to monitor.');
|
||||
return self::SUCCESS;
|
||||
}
|
||||
|
||||
$this->info("Found {$tcpPorts->count()} TCP port(s) to check.");
|
||||
|
||||
$progressBar = $this->output->createProgressBar($tcpPorts->count());
|
||||
$progressBar->start();
|
||||
|
||||
$dispatched = 0;
|
||||
$failed = 0;
|
||||
|
||||
foreach ($tcpPorts as $tcpPort) {
|
||||
try {
|
||||
if ($this->option('sync')) {
|
||||
// Run synchronously for testing/debugging
|
||||
CheckTcpPort::dispatchSync($tcpPort);
|
||||
} else {
|
||||
// Dispatch to queue
|
||||
CheckTcpPort::dispatch($tcpPort);
|
||||
}
|
||||
|
||||
$dispatched++;
|
||||
} catch (\Exception $e) {
|
||||
$failed++;
|
||||
Log::error('MonitorTcpPorts: Failed to dispatch job', [
|
||||
'tcp_port_id' => $tcpPort->id,
|
||||
'site_id' => $tcpPort->site_id,
|
||||
'port' => $tcpPort->port,
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
}
|
||||
|
||||
$progressBar->advance();
|
||||
}
|
||||
|
||||
$progressBar->finish();
|
||||
$this->newLine(2);
|
||||
|
||||
$this->info("Successfully dispatched {$dispatched} TCP port check job(s).");
|
||||
|
||||
if ($failed > 0) {
|
||||
$this->error("Failed to dispatch {$failed} job(s).");
|
||||
return self::FAILURE;
|
||||
}
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user