add status check command

This commit is contained in:
flash 2016-12-10 20:47:09 +01:00
parent 2b4750cc6b
commit 687d49a958

View 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();
}
}
}