1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Liip\MonitorBundle\Check; |
4
|
|
|
|
5
|
|
|
use Laminas\Diagnostics\Check\CheckInterface; |
6
|
|
|
use Laminas\Diagnostics\Result\Failure; |
7
|
|
|
use Laminas\Diagnostics\Result\Success; |
8
|
|
|
use Laminas\Diagnostics\Result\Warning; |
9
|
|
|
use Symfony\Component\ExpressionLanguage\ExpressionLanguage; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @author Kevin Bond <[email protected]> |
13
|
|
|
*/ |
14
|
|
|
class Expression implements CheckInterface |
15
|
|
|
{ |
16
|
|
|
private $label; |
17
|
|
|
private $warningCheck; |
18
|
|
|
private $criticalCheck; |
19
|
|
|
private $warningMessage; |
20
|
|
|
private $criticalMessage; |
21
|
|
|
|
22
|
5 |
|
public function __construct($label, $warningCheck = null, $criticalCheck = null, $warningMessage = null, $criticalMessage = null) |
23
|
|
|
{ |
24
|
5 |
|
if (!class_exists('Symfony\Component\ExpressionLanguage\ExpressionLanguage')) { |
25
|
|
|
throw new \Exception('The symfony/expression-language is required for this check.'); |
26
|
|
|
} |
27
|
|
|
|
28
|
5 |
|
if (!$warningCheck && !$criticalCheck) { |
29
|
|
|
throw new \InvalidArgumentException('Not checks set.'); |
30
|
|
|
} |
31
|
|
|
|
32
|
5 |
|
$this->label = $label; |
33
|
5 |
|
$this->warningCheck = $warningCheck; |
34
|
5 |
|
$this->warningMessage = $warningMessage; |
35
|
5 |
|
$this->criticalCheck = $criticalCheck; |
36
|
5 |
|
$this->criticalMessage = $criticalMessage; |
37
|
5 |
|
} |
38
|
|
|
|
39
|
4 |
|
public function check() |
40
|
|
|
{ |
41
|
4 |
|
$language = $this->getExpressionLanguage(); |
42
|
|
|
|
43
|
4 |
|
if ($this->criticalCheck && false === $language->evaluate($this->criticalCheck)) { |
44
|
2 |
|
return new Failure($this->criticalMessage); |
45
|
|
|
} |
46
|
|
|
|
47
|
2 |
|
if ($this->warningCheck && false === $language->evaluate($this->warningCheck)) { |
48
|
1 |
|
return new Warning($this->warningMessage); |
49
|
|
|
} |
50
|
|
|
|
51
|
1 |
|
return new Success(); |
52
|
|
|
} |
53
|
|
|
|
54
|
4 |
|
public function getLabel() |
55
|
|
|
{ |
56
|
4 |
|
return $this->label; |
57
|
|
|
} |
58
|
|
|
|
59
|
4 |
|
protected function getExpressionLanguage() |
60
|
|
|
{ |
61
|
4 |
|
$language = new ExpressionLanguage(); |
62
|
4 |
|
$language->register( |
63
|
4 |
|
'ini', |
64
|
|
|
function ($value) { |
65
|
|
|
return $value; |
66
|
4 |
|
}, |
67
|
|
|
function ($arguments, $value) { |
68
|
|
|
return ini_get($value); |
69
|
4 |
|
} |
70
|
|
|
); |
71
|
|
|
|
72
|
4 |
|
return $language; |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|