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\RabbitMQ; |
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'; |
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
|
56 |
|
public function checkFactoryConf(TreeBuilder $builder): ArrayNodeDefinition |
|
|
|
|
45
|
|
|
{ |
46
|
|
|
/* @var ArrayNodeDefinition $node */ |
47
|
56 |
|
$node = parent::checkFactoryConf($builder); |
48
|
|
|
|
49
|
|
|
$keys = [ |
50
|
56 |
|
'host', |
51
|
|
|
'port', |
52
|
|
|
'user', |
53
|
|
|
'password', |
54
|
|
|
'vhost', |
55
|
|
|
'dsn', |
56
|
|
|
]; |
57
|
|
|
$node = $node |
58
|
56 |
|
->beforeNormalization() |
59
|
56 |
|
->ifArray() |
60
|
56 |
|
->then(static function ($value) use($keys) { |
|
|
|
|
61
|
|
|
|
62
|
1 |
|
foreach ($keys as $key) { |
63
|
|
|
|
64
|
1 |
|
if (isset($value[$key])) { |
65
|
|
|
foreach ($value['items'] as &$v) { |
66
|
|
|
if (!array_key_exists($key, $v['check'])) { |
67
|
1 |
|
$v['check'][$key] = $value[$key]; |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
} |
72
|
1 |
|
return $value; |
73
|
56 |
|
}) |
|
|
|
|
74
|
56 |
|
->end(); |
75
|
|
|
|
76
|
56 |
|
$node->children() |
77
|
56 |
|
->scalarNode('host')->end() |
78
|
56 |
|
->integerNode('port')->end() |
79
|
56 |
|
->scalarNode('user')->end() |
80
|
56 |
|
->scalarNode('password')->end() |
81
|
56 |
|
->scalarNode('vhost')->end() |
82
|
56 |
|
->scalarNode('dsn')->end() |
83
|
56 |
|
->end(); |
|
|
|
|
84
|
|
|
|
85
|
56 |
|
return $node; |
|
|
|
|
86
|
|
|
} |
87
|
|
|
|
88
|
56 |
|
protected function _check(ArrayNodeDefinition $node): ArrayNodeDefinition |
|
|
|
|
89
|
|
|
{ |
90
|
|
|
$node = $node |
91
|
56 |
|
->children() |
92
|
56 |
|
->arrayNode('check') |
|
|
|
|
93
|
56 |
|
->beforeNormalization() |
|
|
|
|
94
|
56 |
|
->ifString() |
|
|
|
|
95
|
|
|
->then(static function ($v) { return ['dsn' => $v]; }) |
|
|
|
|
96
|
56 |
|
->end() |
97
|
56 |
|
->children() |
98
|
56 |
|
->scalarNode('host')->defaultValue('localhost')->end() |
99
|
56 |
|
->integerNode('port')->defaultValue(5672)->end() |
100
|
56 |
|
->scalarNode('user')->defaultValue('guest')->end() |
101
|
56 |
|
->scalarNode('password')->defaultValue('guest')->end() |
102
|
56 |
|
->scalarNode('vhost')->defaultValue('/')->end() |
103
|
56 |
|
->scalarNode('dsn')->defaultNull()->end() |
104
|
56 |
|
->end() |
105
|
56 |
|
->end() |
106
|
56 |
|
->end(); |
107
|
|
|
|
108
|
56 |
|
$this->_addition($node); |
109
|
|
|
|
110
|
56 |
|
return $node; |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|