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\etcd\Etcd; |
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 = 'etcd'; |
32
|
|
|
const CHECK_NAME = 'core:etcd'; |
33
|
|
|
|
34
|
|
|
/** |
|
|
|
|
35
|
|
|
* @throws FeatureRequired |
36
|
|
|
*/ |
|
|
|
|
37
|
1 |
|
public function checkRequirements(array $checkSettings) |
38
|
|
|
{ |
39
|
1 |
|
if (!interface_exists('\GuzzleHttp\ClientInterface')) { |
40
|
|
|
throw new FeatureRequired('GuzzleHttp is not installed'); |
41
|
|
|
} |
42
|
1 |
|
} |
43
|
|
|
|
44
|
57 |
|
public function checkFactoryConf(TreeBuilder $builder): ArrayNodeDefinition |
|
|
|
|
45
|
|
|
{ |
46
|
|
|
/* @var ArrayNodeDefinition $node */ |
47
|
57 |
|
$node = parent::checkFactoryConf($builder); |
48
|
|
|
|
49
|
|
|
$keys = [ |
50
|
57 |
|
'url', |
51
|
|
|
'verify', |
52
|
|
|
'cert', |
53
|
|
|
'sslKey', |
54
|
|
|
'ca' |
55
|
|
|
]; |
56
|
|
|
$node = $node |
57
|
57 |
|
->beforeNormalization() |
58
|
57 |
|
->ifArray() |
59
|
57 |
|
->then(static function ($value) use ($keys) { |
|
|
|
|
60
|
1 |
|
foreach ($keys as $key) { |
61
|
1 |
|
if (isset($value[$key])) { |
62
|
|
|
foreach ($value['items'] as &$v) { |
63
|
|
|
if (!array_key_exists($key, $v['check'])) { |
64
|
1 |
|
$v['check'][$key] = $value[$key]; |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
70
|
1 |
|
return $value; |
71
|
57 |
|
}) |
|
|
|
|
72
|
57 |
|
->end(); |
73
|
|
|
|
74
|
57 |
|
$node->children() |
75
|
57 |
|
->scalarNode('url')->end() |
76
|
57 |
|
->booleanNode('verify')->end() |
77
|
57 |
|
->scalarNode('cert')->end() |
78
|
57 |
|
->scalarNode('sslKey')->end() |
79
|
57 |
|
->scalarNode('ca')->end() |
80
|
57 |
|
->end(); |
|
|
|
|
81
|
|
|
|
82
|
57 |
|
return $node; |
|
|
|
|
83
|
|
|
} |
84
|
|
|
|
85
|
57 |
|
protected function _check(ArrayNodeDefinition $node): ArrayNodeDefinition |
|
|
|
|
86
|
|
|
{ |
87
|
|
|
$node = $node |
88
|
57 |
|
->children() |
89
|
57 |
|
->arrayNode('check') |
|
|
|
|
90
|
57 |
|
->children() |
|
|
|
|
91
|
57 |
|
->scalarNode('url')->defaultValue('https://localhost:2379')->end() |
|
|
|
|
92
|
57 |
|
->booleanNode('verify')->defaultValue(false)->end() |
|
|
|
|
93
|
57 |
|
->scalarNode('cert')->defaultValue('/etc/etcd/cert/client-etcd.crt')->end() |
|
|
|
|
94
|
57 |
|
->scalarNode('sslKey')->defaultValue('/etc/etcd/cert/client-etcd.key')->end() |
|
|
|
|
95
|
57 |
|
->scalarNode('ca')->defaultValue('/etc/etcd/cert/ca.crt')->end() |
|
|
|
|
96
|
57 |
|
->end() |
|
|
|
|
97
|
57 |
|
->end() |
|
|
|
|
98
|
57 |
|
->end(); |
99
|
|
|
|
100
|
57 |
|
$this->_addition($node); |
101
|
|
|
|
102
|
57 |
|
return $node; |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|