|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of the `tvi/monitor-bundle` project. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) https://github.com/turnaev/monitor-bundle/graphs/contributors |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE.md |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
namespace Tvi\MonitorBundle\Check\php\Expression; |
|
13
|
|
|
|
|
14
|
|
|
use Symfony\Component\Config\Definition\Builder\NodeDefinition; |
|
15
|
|
|
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; |
|
16
|
|
|
use Tvi\MonitorBundle\Check\CheckPluginAbstract; |
|
17
|
|
|
use Tvi\MonitorBundle\Exception\FeatureRequired; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
|
|
|
|
|
20
|
|
|
* @author Vladimir Turnaev <[email protected]> |
|
21
|
|
|
*/ |
|
|
|
|
|
|
22
|
|
|
class Plugin extends CheckPluginAbstract |
|
23
|
|
|
{ |
|
24
|
|
|
public const DESCR = |
|
|
|
|
|
|
25
|
|
|
<<<'TXT' |
|
|
|
|
|
|
26
|
|
|
expression description |
|
27
|
|
|
TXT; |
|
28
|
|
|
|
|
29
|
|
|
public const PATH = __DIR__; |
|
30
|
|
|
|
|
31
|
|
|
public const GROUP = 'php'; |
|
32
|
|
|
public const CHECK_NAME = 'expression'; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
|
|
|
|
|
35
|
|
|
* @throws FeatureRequired |
|
36
|
|
|
*/ |
|
|
|
|
|
|
37
|
1 |
|
public function checkRequirements() |
|
38
|
|
|
{ |
|
39
|
1 |
|
if (!class_exists('Symfony\Component\ExpressionLanguage\ExpressionLanguage')) { |
|
40
|
|
|
throw new FeatureRequired('The symfony/expression-language is required for ' . static::class . ' check.'); |
|
41
|
|
|
} |
|
42
|
1 |
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
|
|
|
|
|
45
|
|
|
* @param NodeDefinition|ArrayNodeDefinition $node |
|
|
|
|
|
|
46
|
|
|
* |
|
47
|
|
|
* @return NodeDefinition|ArrayNodeDefinition |
|
48
|
|
|
*/ |
|
49
|
45 |
|
protected function _check(NodeDefinition $node): NodeDefinition |
|
|
|
|
|
|
50
|
|
|
{ |
|
51
|
|
|
$node = $node |
|
52
|
45 |
|
->children() |
|
53
|
45 |
|
->arrayNode('check') |
|
|
|
|
|
|
54
|
45 |
|
->addDefaultsIfNotSet() |
|
|
|
|
|
|
55
|
45 |
|
->validate() |
|
|
|
|
|
|
56
|
45 |
|
->ifTrue(static function ($value) { |
|
|
|
|
|
|
57
|
1 |
|
return !$value['warningExpression'] && !$value['criticalExpression']; |
|
58
|
45 |
|
}) |
|
|
|
|
|
|
59
|
45 |
|
->thenInvalid('A warningExpression or a criticalExpression must be set.') |
|
60
|
45 |
|
->end() |
|
61
|
45 |
|
->children() |
|
62
|
45 |
|
->scalarNode('criticalExpression')->defaultNull()->example('ini(\'apc.stat\') == 0')->end() |
|
63
|
45 |
|
->scalarNode('criticalMessage')->defaultNull()->end() |
|
64
|
45 |
|
->scalarNode('warningExpression')->defaultNull()->example('ini(\'short_open_tag\') == 1')->end() |
|
65
|
45 |
|
->scalarNode('warningMessage')->defaultNull()->end() |
|
66
|
45 |
|
->end() |
|
67
|
45 |
|
->end() |
|
68
|
45 |
|
->end(); |
|
69
|
|
|
|
|
70
|
45 |
|
$this->_group($node); |
|
71
|
45 |
|
$this->_tags($node); |
|
72
|
45 |
|
$this->_label($node); |
|
73
|
|
|
|
|
74
|
45 |
|
return $node; |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|