Elasticsearch::command()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
namespace Spatie\ServerMonitor\CheckDefinitions;
4
5
use Illuminate\Support\Str;
6
use Symfony\Component\Process\Process;
7
8
class Elasticsearch extends CheckDefinition
9
{
10
    public $command = 'curl --silent http://localhost:9200';
11
12
    public function command(): string
13
    {
14
        $command = $this->command;
15
16
        $customIp = $this->check->getCustomProperty('ip');
17
18
        if (! empty($customIp)) {
19
            $command = str_replace('localhost', $customIp, $command);
20
        }
21
22
        return $command;
23
    }
24
25
    public function resolve(Process $process)
26
    {
27
        $checkSucceeded = Str::contains($process->getOutput(), 'lucene_version');
28
29
        if ($checkSucceeded) {
30
            $this->check->succeed('is running');
31
32
            return;
33
        }
34
35
        $this->check->fail('is not running');
36
    }
37
}
38