fix: improve error handling when supervisor is not available or connection settings are wrong

pull/7994/head
Luciano Righetti 2021-11-25 10:29:16 +01:00
parent 31e96dbe77
commit cab5262d65
3 changed files with 41 additions and 4 deletions

View File

@ -278,9 +278,19 @@ class BackgroundJobsTool
*/
public function getWorkers(): array
{
$workers = [];
$procs = $this->getSupervisor()->getAllProcesses();
try {
$procs = $this->getSupervisor()->getAllProcesses();
} catch (\Exception $exception) {
CakeLog::error(
"An error occured when getting the workers statuses via Supervisor API: {$exception->getMessage()}",
0,
$exception
);
return [];
}
$workers = [];
foreach ($procs as $proc) {
if ($proc->offsetGet('group') === self::MISP_WORKERS_PROCESS_GROUP) {
if ($proc->offsetGet('pid') > 0) {
@ -471,7 +481,7 @@ class BackgroundJobsTool
}
try {
$supervisorStatus = $this->getSupervisor()->getState()['statecode'] === \Supervisor\Supervisor::RUNNING;
$supervisorStatus = $this->getSupervisorStatus();
} catch (Exception $exception) {
CakeLog::error("SimpleBackgroundJobs Supervisor error: {$exception->getMessage()}");
$supervisorStatus = false;
@ -488,6 +498,16 @@ class BackgroundJobsTool
}
}
/**
* Return true if Supervisor process is running.
*
* @return boolean
*/
public function getSupervisorStatus(): bool
{
return $this->getSupervisor()->getState()['statecode'] === \Supervisor\Supervisor::RUNNING;
}
/**
* Validate queue
*

View File

@ -3443,6 +3443,16 @@ class Server extends AppModel
if (Configure::check('MISP.manage_workers')) {
$worker_array['controls'] = Configure::read('MISP.manage_workers');
}
if (Configure::read('SimpleBackgroundJobs.enabled')) {
try {
$worker_array['supervisord_status'] = $this->getBackgroundJobsTool()->getSupervisorStatus();
} catch (Exception $exception) {
$this->logException('Error getting supervisor status.', $exception);
$worker_array['supervisord_status'] = false;
}
}
return $worker_array;
}

View File

@ -1,10 +1,17 @@
<div style="border:1px solid #dddddd; margin-top:1px; width:100%; padding:10px">
<?php
<?php
if (!$worker_array['proc_accessible']):
?>
<div style="background-color:red !important;color:white;"><b><?php echo __('Warning');?></b>: <?php echo __('MISP cannot access your /proc directory to check the status of the worker processes, which means that dead workers will not be detected by the diagnostic tool. If you would like to regain this functionality, make sure that the open_basedir directive is not set, or that /proc is included in it.');?></div>
<?php
endif;
if(Configure::read('SimpleBackgroundJobs.enabled') && !$worker_array['supervisord_status']):
?>
<div style="background-color:red !important;color:white;"><b><?php echo __('Warning');?></b>: <?php echo __('MISP cannot connect to the Supervisord API, check the following settings are correct: [`supervisor_host`, `supervisor_port`, `supervisor_user`, `supervisor_password`] and restart the service. For details check the MISP error logs.');?></div>
<?php
endif;
if (!$worker_array['controls']):
?>
<div><b><?php echo __('Note:');?></b>: <?php echo __('You have set the "manage_workers" variable to "false", therefore worker controls have been disabled.');?></div>