Skip to content

Commit

Permalink
Adding a check for mongodb connection
Browse files Browse the repository at this point in the history
  • Loading branch information
tegbessou committed Jul 13, 2017
1 parent 255f7a5 commit 357cfdb
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 0 deletions.
27 changes: 27 additions & 0 deletions Check/DoctrineMongoDb.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Liip\MonitorBundle\Check;

use Doctrine\Bundle\MongoDBBundle\ManagerRegistry;
use ZendDiagnostics\Check\AbstractCheck;
use ZendDiagnostics\Result\Success;

class DoctrineMongoDb extends AbstractCheck
{
protected $manager;
protected $connectionName;

public function __construct(ManagerRegistry $registry, $connectionName = null)
{
$this->manager = $registry;
$this->connectionName = $connectionName;
}

public function check()
{
$connection = $this->manager->getConnection();
$connection->connect();

return new Success();
}
}
36 changes: 36 additions & 0 deletions Check/DoctrineMongoDbCollection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace Liip\MonitorBundle\Check;

use Doctrine\Common\Persistence\ConnectionRegistry;
use ZendDiagnostics\Check\CheckCollectionInterface;

/**
* @author Hugues Gobet <hugues.gobet@gmail.com>
*/
class DoctrineMongoDbCollection implements CheckCollectionInterface
{
private $checks = array();

public function __construct(ConnectionRegistry $manager, $connections)
{
if (!is_array($connections)) {
$connections = array($connections);
}

foreach ($connections as $connection) {
$check = new DoctrineMongoDb($manager, $connection);
$check->setLabel(sprintf('Doctrine Mongo Db "%s" connection', $connection));

$this->checks[sprintf('doctrine_dbal_%s_connection', $connection)] = $check;
}
}

/**
* {@inheritdoc}
*/
public function getChecks()
{
return $this->checks;
}
}
5 changes: 5 additions & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ private function createGroupsNode()
->info('Connection name or an array of connection names')
->example('[default, crm]')
->end()
->variableNode('doctrine_mongodb')
->defaultNull()
->info('Connection name or an array of connection names')
->example('[default, crm]')
->end()
->arrayNode('doctrine_migrations')
->useAttributeAsKey('name')
->info('Check if doctrine migrations are applied')
Expand Down
1 change: 1 addition & 0 deletions DependencyInjection/LiipMonitorExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ private function setParameters(ContainerBuilder $container, $checkName, $group,
case 'writable_directory':
case 'process_running':
case 'doctrine_dbal':
case 'doctrine_mongodb':
case 'http_service':
case 'guzzle_http_service':
case 'memcache':
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,9 @@ liip_monitor:

# Connection name or an array of connection names
doctrine_dbal: null # Example: [default, crm]

# Connection name or an array of connection names
doctrine_mongodb: null # Example: [default, crm]

# Check if MemCache extension is loaded and given server is reachable
memcache:
Expand Down
18 changes: 18 additions & 0 deletions Resources/config/checks/doctrine_mongodb.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" ?>

<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

<parameters>
<parameter key="liip_monitor.check.doctrine_mongodb.class">Liip\MonitorBundle\Check\DoctrineMongoDbCollection</parameter>
</parameters>

<services>
<service id="liip_monitor.check.doctrine_mongodb" public="false" class="%liip_monitor.check.doctrine_mongodb.class%">
<argument type="service" id="doctrine_mongodb" />
<argument>%%liip_monitor.check.doctrine_mongodb%%</argument>
<tag name="liip_monitor.check_collection" />
</service>
</services>
</container>

0 comments on commit 357cfdb

Please sign in to comment.