Compare commits

...

2 Commits

Author SHA1 Message Date
fd8a67c23c
Refactor conditional logic for response handling
- Adjusted code to handle different scenarios when processing responses.
2024-06-04 13:22:16 +02:00
439d658d14
Refactor error handling for command execution
- Added try-catch block to handle exceptions during command execution.
2024-06-04 13:20:43 +02:00

View File

@ -13,8 +13,12 @@ if(php_sapi_name() == 'cli' || $_SERVER["REQUEST_URI"] == '/metrics') {
if (isset($submetric['command'])) { if (isset($submetric['command'])) {
$output = null; $output = null;
$retval = null; $retval = null;
try {
exec($submetric['command'], $output, $retval); exec($submetric['command'], $output, $retval);
$output = implode("\n", $output); $output = implode("\n", $output);
} catch (Exception $e) {
$output = '';
}
} elseif (isset($submetric['http'])) { } elseif (isset($submetric['http'])) {
$client = new GuzzleHttp\Client(); $client = new GuzzleHttp\Client();
@ -43,9 +47,17 @@ if(php_sapi_name() == 'cli' || $_SERVER["REQUEST_URI"] == '/metrics') {
} }
if (isset($submetric['http']['data']) && $submetric['http']['data'] == 'responsebody') { if (isset($submetric['http']['data']) && $submetric['http']['data'] == 'responsebody') {
if ($hasresponse) {
$output = $res->getBody()->getContents(); $output = $res->getBody()->getContents();
} else {
$output = '';
}
} elseif ((isset($submetric['http']['statuscode'])) && (isset($submetric['http']['data']) && $submetric['http']['data'] == 'hasresponse')) { } elseif ((isset($submetric['http']['statuscode'])) && (isset($submetric['http']['data']) && $submetric['http']['data'] == 'hasresponse')) {
$output = (int)in_array($res->getStatusCode(), $submetric['http']['statuscode']); if ($hasresponse) {
$output = $output = (int)in_array($res->getStatusCode(), $submetric['http']['statuscode']);;
} else {
$output = 0;
}
} elseif (isset($submetric['http']['data']) && $submetric['http']['data'] == 'hasresponse') { } elseif (isset($submetric['http']['data']) && $submetric['http']['data'] == 'hasresponse') {
$output = (int)$hasresponse; $output = (int)$hasresponse;
} }