-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
44 lines (33 loc) · 1.61 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
include_once(__DIR__ . "/vendor/autoload.php");
use AmazeeIO\Health\CheckDriver;
// Note, we don't use 500s because of potential negative caching
// for example, Akamai
const DEFAULT_FAIL_HTTP_RESPONSE = 500;
//Wrap any environment vars we want to pass to our checks
$environment = new \AmazeeIO\Health\EnvironmentCollection($_SERVER);
$psr17Factory = new \Nyholm\Psr7\Factory\Psr17Factory();
$creator = new \Nyholm\Psr7Server\ServerRequestCreator(
$psr17Factory, // ServerRequestFactory
$psr17Factory, // UriFactory
$psr17Factory, // UploadedFileFactory
$psr17Factory // StreamFactory
);
$serverRequest = $creator->fromGlobals();
$driver = new CheckDriver();
foreach (include(__DIR__ . '/checks.conf.php') as $check) {
$driver->registerCheck(new $check($environment));
}
$queryParams = $serverRequest->getQueryParams();
if(key_exists("format", $queryParams) && $queryParams["format"] == "prometheus") {
$formatter = new \AmazeeIO\Health\Format\PrometheusFormat($driver);
} else {
$formatter = new \AmazeeIO\Health\Format\JsonFormat($driver);
}
$responseBody = $psr17Factory->createStream($formatter->formattedResults());
//$responseBody = $psr17Factory->createStream(print_r($queryParams, true));
$response = $psr17Factory->createResponse($driver->pass() ? 200 : $environment->get('HEALTHZ_PHP_HTTP_FAIL_CODE', DEFAULT_FAIL_HTTP_RESPONSE))->withBody($responseBody)
->withHeader('Cache-Control','must-revalidate, no-cache, private')
->withHeader('Vary','User-Agent')
->withHeader('Content-Type', $formatter->httpHeaderContentType());
(new \Zend\HttpHandlerRunner\Emitter\SapiEmitter())->emit($response);