|
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 GuzzleHttp\Client; |
|
15
|
|
|
use GuzzleHttp\ClientInterface; |
|
16
|
|
|
use JMS\Serializer\Annotation as JMS; |
|
17
|
|
|
use Tvi\MonitorBundle\Check\CheckAbstract; |
|
18
|
|
|
use ZendDiagnostics\Result\Failure; |
|
19
|
|
|
use ZendDiagnostics\Result\Success; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
|
|
|
|
|
22
|
|
|
* @JMS\ExclusionPolicy("all") |
|
23
|
|
|
* |
|
24
|
|
|
* @author Vladimir Turnaev <[email protected]> |
|
25
|
|
|
*/ |
|
|
|
|
|
|
26
|
|
|
class Check extends CheckAbstract |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
|
|
|
|
|
29
|
|
|
* @var string |
|
30
|
|
|
*/ |
|
31
|
|
|
protected $uri; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
|
|
|
|
|
34
|
|
|
* @var string |
|
35
|
|
|
*/ |
|
36
|
|
|
protected $cert; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
|
|
|
|
|
39
|
|
|
* @var string |
|
40
|
|
|
*/ |
|
41
|
|
|
protected $sslKey; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
|
|
|
|
|
44
|
|
|
* @var string |
|
45
|
|
|
*/ |
|
46
|
|
|
protected $ca; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
|
|
|
|
|
49
|
|
|
* @var boolean |
|
50
|
|
|
*/ |
|
51
|
|
|
protected $verify; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
|
|
|
|
|
54
|
|
|
* @var ClientInterface |
|
55
|
|
|
*/ |
|
56
|
|
|
protected $client; |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
|
|
|
|
|
59
|
|
|
* @param string $uri |
|
|
|
|
|
|
60
|
|
|
* @param bool $verify |
|
|
|
|
|
|
61
|
|
|
* @param string $cert |
|
|
|
|
|
|
62
|
|
|
* @param string $sslKey |
|
|
|
|
|
|
63
|
|
|
* @param string $ca |
|
|
|
|
|
|
64
|
|
|
* |
|
65
|
|
|
* @throws \Exception |
|
66
|
|
|
*/ |
|
67
|
2 |
|
public function __construct( |
|
68
|
|
|
$url = 'https://localhost:2379', |
|
69
|
|
|
$verify = false, |
|
70
|
|
|
$cert = '/etc/etcd/cert/client-etcd.crt', |
|
71
|
|
|
$sslKey = '/etc/etcd/cert/client-etcd.key', |
|
72
|
|
|
$ca = '/etc/etcd/cert/ca.crt') |
|
|
|
|
|
|
73
|
|
|
{ |
|
|
|
|
|
|
74
|
2 |
|
$this->url = $url; |
|
|
|
|
|
|
75
|
2 |
|
$this->verify = $verify; |
|
76
|
2 |
|
$this->cert = $cert; |
|
77
|
2 |
|
$this->sslKey = $sslKey; |
|
78
|
2 |
|
$this->ca = $ca; |
|
79
|
|
|
|
|
80
|
2 |
|
$this->client = $this->createClient(); |
|
81
|
2 |
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* {@inheritdoc} |
|
85
|
|
|
*/ |
|
|
|
|
|
|
86
|
2 |
|
public function check() |
|
87
|
|
|
{ |
|
88
|
|
|
try { |
|
89
|
2 |
|
$version = $this->getVersion(); |
|
90
|
|
|
return new Success(null, json_decode($version, true)); |
|
91
|
2 |
|
} catch (\Exception $e) { |
|
92
|
2 |
|
return new Failure($e->getMessage()); |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
|
|
|
|
|
97
|
|
|
* @return ClientInterface |
|
98
|
|
|
* @throws \Exception |
|
99
|
|
|
*/ |
|
100
|
2 |
|
private function createClient() |
|
|
|
|
|
|
101
|
|
|
{ |
|
102
|
2 |
|
return new Client([ |
|
|
|
|
|
|
103
|
2 |
|
'base_uri' => $this->url, |
|
104
|
2 |
|
'verify' => $this->verify, |
|
105
|
|
|
'exceptions' => true, |
|
106
|
2 |
|
'cert' => $this->cert, |
|
107
|
2 |
|
'ssl_key' => $this->sslKey, |
|
108
|
|
|
]); |
|
|
|
|
|
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
|
|
|
|
|
112
|
|
|
* @return string |
|
113
|
|
|
*/ |
|
114
|
2 |
|
private function getVersion() |
|
|
|
|
|
|
115
|
|
|
{ |
|
116
|
2 |
|
$response = $this->client->get('/version'); |
|
117
|
|
|
|
|
118
|
|
|
return $response->getBody().''; |
|
119
|
|
|
} |
|
120
|
|
|
} |
|
121
|
|
|
|