new: [ZMQ] Send warninglist changes to ZMQ

pull/7464/head
Jakub Onderka 2021-06-02 18:03:13 +02:00
parent b39dc5cd14
commit d87ae7627c
3 changed files with 33 additions and 1 deletions

View File

@ -136,6 +136,14 @@ class PubSubTool
return $this->pushToRedis(':data:misp_json_sighting', json_encode($sighting, JSON_PRETTY_PRINT));
}
public function warninglist_save(array $warninglist, $action = false)
{
if (!empty($action)) {
$warninglist['action'] = $action;
}
return $this->pushToRedis(':data:misp_json_warninglist', json_encode($warninglist, JSON_PRETTY_PRINT));
}
public function modified($data, $type, $action = false)
{
if (!empty($action)) {

View File

@ -6617,6 +6617,14 @@ class Server extends AppModel
'test' => 'testBool',
'type' => 'boolean'
),
'ZeroMQ_warninglist_notifications_enable' => array(
'level' => 2,
'description' => __('Enables or disables the publishing of new/modified warninglist to the ZMQ pubsub feed.'),
'value' => false,
'errorMessage' => '',
'test' => 'testBool',
'type' => 'boolean'
),
'ElasticSearch_logging_enable' => array(
'level' => 2,
'description' => __('Enabled logging to an ElasticSearch instance'),

View File

@ -726,7 +726,6 @@ class Warninglist extends AppModel
}
}
$this->regenerateWarninglistCaches($id);
} catch (Exception $e) {
if ($transactionBegun) {
$db->rollback();
@ -737,6 +736,23 @@ class Warninglist extends AppModel
return $success;
}
public function afterSave($created, $options = array())
{
if (isset($this->data['Warninglist']['default']) && $this->data['Warninglist']['default'] == 0) {
$this->regenerateWarninglistCaches($this->data['Warninglist']['id']);
}
$pubToZmq = Configure::read('Plugin.ZeroMQ_enable') && Configure::read('Plugin.ZeroMQ_warninglist_notifications_enable');
if ($pubToZmq) {
$warninglist = $this->find('first', [
'conditions' => ['id' => $this->data['Warninglist']['id']],
'contains' => ['WarninglistEntry', 'WarninglistType'],
]);
$pubSubTool = $this->getPubSubTool();
$pubSubTool->warninglist_save($warninglist, $created ? 'add' : 'edit');
}
}
/**
* @param string $input
* @return array