Completed
Push — master ( b660c0...31ecd4 )
by Freek
01:48
created

Elasticsearch::command()   A

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 Symfony\Component\Process\Process;
6
7
class Elasticsearch extends CheckDefinition
8
{
9
    public $command = 'curl --silent http://localhost:9200';
10
11
    public function command(): string
12
    {
13
        $command = $this->command;
14
15
        $customIp = $this->check->getCustomProperty('ip');
16
17
        if (! empty($customIp)) {
18
            $command = str_replace('localhost', $customIp, $command);
19
        }
20
21
        return $command;
22
    }
23
24
    public function resolve(Process $process)
25
    {
26
        $checkSucceeded = str_contains($process->getOutput(), 'lucene_version');
27
28
        if ($checkSucceeded) {
29
            $this->check->succeed('is running');
30
31
            return;
32
        }
33
34
        $this->check->fail('is not running');
35
    }
36
}
37