Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add PingCheck #28

Merged
merged 2 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions src/Checks/PingCheck.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace Vormkracht10\LaravelOK\Checks;

use Illuminate\Support\Facades\Process;
use Vormkracht10\LaravelOK\Checks\Base\Check;
use Vormkracht10\LaravelOK\Checks\Base\Result;

class PingCheck extends Check
{
protected string $address = 'www.google.com';

protected int $waitTime = 100;

public function address(string $address): static
{
$this->address = $address;

return $this;
}

public function maxTimeout(int $milliseconds): static
{
$this->waitTime = $milliseconds;

return $this;
}

public function run(): Result
{
$result = Result::new();

$process = Process::run("ping {$this->address} -c 1 -W {$this->waitTime}");

if (! $process->successful()) {
throw new \Exception($process->errorOutput());
}

return ! str_contains($output = $process->output(), '1 packets out of wait time') && str_contains($output, '1 packets received')
? $result->ok("Application is able to ping address [{$this->address}]")
: $result->failed("Application is unable to ping address [{$this->address}],");
}
}
2 changes: 1 addition & 1 deletion src/Checks/StorageCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function run(): Result
foreach ($directories as $directory) {
$checked[] = $directory;
$directory = implode('/', $checked);

if (! empty($disk->allFiles($directory))) {
continue;
}
Expand Down