Passed
Push — master ( f2f3ef...f406b6 )
by Nils
01:48
created

NumberProcessesCheck::getIdentifier()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Leankoala\HealthFoundation\Check\System;
4
5
use Leankoala\HealthFoundation\Check\Check;
6
use Leankoala\HealthFoundation\Check\Result;
7
8
class NumberProcessesCheck implements Check
9
{
10
    const IDENTIFIER = 'base:system:numberProcesses';
11
12
    private $processName;
13
    private $maxNumber;
14
    private $minNumber;
15
16
    public function init($processName, $maxNumber, $minNumber = 0)
17
    {
18
        $this->processName = $processName;
19
        $this->maxNumber = $maxNumber;
20
        $this->minNumber = $minNumber;
21
    }
22
23
    public function run()
24
    {
25
        $command = 'ps aux | grep ' . $this->processName . ' | wc -l';
26
27
        exec($command, $output);
28
29
        $count = (int)$output[0];
30
31
        var_dump($count);
0 ignored issues
show
Security Debugging Code introduced by
var_dump($count) looks like debug code. Are you sure you do not want to remove it?
Loading history...
32
        var_dump($this->maxNumber);
33
34
        if ($count > $this->maxNumber) {
35
            return new Result(Result::STATUS_FAIL, 'Too many processes found "' . $this->processName . '". Current: ' . $count . ' / expected < ' . $this->maxNumber . '.');
36
        }
37
38
        if ($count < $this->minNumber) {
39
            return new Result(Result::STATUS_FAIL, 'Too few processes found "' . $this->processName . '". Current: ' . $count . ' / expected > ' . $this->maxNumber . '.');
40
        }
41
42
        return new Result(Result::STATUS_PASS, 'Number of processes "' . $this->processName . '" was within limits. Current number is ' . $count . '.');
43
    }
44
45
    public function getIdentifier()
46
    {
47
        return self::IDENTIFIER . ':' . md5($this->processName);
48
    }
49
}
50