Skip to content

Commit 5d0a66c

Browse files
committed
Merge pull request #91 from Bladrak/http_status
Added http_status_checks method
2 parents 2719cb6 + a70a65d commit 5d0a66c

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

Controller/HealthCheckController.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,20 @@ public function runAllChecksAction(Request $request)
8585
));
8686
}
8787

88+
/**
89+
* @param Request $request
90+
* @return \Symfony\Component\HttpFoundation\Response
91+
*/
92+
public function runAllChecksHttpStatusAction(Request $request)
93+
{
94+
$report = $this->runTests($request);
95+
96+
return new Response(
97+
'',
98+
($report->getGlobalStatus() === ArrayReporter::STATUS_OK ? 200 : 502)
99+
);
100+
}
101+
88102
/**
89103
* @param string $checkId
90104
* @param Request $request

Resources/config/routing.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
<route id="liip_monitor_list_checks" pattern="/checks">
1010
<default key="_controller">liip_monitor.health_controller:listAction</default>
1111
</route>
12+
<route id="liip_monitor_run_all_checks_http_status" pattern="/http_status_checks">
13+
<default key="_controller">liip_monitor.health_controller:runAllChecksHttpStatusAction</default>
14+
</route>
1215
<route id="liip_monitor_run_all_checks" pattern="/run">
1316
<default key="_controller">liip_monitor.health_controller:runAllChecksAction</default>
1417
</route>

Resources/views/health/index.html.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,21 @@
7373
]</pre>
7474
</dd>
7575

76+
<dt><a href="<?php echo $request->getUriForPath($request->getPathInfo().'http_status_checks') ?>"><?php echo $request->getPathInfo().'http_status_checks' ?></a></dt>
77+
<dd>Performs all health checks and returns the results within the HTTP Status Code (200 if checks are OK, 502 otherwise).
78+
<pre>
79+
$ curl -XPOST -H "Accept: application/json" <?php echo $request->getUriForPath($request->getPathInfo().'http_status_checks') ?>
80+
81+
HTTP/1.1 200 OK
82+
</pre>
83+
84+
<pre>
85+
$ curl -XPOST -H "Accept: application/json" <?php echo $request->getUriForPath($request->getPathInfo().'http_status_checks') ?>
86+
87+
HTTP/1.1 502 Bad Gateway
88+
</pre>
89+
</dd>
90+
7691
<dt><a href="<?php echo $request->getUriForPath($request->getPathInfo().'run') ?>"><?php echo $request->getPathInfo().'run' ?></a></dt>
7792
<dd>Performs all health checks and returns the results as an array of JSON objects.
7893
<pre>

0 commit comments

Comments
 (0)