Refactor error handling for command execution

- Added try-catch block to handle exceptions during command execution.
This commit is contained in:
Jeroen De Meerleer 2024-06-04 13:20:43 +02:00
parent e004a1002e
commit 439d658d14
Signed by: JeroenED
GPG Key ID: 28CCCB8F62BFADD6

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();