Skip to content
This repository was archived by the owner on Jan 31, 2020. It is now read-only.

Commit c4c9eff

Browse files
committed
added RabbitMQ and Redis checks
1 parent b8b34f1 commit c4c9eff

File tree

3 files changed

+160
-1
lines changed

3 files changed

+160
-1
lines changed

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828
"ext-bcmath" : "Required by Check\\CpuPerformance",
2929
"sensiolabs/security-checker": "Required by Check\\SecurityAdvisory",
3030
"symfony/yaml": "Required by Check\\YamlFile",
31-
"guzzle/http": "Required by Check\\GuzzleHttpService"
31+
"guzzle/http": "Required by Check\\GuzzleHttpService",
32+
"predis/predis": "Required by Check\\Redis",
33+
"videlalvaro/php-amqplib": "TRequired by Check\\RabbitMQ"
3234
},
3335
"extra": {
3436
"branch-alias": {
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?php
2+
/**
3+
* @license http://framework.zend.com/license/new-bsd New BSD License
4+
*/
5+
6+
namespace ZendDiagnostics\Check;
7+
8+
use PhpAmqpLib\Connection\AMQPConnection;
9+
use ZendDiagnostics\Result\Failure;
10+
use ZendDiagnostics\Result\Success;
11+
12+
/**
13+
* Validate that a RabbitMQ service is running
14+
*
15+
* @author Cédric Dugat <[email protected]>
16+
*/
17+
class RabbitMQ extends AbstractCheck
18+
{
19+
/**
20+
* @var string
21+
*/
22+
protected $host;
23+
24+
/**
25+
* @var integer
26+
*/
27+
protected $port;
28+
29+
/**
30+
* @var string
31+
*/
32+
protected $user;
33+
34+
/**
35+
* @var string
36+
*/
37+
protected $password;
38+
39+
/**
40+
* @var string
41+
*/
42+
protected $vhost;
43+
44+
/**
45+
* @param string $host
46+
* @param integer $port
47+
* @param string $user
48+
* @param string $password
49+
* @param string $vhost
50+
*/
51+
public function __construct(
52+
$host = 'localhost',
53+
$port = 5672,
54+
$user = 'guest',
55+
$password = 'guest',
56+
$vhost = '/'
57+
) {
58+
$this->host = $host;
59+
$this->port = $port;
60+
$this->user = $user;
61+
$this->password = $password;
62+
$this->vhost = $vhost;
63+
}
64+
65+
/**
66+
* Perform the check
67+
*
68+
* @see \ZendDiagnostics\Check\CheckInterface::check()
69+
* @return Failure|Success
70+
*/
71+
public function check()
72+
{
73+
if (!class_exists('PhpAmqpLib\Connection\AMQPConnection', false)) {
74+
return new Failure('PhpAmqpLib is not installed');
75+
}
76+
77+
$conn = new AMQPConnection(
78+
$this->host,
79+
$this->port,
80+
$this->user,
81+
$this->password,
82+
$this->vhost
83+
);
84+
85+
$conn->channel();
86+
87+
return new Success();
88+
}
89+
}

src/ZendDiagnostics/Check/Redis.php

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
/**
3+
* @license http://framework.zend.com/license/new-bsd New BSD License
4+
*/
5+
6+
namespace ZendDiagnostics\Check;
7+
8+
use Predis\Client;
9+
use ZendDiagnostics\Result\Failure;
10+
use ZendDiagnostics\Result\Success;
11+
12+
/**
13+
* Validate that a Redis service is running
14+
*
15+
* @author Cédric Dugat <[email protected]>
16+
*/
17+
class Redis extends AbstractCheck
18+
{
19+
/**
20+
* @var string
21+
*/
22+
protected $host;
23+
24+
/**
25+
* @var int
26+
*/
27+
protected $port;
28+
29+
/**
30+
* @param string $host
31+
* @param int $port
32+
*/
33+
public function __construct($host = 'localhost', $port = 6379)
34+
{
35+
$this->host = $host;
36+
$this->port = $port;
37+
}
38+
39+
/**
40+
* Perform the check
41+
*
42+
* @see \ZendDiagnostics\Check\CheckInterface::check()
43+
* @return Failure|Success
44+
*/
45+
public function check()
46+
{
47+
if (!class_exists('Predis\Client', false)) {
48+
return new Failure('Predis is not installed');
49+
}
50+
51+
$client = new Client(array(
52+
'host' => $this->host,
53+
'port' => $this->port,
54+
));
55+
56+
if (!$client->ping()) {
57+
return new Failure(
58+
sprintf(
59+
'No Redis server running at host %s on port %s',
60+
$this->host,
61+
$this->port
62+
)
63+
);
64+
}
65+
66+
return new Success();
67+
}
68+
}

0 commit comments

Comments
 (0)