mirror of https://github.com/MISP/MISP
new: [dashboard] Resource widget added
parent
0e635548b9
commit
44ff66445d
|
@ -8,6 +8,7 @@ class MispAdminResourceWidget
|
|||
public $height = 2;
|
||||
public $params = array();
|
||||
public $description = 'Basic widget showing some server statistics in regards to MISP.';
|
||||
public $cacheLifetime = 5;
|
||||
|
||||
|
||||
public function handler($user, $options = array())
|
||||
|
@ -18,7 +19,12 @@ class MispAdminResourceWidget
|
|||
if ($redis) {
|
||||
$memory_stats = round($redis->rawCommand('memory', 'stats')[3] / 1024 / 1024) . 'M';
|
||||
$data[] = array(
|
||||
'title' => __('Redis memory usage'),
|
||||
'title' => __('Current Redis memory usage'),
|
||||
'value' => h($memory_stats)
|
||||
);
|
||||
$memory_stats = round($redis->rawCommand('memory', 'stats')[1] / 1024 / 1024) . 'M';
|
||||
$data[] = array(
|
||||
'title' => __('Peak Redis memory usage'),
|
||||
'value' => h($memory_stats)
|
||||
);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
<?php
|
||||
|
||||
class MispAdminSyncTestWidget
|
||||
{
|
||||
public $title = 'MISP Sync Test';
|
||||
public $render = 'SimpleList';
|
||||
public $width = 3;
|
||||
public $height = 2;
|
||||
public $params = array();
|
||||
public $description = 'Basic widget showing some server statistics in regards to MISP.';
|
||||
public $cacheLifetime = 5;
|
||||
|
||||
|
||||
public function handler($user, $options = array())
|
||||
{
|
||||
$this->Server = ClassRegistry::init('Server');
|
||||
$servers = $this->Server->find('all', array(
|
||||
'fields' => array('id', 'url', 'name', 'pull', 'push', 'caching_enabled'),
|
||||
'conditions' => array('OR' => array('pull' => 1, 'push' => 1, 'caching_enabled' => 1)),
|
||||
'recursive' => -1
|
||||
));
|
||||
$syncTestErrorCodes = $this->Server->syncTestErrorCodes;
|
||||
foreach ($servers as $server) {
|
||||
$result = $this->Server->runConnectionTest($server['Server']['id']);
|
||||
if ($result['status'] === 1) {
|
||||
$message = __('Connected.');
|
||||
$colour = 'green';
|
||||
$flags = json_decode($result['message'], true);
|
||||
if (empty($flags['perm_sync'])) {
|
||||
$colour = 'orange';
|
||||
$message .= ' ' . __('No sync access.');
|
||||
}
|
||||
if (empty($flags['perm_sighting'])) {
|
||||
$colour = 'orange';
|
||||
$message .= ' ' . __('No sighting access.');
|
||||
}
|
||||
} else {
|
||||
$colour = 'red';
|
||||
$message = $syncTestErrorCodes[$result['status']];
|
||||
}
|
||||
$data[] = array(
|
||||
'title' => sprintf(
|
||||
'Server #%s (%s - %s)',
|
||||
h($server['Server']['id']),
|
||||
h($server['Server']['name']),
|
||||
h($server['Server']['url'])
|
||||
),
|
||||
'value' => h($message),
|
||||
'class' => $colour
|
||||
);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function checkPermissions($user)
|
||||
{
|
||||
if (empty($user['Role']['perm_site_admin'])) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
<?php
|
||||
|
||||
class MispAdminWorkerWidget
|
||||
{
|
||||
public $title = 'MISP Workers';
|
||||
public $render = 'SimpleList';
|
||||
public $width = 2;
|
||||
public $height = 2;
|
||||
public $params = array();
|
||||
public $description = 'Basic widget showing some server statistics in regards to MISP.';
|
||||
public $cacheLifetime = 5;
|
||||
|
||||
|
||||
public function handler($user, $options = array())
|
||||
{
|
||||
$this->Server = ClassRegistry::init('Server');
|
||||
$workerIssueCount = array();
|
||||
$results = $this->Server->workerDiagnostics($workerIssueCount);
|
||||
$data = array();
|
||||
foreach ($results as $queueName => $queue) {
|
||||
if (in_array($queueName, array('controls', 'proc_accessible'))) {
|
||||
continue;
|
||||
}
|
||||
$total = 0;
|
||||
$alive = 0;
|
||||
foreach ($queue['workers'] as $worker) {
|
||||
if ($worker['alive']) {
|
||||
$alive += 1;
|
||||
}
|
||||
$total += 1;
|
||||
}
|
||||
$colour = 'green';
|
||||
if ($alive == 0) {
|
||||
$colour = 'red';
|
||||
} else {
|
||||
if ($alive != $total) {
|
||||
$colour = 'orange';
|
||||
}
|
||||
}
|
||||
$data[] = array(
|
||||
'title' => h($queueName) . ' workers alive',
|
||||
'value' => sprintf('[%s/%s]', $alive, $total),
|
||||
'class' => $colour
|
||||
);
|
||||
$data[] = array(
|
||||
'title' => h($queueName) . ' jobs pending',
|
||||
'value' => empty($queue['jobCount']) ? '0' : h($queue['jobCount'])
|
||||
);
|
||||
$data[] = array(
|
||||
'type' => 'gap'
|
||||
);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function checkPermissions($user)
|
||||
{
|
||||
if (empty($user['Role']['perm_site_admin'])) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue