diff --git a/Controller/HealthCheckController.php b/Controller/HealthCheckController.php index eaecfd4c..a88dcdce 100644 --- a/Controller/HealthCheckController.php +++ b/Controller/HealthCheckController.php @@ -15,17 +15,20 @@ class HealthCheckController protected $runnerManager; protected $pathHelper; protected $template; + protected $failureStatusCode; /** * @param RunnerManager $runnerManager * @param PathHelper $pathHelper * @param $template + * @param $failureStatusCode */ - public function __construct(RunnerManager $runnerManager, PathHelper $pathHelper, $template) + public function __construct(RunnerManager $runnerManager, PathHelper $pathHelper, $template, $failureStatusCode) { $this->runnerManager = $runnerManager; $this->pathHelper = $pathHelper; $this->template = $template; + $this->failureStatusCode = $failureStatusCode; } /** @@ -130,7 +133,7 @@ public function runAllChecksHttpStatusAction(Request $request) return new Response( '', - ($report->getGlobalStatus() === ArrayReporter::STATUS_OK ? 200 : 502) + ($report->getGlobalStatus() === ArrayReporter::STATUS_OK ? 200 : $this->failureStatusCode) ); } @@ -146,7 +149,7 @@ public function runSingleCheckHttpStatusAction($checkId, Request $request) return new Response( '', - ($report->getGlobalStatus() === ArrayReporter::STATUS_OK ? 200 : 502) + ($report->getGlobalStatus() === ArrayReporter::STATUS_OK ? 200 : $this->failureStatusCode) ); } diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 90aa7bd0..20f07336 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -23,7 +23,7 @@ class Configuration implements ConfigurationInterface public function getConfigTreeBuilder() { $treeBuilder = new TreeBuilder('liip_monitor'); - + // Keep compatibility with symfony/config < 4.2 if (\method_exists($treeBuilder, 'getRootNode')) { $rootNode = $treeBuilder->getRootNode(); @@ -51,6 +51,10 @@ public function getConfigTreeBuilder() ->children() ->booleanNode('enable_controller')->defaultFalse()->end() ->scalarNode('view_template')->defaultNull()->end() + ->integerNode('failure_status_code') + ->min(100)->max(598) + ->defaultValue(502) + ->end() ->arrayNode('mailer') ->canBeEnabled() ->children() diff --git a/DependencyInjection/LiipMonitorExtension.php b/DependencyInjection/LiipMonitorExtension.php index 73407855..1ccc6a1f 100644 --- a/DependencyInjection/LiipMonitorExtension.php +++ b/DependencyInjection/LiipMonitorExtension.php @@ -63,6 +63,7 @@ public function load(array $configs, ContainerBuilder $container) if ($config['enable_controller']) { $container->setParameter(sprintf('%s.view_template', $this->getAlias()), $config['view_template']); + $container->setParameter(sprintf('%s.failure_status_code', $this->getAlias()), $config['failure_status_code']); $loader->load('controller.xml'); } diff --git a/README.md b/README.md index 9b534f3d..bb850432 100644 --- a/README.md +++ b/README.md @@ -260,6 +260,7 @@ groups. Additionally, the `monitor:list` has an option `--groups` to list all re liip_monitor: enable_controller: false view_template: null + failure_status_code: 502 mailer: enabled: false recipient: ~ # Required diff --git a/Resources/config/controller.xml b/Resources/config/controller.xml index 6a6db7fd..8b46277f 100644 --- a/Resources/config/controller.xml +++ b/Resources/config/controller.xml @@ -16,6 +16,7 @@ %liip_monitor.view_template% + %liip_monitor.failure_status_code% diff --git a/Resources/views/health/index.html.php b/Resources/views/health/index.html.php index d629cef4..e3d471d5 100644 --- a/Resources/views/health/index.html.php +++ b/Resources/views/health/index.html.php @@ -126,7 +126,7 @@
getPathInfo().'http_status_checks' ?>
-
Performs all health checks and returns the results within the HTTP Status Code (200 if checks are OK, 502 otherwise). +
Performs all health checks and returns the results within the HTTP Status Code (200 if checks are OK, 502 otherwise). The failure status code is configurable as failure_status_code.
 $ curl -XPOST -H "Accept: application/json" getUriForPath($request->getPathInfo().'http_status_checks') ?>
 
@@ -141,7 +141,7 @@
         
getPathInfo().'http_status_check/check_id' ?>
-
Performs the health check specified by check_id and returns the result within the HTTP Status Code (200 if checks are OK, 502 otherwise). +
Performs the health check specified by check_id and returns the result within the HTTP Status Code (200 if checks are OK, 502 otherwise). The failure status code is configurable as failure_status_code.
 $ curl -XPOST -H "Accept: application/json" getUriForPath($request->getPathInfo().'http_status_check/monitor.check.redis') ?>