mirror of https://github.com/MISP/MISP
chg: [feed] Provide more info when caching feeds about failures
parent
0c1dba99d2
commit
94b36c9259
|
@ -303,23 +303,21 @@ class ServerShell extends AppShell
|
||||||
$result = false;
|
$result = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->Job->id = $jobId;
|
if ($result === false) {
|
||||||
if ($result !== true) {
|
$message = __('Job failed. See error logs for more details.');
|
||||||
$message = 'Job failed. See logs for more details.';
|
$this->saveJobStatus($jobId, true, $message);
|
||||||
$this->Job->save(array(
|
|
||||||
'id' => $jobId,
|
|
||||||
'message' => $message,
|
|
||||||
'progress' => 0,
|
|
||||||
'status' => 3
|
|
||||||
));
|
|
||||||
} else {
|
} else {
|
||||||
$message = 'Job done.';
|
$total = $result['successes'] + $result['fails'];
|
||||||
$this->Job->save(array(
|
$message = __n(
|
||||||
'id' => $jobId,
|
'%s feed from %s cached. Failed: %s',
|
||||||
'message' => $message,
|
'%s feeds from %s cached. Failed: %s',
|
||||||
'progress' => 100,
|
$result['successes'], $total, $result['fails']
|
||||||
'status' => 4
|
);
|
||||||
));
|
if ($result['fails'] > 0) {
|
||||||
|
$message .= ' ' . __('See error logs for more details.');
|
||||||
|
}
|
||||||
|
$this->saveJobStatus($jobId, false, $message);
|
||||||
}
|
}
|
||||||
echo $message . PHP_EOL;
|
echo $message . PHP_EOL;
|
||||||
}
|
}
|
||||||
|
@ -462,18 +460,22 @@ class ServerShell extends AppShell
|
||||||
CakeLog::error($e->getMessage());
|
CakeLog::error($e->getMessage());
|
||||||
$result = false;
|
$result = false;
|
||||||
}
|
}
|
||||||
if ($result) {
|
|
||||||
$this->Job->save(array(
|
if ($result === false) {
|
||||||
'message' => 'Job done.',
|
$message = __('Job failed. See error logs for more details.');
|
||||||
'progress' => 100,
|
$this->saveJobStatus($jobId, true, $message);
|
||||||
'status' => 4
|
|
||||||
));
|
|
||||||
} else {
|
} else {
|
||||||
$this->Job->save(array(
|
$total = $result['successes'] + $result['fails'];
|
||||||
'message' => 'Job failed. See logs for more details.',
|
$message = __n(
|
||||||
'progress' => 100,
|
'%s feed from %s cached. Failed: %s',
|
||||||
'status' => 3,
|
'%s feeds from %s cached. Failed: %s',
|
||||||
));
|
$result['successes'], $total, $result['fails']
|
||||||
|
);
|
||||||
|
if ($result['fails'] > 0) {
|
||||||
|
$message .= ' ' . __('See error logs for more details.');
|
||||||
|
}
|
||||||
|
$this->saveJobStatus($jobId, false, $message);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->Task->id = $task['Task']['id'];
|
$this->Task->id = $task['Task']['id'];
|
||||||
|
@ -518,4 +520,21 @@ class ServerShell extends AppShell
|
||||||
$this->Task->id = $task['Task']['id'];
|
$this->Task->id = $task['Task']['id'];
|
||||||
$this->Task->saveField('message', count($servers) . ' job(s) completed at ' . date('d/m/Y - H:i:s') . '.');
|
$this->Task->saveField('message', count($servers) . ' job(s) completed at ' . date('d/m/Y - H:i:s') . '.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $jobId
|
||||||
|
* @param bool $failed
|
||||||
|
* @param string $message
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
private function saveJobStatus($jobId, $failed, $message)
|
||||||
|
{
|
||||||
|
$this->Job->id = $jobId;
|
||||||
|
return $this->Job->save(array(
|
||||||
|
'id' => $jobId,
|
||||||
|
'message' => $message,
|
||||||
|
'progress' => $failed ? 0 : 100,
|
||||||
|
'status' => $failed ? 3 : 4,
|
||||||
|
));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -971,7 +971,7 @@ class FeedsController extends AppController
|
||||||
$message = 'Feed caching job initiated.';
|
$message = 'Feed caching job initiated.';
|
||||||
} else {
|
} else {
|
||||||
$result = $this->Feed->cacheFeedInitiator($this->Auth->user(), false, $scope);
|
$result = $this->Feed->cacheFeedInitiator($this->Auth->user(), false, $scope);
|
||||||
if (!$result) {
|
if ($result['fails'] > 0) {
|
||||||
$this->Flash->error(__('Caching the feeds has failed.'));
|
$this->Flash->error(__('Caching the feeds has failed.'));
|
||||||
$this->redirect(array('action' => 'index'));
|
$this->redirect(array('action' => 'index'));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1008,10 +1008,10 @@ class Feed extends AppModel
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $user Not used
|
* @param $user - Not used
|
||||||
* @param int|bool $jobId
|
* @param int|bool $jobId
|
||||||
* @param string $scope
|
* @param string $scope
|
||||||
* @return bool Returns true if at least one feed was cached successfully.
|
* @return array
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function cacheFeedInitiator($user, $jobId = false, $scope = 'freetext')
|
public function cacheFeedInitiator($user, $jobId = false, $scope = 'freetext')
|
||||||
|
@ -1021,10 +1021,7 @@ class Feed extends AppModel
|
||||||
'recursive' => -1,
|
'recursive' => -1,
|
||||||
'fields' => array('source_format', 'input_source', 'url', 'id', 'settings', 'headers')
|
'fields' => array('source_format', 'input_source', 'url', 'id', 'settings', 'headers')
|
||||||
);
|
);
|
||||||
$redis = $this->setupRedis();
|
$redis = $this->setupRedisWithException();
|
||||||
if ($redis === false) {
|
|
||||||
throw new Exception('Could not reach Redis.');
|
|
||||||
}
|
|
||||||
if ($scope !== 'all') {
|
if ($scope !== 'all') {
|
||||||
if (is_numeric($scope)) {
|
if (is_numeric($scope)) {
|
||||||
$params['conditions']['id'] = $scope;
|
$params['conditions']['id'] = $scope;
|
||||||
|
@ -1041,18 +1038,20 @@ class Feed extends AppModel
|
||||||
$redis->del($redis->keys('misp:feed_cache:event_uuid_lookup:*'));
|
$redis->del($redis->keys('misp:feed_cache:event_uuid_lookup:*'));
|
||||||
}
|
}
|
||||||
$feeds = $this->find('all', $params);
|
$feeds = $this->find('all', $params);
|
||||||
$atLeastOneSuccess = false;
|
|
||||||
|
$results = array('successes' => 0, 'fails' => 0);
|
||||||
foreach ($feeds as $k => $feed) {
|
foreach ($feeds as $k => $feed) {
|
||||||
if ($this->__cacheFeed($feed, $redis, $jobId)) {
|
if ($this->__cacheFeed($feed, $redis, $jobId)) {
|
||||||
$message = 'Feed ' . $feed['Feed']['id'] . ' cached.';
|
$message = 'Feed ' . $feed['Feed']['id'] . ' cached.';
|
||||||
$atLeastOneSuccess = true;
|
$results['successes']++;
|
||||||
} else {
|
} else {
|
||||||
$message = 'Failed to cache feed ' . $feed['Feed']['id'] . '. See logs for more details.';
|
$message = 'Failed to cache feed ' . $feed['Feed']['id'] . '. See logs for more details.';
|
||||||
|
$results['fails']++;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->jobProgress($jobId, $message, 100 * $k / count($feeds));
|
$this->jobProgress($jobId, $message, 100 * $k / count($feeds));
|
||||||
}
|
}
|
||||||
return $atLeastOneSuccess;
|
return $results;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function attachFeedCacheTimestamps($data)
|
public function attachFeedCacheTimestamps($data)
|
||||||
|
|
Loading…
Reference in New Issue