add status check command
This commit is contained in:
parent
2b4750cc6b
commit
687d49a958
1 changed files with 45 additions and 0 deletions
45
app/Console/Command/StatusCheckCommand.php
Normal file
45
app/Console/Command/StatusCheckCommand.php
Normal file
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
/**
|
||||
* Holds the status-check command controller.
|
||||
* @package Sakura
|
||||
*/
|
||||
|
||||
namespace Sakura\Console\Command;
|
||||
|
||||
use CLIFramework\Command;
|
||||
use Sakura\Status;
|
||||
|
||||
/**
|
||||
* Checks status for hosts set in config and saves results to the database.
|
||||
* @package Sakura
|
||||
* @author Julian van de Groep <me@flash.moe>
|
||||
*/
|
||||
class StatusCheckCommand extends Command
|
||||
{
|
||||
/**
|
||||
* A quick description of this command.
|
||||
* @return string.
|
||||
*/
|
||||
public function brief(): string
|
||||
{
|
||||
return 'Checks status for hosts set in config and saves results to the database.';
|
||||
}
|
||||
|
||||
/**
|
||||
* Command.
|
||||
*/
|
||||
public function execute(): void
|
||||
{
|
||||
$endpoints = config('status.check');
|
||||
|
||||
foreach ($endpoints as $name => $data) {
|
||||
[$host, $port, $proc] = explode('/', $data, 3);
|
||||
|
||||
$this->getLogger()->writeln("Checking {$host} ($proc) on port {$port}...");
|
||||
|
||||
$status = new Status($host, $port, $proc);
|
||||
$status->check();
|
||||
$status->save();
|
||||
}
|
||||
}
|
||||
}
|
Reference in a new issue