Merge branch 'ent-8069-command-center-anadir-una-notificacion-si-la-cola-de-tareas-de-los-nodos-tiene-un-fallo-o-es' into 'develop'

Notifications if syncqueue exceeds limits in MC

See merge request artica/pandorafms!4515
This commit is contained in:
Daniel Rodriguez 2021-11-18 12:09:06 +00:00
commit 3c71ecfec2
1 changed files with 139 additions and 0 deletions

View File

@ -52,6 +52,12 @@ class ConsoleSupervisor
*/ */
public const MIN_PERFORMANCE_MODULES = 100; public const MIN_PERFORMANCE_MODULES = 100;
/**
* Minimum queued elements in synchronization queue to be warned..
*/
public const MIN_SYNC_QUEUE_LENGTH = 200;
/** /**
* Show if console supervisor is enabled or not. * Show if console supervisor is enabled or not.
* *
@ -242,6 +248,16 @@ class ConsoleSupervisor
$this->checkAuditLogOldLocation(); $this->checkAuditLogOldLocation();
/*
* Checks if sync queue is longer than limits.
* NOTIF.SYNCQUEUE.LENGTH
*/
if (is_metaconsole() === true) {
$this->checkSyncQueueLength();
$this->checkSyncQueueStatus();
}
} }
@ -492,6 +508,16 @@ class ConsoleSupervisor
*/ */
$this->checkAuditLogOldLocation(); $this->checkAuditLogOldLocation();
/*
* Checks if sync queue is longer than limits.
* NOTIF.SYNCQUEUE.LENGTH
*/
if (is_metaconsole() === true) {
$this->checkSyncQueueLength();
$this->checkSyncQueueStatus();
}
} }
@ -2684,4 +2710,117 @@ class ConsoleSupervisor
} }
/**
* Verifies the status of synchronization queue and warns if something is
* not working as expected.
*
* @return void
*/
public function checkSyncQueueLength()
{
global $config;
if (is_metaconsole() !== true) {
return;
}
$sync = new PandoraFMS\Enterprise\Metaconsole\Synchronizer();
$counts = $sync->getQueues(true);
if (count($counts) === 0) {
// Clean all.
$this->cleanNotifications('NOTIF.SYNCQUEUE.LENGTH.%');
}
$items_min = $config['sync_queue_items_max'];
if (is_numeric($items_min) !== true && $items_min <= 0) {
$items_min = self::MIN_SYNC_QUEUE_LENGTH;
}
foreach ($counts as $node_id => $count) {
if ($count < $items_min) {
$this->cleanNotifications('NOTIF.SYNCQUEUE.LENGTH.'.$node_id);
} else {
try {
$node = new PandoraFMS\Enterprise\Metaconsole\Node($node_id);
$url = '__url__/index.php?sec=advanced&sec2=advanced/metasetup&tab=consoles';
$this->notify(
[
'type' => 'NOTIF.SYNCQUEUE.LENGTH.'.$node_id,
'title' => __('Node %s sync queue length exceeded, ', $node->server_name()),
'message' => __(
'Synchronization queue lenght for node %s is %d items, this value should be 0 or lower than %d, please check the queue status.',
$node->server_name(),
$count,
$items_min
),
'url' => $url,
]
);
} catch (\Exception $e) {
// Clean, exception in node finding.
$this->cleanNotifications('NOTIF.SYNCQUEUE.LENGTH.'.$node_id);
}
}
}
}
/**
* Verifies the status of synchronization queue and warns if something is
* not working as expected.
*
* @return void
*/
public function checkSyncQueueStatus()
{
if (is_metaconsole() !== true) {
return;
}
$sync = new PandoraFMS\Enterprise\Metaconsole\Synchronizer();
$queues = $sync->getQueues();
if (count($queues) === 0) {
// Clean all.
$this->cleanNotifications('NOTIF.SYNCQUEUE.STATUS.%');
}
foreach ($queues as $node_id => $queue) {
if (count($queue) === 0) {
$this->cleanNotifications('NOTIF.SYNCQUEUE.STATUS.'.$node_id);
continue;
}
$item = $queue[0];
if (empty($item->error()) === false) {
try {
$node = new PandoraFMS\Enterprise\Metaconsole\Node($node_id);
$url = '__url__/index.php?sec=advanced&sec2=advanced/metasetup&tab=consoles';
$this->notify(
[
'type' => 'NOTIF.SYNCQUEUE.STATUS.'.$node_id,
'title' => __('Node %s sync queue failed, ', $node->server_name()),
'message' => __(
'Node %s cannot process synchronization queue due %s, please check the queue status.',
$node->server_name(),
$item->error()
),
'url' => $url,
]
);
} catch (\Exception $e) {
// Clean, exception in node finding.
$this->cleanNotifications('NOTIF.SYNCQUEUE.STATUS.'.$node_id);
}
}
}
}
} }