#10194 added automonitoritation modules and interval refresh async

This commit is contained in:
Daniel Cebrian 2023-10-02 16:44:53 +02:00
parent 63bd979855
commit 438cb11f95
17 changed files with 536 additions and 186 deletions

View File

@ -66,7 +66,7 @@ if (is_ajax()) {
if (class_exists($class) === true) { if (class_exists($class) === true) {
$instance = new $class(); $instance = new $class();
if ($instance->ajaxMethod($method) === true) { if ($instance->ajaxMethod($method) === true) {
$instance->{$method}(); echo $instance->{$method}();
} else { } else {
$instance->error('Unavailable method.'); $instance->error('Unavailable method.');
} }

View File

@ -0,0 +1,72 @@
/* global $ */
$(document).ready(function() {
$.ajax({
url: "ajax.php",
data: {
page: "include/ajax/general_tactical_view.ajax",
method: "getEventsGraph",
class: "Events"
},
type: "POST",
success: function(data) {
$("#events-last-24").html(data);
}
});
$.ajax({
url: "ajax.php",
data: {
page: "include/ajax/general_tactical_view.ajax",
method: "getEventsCriticalityGraph",
class: "Events"
},
type: "POST",
success: function(data) {
$("#events-criticality").html(data);
}
});
$.ajax({
url: "ajax.php",
data: {
page: "include/ajax/general_tactical_view.ajax",
method: "getEventsStatusValidateGraph",
class: "Events"
},
type: "POST",
success: function(data) {
$("#events-status-validate").html(data);
}
});
$.ajax({
url: "ajax.php",
data: {
page: "include/ajax/general_tactical_view.ajax",
method: "getEventsStatusValidateGraph",
class: "Events"
},
type: "POST",
success: function(data) {
$("#events-status-pending-validate").html(data);
}
});
});
function autoRefresh(interval, id, method, php_class) {
setInterval(() => {
$.ajax({
url: "ajax.php",
data: {
page: "include/ajax/general_tactical_view.ajax",
method: method,
class: php_class
},
type: "POST",
success: function(data) {
var content = $(data).html();
$("#" + id).html(content);
}
});
}, interval);
}

View File

@ -54,7 +54,21 @@ class Element
* *
* @var integer * @var integer
*/ */
protected $interval; public $interval;
/**
* Agent of automonitoritation
*
* @var array
*/
protected $monitoringAgent;
/**
* Refresh config for async method.
*
* @var array
*/
public $refreshConfig = [];
/** /**
@ -68,6 +82,11 @@ class Element
$this->interval = 0; $this->interval = 0;
$this->title = __('Default element'); $this->title = __('Default element');
$this->ajaxController = $ajax_controller; $this->ajaxController = $ajax_controller;
$agent = agents_get_agents(['nombre' => 'pandora.internals']);
if (is_array($agent) === true && count($agent) > 0) {
$this->monitoringAgent = $agent[0];
}
} }
@ -116,4 +135,65 @@ class Element
} }
/**
* Return a valur from Module of monitoring.
*
* @param string $moduleName Name of module value.
* @param integer $dateInit Date init for filter.
* @param integer $dateEnd Date end for filter.
*
* @return array Array of module data.
*/
protected function valueMonitoring(string $moduleName, int $dateInit=0, int $dateEnd=0):array
{
if (empty($this->monitoringAgent) === false) {
$module = modules_get_agentmodule_id(io_safe_input($moduleName), $this->monitoringAgent['id_agente']);
if (is_array($module) === true && key_exists('id_agente_modulo', $module) === true) {
if ($dateInit === 0 && $dateEnd === 0) {
$value = modules_get_last_value($module['id_agente_modulo']);
$rawData = [['datos' => $value]];
} else {
$rawData = modules_get_raw_data($module['id_agente_modulo'], $dateInit, $dateEnd);
}
return $rawData;
} else {
return [['datos' => 0]];
}
return [['datos' => 0]];
} else {
return [['datos' => 0]];
}
}
/**
* Simple image loading for async functions.
*
* @return string
*/
public static function loading():string
{
return html_print_div(
[
'content' => '<span></span>',
'class' => 'spinner-fixed inherit',
],
true
);
}
/**
* Return the name of class
*
* @return string
*/
public static function nameClass():string
{
return static::class;
}
} }

View File

@ -45,6 +45,7 @@ class GeneralTacticalView
public function __construct() public function __construct()
{ {
ui_require_css_file('general_tactical_view'); ui_require_css_file('general_tactical_view');
ui_require_javascript_file('general_tactical_view');
$this->elements = $this->instanceElements(); $this->elements = $this->instanceElements();
} }
@ -106,13 +107,37 @@ class GeneralTacticalView
*/ */
public function render():void public function render():void
{ {
$data = [];
$data['javascript'] = $this->javascript();
$data = array_merge($data, $this->elements);
View::render( View::render(
'tacticalView/view', 'tacticalView/view',
$this->elements $data
); );
} }
/**
* Function for print js embedded in html.
*
* @return string
*/
public function javascript():string
{
$js = '<script>';
foreach ($this->elements as $key => $element) {
if ($element->interval > 0) {
foreach ($element->refreshConfig as $key => $conf) {
$js .= 'autoRefresh('.$element->interval.',"'.$conf['id'].'", "'.$conf['method'].'", "'.$element->nameClass().'");';
}
}
}
$js .= '</script>';
return $js;
}
/** /**
* Return the welcome message. * Return the welcome message.
* *

View File

@ -47,10 +47,11 @@ class Agents extends Element
*/ */
public function getTotalAgents():string public function getTotalAgents():string
{ {
// TODO connect to automonitorization. $value = $this->valueMonitoring('total_agents');
$total = round($value[0]['datos']);
return html_print_div( return html_print_div(
[ [
'content' => '9.999.999', 'content' => $total,
'class' => 'text-l', 'class' => 'text-l',
'style' => 'margin: 0px 10px 10px 10px;', 'style' => 'margin: 0px 10px 10px 10px;',
], ],
@ -66,10 +67,11 @@ class Agents extends Element
*/ */
public function getAlerts():string public function getAlerts():string
{ {
// TODO connect to automonitorization. $value = $this->valueMonitoring('triggered_alerts_24h');
$total = round($value[0]['datos']);
return html_print_div( return html_print_div(
[ [
'content' => '9.999.999', 'content' => $total,
'class' => 'text-l', 'class' => 'text-l',
'style' => 'margin: 0px 10px 10px 10px;', 'style' => 'margin: 0px 10px 10px 10px;',
], ],
@ -105,7 +107,10 @@ class Agents extends Element
'columns' => $columns, 'columns' => $columns,
'column_names' => $columnNames, 'column_names' => $columnNames,
'ajax_url' => $this->ajaxController, 'ajax_url' => $this->ajaxController,
'no-filtered' => [-1], 'no_sortable_columns' => [
0,
1,
],
'ajax_data' => [ 'ajax_data' => [
'method' => 'getGroups', 'method' => 'getGroups',
'class' => static::class, 'class' => static::class,
@ -125,9 +130,9 @@ class Agents extends Element
/** /**
* Return top 20 groups with more agents for ajax datatable. * Return top 20 groups with more agents for ajax datatable.
* *
* @return void * @return string
*/ */
public function getGroups():void public function getGroups():string
{ {
global $config; global $config;
@ -195,26 +200,25 @@ class Agents extends Element
$total = db_get_num_rows($sql_count); $total = db_get_num_rows($sql_count);
echo json_encode( // Capture output.
$response = ob_get_clean();
return json_encode(
[ [
'data' => $rows, 'data' => $rows,
'recordsTotal' => $total, 'recordsTotal' => $total,
'recordsFiltered' => $total, 'recordsFiltered' => $total,
] ]
); );
// Capture output.
$response = ob_get_clean();
} catch (Exception $e) { } catch (Exception $e) {
echo json_encode(['error' => $e->getMessage()]); return json_encode(['error' => $e->getMessage()]);
exit;
} }
json_decode($response); json_decode($response);
if (json_last_error() === JSON_ERROR_NONE) { if (json_last_error() === JSON_ERROR_NONE) {
echo $response; return $response;
} else { } else {
echo json_encode( return json_encode(
[ [
'success' => false, 'success' => false,
'error' => $response, 'error' => $response,
@ -279,16 +283,71 @@ class Agents extends Element
*/ */
public function getStatusGraph():string public function getStatusGraph():string
{ {
// TODO Find the method for calculate status in agents. $agents = agents_get_agents(
$labels = []; false,
$data = []; [
foreach ([] as $key => $row) { 'id_agente',
if (empty($row['alias']) === true) { 'id_grupo',
continue; 'nombre',
'alias',
'id_os',
'ultimo_contacto',
'intervalo',
'comentarios description',
'quiet',
'normal_count',
'warning_count',
'critical_count',
'unknown_count',
'notinit_count',
'total_count',
'fired_count',
'ultimo_contacto_remoto',
'remote',
'agent_version',
]
);
$labels = [
__('No Monitors'),
__('CRITICAL'),
__('WARNING'),
__('UKNOWN'),
__('NORMAL'),
];
$totals = [
'no_monitors' => 0,
'critical' => 0,
'warning' => 0,
'unknown' => 0,
'ok' => 0,
];
$colors = [
COL_NOTINIT,
COL_CRITICAL,
COL_WARNING,
COL_UNKNOWN,
COL_NORMAL,
];
foreach ($agents as $key => $agent) {
if ($agent['total_count'] == 0 || $agent['total_count'] == $agent['notinit_count']) {
$totals['no_monitors']++;
} }
$labels[] = $this->controlSizeText($row['alias']); if ($agent['critical_count'] > 0) {
$data[] = $row['status']; $totals['critical']++;
} else if ($agent['warning_count'] > 0) {
$totals['warning']++;
} else if ($agent['unknown_count'] > 0) {
$totals['unknown']++;
} else {
$totals['ok']++;
}
}
foreach ($totals as $key => $total) {
$data[] = $total;
} }
$options = [ $options = [
@ -300,6 +359,7 @@ class Agents extends Element
], ],
'cutout' => 80, 'cutout' => 80,
'nodata_image' => ['width' => '80%'], 'nodata_image' => ['width' => '80%'],
'colors' => $colors,
]; ];
$pie = ring_graph($data, $options); $pie = ring_graph($data, $options);
$output = html_print_div( $output = html_print_div(

View File

@ -37,6 +37,22 @@ class Alerts extends Element
parent::__construct(); parent::__construct();
$this->title = __('Alerts'); $this->title = __('Alerts');
$this->ajaxMethods = ['getUsers']; $this->ajaxMethods = ['getUsers'];
$this->ajaxMethods = [
'getUsers',
'getCurrentlyTriggered',
'getActiveCorrelation',
];
$this->interval = 300000;
$this->refreshConfig = [
'triggered' => [
'id' => 'currently-triggered',
'method' => 'getCurrentlyTriggered',
],
'active-correlation' => [
'id' => 'active-correlation',
'method' => 'getActiveCorrelation',
],
];
} }
@ -47,11 +63,13 @@ class Alerts extends Element
*/ */
public function getCurrentlyTriggered():string public function getCurrentlyTriggered():string
{ {
// TODO connect to automonitorization. $value = $this->valueMonitoring('triggered_alerts');
$total = round($value[0]['datos']);
return html_print_div( return html_print_div(
[ [
'content' => '9.999.999', 'content' => $total,
'class' => 'text-l', 'class' => 'text-l',
'id' => 'currently-triggered',
'style' => 'margin: 0px 10px 10px 10px;', 'style' => 'margin: 0px 10px 10px 10px;',
], ],
true true
@ -66,11 +84,13 @@ class Alerts extends Element
*/ */
public function getActiveCorrelation():string public function getActiveCorrelation():string
{ {
// TODO connect to automonitorization. $value = $this->valueMonitoring('triggered_correlative_alerts');
$total = round($value[0]['datos']);
return html_print_div( return html_print_div(
[ [
'content' => '9.999.999', 'content' => $total,
'class' => 'text-l', 'class' => 'text-l',
'id' => 'active-correlation',
'style' => 'margin: 0px 10px 10px 10px;', 'style' => 'margin: 0px 10px 10px 10px;',
], ],
true true
@ -126,9 +146,9 @@ class Alerts extends Element
/** /**
* Return all users for ajax. * Return all users for ajax.
* *
* @return void * @return string
*/ */
public function getUsers():void public function getUsers():string
{ {
global $config; global $config;
@ -188,26 +208,25 @@ class Alerts extends Element
$total = db_process_sql($sql_count); $total = db_process_sql($sql_count);
echo json_encode( // Capture output.
$response = ob_get_clean();
return json_encode(
[ [
'data' => $rows, 'data' => $rows,
'recordsTotal' => $total[0]['total'], 'recordsTotal' => $total[0]['total'],
'recordsFiltered' => $total[0]['total'], 'recordsFiltered' => $total[0]['total'],
] ]
); );
// Capture output.
$response = ob_get_clean();
} catch (Exception $e) { } catch (Exception $e) {
echo json_encode(['error' => $e->getMessage()]); return json_encode(['error' => $e->getMessage()]);
exit;
} }
json_decode($response); json_decode($response);
if (json_last_error() === JSON_ERROR_NONE) { if (json_last_error() === JSON_ERROR_NONE) {
echo $response; return $response;
} else { } else {
echo json_encode( return json_encode(
[ [
'success' => false, 'success' => false,
'error' => $response, 'error' => $response,

View File

@ -46,12 +46,13 @@ class Configurations extends Element
*/ */
public function getTotalGroups():string public function getTotalGroups():string
{ {
// TODO connect to automonitorization. $value = $this->valueMonitoring('total_groups');
$total = round($value[0]['datos']);
$image = html_print_image('images/Tactical_Groups.svg', true); $image = html_print_image('images/Tactical_Groups.svg', true);
$text = '<span class="subtitle">'.__('Groups').'</span>'; $text = '<span class="subtitle">'.__('Groups').'</span>';
$number = html_print_div( $number = html_print_div(
[ [
'content' => '999.999', 'content' => $total,
'class' => 'text-l text_center', 'class' => 'text-l text_center',
'style' => '', 'style' => '',
], ],
@ -69,12 +70,13 @@ class Configurations extends Element
*/ */
public function getTotalModules():string public function getTotalModules():string
{ {
// TODO connect to automonitorization. $value = $this->valueMonitoring('total_modules');
$total = round($value[0]['datos']);
$image = html_print_image('images/Tactical_Modules.svg', true); $image = html_print_image('images/Tactical_Modules.svg', true);
$text = '<span class="subtitle">'.__('Modules').'</span>'; $text = '<span class="subtitle">'.__('Modules').'</span>';
$number = html_print_div( $number = html_print_div(
[ [
'content' => '999.999', 'content' => $total,
'class' => 'text-l text_center', 'class' => 'text-l text_center',
'style' => '', 'style' => '',
], ],
@ -182,12 +184,13 @@ class Configurations extends Element
*/ */
public function getNotInitModules():string public function getNotInitModules():string
{ {
// TODO connect to automonitorization. $value = $this->valueMonitoring('total_notinit');
$total = round($value[0]['datos']);
$image = html_print_image('images/Tactical_Not_init_module.svg', true); $image = html_print_image('images/Tactical_Not_init_module.svg', true);
$text = '<span class="subtitle">'.__('Not-init modules').'</span>'; $text = '<span class="subtitle">'.__('Not-init modules').'</span>';
$number = html_print_div( $number = html_print_div(
[ [
'content' => '999.999', 'content' => $total,
'class' => 'text-l text_center', 'class' => 'text-l text_center',
'style' => '', 'style' => '',
], ],
@ -205,12 +208,13 @@ class Configurations extends Element
*/ */
public function getTotalUnknowAgents():string public function getTotalUnknowAgents():string
{ {
// TODO connect to automonitorization. $value = $this->valueMonitoring('total_notinit');
$total = round($value[0]['total_unknown']);
$image = html_print_image('images/Tactical_Unknown_agent.svg', true); $image = html_print_image('images/Tactical_Unknown_agent.svg', true);
$text = '<span class="subtitle">'.__('Unknown agents').'</span>'; $text = '<span class="subtitle">'.__('Unknown agents').'</span>';
$number = html_print_div( $number = html_print_div(
[ [
'content' => '999.999', 'content' => $total,
'class' => 'text-l text_center', 'class' => 'text-l text_center',
'style' => '', 'style' => '',
], ],

View File

@ -36,6 +36,42 @@ class Database extends Element
{ {
parent::__construct(); parent::__construct();
$this->title = __('Database'); $this->title = __('Database');
$this->ajaxMethods = [
'getStatus',
'getDataRecords',
'getEvents',
'getStringRecords',
'getReadsGraph',
'getWritesGraph',
];
$this->interval = 300000;
$this->refreshConfig = [
'status' => [
'id' => 'status-database',
'method' => 'getStatus',
],
'records' => [
'id' => 'data-records',
'method' => 'getDataRecords',
],
'events' => [
'id' => 'total-events',
'method' => 'getEvents',
],
'totalRecords' => [
'id' => 'total-records',
'method' => 'getStringRecords',
],
'reads' => [
'id' => 'database-reads',
'method' => 'getReadsGraph',
],
'writes' => [
'id' => 'database-writes',
'method' => 'getWritesGraph',
],
];
} }
@ -75,6 +111,7 @@ class Database extends Element
[ [
'content' => $output, 'content' => $output,
'class' => 'flex_center margin-top-5', 'class' => 'flex_center margin-top-5',
'id' => 'status-database',
'style' => 'margin: 0px 10px 10px 10px;', 'style' => 'margin: 0px 10px 10px 10px;',
], ],
true true
@ -89,11 +126,13 @@ class Database extends Element
*/ */
public function getDataRecords():string public function getDataRecords():string
{ {
// TODO connect to automonitorization. $data = $this->valueMonitoring('mysql_size_of_data');
$value = round($data[0]['datos'], 2).' MB';
return html_print_div( return html_print_div(
[ [
'content' => '9.999.999', 'content' => $value,
'class' => 'text-l', 'class' => 'text-l',
'id' => 'data-records',
'style' => 'margin: 0px 10px 10px 10px;', 'style' => 'margin: 0px 10px 10px 10px;',
], ],
true true
@ -113,6 +152,7 @@ class Database extends Element
[ [
'content' => '9.999.999', 'content' => '9.999.999',
'class' => 'text-l', 'class' => 'text-l',
'id' => 'total-events',
'style' => 'margin: 0px 10px 10px 10px;', 'style' => 'margin: 0px 10px 10px 10px;',
], ],
true true
@ -127,11 +167,13 @@ class Database extends Element
*/ */
public function getStringRecords():string public function getStringRecords():string
{ {
// TODO connect to automonitorization. $data = $this->valueMonitoring('total_string_data');
$value = round($data[0]['datos']);
return html_print_div( return html_print_div(
[ [
'content' => '9.999.999', 'content' => $value,
'class' => 'text-l', 'class' => 'text-l',
'id' => 'total-records',
'style' => 'margin: 0px 10px 10px 10px;', 'style' => 'margin: 0px 10px 10px 10px;',
], ],
true true
@ -146,33 +188,17 @@ class Database extends Element
*/ */
public function getReadsGraph():string public function getReadsGraph():string
{ {
// TODO connect to automonitorization. $dateInit = (time() - 86400);
$dates = [ $reads = $this->valueMonitoring('mysql_questions_reads', $dateInit, time());
1, $dates = [];
2, $string_reads = [];
3, $total = 0;
4, foreach ($reads as $key => $read) {
5, $dates[] = date('d-m-Y H:i:s', $read['utimestamp']);
6, $string_reads[] = $read['datos'];
7, $total += $read['datos'];
8, }
9,
10,
];
$string_reads = [
1,
0.5,
2,
1.5,
3,
2.5,
4,
3.5,
5,
4.5,
6,
];
$total = '9.999.999';
$options = [ $options = [
'labels' => $dates, 'labels' => $dates,
'legend' => [ 'display' => false ], 'legend' => [ 'display' => false ],
@ -217,7 +243,13 @@ class Database extends Element
true true
); );
$output = $total.$graph_area; $output = html_print_div(
[
'content' => $total.$graph_area,
'id' => 'database-reads',
],
true
);
return $output; return $output;
} }
@ -230,33 +262,17 @@ class Database extends Element
*/ */
public function getWritesGraph():string public function getWritesGraph():string
{ {
// TODO connect to automonitorization. $dateInit = (time() - 86400);
$dates = [ $writes = $this->valueMonitoring('mysql_questions_writes', $dateInit, time());
1, $dates = [];
2, $string_writes = [];
3, $total = 0;
4, foreach ($writes as $key => $write) {
5, $dates[] = date('d-m-Y H:i:s', $write['utimestamp']);
6, $string_writes[] = $write['datos'];
7, $total += $write['datos'];
8, }
9,
10,
];
$string_writes = [
1,
0.5,
2,
1.5,
3,
2.5,
4,
3.5,
5,
4.5,
6,
];
$total = '9.999.999';
$options = [ $options = [
'labels' => $dates, 'labels' => $dates,
'legend' => [ 'display' => false ], 'legend' => [ 'display' => false ],
@ -301,7 +317,13 @@ class Database extends Element
true true
); );
$output = $total.$graph_area; $output = html_print_div(
[
'content' => $total.$graph_area,
'id' => 'database-writes',
],
true
);
return $output; return $output;
} }

View File

@ -36,6 +36,11 @@ class Events extends Element
{ {
parent::__construct(); parent::__construct();
$this->title = __('Events'); $this->title = __('Events');
$this->ajaxMethods = [
'getEventsGraph',
'getEventsCriticalityGraph',
'getEventsStatusValidateGraph',
];
} }
@ -84,7 +89,6 @@ class Events extends Element
} }
$danger = $max_value; $danger = $max_value;
$warning = ($max_value / 2);
$ok = ($max_value / 3); $ok = ($max_value / 3);
foreach ($graph_values as $key => $value) { foreach ($graph_values as $key => $value) {
@ -92,7 +96,7 @@ class Events extends Element
$colors[] = '#EC7176'; $colors[] = '#EC7176';
} }
if ($value['y'] >= $warning && $value['y'] < $danger) { if ($value['y'] >= $ok && $value['y'] < $danger) {
$colors[] = '#FCAB10'; $colors[] = '#FCAB10';
} }
@ -120,7 +124,7 @@ class Events extends Element
$bar = vbar_graph($graph_values, $options); $bar = vbar_graph($graph_values, $options);
return html_print_div( $output = html_print_div(
[ [
'content' => $bar, 'content' => $bar,
'class' => 'margin-top-5 w100p relative', 'class' => 'margin-top-5 w100p relative',
@ -128,6 +132,8 @@ class Events extends Element
], ],
true true
); );
return $output;
} }

View File

@ -41,7 +41,11 @@ class Groups extends Element
*/ */
public function __construct() public function __construct()
{ {
global $config;
parent::__construct(); parent::__construct();
include_once $config['homedir'].'/include/functions_users.php';
include_once 'include/functions_groupview.php';
ui_require_css_file('heatmap');
$this->title = __('Groups'); $this->title = __('Groups');
$this->total = $this->calculateTotalGroups(); $this->total = $this->calculateTotalGroups();
} }
@ -54,7 +58,7 @@ class Groups extends Element
*/ */
public function calculateTotalGroups():int public function calculateTotalGroups():int
{ {
$total = db_get_num_rows('SELECT * FROM tgrupo;'); $total = db_get_value_sql('SELECT count(*) FROM tgrupo');
return $total; return $total;
} }
@ -66,19 +70,22 @@ class Groups extends Element
*/ */
public function getStatusHeatMap():string public function getStatusHeatMap():string
{ {
ui_require_css_file('heatmap'); global $config;
// ACL Check.
$agent_a = check_acl($config['id_user'], 0, 'AR');
$agent_w = check_acl($config['id_user'], 0, 'AW');
$width = 350; $width = 350;
$height = 275; $height = 275;
$sql = 'SELECT * FROM tagente a
LEFT JOIN tagent_secondary_group g ON g.id_agent = a.id_agente';
$all_agents = db_get_all_rows_sql($sql); $groups_list = groupview_get_groups_list(
if (empty($all_agents)) { $config['id_user'],
return null; ($agent_a == true) ? 'AR' : (($agent_w == true) ? 'AW' : 'AR'),
} true
);
$total_agents = count($all_agents);
$total_groups = $groups_list['counter'];
$groups = $groups_list['groups'];
// Best square. // Best square.
$high = (float) max($width, $height); $high = (float) max($width, $height);
$low = 0.0; $low = 0.0;
@ -86,7 +93,7 @@ class Groups extends Element
while (abs($high - $low) > 0.000001) { while (abs($high - $low) > 0.000001) {
$mid = (($high + $low) / 2.0); $mid = (($high + $low) / 2.0);
$midval = (floor($width / $mid) * floor($height / $mid)); $midval = (floor($width / $mid) * floor($height / $mid));
if ($midval >= $total_agents) { if ($midval >= $total_groups) {
$low = $mid; $low = $mid;
} else { } else {
$high = $mid; $high = $mid;
@ -107,38 +114,21 @@ class Groups extends Element
$x = 0; $x = 0;
$y = 0; $y = 0;
$cont = 1; $cont = 1;
foreach ($groups as $key => $value) {
if ($value['_name_'] === 'All') {
continue;
}
foreach ($all_agents as $key => $value) { if ($value['_monitors_critical_'] > 0) {
// Colour by status. $status = 'critical';
$status = agents_get_status_from_counts($value); } else if ($value['_monitors_warning_'] > 0) {
$status = 'warning';
switch ($status) { } else if (($value['_monitors_unknown_'] > 0) || ($value['_agents_unknown_'] > 0)) {
case 5: $status = 'unknown';
// Not init status. } else if ($value['_monitors_ok_'] > 0) {
$status = 'notinit'; $status = 'normal';
break; } else {
$status = 'unknown';
case 1:
// Critical status.
$status = 'critical';
break;
case 2:
// Warning status.
$status = 'warning';
break;
case 0:
// Normal status.
$status = 'normal';
break;
case 3:
case -1:
default:
// Unknown status.
$status = 'unknown';
break;
} }
$heatmap .= sprintf( $heatmap .= sprintf(
@ -175,14 +165,13 @@ class Groups extends Element
$heatmap .= '<script type="text/javascript"> $heatmap .= '<script type="text/javascript">
$(document).ready(function() { $(document).ready(function() {
const total_agents = "'.$total_agents.'"; const total_groups = "'.$total_groups.'";
function getRandomInteger(min, max) { function getRandomInteger(min, max) {
return Math.floor(Math.random() * max) + min; return Math.floor(Math.random() * max) + min;
} }
function oneSquare(solid, time) { function oneSquare(solid, time) {
var randomPoint = getRandomInteger(1, total_agents); var randomPoint = getRandomInteger(1, total_groups);
let target = $(`#rect_${randomPoint}`); let target = $(`#rect_${randomPoint}`);
let class_name = target.attr("class"); let class_name = target.attr("class");
class_name = class_name.split("_")[0]; class_name = class_name.split("_")[0];
@ -194,7 +183,7 @@ class Groups extends Element
} }
let cont = 0; let cont = 0;
while (cont < Math.ceil(total_agents / 3)) { while (cont < Math.ceil(total_groups / 3)) {
oneSquare(getRandomInteger(1, 10), getRandomInteger(100, 900)); oneSquare(getRandomInteger(1, 10), getRandomInteger(100, 900));
cont ++; cont ++;
} }

View File

@ -36,6 +36,31 @@ class LogStorage extends Element
{ {
parent::__construct(); parent::__construct();
$this->title = __('Log storage'); $this->title = __('Log storage');
$this->ajaxMethods = [
'getStatus',
'getTotalSources',
'getStoredData',
'getAgeOfStoredData',
];
$this->interval = 300000;
$this->refreshConfig = [
'status' => [
'id' => 'status-log-storage',
'method' => 'getStatus',
],
'total-source' => [
'id' => 'total-source-log-storage',
'method' => 'getTotalSources',
],
'total-lines' => [
'id' => 'total-lines-log-storage',
'method' => 'getStoredData',
],
'age' => [
'id' => 'age-of-stored',
'method' => 'getAgeOfStoredData',
],
];
} }
@ -46,9 +71,8 @@ class LogStorage extends Element
*/ */
public function getStatus():string public function getStatus():string
{ {
// TODO connect to automonitorization. $value = $this->valueMonitoring('Log server connection');
$status = true; $status = ((int) $value[0]['datos'] === 1) ? true : false;
if ($status === true) { if ($status === true) {
$image_status = html_print_image('images/status_check@svg.svg', true); $image_status = html_print_image('images/status_check@svg.svg', true);
$text = html_print_div( $text = html_print_div(
@ -76,6 +100,7 @@ class LogStorage extends Element
'content' => $output, 'content' => $output,
'class' => 'flex_center margin-top-5', 'class' => 'flex_center margin-top-5',
'style' => 'margin: 0px 10px 10px 10px;', 'style' => 'margin: 0px 10px 10px 10px;',
'id' => 'status-log-storage',
], ],
true true
); );
@ -89,12 +114,14 @@ class LogStorage extends Element
*/ */
public function getTotalSources():string public function getTotalSources():string
{ {
// TODO connect to automonitorization. $data = $this->valueMonitoring('Total sources');
$value = round($data[0]['datos']);
return html_print_div( return html_print_div(
[ [
'content' => '9.999.999', 'content' => $value,
'class' => 'text-l', 'class' => 'text-l',
'style' => 'margin: 0px 10px 0px 10px;', 'style' => 'margin: 0px 10px 0px 10px;',
'id' => 'total-source-log-storage',
], ],
true true
); );
@ -108,12 +135,14 @@ class LogStorage extends Element
*/ */
public function getStoredData():string public function getStoredData():string
{ {
// TODO connect to automonitorization. $data = $this->valueMonitoring('Total lines of data');
$value = round($data[0]['datos']);
return html_print_div( return html_print_div(
[ [
'content' => '9.999.999', 'content' => $value,
'class' => 'text-l', 'class' => 'text-l',
'style' => 'margin: 0px 10px 0px 10px;', 'style' => 'margin: 0px 10px 0px 10px;',
'id' => 'total-lines-log-storage',
], ],
true true
); );
@ -127,12 +156,16 @@ class LogStorage extends Element
*/ */
public function getAgeOfStoredData():string public function getAgeOfStoredData():string
{ {
// TODO connect to automonitorization. $data = $this->valueMonitoring('Longest data archived');
$date = $data[0]['datos'];
$interval = (time() - strtotime($date));
$days = round($interval / 86400);
return html_print_div( return html_print_div(
[ [
'content' => '9.999.999', 'content' => $days,
'class' => 'text-l', 'class' => 'text-l',
'style' => 'margin: 0px 10px 0px 10px;', 'style' => 'margin: 0px 10px 0px 10px;',
'id' => 'age-of-stored',
], ],
true true
); );

View File

@ -200,7 +200,6 @@ class MonitoringElements extends Element
*/ */
public function getMonitoringStatusGraph():string public function getMonitoringStatusGraph():string
{ {
// TODO add labels.
$pie = graph_agent_status(false, '', '', true, true, false, true); $pie = graph_agent_status(false, '', '', true, true, false, true);
$output = html_print_div( $output = html_print_div(
[ [

View File

@ -36,6 +36,21 @@ class Overview extends Element
{ {
parent::__construct(); parent::__construct();
$this->title = __('General overview'); $this->title = __('General overview');
$this->ajaxMethods = [
'getLogSizeStatus',
'getWuxServerStatus',
];
$this->interval = 300000;
$this->refreshConfig = [
'logSizeStatus' => [
'id' => 'status-log-size',
'method' => 'getLogSizeStatus',
],
'wuxServerStatus' => [
'id' => 'status-wux',
'method' => 'getWuxServerStatus',
],
];
} }
@ -46,8 +61,8 @@ class Overview extends Element
*/ */
public function getLogSizeStatus():string public function getLogSizeStatus():string
{ {
// TODO connect to automonitorization. $size = $this->valueMonitoring('console_log_size');
$status = true; $status = ($size[0]['datos'] < 1000) ? true : false;
if ($status === true) { if ($status === true) {
$image_status = html_print_image('images/status_check@svg.svg', true); $image_status = html_print_image('images/status_check@svg.svg', true);
@ -62,7 +77,7 @@ class Overview extends Element
$image_status = html_print_image('images/status_error@svg.svg', true); $image_status = html_print_image('images/status_error@svg.svg', true);
$text = html_print_div( $text = html_print_div(
[ [
'content' => __('Somethings wrong'), 'content' => __('Too size log size'),
'class' => 'status-text', 'class' => 'status-text',
], ],
true true
@ -75,6 +90,7 @@ class Overview extends Element
[ [
'content' => $output, 'content' => $output,
'class' => 'flex_center margin-top-5', 'class' => 'flex_center margin-top-5',
'id' => 'status-log-size',
], ],
true true
); );
@ -89,8 +105,8 @@ class Overview extends Element
*/ */
public function getWuxServerStatus():string public function getWuxServerStatus():string
{ {
// TODO connect to automonitorization. $wux = $this->valueMonitoring('WUX connection');
$status = false; $status = ($wux[0]['datos'] > 0) ? true : false;
if ($status === true) { if ($status === true) {
$image_status = html_print_image('images/status_check@svg.svg', true); $image_status = html_print_image('images/status_check@svg.svg', true);
@ -118,6 +134,7 @@ class Overview extends Element
[ [
'content' => $output, 'content' => $output,
'class' => 'flex_center margin-top-5', 'class' => 'flex_center margin-top-5',
'id' => 'status-wux',
], ],
true true
); );

View File

@ -36,6 +36,21 @@ class SnmpTraps extends Element
{ {
parent::__construct(); parent::__construct();
$this->title = __('SNMP Traps'); $this->title = __('SNMP Traps');
$this->ajaxMethods = [
'getQueues',
'getTotalSources',
];
$this->interval = 300000;
$this->refreshConfig = [
'queues' => [
'id' => 'total-queues',
'method' => 'getQueues',
],
'total-snmp' => [
'id' => 'total-snmp',
'method' => 'getTotalSources',
],
];
} }
@ -46,12 +61,14 @@ class SnmpTraps extends Element
*/ */
public function getQueues():string public function getQueues():string
{ {
// TODO connect to automonitorization. $value = $this->valueMonitoring('snmp_trap_queue');
$total = round($value[0]['data']);
return html_print_div( return html_print_div(
[ [
'content' => '9.999.999', 'content' => $total,
'class' => 'text-l', 'class' => 'text-l',
'style' => 'margin: 0px 10px 10px 10px;', 'style' => 'margin: 0px 10px 10px 10px;',
'id' => 'total-queues',
], ],
true true
); );
@ -65,12 +82,14 @@ class SnmpTraps extends Element
*/ */
public function getTotalSources():string public function getTotalSources():string
{ {
// TODO connect to automonitorization. $value = $this->valueMonitoring('total_trap');
$total = round($value[0]['data']);
return html_print_div( return html_print_div(
[ [
'content' => '9.999.999', 'content' => $total,
'class' => 'text-l', 'class' => 'text-l',
'style' => 'margin: 0px 10px 10px 10px;', 'style' => 'margin: 0px 10px 10px 10px;',
'id' => 'total-snmp',
], ],
true true
); );

View File

@ -20,7 +20,6 @@
.row { .row {
display: flex; display: flex;
width: 100%; width: 100%;
justify-content: space-between;
} }
.col-6, .col-6,
.col-xl-6 { .col-xl-6 {

View File

@ -12090,6 +12090,10 @@ span.help_icon_15px > img {
border-radius: 50%; border-radius: 50%;
} }
.spinner-fixed.inherit {
position: inherit;
}
@keyframes animate { @keyframes animate {
0% { 0% {
transform: rotate(0deg); transform: rotate(0deg);

View File

@ -131,7 +131,7 @@
</div> </div>
<div class="br-t"> <div class="br-t">
<div class="subtitle link padding10 padding2"> <div class="subtitle link padding10 padding2">
<?php echo __('Reads (last 24 hrs)'); ?> <a href=""><?php echo __('Info'); ?></a> <?php echo __('Writes (last 24 hrs)'); ?> <a href=""><?php echo __('Info'); ?></a>
</div> </div>
<?php echo $Database->getWritesGraph(); ?> <?php echo $Database->getWritesGraph(); ?>
</div> </div>
@ -249,7 +249,7 @@
</div> </div>
</div> </div>
<div class="col-md-9"> <div class="col-md-9">
<div class="container" id="Events"> <div class="container overflow_hidden" id="Events">
<div class="title br-b"> <div class="title br-b">
<?php echo $Events->title; ?> <?php echo $Events->title; ?>
</div> </div>
@ -258,25 +258,25 @@
<div class="subtitle link padding10 padding2"> <div class="subtitle link padding10 padding2">
<?php echo __('Number of events per hour (24 hrs)'); ?></b> <a href=""><?php echo __('Info'); ?></a> <?php echo __('Number of events per hour (24 hrs)'); ?></b> <a href=""><?php echo __('Info'); ?></a>
</div> </div>
<?php echo $Events->getEventsGraph(); ?> <div id="events-last-24"><?php echo $Events->loading(); ?></div>
<div class="row br-t"> <div class="row br-t h100p">
<div class="col-4 br-r"> <div class="col-4 br-r">
<div class="subtitle link padding10 padding2"> <div class="subtitle link padding10 padding2">
<?php echo __('Criticality'); ?></b> <a href=""><?php echo __('Info'); ?></a> <?php echo __('Criticality'); ?></b> <a href=""><?php echo __('Info'); ?></a>
</div> </div>
<?php echo $Events->getEventsCriticalityGraph(); ?> <div id="events-criticality"><?php echo $Events->loading(); ?></div>
</div> </div>
<div class="col-4 br-r"> <div class="col-4 br-r">
<div class="subtitle link padding10 padding2"> <div class="subtitle link padding10 padding2">
<?php echo __('Status'); ?></b> <a href=""><?php echo __('Info'); ?></a> <?php echo __('Status'); ?></b> <a href=""><?php echo __('Info'); ?></a>
</div> </div>
<?php echo $Events->getEventsStatusValidateGraph(); ?> <div id="events-status-validate"><?php echo $Events->loading(); ?></div>
</div> </div>
<div class="col-4"> <div class="col-4">
<div class="subtitle link padding10 padding2"> <div class="subtitle link padding10 padding2">
<?php echo __('Pending validation'); ?></b> <a href=""><?php echo __('Info'); ?></a> <?php echo __('Pending validation'); ?></b> <a href=""><?php echo __('Info'); ?></a>
</div> </div>
<?php echo $Events->getEventsStatusValidateGraph(); ?> <div id="events-status-pending-validate"><?php echo $Events->loading(); ?></div>
</div> </div>
</div> </div>
</div> </div>
@ -327,7 +327,7 @@
<div class="subtitle link padding10 padding2 br-t"> <div class="subtitle link padding10 padding2 br-t">
<?php echo __('Status'); ?></b> <a href=""><?php echo __('Info'); ?></a> <?php echo __('Status'); ?></b> <a href=""><?php echo __('Info'); ?></a>
</div> </div>
<?php echo $Agents->getOperatingSystemGraph(); ?> <?php echo $Agents->getStatusGraph(); ?>
</div> </div>
</div> </div>
</div> </div>
@ -370,4 +370,6 @@
<?php echo $ScheduledDowntime->list(); ?> <?php echo $ScheduledDowntime->list(); ?>
</div> </div>
</div> </div>
</div> </div>
<?php
echo $javascript;