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\rabbitmq\QueueSize; |
13
|
|
|
|
14
|
|
|
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; |
15
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
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
|
|
|
const DESCR = |
|
|
|
|
25
|
|
|
<<<'TXT' |
|
|
|
|
26
|
|
|
rabbit_mq description |
27
|
|
|
TXT; |
28
|
|
|
|
29
|
|
|
const PATH = __DIR__; |
30
|
|
|
|
31
|
|
|
const GROUP = 'rabbit_mq'; |
32
|
|
|
const CHECK_NAME = 'core:rabbit_mq:queue_size'; |
33
|
|
|
|
34
|
|
|
/** |
|
|
|
|
35
|
|
|
* @throws FeatureRequired |
36
|
|
|
*/ |
|
|
|
|
37
|
1 |
|
public function checkRequirements(array $checkSettings) |
38
|
|
|
{ |
39
|
1 |
|
if (!class_exists('PhpAmqpLib\Connection\AMQPConnection')) { |
40
|
|
|
throw new FeatureRequired('PhpAmqpLib is not installed'); |
41
|
|
|
} |
42
|
1 |
|
} |
43
|
|
|
|
44
|
55 |
|
public function checkFactoryConf(TreeBuilder $builder): ArrayNodeDefinition |
|
|
|
|
45
|
|
|
{ |
46
|
|
|
/* @var ArrayNodeDefinition $node */ |
47
|
55 |
|
$node = parent::checkFactoryConf($builder); |
48
|
|
|
|
49
|
|
|
$node = $node |
50
|
55 |
|
->beforeNormalization() |
51
|
55 |
|
->ifArray() |
|
|
|
|
52
|
55 |
|
->then(static function ($value) { |
|
|
|
|
53
|
1 |
|
if (isset($value['dsn'])) { |
54
|
1 |
|
foreach ($value['items'] as &$v) { |
55
|
1 |
|
if (!array_key_exists('dsn', $v['check'])) { |
56
|
1 |
|
$v['check']['dsn'] = $value['dsn']; |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
61
|
1 |
|
return $value; |
62
|
55 |
|
}) |
|
|
|
|
63
|
55 |
|
->end(); |
64
|
|
|
|
65
|
55 |
|
$node->children()->scalarNode('dsn')->defaultNull()->end(); |
66
|
|
|
|
67
|
55 |
|
return $node; |
|
|
|
|
68
|
|
|
} |
69
|
|
|
|
70
|
55 |
|
protected function _check(ArrayNodeDefinition $node): ArrayNodeDefinition |
|
|
|
|
71
|
|
|
{ |
72
|
|
|
$node = $node |
73
|
55 |
|
->children() |
74
|
55 |
|
->arrayNode('check') |
|
|
|
|
75
|
55 |
|
->beforeNormalization() |
|
|
|
|
76
|
55 |
|
->ifString() |
|
|
|
|
77
|
|
|
->then(static function ($v) { return ['dsn' => $v]; }) |
|
|
|
|
78
|
55 |
|
->end() |
79
|
55 |
|
->children() |
80
|
55 |
|
->scalarNode('queue')->isRequired()->end() |
81
|
55 |
|
->integerNode('warningThreshold')->defaultValue(null)->end() |
82
|
55 |
|
->integerNode('criticalThreshold')->defaultValue(100)->end() |
83
|
55 |
|
->scalarNode('host')->defaultValue('localhost')->end() |
84
|
55 |
|
->integerNode('port')->defaultValue(5672)->end() |
85
|
55 |
|
->scalarNode('user')->defaultValue('guest')->end() |
86
|
55 |
|
->scalarNode('password')->defaultValue('guest')->end() |
87
|
55 |
|
->scalarNode('vhost')->defaultValue('/')->end() |
88
|
55 |
|
->scalarNode('dsn')->defaultNull()->end() |
89
|
55 |
|
->end() |
90
|
55 |
|
->end() |
91
|
55 |
|
->end(); |
92
|
|
|
|
93
|
55 |
|
$this->_addition($node); |
94
|
|
|
|
95
|
55 |
|
return $node; |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|