Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

refactored the Bundle to move all lib code to a separate package

  • Loading branch information...
commit 8aa13ecb2bcbaf1daf521b18e122e9ae105e1adb 1 parent 2cbff90
@lsmith77 lsmith77 authored
View
26 Check/Check.php
@@ -1,26 +0,0 @@
-<?php
-
-namespace Liip\MonitorBundle\Check;
-
-use Liip\MonitorBundle\Result\CheckResult;
-
-abstract class Check implements CheckInterface
-{
- /**
- * {@inheritdoc}
- */
- public function getName()
- {
- return get_called_class();
- }
-
- /**
- * @param string $message
- * @param integer $status
- * @return \Liip\MonitorBundle\Result\CheckResult
- */
- protected function buildResult($message, $status)
- {
- return new CheckResult($this->getName(), $message, $status);
- }
-}
View
59 Check/CheckChain.php
@@ -1,59 +0,0 @@
-<?php
-
-namespace Liip\MonitorBundle\Check;
-
-use Liip\MonitorBundle\Check\CheckInterface;
-
-final class CheckChain
-{
- protected $checks = array();
-
- /**
- * @param array $checks
- */
- public function __construct(array $checks = array())
- {
- foreach ($checks as $serviceId => $check) {
- $this->addCheck($serviceId, $check);
- }
- }
-
- /**
- * @param string $serviceId
- * @param CheckInterface $check
- */
- public function addCheck($serviceId, CheckInterface $check)
- {
- $this->checks[$serviceId] = $check;
- }
-
- /**
- * @return array
- */
- public function getChecks()
- {
- return $this->checks;
- }
-
- /**
- * @return array
- */
- public function getAvailableChecks()
- {
- return array_keys($this->checks);
- }
-
- /**
- * @throws \InvalidArgumentException
- * @param string $id
- * @return \Liip\MonitorBundle\Check\CheckInterface
- */
- public function getCheckById($id)
- {
- if (!isset($this->checks[$id])) {
- throw new \InvalidArgumentException(sprintf("Check with id: %s doesn't exists", $id));
- }
-
- return $this->checks[$id];
- }
-}
View
16 Check/CheckInterface.php
@@ -1,16 +0,0 @@
-<?php
-
-namespace Liip\MonitorBundle\Check;
-
-interface CheckInterface
-{
- /**
- * @return \Liip\MonitorBundle\Result\CheckResult
- */
- function check();
-
- /**
- * @return string
- */
- function getName();
-}
View
97 Check/CustomErrorPagesCheck.php
@@ -0,0 +1,97 @@
+<?php
+
+namespace Liip\Monitor\Check;
+
+use Liip\Monitor\Check\Check;
+use Liip\Monitor\Result\CheckResult;
+use Liip\Monitor\Exception\CheckFailedException;
+
+use Symfony\Bundle\TwigBundle\DependencyInjection\Configuration;
+
+/**
+ * Checks if error pages have been customized.
+ *
+ * @author Cédric Girard <c.girard@lexik.fr>
+ */
+class CustomErrorPagesCheck extends Check
+{
+ /**
+ * @var string
+ */
+ protected $kernelRootDir;
+
+ /**
+ * @var array
+ */
+ protected $errorCodes;
+
+ /**
+ * @var string
+ */
+ protected $exceptionController;
+
+ /**
+ * Construct.
+ *
+ * @param array $errorCodes
+ * @param string $kernelRootDir
+ * @param string $exceptionController
+ */
+ public function __construct($errorCodes, $kernelRootDir, $exceptionController)
+ {
+ $this->errorCodes = $errorCodes;
+ $this->kernelRootDir = $kernelRootDir;
+ $this->exceptionController = $exceptionController;
+ }
+
+ /**
+ * @see Liip\Monitor\Check\CheckInterface::check()
+ */
+ public function check()
+ {
+ try {
+ // check if twig exception controller is not the default one.
+ $config = new Configuration();
+ $tree = $config->getConfigTreeBuilder()->buildTree();
+
+ $reflectionTree = new \ReflectionClass($tree);
+ $reflectionChildren = $reflectionTree->getProperty('children');
+ $reflectionChildren->setAccessible(true);
+
+ $values = $reflectionChildren->getValue($tree);
+
+ // we suppose pages has been customized if the execption controller is not the default one,
+ // so we don't look for template file in this case.
+ if ($values['exception_controller']->getDefaultValue() == $this->exceptionController) {
+ $missingTemplate = array();
+
+ foreach ($this->errorCodes as $errorCode) {
+ $template = sprintf('%s/Resources/TwigBundle/views/Exception/error%d.html.twig', $this->kernelRootDir, $errorCode);
+
+ if (!file_exists($template)) {
+ $missingTemplate[] = $errorCode;
+ }
+ }
+
+ if (count($missingTemplate) > 0) {
+ throw new CheckFailedException(sprintf('No custom error page found for the following codes: %s', implode(', ', $missingTemplate)));
+ }
+ }
+
+ $result = $this->buildResult('OK', CheckResult::OK);
+
+ } catch (\Exception $e) {
+ $result = $this->buildResult($e->getMessage(), CheckResult::CRITICAL);
+ }
+
+ return $result;
+ }
+
+ /**
+ * @see Liip\Monitor\Check\Check::getName()
+ */
+ public function getName()
+ {
+ return 'Custom error pages';
+ }
+}
View
72 Check/DepsEntriesCheck.php
@@ -0,0 +1,72 @@
+<?php
+
+namespace Liip\Monitor\Check;
+
+use Liip\Monitor\Check\Check;
+use Liip\Monitor\Exception\CheckFailedException;
+use Liip\Monitor\Result\CheckResult;
+
+/**
+ * Checks all entries from deps are defined in deps.lock
+ *
+ * @author Cédric Girard <c.girard@lexik.fr>
+ */
+class DepsEntriesCheck extends Check
+{
+ /**
+ * @var string
+ */
+ protected $kernelRootDir;
+
+ /**
+ * Construct.
+ *
+ * @param string $kernelRootDir
+ */
+ public function __construct($kernelRootDir)
+ {
+ $this->kernelRootDir = $kernelRootDir;
+ }
+
+ /**
+ * @see Liip\Monitor\Check\CheckInterface::check()
+ */
+ public function check()
+ {
+ try {
+ $deps = parse_ini_file($this->kernelRootDir.'/../deps', true, INI_SCANNER_RAW);
+
+ $depsLock = array();
+ foreach (file($this->kernelRootDir.'/../deps.lock', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) as $line) {
+ $values = explode(' ', $line);
+ $depsLock[$values[0]] = isset($values[1]) ? $values[1] : '';
+ }
+
+ $unlocked = array();
+ foreach ($deps as $name => $data) {
+ if (!isset($depsLock[$name]) || $depsLock[$name] == '') {
+ $unlocked[] = $name;
+ }
+ }
+
+ if (count($unlocked) > 0) {
+ throw new CheckFailedException(sprintf('The following entries are not defined in the deps.lock file: %s', implode(', ', $unlocked)));
+ }
+
+ $result = $this->buildResult('OK', CheckResult::OK);
+
+ } catch (\Exception $e) {
+ $result = $this->buildResult($e->getMessage(), CheckResult::CRITICAL);
+ }
+
+ return $result;
+ }
+
+ /**
+ * @see Liip\Monitor\Check\Check::getName()
+ */
+ public function getName()
+ {
+ return 'Deps files entries check';
+ }
+}
View
49 Check/Runner.php
@@ -1,49 +0,0 @@
-<?php
-
-namespace Liip\MonitorBundle\Check;
-
-use Symfony\Component\DependencyInjection\ContainerAware;
-
-class Runner extends ContainerAware
-{
- protected $chain;
-
- /**
- * @param \Liip\MonitorBundle\Check\CheckChain $chain
- */
- public function __construct(CheckChain $chain)
- {
- $this->chain = $chain;
- }
-
- /**
- * @param string $checkId
- * @return \Liip\MonitorBundle\Result\CheckResult
- */
- public function runCheckById($checkId)
- {
- return $this->runCheck($this->chain->getCheckById($checkId));
- }
-
- /**
- * @param \Liip\MonitorBundle\Check\CheckInterface $checkService
- * @return \Liip\MonitorBundle\Result\CheckResult
- */
- public function runCheck(CheckInterface $checkService)
- {
- return $checkService->check();
- }
-
- /**
- * @return array
- */
- public function runAllChecks()
- {
- $results = array();
- foreach ($this->chain->getChecks() as $id => $checkService) {
- $results[$id] = $this->runCheck($checkService);
- }
-
- return $results;
- }
-}
View
89 Check/SymfonyVersionCheck.php
@@ -0,0 +1,89 @@
+<?php
+
+namespace Liip\Monitor\Check;
+
+use Symfony\Component\HttpKernel\Kernel;
+use Exception;
+use Liip\Monitor\Check\Check;
+use Liip\Monitor\Result\CheckResult;
+
+/**
+ * Checks the version of this website against the latest stable release.
+ *
+ * Add this to your config.yml
+ *
+ * monitor.check.symfony_version:
+ * class: Liip\Monitor\Check\SymfonyVersionCheck
+ * tags:
+ * - { name: monitor.check }
+ *
+ * @author Roderik van der Veer <roderik@vanderveer.be>
+ */
+class SymfonyVersionCheck extends Check
+{
+
+ /**
+ * {@inheritdoc}
+ */
+ public function check()
+ {
+ try {
+ $latestRelease = $this->getLatestSymfonyVersion(); // eg. 2.0.12
+ $currentVersion = Kernel::VERSION;
+ if (version_compare($currentVersion, $latestRelease) >= 0) {
+ $result = $this->buildResult('OK', CheckResult::OK);
+ } else {
+ $result = $this->buildResult('Update to ' . $latestRelease . ' from ' . $currentVersion, CheckResult::WARNING);
+ }
+ } catch (\Exception $e) {
+ $result = $this->buildResult($e->getMessage(), CheckResult::UNKNOWN);
+ }
+
+ return $result;
+ }
+
+ private function getLatestSymfonyVersion()
+ {
+ // Get GitHub JSON request
+
+ $githubUrl = 'https://api.github.com/repos/symfony/symfony/tags';
+ $githubJSONResponse = file_get_contents($githubUrl);
+
+ // Convert it to a PHP object
+
+ $githubResponseArray = json_decode($githubJSONResponse, true);
+ if (empty($githubResponseArray)) {
+ throw new Exception("No valid response or no tags received from GitHub.");
+ }
+
+ $tags = array();
+
+ foreach ($githubResponseArray as $tag) {
+ $tags[] = $tag['name'];
+ }
+
+ // Sort tags
+
+ usort($tags, "version_compare");
+
+ // Filter out non final tags
+
+ $filteredTagList = array_filter($tags, function($tag) {
+ return !stripos($tag, "PR") && !stripos($tag, "RC") && !stripos($tag, "BETA");
+ });
+
+ // The first one is the last stable release for Symfony 2
+
+ $reverseFilteredTagList = array_reverse($filteredTagList);
+
+ return str_replace("v", "", $reverseFilteredTagList[0]);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getName()
+ {
+ return 'Symfony version';
+ }
+}
View
4 Command/HealthCheckCommand.php
@@ -7,7 +7,7 @@
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
-use Liip\MonitorBundle\Result\CheckResult;
+use Liip\Monitor\Result\CheckResult;
class HealthCheckCommand extends ContainerAwareCommand
{
@@ -34,7 +34,7 @@ protected function configure()
protected function execute(InputInterface $input, OutputInterface $output)
{
$checkName = $input->getArgument('checkName');
- $runner = $this->getContainer()->get('monitor.check.runner');
+ $runner = $this->getContainer()->get('liip_monitor.check.runner');
if ($checkName == 'all') {
$results = $runner->runAllChecks();
View
2  Command/ListChecksCommand.php
@@ -24,7 +24,7 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
- $chain = $this->getContainer()->get('monitor.check_chain');
+ $chain = $this->getContainer()->get('liip_monitor.check_chain');
foreach ($chain->getAvailableChecks() as $service_id) {
$output->writeln($service_id);
}
View
8 Controller/HealthCheckController.php
@@ -4,9 +4,9 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
-use Liip\MonitorBundle\Check\Runner;
+use Liip\Monitor\Check\Runner;
use Liip\MonitorBundle\Helper\PathHelper;
-use Liip\MonitorBundle\Check\CheckChain;
+use Liip\Monitor\Check\CheckChain;
class HealthCheckController
{
@@ -15,8 +15,8 @@ class HealthCheckController
protected $pathHelper;
/**
- * @param \Liip\MonitorBundle\Check\CheckChain $healthCheckChain
- * @param \Liip\MonitorBundle\Check\Runner $runner
+ * @param \Liip\Monitor\Check\CheckChain $healthCheckChain
+ * @param \Liip\Monitor\Check\Runner $runner
* @param \Liip\MonitorBundle\Helper\PathHelper $pathHelper
*/
public function __construct(CheckChain $healthCheckChain, Runner $runner, PathHelper $pathHelper)
View
6 DependencyInjection/Compiler/HealthCheckTagCompilerPass.php
@@ -10,13 +10,13 @@ class HealthCheckTagCompilerPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
- if (false === $container->hasDefinition('monitor.check_chain')) {
+ if (false === $container->hasDefinition('liip_monitor.check_chain')) {
return;
}
- $definition = $container->getDefinition('monitor.check_chain');
+ $definition = $container->getDefinition('liip_monitor.check_chain');
- foreach ($container->findTaggedServiceIds('monitor.check') as $id => $attributes) {
+ foreach ($container->findTaggedServiceIds('liip_monitor.check') as $id => $attributes) {
$definition->addMethodCall('addCheck', array($id, new Reference($id)));
}
}
View
41 DependencyInjection/Configuration.php
@@ -0,0 +1,41 @@
+<?php
+
+namespace Liip\MonitorBundle\DependencyInjection;
+
+use Symfony\Component\Config\Definition\Builder\TreeBuilder,
+ Symfony\Component\Config\Definition\ConfigurationInterface;
+
+/**
+ * This class contains the configuration information for the bundle
+ *
+ * This information is solely responsible for how the different configuration
+ * sections are normalized, and merged.
+ *
+ * @author Lukas Kahwe Smith <smith@pooteeweet.org>
+ */
+class Configuration implements ConfigurationInterface
+{
+ /**
+ * Generates the configuration tree.
+ *
+ * @return TreeBuilder
+ */
+ public function getConfigTreeBuilder()
+ {
+ $treeBuilder = new TreeBuilder();
+ $rootNode = $treeBuilder->root('liip_monitor', 'array');
+
+ $rootNode
+ ->fixXmlConfig('check', 'checks')
+ ->children()
+ ->arrayNode('checks')
+ ->useAttributeAsKey('services')
+ ->prototype('variable')->end()
+ ->end()
+ ->end()
+ ->end();
+
+ return $treeBuilder;
+ }
+
+}
View
80 DependencyInjection/LiipMonitorExtension.php
@@ -5,7 +5,8 @@
use Symfony\Component\Config\FileLocator,
Symfony\Component\HttpKernel\DependencyInjection\Extension,
Symfony\Component\DependencyInjection\ContainerBuilder,
- Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
+ Symfony\Component\DependencyInjection\Loader\YamlFileLoader,
+ Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
class LiipMonitorExtension extends Extension
{
@@ -19,5 +20,82 @@ public function load(array $configs, ContainerBuilder $container)
{
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('config.yml');
+
+ $configuration = new Configuration();
+ $config = $this->processConfiguration($configuration, $configs);
+
+ foreach ($config['checks'] as $check => $values) {
+ $serviceId = $this->getAlias().'.check.'.$check;
+ if ($container->hasDefinition($serviceId)) {
+ $service = $container->getDefinition($serviceId);
+ }
+
+ switch ($check) {
+ case 'custom_error_pages':
+ if (isset($values['error_codes'])) {
+ $service->replaceArgument(0, $values['error_codes']);
+ }
+ if (isset($values['kernel_root_dir'])) {
+ $service->replaceArgument(1, $values['kernel_root_dir']);
+ }
+ if (isset($values['twig.exception_listener.controller'])) {
+ $service->replaceArgument(2, $values['twig.exception_listener.controller']);
+ }
+ break;
+
+ case 'symfony_version_check':
+ break;
+
+ case 'deps_entries':
+ if (isset($values['kernel_root_dir'])) {
+ $service->replaceArgument(0, $values['kernel_root_dir']);
+ }
+ break;
+
+ case 'memcache':
+ if (isset($values['host'])) {
+ $service->replaceArgument(0, $values['host']);
+ }
+ if (isset($values['port'])) {
+ $service->replaceArgument(1, $values['port']);
+ }
+ break;
+
+ case 'php_extensions':
+ if (isset($values['extensions'])) {
+ $service->replaceArgument(0, $values['extensions']);
+ }
+ break;
+
+ case 'process_active':
+ if (isset($values['processes'])) {
+ $service->replaceArgument(0, $values['processes']);
+ }
+ break;
+
+ case 'writable_directory':
+ if (isset($values['dirs'])) {
+ $service->replaceArgument(0, $values['dirs']);
+ }
+ break;
+
+ case 'disc_usage':
+ if (isset($values['percentage'])) {
+ $service->replaceArgument(0, $values['percentage']);
+ }
+ if (isset($values['path'])) {
+ $service->replaceArgument(1, $values['path']);
+ }
+ break;
+
+ default:
+ if (!$container->hasDefinition($check)) {
+ throw new InvalidConfigurationException("LiipMonitorBundle does not provide a service definition for '$check'");
+ }
+ $service = $container->getDefinition($check);
+ }
+
+ $service->addTag('liip_monitor.check');
+ }
}
}
View
7 Exception/CheckFailedException.php
@@ -1,7 +0,0 @@
-<?php
-
-namespace Liip\MonitorBundle\Exception;
-
-class CheckFailedException extends \RuntimeException
-{
-}
View
121 README.md
@@ -1,15 +1,29 @@
# Liip Monitor Bundle #
-This bundle provides a way to run a series of application related health checks. Health checks in the scope of this bundle go beyond simple actions like performing a _ping_ to a server to see if it's alive. For example a Memcache server can be alive and not displaying any errors in your Nagios but you might not be able to access it from your PHP application. Each health check should then implement some application logic that you want to make sure always works. Another usage can be testing for specific requirements, like availability of PHP extensions.
-
-Another design goal of the bundle was to be able to perform the checks using the same configuration and environment that your application is using. In that way you can make sure that if the health check runs successfully then your app should work too.
-
-So each health check will be a class that will implement the `CheckInterface::check` method which must return a `CheckResult` object. What happens inside that method
+This bundle provides a way to run a series of application related health checks.
+Health checks in the scope of this bundle go beyond simple actions like performing
+a _ping_ to a server to see if it's alive. For example a Memcache server can be
+alive and not displaying any errors in your Nagios but you might not be able to
+access it from your PHP application. Each health check should then implement some
+application logic that you want to make sure always works. Another usage can be
+testing for specific requirements, like availability of PHP extensions.
+
+Another design goal of the bundle was to be able to perform the checks using the
+same configuration and environment that your application is using. In that way you
+can make sure that if the health check runs successfully then your app should work
+too.
+
+So each health check will be a class that will implement the `CheckInterface::check`
+method which must return a `CheckResult` object. What happens inside that method
is up to the Check developer.
-Health checks are defined as Symfony services and they have to be tagged as `monitor.check` in order to be picked up by the _Health Check Runner_. This gives a lot of flexibility to application and bundle developers when they want to add their own checks.
+Health checks are defined as Symfony services and they have to be tagged as
+`monitor.check` in order to be picked up by the _Health Check Runner_. This gives a
+lot of flexibility to application and bundle developers when they want to add their
+own checks.
-Checks are run via the command line using a Symfony command or via a REST api that delivers the results in JSON format.
+Checks are run via the command line using a Symfony command or via a REST api that
+delivers the results in JSON format.
Here's the web interface:
@@ -21,9 +35,14 @@ Here's the web interface:
Add the following code to your ```composer.json``` file:
+ "require": {
+ ..
+ "liip/monitor-bundle": "dev-master"
+ },
+
And then run the Composer update command:
- $ php composer.phar update
+ $ php composer.phar update liip/monitor-bundle
Then register the bundle in the `AppKernel.php` file:
@@ -48,73 +67,44 @@ And finally don't forget to install the bundle assets into your web root:
$ ./app/console assets:install web --symlink --relative
-## Writing Health Checks ##
+## Adding Health Checks ##
-Let's see an example on how to implement a Health Check class. In this case we are going to test for the availability of PHP Extensions:
-
- namespace Acme\HelloBundle\Check;
-
- use Liip\MonitorBundle\Check\Check;
- use Liip\MonitorBundle\Exception\CheckFailedException;
- use Liip\MonitorBundle\Result\CheckResult;
+Once you implemented the class then it's time to register the check service with our service container:
- class PhpExtensionsCheck extends Check
- {
- protected $extensions;
-
- public function __construct($extensions)
- {
- $this->extensions = $extensions;
- }
-
- public function check()
- {
- try {
- foreach ($this->extensions as $extension) {
- if (!extension_loaded($extension)) {
- throw new CheckFailedException(sprintf('Extension %s not loaded', $extension));
- }
- }
- return $this->buildResult('OK', CheckResult::OK);
- } catch (\Exception $e) {
- return $this->buildResult(sprintf('KO - %s', $e->getMessage()), CheckResult::CRITICAL);
- }
- }
-
- public function getName()
- {
- return "PHP Extensions Health Check";
- }
- }
+ services:
+ monitor.check.php_extensions:
+ class: Acme\HelloBundle\Check\PhpExtensionsCheck
+ arguments:
+ - [ xhprof, apc, memcache ]
+ tags:
+ - { name: liip_monitor.check }
+The important bit there is to remember to tag your services with the `liip_monitor.check` tag.
+By doing that the check runner will be able to find your checks. Keep in mind that checks
+can reside either in your bundles or in your app specific code. The location doesn't matter
+as long as the service is properly tagged.
-### CheckResult values ###
+## Available Health Checks ##
-These values has been taken from the [nagios documentation](http://nagiosplug.sourceforge.net/developer-guidelines.html#RETURNCODES) :
+On top of all the checks provided by the LiipMonitor library this Bundle adds the following
+Symfony2 specific health checks:
- * ``CheckResult::OK`` - The plugin was able to check the service and it appeared to be functioning properly
- * ``CheckResult::WARNING`` - The plugin was able to check the service, but it appeared to be above some "warning" threshold or did not appear to be working properly
- * ``CheckResult::CRITICAL`` - The plugin detected that either the service was not running or it was above some "critical" threshold
- * ``CheckResult::UNKNOWN`` - Invalid command line arguments were supplied to the plugin or low-level failures internal to the plugin (such as unable to fork, or open a tcp socket) that prevent it from performing the specified operation. Higher-level errors (such as name resolution errors, socket timeouts, etc) are outside of the control of plugins and should generally NOT be reported as UNKNOWN states.
+### CustomErrorPagesCheck ###
+Checks if error pages have been customized for given error codes.
-As you can see our constructor will take an array with the names of the extensions our application requires. Then on the `check` method it will iterate over that array to test for each of the extensions. If there are no problems then the check will return a `CheckResult` object with a message (`OK` in our case) and the result status (`CheckResult::SUCCESS` in our case). As you can see this is as easy as it gets.
+### DepsEntriesCheck ###
-Once you implemented the class then it's time to register the check service with our service container:
+Checks all entries from `deps` are defined in `deps.lock`.
- services:
- monitor.check.php_extensions:
- class: Acme\HelloBundle\Check\PhpExtensionsCheck
- arguments:
- - [ xhprof, apc, memcache ]
- tags:
- - { name: monitor.check }
+### SymfonyVersionCheck ###
-The important bit there is to remember to tag your services with the `monitor.check` tag. By doing that the Check Runner will be able to find your checks. Keep in mind that Checks can reside either in your bundles or in your app specific code. The location doesn't matter as long as the service is properly tagged.
+Checks the version of this website against the latest stable release.
-## Running Checks ##
+### Running Checks ###
-There are two ways of running the health checks: by using the CLI or by using the REST API provided by the bundle. Let's see what commands we have available for the CLI:
+There are two ways of running the health checks: by using the CLI or by using the REST API
+provided by the bundle. Let's see what commands we have available for the CLI:
### List Checks ###
@@ -144,8 +134,5 @@ To run an individual check you need to provide the check id to the `health` comm
## REST API DOCS ##
-For documentation on the REST API see: [http://myproject/monitor/health/](http://myproject/monitor/health/). Don't forget to add the bundle routes in your `routing.yml` file.
-
-## LiipMonitorExtraBundle ##
-
-We created a bundle where the community can share reusable health checks. We want this bundle to be a useful repository of health checks so go to the [https://github.com/liip/LiipMonitorExtraBundle](https://github.com/liip/LiipMonitorExtraBundle) and fork it to add your own.
+For documentation on the REST API see: [http://myproject/monitor/health/](http://myproject/monitor/health/).
+Don't forget to add the bundle routes in your `routing.yml` file.
View
62 Resources/config/config.yml
@@ -1,20 +1,60 @@
services:
- monitor.check.runner:
- class: Liip\MonitorBundle\Check\Runner
+ liip_monitor.check.runner:
+ class: Liip\Monitor\Check\Runner
arguments:
- - @monitor.check_chain
+ - @liip_monitor.check_chain
- monitor.check_chain:
- class: Liip\MonitorBundle\Check\CheckChain
+ liip_monitor.check_chain:
+ class: Liip\Monitor\Check\CheckChain
- monitor.health.controller:
+ liip_monitor.health.controller:
class: Liip\MonitorBundle\Controller\HealthCheckController
arguments:
- - @monitor.check_chain
- - @monitor.check.runner
- - @monitor.helper.path
+ - @liip_monitor.check_chain
+ - @liip_monitor.check.runner
+ - @liip_monitor.helper.path
- monitor.helper.path:
+ liip_monitor.helper.path:
class: Liip\MonitorBundle\Helper\PathHelper
arguments:
- - @service_container
+ - @service_container
+
+ liip_monitor.check.custom_error_pages:
+ class: Liip\Monitor\Check\CustomErrorPagesCheck
+ arguments:
+ - [ 404, 500 ]
+ - %kernel.root_dir%
+ - %twig.exception_listener.controller%
+
+ liip_monitor.check.symfony_version_check:
+ class: Liip\Monitor\Check\SymfonyVersionCheck
+
+ liip_monitor.check.deps_entries:
+ class: Liip\Monitor\Check\DepsEntriesCheck
+ arguments:
+ - %kernel.root_dir%
+
+ liip_monitor.check.memcache:
+ class: Liip\Monitor\Check\MemcacheCheck
+ arguments:
+ host: localhost
+ port: 11211
+
+ liip_monitor.check.php_extensions:
+ class: Liip\Monitor\Check\PhpExtensionsCheck
+ arguments:
+ - [ ]
+
+ liip_monitor.check.process_active:
+ class: Liip\Monitor\Check\ProcessActiveCheck
+ arguments:
+ command: ~
+
+ liip_monitor.check.writable_directory:
+ class: Liip\Monitor\Check\WritableDirectoryCheck
+ arguments:
+ - [ ]
+
+ liip_monitor.check.disc_usage:
+ class: Liip\Monitor\Check\DiscUsageCheck
+ arguments: [ ]
View
92 Result/CheckResult.php
@@ -1,92 +0,0 @@
-<?php
-
-namespace Liip\MonitorBundle\Result;
-
-class CheckResult
-{
- const OK = 0;
- const WARNING = 1;
- const CRITICAL = 2;
- const UNKNOWN = 3;
-
- protected $checkName;
- protected $message;
- protected $status;
-
- /**
- * @param string $checkName
- * @param string $message
- * @param integer $status
- */
- public function __construct($checkName, $message, $status)
- {
- $this->checkName = $checkName;
- $this->message = $message;
- $this->status = $status;
- }
-
- /**
- * @return string
- */
- public function getCheckName()
- {
- return $this->checkName;
- }
-
- /**
- * @return string
- */
- public function getMessage()
- {
- return $this->message;
- }
-
- /**
- * @return integer
- */
- public function getStatus()
- {
- return $this->status;
- }
-
- /**
- * @return array
- */
- public function toArray()
- {
- return array(
- 'checkName' => $this->checkName,
- 'message' => $this->message,
- 'status' => $this->status,
- 'status_name' => $this->getStatusName()
- );
- }
-
- /**
- * @return string
- */
- public function getStatusName()
- {
- $list = self::getStatusList();
-
- if (!isset($list[$this->getStatus()])) {
- return 'n/a';
- }
-
- return $list[$this->getStatus()];
- }
-
- /**
- * @static
- * @return array
- */
- static public function getStatusList()
- {
- return array(
- self::OK => 'check_result_ok',
- self::WARNING => 'check_result_warning',
- self::CRITICAL => 'check_result_critical',
- self::UNKNOWN => 'check_result_unknown',
- );
- }
-}
View
6 Tests/Check/CheckChainTest.php
@@ -2,20 +2,20 @@
namespace Liip\MonitorBundle\Tests\DependencyInjection;
-use Liip\MonitorBundle\Check\CheckChain;
+use Liip\Monitor\Check\CheckChain;
class CheckChainTest extends \PHPUnit_Framework_TestCase
{
public function testAddCheck()
{
- $check = $this->getMock('Liip\MonitorBundle\Check\CheckInterface');
+ $check = $this->getMock('Liip\Monitor\Check\CheckInterface');
$checkChain = new CheckChain();
$checkChain->addCheck('foo', $check);
$this->assertEquals(1, count($checkChain->getChecks()));
- $this->assertInstanceOf('Liip\MonitorBundle\Check\CheckInterface', $checkChain->getCheckById('foo'));
+ $this->assertInstanceOf('Liip\Monitor\Check\CheckInterface', $checkChain->getCheckById('foo'));
}
/**
Please sign in to comment.
Something went wrong with that request. Please try again.