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 = 'core: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
|
49 |
|
protected function _check(NodeDefinition $node): NodeDefinition |
|
|
|
|
50
|
|
|
{ |
51
|
|
|
$node = $node |
52
|
49 |
|
->children() |
53
|
49 |
|
->arrayNode('check') |
|
|
|
|
54
|
49 |
|
->addDefaultsIfNotSet() |
|
|
|
|
55
|
49 |
|
->validate() |
|
|
|
|
56
|
49 |
|
->ifTrue(static function ($value) { |
|
|
|
|
57
|
1 |
|
return !$value['warningExpression'] && !$value['criticalExpression']; |
58
|
49 |
|
}) |
|
|
|
|
59
|
49 |
|
->thenInvalid('A warningExpression or a criticalExpression must be set.') |
60
|
49 |
|
->end() |
61
|
49 |
|
->children() |
62
|
49 |
|
->scalarNode('criticalExpression')->defaultNull()->example('ini(\'apc.stat\') == 0')->end() |
63
|
49 |
|
->scalarNode('criticalMessage')->defaultNull()->end() |
64
|
49 |
|
->scalarNode('warningExpression')->defaultNull()->example('ini(\'short_open_tag\') == 1')->end() |
65
|
49 |
|
->scalarNode('warningMessage')->defaultNull()->end() |
66
|
49 |
|
->end() |
67
|
49 |
|
->end() |
68
|
49 |
|
->end(); |
69
|
|
|
|
70
|
49 |
|
$this->_addition($node); |
71
|
|
|
|
72
|
49 |
|
return $node; |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|