Refactor HTTP handling, update Guzzle requests and Twig config.

- Refactored HTTP handling to use nested arrays for options
- Updated Guzzle requests based on new array structure
- Adjusted Twig cache configuration in the code
This commit is contained in:
Jeroen De Meerleer 2024-06-03 13:50:56 +02:00
parent 1dfddd64ba
commit 1534574e97
No known key found for this signature in database
GPG Key ID: 3B23D1B3498D7641

View File

@ -9,31 +9,27 @@ if($_SERVER["REQUEST_URI"] == '/metrics') {
$retval=null; $retval=null;
exec($c['command'], $output, $retval); exec($c['command'], $output, $retval);
$output = implode("\n", $output); $output = implode("\n", $output);
} elseif(isset($c['httpurl'])) { } elseif(isset($c['http'])) {
$client = new GuzzleHttp\Client(); $client = new GuzzleHttp\Client();
$options = []; $options = [];
if (isset($c['proxy'])) {
$options['proxy'] = $c['proxy'];
}
$res = $client->request('GET', $c['httpurl'], $options);
$output = $res->getBody()->getContents();
} elseif(isset($c['httpresponsetime'])) {
$client = new GuzzleHttp\Client();
$output = NULL; $output = NULL;
if (isset($c['http']['proxy'])) {
$options = [ $options['proxy'] = $c['http']['proxy'];
'on_stats' => function (GuzzleHttp\TransferStats $stats) use (&$output) { }
if (isset($c['http']['data']) && $c['http']['data'] == 'responsetime') {
$options['on_stats'] = function (GuzzleHttp\TransferStats $stats) use (&$output) {
$output = $stats->getTransferTime(); $output = $stats->getTransferTime();
} };
];
if (isset($c['proxy'])) {
$options['proxy'] = $c['proxy'];
} }
$res = $client->request('GET', $c['httpresponsetime'], $options); $res = $client->request('GET', $c['http']['url'], $options);
if (isset($c['http']['data']) && $c['http']['data'] == 'responsebody') {
$output = $res->getBody()->getContents();
} }
}
if(isset($c['jsonelem'])) { if(isset($c['jsonelem'])) {
$c['value'] = getArrayValue($c['jsonelem'], json_decode($output, true)); $c['value'] = getArrayValue($c['jsonelem'], json_decode($output, true));
} else { } else {