|
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\http\GuzzleHttpService; |
|
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
|
|
|
guzzle_http_service description |
|
27
|
|
|
TXT; |
|
28
|
|
|
|
|
29
|
|
|
const PATH = __DIR__; |
|
30
|
|
|
|
|
31
|
|
|
const GROUP = 'http'; |
|
32
|
|
|
const CHECK_NAME = 'core:guzzle_http_service'; |
|
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
|
|
|
$keys = [ |
|
49
|
57 |
|
'headers', |
|
50
|
|
|
'options', |
|
51
|
|
|
'statusCode', |
|
52
|
|
|
'method', |
|
53
|
|
|
'content', |
|
54
|
|
|
'body', |
|
55
|
|
|
'withData', |
|
56
|
|
|
]; |
|
57
|
|
|
|
|
58
|
|
|
$node = $node |
|
59
|
57 |
|
->beforeNormalization() |
|
60
|
57 |
|
->ifArray() |
|
61
|
57 |
|
->then(static function ($value) use ($keys) { |
|
|
|
|
|
|
62
|
1 |
|
foreach ($keys as $key) { |
|
63
|
1 |
|
if (isset($value[$key])) { |
|
64
|
|
|
foreach ($value['items'] as &$v) { |
|
65
|
|
|
if (!array_key_exists($key, $v['check'])) { |
|
66
|
1 |
|
$v['check'][$key] = $value[$key]; |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
1 |
|
return $value; |
|
73
|
57 |
|
}) |
|
|
|
|
|
|
74
|
57 |
|
->end(); |
|
75
|
57 |
|
$node->children() |
|
76
|
57 |
|
->variableNode('headers')->end() |
|
77
|
57 |
|
->variableNode('options')->end() |
|
78
|
57 |
|
->integerNode('statusCode')->end() |
|
79
|
57 |
|
->scalarNode('method')->end() |
|
80
|
57 |
|
->scalarNode('content')->end() |
|
81
|
57 |
|
->scalarNode('body')->end() |
|
82
|
57 |
|
->booleanNode('withData')->end() |
|
83
|
57 |
|
->end(); |
|
|
|
|
|
|
84
|
|
|
|
|
85
|
57 |
|
return $node; |
|
|
|
|
|
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
57 |
|
protected function _check(ArrayNodeDefinition $node): ArrayNodeDefinition |
|
|
|
|
|
|
89
|
|
|
{ |
|
90
|
|
|
$node = $node |
|
91
|
57 |
|
->children() |
|
92
|
57 |
|
->arrayNode('check') |
|
|
|
|
|
|
93
|
57 |
|
->children() |
|
|
|
|
|
|
94
|
57 |
|
->scalarNode('requestOrUrl')->defaultValue('localhost')->end() |
|
|
|
|
|
|
95
|
57 |
|
->variableNode('headers')->defaultValue([])->end() |
|
|
|
|
|
|
96
|
57 |
|
->variableNode('options')->defaultValue([])->end() |
|
|
|
|
|
|
97
|
57 |
|
->integerNode('statusCode')->defaultValue(200)->end() |
|
|
|
|
|
|
98
|
57 |
|
->scalarNode('method')->defaultValue('GET')->end() |
|
|
|
|
|
|
99
|
57 |
|
->scalarNode('content')->defaultNull()->end() |
|
|
|
|
|
|
100
|
57 |
|
->scalarNode('body')->defaultNull()->end() |
|
|
|
|
|
|
101
|
57 |
|
->booleanNode('withData')->defaultFalse()->end() |
|
|
|
|
|
|
102
|
57 |
|
->end() |
|
|
|
|
|
|
103
|
57 |
|
->end() |
|
|
|
|
|
|
104
|
57 |
|
->end(); |
|
105
|
|
|
|
|
106
|
57 |
|
$this->_addition($node); |
|
107
|
|
|
|
|
108
|
57 |
|
return $node; |
|
109
|
|
|
} |
|
110
|
|
|
} |
|
111
|
|
|
|