Skip to content

Commit

Permalink
Adds a scrutiny:check-probes artisan command
Browse files Browse the repository at this point in the history
  • Loading branch information
kelvinj committed Dec 14, 2017
1 parent 66ade1b commit 315c06b
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 4 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,17 @@ to bypass this locally set `DEBUG=true` in your `.env` file.

----

## Artisan command

Run `php artisan scrutiny:check-probes` to check if your probes are passing.

This command is not rate-limited, so it's a good way to test immediately after making a change,
or even as part of a deployment process.

The command will return `0` on success and `1` on failure.

----

## How to configure pingdom

Configure a new check in pingdom with the following setting:
Expand Down
7 changes: 4 additions & 3 deletions src/CheckProbes.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,18 @@ public function __construct(ProbeManager $probeManager)
}

/**
* @return CheckProbesResult[]|CheckProbeHistory
* @param bool $ignoreCache
* @return CheckProbeHistory|CheckProbesResult[]
*/
public function handle()
public function handle($ignoreCache = false)
{
$callback = function () {
$checks = $this->runChecks();
return $this->addToResultSet($checks);
};

// no caching if in debug mode
if (config('app.debug')) {
if (config('app.debug') || $ignoreCache === true) {
return $callback();
}

Expand Down
70 changes: 70 additions & 0 deletions src/Console/CheckProbesCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

namespace Scrutiny\Console;

use Illuminate\Console\Command;
use Scrutiny\CheckProbes;
use Scrutiny\CheckProbesResult;

class CheckProbesCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'scrutiny:check-probes';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Check the Scrutiny probes';

public function handle(CheckProbes $checkProbes)
{
/** @var CheckProbesResult $result */
$result = $checkProbes->handle(true)->first();

$this->line('');
$this->line($result->pluck('icon')->implode(' '));
$this->info("*** {$result->passed()->count()} passed ***");

$failed = $result->failed();
if ($failed->count() > 0) {
$this->line('');
$this->error("*** {$failed->count()} failed ***");

$this->table(
['Probe', 'Message'],
$failed->map(function ($value) {
return [
$value['name'],
$value['message']
];
})
);
}

$skipped = $result->skipped();
if ($skipped->count() > 0) {
$this->line('');
$this->warn("*** {$skipped->count()} skipped ***");

$this->table(
['Probe', 'Message'],
$skipped->map(function ($value) {
return [
$value['name'],
$value['message']
];
})
);
}

$this->line('');

return $failed->count() ? 1 : 0;
}
}
13 changes: 12 additions & 1 deletion src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Scrutiny;

use Scrutiny\Console\CheckProbesCommand;
use Scrutiny\Support\AvailabilityMonitorValidator;

class ServiceProvider extends \Illuminate\Support\ServiceProvider
Expand All @@ -16,6 +17,7 @@ public function boot()
$this->loadRoutes();
$this->configureViews();
$this->configureCache();
$this->registerConsoleCommands();
}

protected function loadRoutes()
Expand All @@ -41,7 +43,16 @@ protected function configureCache()
'cache.stores.scrutiny-file' => [
'driver' => 'file',
'path' => storage_path('app/scrutiny'),
]
],
]);
}

protected function registerConsoleCommands()
{
if (!$this->app->runningInConsole()) {
return;
}

$this->commands(CheckProbesCommand::class);
}
}

0 comments on commit 315c06b

Please sign in to comment.