mirror of https://github.com/MISP/MISP
commit
3f74ed0b39
|
@ -1 +1 @@
|
|||
{"major":2, "minor":3, "hotfix":95}
|
||||
{"major":2, "minor":3, "hotfix":96}
|
|
@ -390,31 +390,10 @@ class ServersController extends AppController {
|
|||
);
|
||||
$viewVars = array_merge($viewVars, $additionalViewVars);
|
||||
foreach ($viewVars as $viewVar) $this->set($viewVar, ${$viewVar});
|
||||
|
||||
|
||||
$workerIssueCount = 0;
|
||||
if (Configure::read('MISP.background_jobs')) {
|
||||
$worker_array = array(
|
||||
'cache' => array(),
|
||||
'default' => array(),
|
||||
'email' => array(),
|
||||
'_schdlr_' => array()
|
||||
);
|
||||
// disable notice errors, getWorkers() is meant to be run from the command line and throws a notice
|
||||
// because STDIN is not defined - since we don't actually log anything this is safe to ignore.
|
||||
$error_reporting = error_reporting();
|
||||
error_reporting(0);
|
||||
$results = CakeResque::getWorkers();
|
||||
error_reporting($error_reporting);
|
||||
foreach ($results as $result) {
|
||||
$result = (array)$result;
|
||||
if (in_array($result["\0*\0queues"][0], array_keys($worker_array))) {
|
||||
$worker_array[$result["\0*\0queues"][0]][] = $result["\0*\0id"];
|
||||
}
|
||||
}
|
||||
$workerIssueCount = 0;
|
||||
foreach ($worker_array as $k => $queue) {
|
||||
if (empty($queue)) $workerIssueCount++;
|
||||
}
|
||||
$this->set('worker_array', $worker_array);
|
||||
$this->set('worker_array', $this->Server->workerDiagnostics($workerIssueCount));
|
||||
} else {
|
||||
$workerIssueCount = 4;
|
||||
$this->set('worker_array', array());
|
||||
|
@ -437,6 +416,21 @@ class ServersController extends AppController {
|
|||
$this->set('priorityErrorColours', $priorityErrorColours);
|
||||
}
|
||||
}
|
||||
|
||||
public function startWorker($type) {
|
||||
if (!$this->_isSiteAdmin() || !$this->request->is('Post')) throw new MethodNotAllowedException();
|
||||
$validTypes = array('default', 'email', 'scheduler', 'cache');
|
||||
if (!in_array($type, $validTypes)) throw new MethodNotAllowedException('Invalid worker type.');
|
||||
if ($type != 'scheduler') shell_exec(APP . 'Console' . DS . 'cake ' . DS . 'CakeResque.CakeResque start --interval 5 --queue ' . $type .' > /dev/null &');
|
||||
else shell_exec(APP . 'Console' . DS . 'cake ' . DS . 'CakeResque.CakeResque startscheduler -i 5 > /dev/null &');
|
||||
$this->redirect('/servers/serverSettings/workers');
|
||||
}
|
||||
|
||||
public function stopWorker($pid) {
|
||||
if (!$this->_isSiteAdmin() || !$this->request->is('Post')) throw new MethodNotAllowedException();
|
||||
$this->Server->killWorker($pid, $this->Auth->user());
|
||||
$this->redirect('/servers/serverSettings/workers');
|
||||
}
|
||||
|
||||
private function __checkVersion() {
|
||||
if (!$this->_isSiteAdmin()) throw new MethodNotAllowedException();
|
||||
|
@ -564,7 +558,8 @@ class ServersController extends AppController {
|
|||
}
|
||||
|
||||
public function restartWorkers() {
|
||||
if (!$this->_isSiteAdmin()) throw new MethodNotAllowedException();
|
||||
if (!$this->_isSiteAdmin() || !$this->request->is('post')) throw new MethodNotAllowedException();
|
||||
$this->Server->workerRemoveDead($this->Auth->user());
|
||||
shell_exec(APP . 'Console' . DS . 'worker' . DS . 'start.sh > /dev/null &');
|
||||
$this->redirect(array('controller' => 'servers', 'action' => 'serverSettings', 'workers'));
|
||||
}
|
||||
|
@ -647,7 +642,8 @@ class ServersController extends AppController {
|
|||
else return new CakeResponse(array('body'=> json_encode(array('saved' => false, 'errors' => 'Could not kill the previous instance of the ZeroMQ script.')),'status'=>200));
|
||||
}
|
||||
|
||||
public function statusZeroMQServer() {
|
||||
private function statusZeroMQServer() {
|
||||
if (!$this->_isSiteAdmin()) throw new MethodNotAllowedException();
|
||||
App::uses('PubSubTool', 'Tools');
|
||||
$pubSubTool = new PubSubTool();
|
||||
$result = $pubSubTool->statusCheck();
|
||||
|
|
|
@ -25,7 +25,8 @@ class Log extends AppModel {
|
|||
'blacklisted',
|
||||
'admin_email',
|
||||
'email',
|
||||
'serverSettingsEdit'
|
||||
'serverSettingsEdit',
|
||||
'remove_dead_workers'
|
||||
)),
|
||||
'message' => 'Options : ...'
|
||||
)
|
||||
|
|
|
@ -1523,6 +1523,39 @@ class Server extends AppModel {
|
|||
return $proxyStatus;
|
||||
}
|
||||
|
||||
public function workerDiagnostics(&$workerIssueCount) {
|
||||
$this->ResqueStatus = new ResqueStatus\ResqueStatus(Resque::redis());
|
||||
$workers = $this->ResqueStatus->getWorkers();
|
||||
$currentUser = get_current_user();
|
||||
$worker_array = array(
|
||||
'cache' => array('ok' => true),
|
||||
'default' => array('ok' => true),
|
||||
'email' => array('ok' => true),
|
||||
'scheduler' => array('ok' => true)
|
||||
);
|
||||
foreach ($workers as $pid => $worker) {
|
||||
$alive = file_exists("/proc/$pid");
|
||||
$entry = ($worker['type'] == 'regular') ? $worker['queue'] : $worker['type'];
|
||||
$correct_user = ($currentUser === $worker['user']);
|
||||
$ok = true;
|
||||
if (!$alive || !$correct_user) {
|
||||
$ok = false;
|
||||
$workerIssueCount++;
|
||||
$worker_array[$entry]['ok'] = false;
|
||||
}
|
||||
$worker_array[$entry]['workers'][] = array('pid' => $pid, 'user' => $worker['user'], 'alive' => $alive, 'correct_user' => $correct_user, 'ok' => $ok);
|
||||
}
|
||||
foreach ($worker_array as $k => &$queue) {
|
||||
if ($k != 'scheduler') $worker_array[$k]['jobCount'] = CakeResque::getQueueSize($k);
|
||||
if (!isset($queue['workers'])) {
|
||||
$workerIssueCount++;
|
||||
$queue['ok'] = false;
|
||||
}
|
||||
}
|
||||
return $worker_array;
|
||||
|
||||
}
|
||||
|
||||
public function retrieveCurrentSettings($branch, $subString) {
|
||||
$settings = array();
|
||||
foreach ($this->serverSettings[$branch] as $settingName => $setting) {
|
||||
|
@ -1534,4 +1567,64 @@ class Server extends AppModel {
|
|||
}
|
||||
return $settings;
|
||||
}
|
||||
|
||||
public function killWorker($pid, $user) {
|
||||
$this->ResqueStatus = new ResqueStatus\ResqueStatus(Resque::redis());
|
||||
$workers = $this->ResqueStatus->getWorkers();
|
||||
$this->Log = ClassRegistry::init('Log');
|
||||
if (isset($workers[$pid])) {
|
||||
$worker = $workers[$pid];
|
||||
if (file_exists("/proc/$pid")) {
|
||||
shell_exec('kill ' . $pid . ' > /dev/null &');
|
||||
$this->Log->create();
|
||||
$this->Log->save(array(
|
||||
'org' => $user['org'],
|
||||
'model' => 'User',
|
||||
'model_id' => $user['id'],
|
||||
'email' => $user['email'],
|
||||
'action' => 'stop_worker',
|
||||
'user_id' => $user['id'],
|
||||
'title' => 'Stopping a worker.',
|
||||
'change' => 'Stopping a worker. Worker was of type ' . $worker['queue'] . ' with pid ' . $pid
|
||||
));
|
||||
} else {
|
||||
$this->ResqueStatus->removeWorker($pid);
|
||||
$this->Log->create();
|
||||
$this->Log->save(array(
|
||||
'org' => $user['org'],
|
||||
'model' => 'User',
|
||||
'model_id' => $user['id'],
|
||||
'email' => $user['email'],
|
||||
'action' => 'remove_dead_workers',
|
||||
'user_id' => $user['id'],
|
||||
'title' => 'Removing a dead worker.',
|
||||
'change' => 'Removind dead worker data. Worker was of type ' . $worker['queue'] . ' with pid ' . $pid
|
||||
));
|
||||
}
|
||||
$this->ResqueStatus->removeWorker($pid);
|
||||
}
|
||||
}
|
||||
|
||||
public function workerRemoveDead($user) {
|
||||
$this->ResqueStatus = new ResqueStatus\ResqueStatus(Resque::redis());
|
||||
$workers = $this->ResqueStatus->getWorkers();
|
||||
$this->Log = ClassRegistry::init('Log');
|
||||
foreach ($workers as $pid => $worker) {
|
||||
$test = $pid;
|
||||
if (!file_exists("/proc/$pid")) {
|
||||
$this->ResqueStatus->removeWorker($pid);
|
||||
$this->Log->create();
|
||||
$this->Log->save(array(
|
||||
'org' => $user['org'],
|
||||
'model' => 'User',
|
||||
'model_id' => $user['id'],
|
||||
'email' => $user['email'],
|
||||
'action' => 'remove_dead_workers',
|
||||
'user_id' => $user['id'],
|
||||
'title' => 'Removing a dead worker.',
|
||||
'change' => 'Removind dead worker data. Worker was of type ' . $worker['queue'] . ' with pid ' . $pid
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,35 +1,92 @@
|
|||
<table class="table table-hover table-condensed" style="border:1px solid #dddddd; margin-top:1px; width:100%; padding:10px">
|
||||
<tr>
|
||||
<th>Worker Type</th>
|
||||
<th>Worker Id</th>
|
||||
<th>Status</th>
|
||||
</tr>
|
||||
<?php
|
||||
foreach ($worker_array as $type => $workers):
|
||||
if (empty($workers)):
|
||||
?>
|
||||
<tr>
|
||||
<td class="short" style="background-color:red; color:white;"><?php echo (h($type));?></td>
|
||||
<td class="short" style="background-color:red; color:white;">N/A</td>
|
||||
<td style="background-color:red; color:white;">Worker not running!</td>
|
||||
</tr>
|
||||
<?php
|
||||
<div style="border:1px solid #dddddd; margin-top:1px; width:100%; padding:10px">
|
||||
<?php
|
||||
foreach ($worker_array as $type => $data):
|
||||
$queueStatusMessage = "Issues prevent jobs from being processed. Please resolve them below.";
|
||||
$queueStatus = false;
|
||||
if ($data['ok']) {
|
||||
$queueStatus = true;
|
||||
$queueStatusMessage = "OK";
|
||||
} else if (!empty($data['workers'])) {
|
||||
foreach ($data['workers'] as $worker) {
|
||||
if ($worker['alive']) {
|
||||
$queueStatus = true;
|
||||
$queueStatusMessage = "There are issues with the worker(s), but at least one healthy worker is monitoring the queue.";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
<h3><?php echo 'Worker type: ' . h($type);?></h3>
|
||||
<?php if ($type !== 'scheduler'): ?>
|
||||
<p><b>Jobs in the queue: </b><?php echo h($data['jobCount']);?></p>
|
||||
<p><b>Queue status: </b><?php echo ($queueStatus ? '<span style="color:green;">' . $queueStatusMessage . '</span>' : '<span style="color:red;font-weight:bold;">' . $queueStatusMessage . '</span>' )?></p>
|
||||
<?php endif; ?>
|
||||
<table class="table table-hover table-condensed" style="border:1px solid #dddddd; margin-top:1px; width:100%; padding:10px">
|
||||
<tr>
|
||||
<th>Worker PID</th>
|
||||
<th>User</th>
|
||||
<th>Worker process</th>
|
||||
<th>Information</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
<?php
|
||||
if (empty($data['workers'])):
|
||||
?>
|
||||
<tr>
|
||||
<td class="shortish" style="background-color:red; color:white;">N/A</td>
|
||||
<td class="short" style="background-color:red; color:white;">N/A</td>
|
||||
<td style="background-color:red; color:white;">N/A</td>
|
||||
<td style="background-color:red; color:white;">Worker not running!</td>
|
||||
<td style="background-color:red; color:white;"> </td>
|
||||
</tr>
|
||||
<?php
|
||||
else:
|
||||
foreach ($workers as $worker):
|
||||
$style = "";
|
||||
foreach ($data['workers'] as $worker):
|
||||
$style = "color:green;";
|
||||
$process = 'OK';
|
||||
$message = 'The worker appears to be healthy.';
|
||||
$icon_modifier = '';
|
||||
if (!$worker['correct_user']) {
|
||||
$message = 'The worker was started with a user other than the apache user.';
|
||||
$style = "color:white;background-color:red;";
|
||||
$icon_modifier = ' icon-white';
|
||||
}
|
||||
if (!$worker['alive']) {
|
||||
$process = 'Dead';
|
||||
$message = 'The Worker appears to be dead.';
|
||||
$style = "color:white;background-color:red;";
|
||||
$icon_modifier = ' icon-white';
|
||||
}
|
||||
|
||||
$status = '<span style="color:green;">OK</span>';
|
||||
?>
|
||||
<tr>
|
||||
<td class="shortish" style="<?php echo $style; ?>"><?php echo h($worker['pid']);?></td>
|
||||
<td class="short" style="<?php echo $style; ?>"><?php echo h($worker['user']); ?></td>
|
||||
<td class="short" style="<?php echo $style; ?>"><?php echo $process; ?></td>
|
||||
<td style="<?php echo $style; ?>"><?php echo $message; ?></td>
|
||||
<td class="actions short" style="<?php echo $style; ?>">
|
||||
<?php
|
||||
echo $this->Form->postLink('', '/servers/stopWorker/' . h($worker['pid']), array('class' => 'icon-trash' . $icon_modifier, 'title' => 'Stop (if still running) and remove this worker. This will immediately terminate any jobs that are being executed by it.'));
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
endforeach;
|
||||
endif;
|
||||
?>
|
||||
</table>
|
||||
<?php
|
||||
echo $this->Form->create('Server', array('url' => '/servers/startWorker/' . h($type)));
|
||||
echo $this->Form->button('Start a worker', array('class' => 'btn btn-inverse'));
|
||||
echo $this->Form->end();
|
||||
endforeach;
|
||||
?>
|
||||
|
||||
</div>
|
||||
|
||||
<?php echo $this->Form->create('Server', array('url' => '/servers/restartWorkers'));
|
||||
echo $this->Form->button('Restart all workers', array('class' => 'btn btn-primary'));
|
||||
echo $this->Form->end();
|
||||
?>
|
||||
<tr>
|
||||
<td class="short" <?php echo $style; ?>><?php echo h($type);?></td>
|
||||
<td class="short" <?php echo $style; ?>><?php echo h($worker); ?></td>
|
||||
<td <?php echo $style; ?>><?php echo $status; ?></td>
|
||||
</tr>
|
||||
<?php
|
||||
endforeach;
|
||||
endif;
|
||||
?>
|
||||
<?php
|
||||
endforeach;
|
||||
?>
|
||||
</table>
|
||||
<a href="/servers/restartWorkers" class="btn btn-primary">Restart all workers</a> This will start / restart all of the workers and refresh the page. Keep in mind, this process can take a few seconds to complete, so refresh the page again in 5-10 seconds to see the correct results.
|
||||
|
||||
|
|
Loading…
Reference in New Issue