Skip to content

Commit

Permalink
allow ""�[Dweb_only" option for checks
Browse files Browse the repository at this point in the history
  • Loading branch information
sarfraznawaz2005 committed Aug 17, 2019
1 parent bfe6ec3 commit d2d93ef
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
12 changes: 12 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,18 @@ dump($checkResults);

You can also run check(s) programmatically (`$sm->runChecks()`), see available methods in file: `vendor/Sarfraznawaz2005/ServerMonitor/src/ServerMonitor.php`

**Running Checks for Web Only**

If for some reasons, you want to run some checks manually and via Web Interface only, you can specify `web_only` option for such checks like this:

````php
\Sarfraznawaz2005\ServerMonitor\Checks\Server\RequiredPhpExtensionsAreInstalled::class => [
'web_only' => true
],
````

Now above check will not be run via console when `servermonitor:check` is run. However this check will be performed when you run all checks via Web Interface.

# Customization

See `config/server-monitor.php` file for all checks. Note that some checks are commented intentionally, you can un-comment them if you need to use them.
Expand Down
5 changes: 3 additions & 2 deletions src/Console/BaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ protected function outputResults(array $results)
$this->info(
'<fg=green>Passed: ' . $results['counts']['passed_checks_count'] . "</fg=green>\t" .
'<fg=red>Failed: ' . $results['counts']['failed_checks_count'] . "</fg=red>\t" .
'<fg=yellow>Total: ' . $results['counts']['total_checks_count'] . '</fg=yellow>'
'<fg=yellow>Total: ' . $results['counts']['total_checks_count'] . "</fg=yellow>\t" .
'<fg=white>Last Run Via: ' . $results['via'] . '</fg=white>'
);

unset($results['counts']);
unset($results['counts'], $results['via']);

foreach ($results as $type => $checks) {

Expand Down
12 changes: 11 additions & 1 deletion src/ServerMonitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,26 @@ public function runChecks(): array

$checksAll = $this->getCheckClasses();

$isConsole = app()->runningInConsole();
$via = $isConsole ? 'Console' : 'Web Interface';

$totalChecksCount = 0;
$passedChecksCount = 0;
foreach ($checksAll as $type => $checks) {
if ($checks) {
foreach ($checks as $check => $config) {
$totalChecksCount++;

if (!is_array($config)) {
$check = $config;
$config = [];
}

if ($isConsole && isset($config['web_only'])) {
continue;
}

$totalChecksCount++;

$sTime = microtime(true);
$object = app()->make($check);

Expand Down Expand Up @@ -111,6 +119,8 @@ public function runChecks(): array
'failed_checks_count' => $totalChecksCount - $passedChecksCount,
];

$results['via'] = $via;

@file_put_contents($this->cacheFile, serialize($results));

return $results;
Expand Down
4 changes: 2 additions & 2 deletions src/Views/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
</span>
</div>
<div class="float-right">
<span class="badge-light badge">Last Checked: {{$lastRun}}</span>
<span class="badge-light badge">Last Checked: {{$lastRun}} via {{$checkResults['via']}}</span>
</div>
<div class="clearfix"></div>
</div>

<?php unset($checkResults['counts']) ?>
<?php unset($checkResults['counts'], $checkResults['via']) ?>
@endif

<div class="table-responsive-sm">
Expand Down

0 comments on commit d2d93ef

Please sign in to comment.