#11550 Fix tactical view widget

This commit is contained in:
miguel angel rasteu 2023-06-21 16:10:13 +02:00
parent 341f5bdb7c
commit 5d4f90ca10
6 changed files with 206 additions and 48 deletions

View File

@ -73,6 +73,7 @@ $meta = get_parameter('meta', 0);
$history = get_parameter('history', 0);
$table_events = get_parameter('table_events', 0);
$total_events = (bool) get_parameter('total_events');
$filter_groups = (string) get_parameter('filter_groups', '');
$total_event_graph = (bool) get_parameter('total_event_graph');
$graphic_event_group = (bool) get_parameter('graphic_event_group');
$get_table_response_command = (bool) get_parameter('get_table_response_command');
@ -2109,12 +2110,42 @@ if ($table_events) {
if ($total_events) {
global $config;
$sql_count_event = 'SELECT SQL_NO_CACHE COUNT(id_evento) FROM tevento ';
if ($config['event_view_hr']) {
$sql_count_event .= 'WHERE utimestamp > (UNIX_TIMESTAMP(NOW()) - '.($config['event_view_hr'] * SECONDS_1HOUR).')';
if (is_metaconsole() === true) {
$system_events = 0;
$servers = metaconsole_get_servers();
// Check if the group can be deleted or not.
if (isset($servers) === true
&& is_array($servers) === true
) {
foreach ($servers as $server) {
if (metaconsole_connect($server) == NOERR) {
$sql_count_event = 'SELECT SQL_NO_CACHE COUNT(id_evento) FROM tevento ';
if ($config['event_view_hr']) {
$sql_count_event .= 'WHERE utimestamp > (UNIX_TIMESTAMP(NOW()) - '.($config['event_view_hr'] * SECONDS_1HOUR).')';
if ($filter_groups !== '') {
$sql_count_event .= ' AND id_grupo in ('.$filter_groups.')';
}
}
$system_events += db_get_value_sql($sql_count_event);
}
metaconsole_restore_db();
}
}
} else {
$sql_count_event = 'SELECT SQL_NO_CACHE COUNT(id_evento) FROM tevento ';
if ($config['event_view_hr']) {
$sql_count_event .= 'WHERE utimestamp > (UNIX_TIMESTAMP(NOW()) - '.($config['event_view_hr'] * SECONDS_1HOUR).')';
if ($filter_groups !== '') {
$sql_count_event .= ' AND id_grupo in ('.$filter_groups.')';
}
}
$system_events = db_get_value_sql($sql_count_event);
}
$system_events = db_get_value_sql($sql_count_event);
echo $system_events;
return;
}

View File

@ -14696,11 +14696,11 @@ function reporting_get_agentmodule_sla_day($id_agent_module, $period=0, $min_val
}
function reporting_get_stats_servers()
function reporting_get_stats_servers($filter=[])
{
global $config;
$server_performance = servers_get_performance();
$server_performance = servers_get_performance($filter);
// Alerts table
$table_srv = html_get_predefined_table();
@ -14836,6 +14836,9 @@ function reporting_get_stats_servers()
$output .= 'var parameters = {};';
$output .= 'parameters["page"] = "include/ajax/events";';
$output .= 'parameters["total_events"] = 1;';
if (empty($filter) === false && empty($filter['groups']) === false) {
$output .= 'parameters["filter_groups"] = "'.$filter['groups'].'";';
}
$output .= '$.ajax({type: "GET",url: "'.ui_get_full_url('ajax.php', false, false, false).'",data: parameters,';
$output .= 'success: function(data) {';

View File

@ -5255,6 +5255,12 @@ function reporting_get_stats_summary($data, $graph_width, $graph_height)
if ($data['monitor_checks'] > 0) {
// Fixed width non interactive charts.
$status_chart_width = $graph_width;
$monitor_data = [];
$monitor_data['monitor_critical'] = $data['monitor_critical'];
$monitor_data['monitor_warning'] = $data['monitor_warning'];
$monitor_data['monitor_ok'] = $data['monitor_ok'];
$monitor_data['monitor_unknown'] = $data['monitor_unknown'];
$monitor_data['monitor_not_init'] = $data['monitor_not_init'];
$tdata[0] = '<div style="margin: auto; width: '.$graph_width.'px;">';
$tdata[0] .= '<div id="status_pie" style="margin: auto; width: '.$graph_width.'">';
@ -5263,12 +5269,13 @@ function reporting_get_stats_summary($data, $graph_width, $graph_height)
$graph_width,
$graph_height,
true,
true
true,
$monitor_data
);
$tdata[0] .= '</div>';
$tdata[0] .= '</div>';
} else {
$tdata[2] = html_print_image(
$tdata[0] = html_print_image(
'images/image_problem_area_small.png',
true,
['width' => $graph_width]

View File

@ -155,10 +155,16 @@ function servers_get_total_modules()
*
* @return array with several data.
*/
function servers_get_performance()
function servers_get_performance($filter=[])
{
global $config;
if (empty($filter) === false && empty($filter['groups']) === false && $filter['groups'] !== 0) {
$filter_group = 'AND tagente.id_grupo IN ('.$filter['groups'].')';
} else {
$filter_group = '';
}
$data = [];
$data['total_modules'] = 0;
$data['total_remote_modules'] = 0;
@ -170,18 +176,58 @@ function servers_get_performance()
$data['network_modules_rate'] = 0;
if ($config['realtimestats'] == 1) {
$counts = db_get_all_rows_sql(
'SELECT tagente_modulo.id_modulo,
COUNT(tagente_modulo.id_agente_modulo) modules
FROM tagente_modulo, tagente_estado, tagente
WHERE tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo
AND tagente.id_agente = tagente_estado.id_agente
AND tagente_modulo.disabled = 0
AND tagente_modulo.id_modulo <> 0
AND delete_pending = 0
AND tagente.disabled = 0
GROUP BY tagente_modulo.id_modulo'
);
if (is_metaconsole() === true) {
$counts = [];
$servers = metaconsole_get_servers();
// Check if the group can be deleted or not.
if (isset($servers) === true
&& is_array($servers) === true
) {
foreach ($servers as $server) {
if (metaconsole_connect($server) == NOERR) {
$meta_counts = db_get_all_rows_sql(
'SELECT tagente_modulo.id_modulo,
COUNT(tagente_modulo.id_agente_modulo) modules
FROM tagente_modulo, tagente_estado, tagente
WHERE tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo
AND tagente.id_agente = tagente_estado.id_agente
AND tagente_modulo.disabled = 0
AND tagente_modulo.id_modulo <> 0
AND delete_pending = 0
AND tagente.disabled = 0
'.$filter_group.'
GROUP BY tagente_modulo.id_modulo'
);
foreach ($meta_counts as $key => $val) {
if (array_key_exists($key, $counts)) {
if ($meta_counts[$key]['id_modulo'] == $counts[$key]['id_modulo']) {
$counts[$key]['modules'] += $meta_counts[$key]['modules'];
}
} else {
$counts[$key] = $meta_counts[$key];
}
}
}
metaconsole_restore_db();
}
}
} else {
$counts = db_get_all_rows_sql(
'SELECT tagente_modulo.id_modulo,
COUNT(tagente_modulo.id_agente_modulo) modules
FROM tagente_modulo, tagente_estado, tagente
WHERE tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo
AND tagente.id_agente = tagente_estado.id_agente
AND tagente_modulo.disabled = 0
AND tagente_modulo.id_modulo <> 0
AND delete_pending = 0
AND tagente.disabled = 0
'.$filter_group.'
GROUP BY tagente_modulo.id_modulo'
);
}
if (empty($counts)) {
$counts = [];
@ -284,28 +330,76 @@ function servers_get_performance()
}
$interval_avgs = [];
if (is_metaconsole() === true) {
$interval_avgs_modules = [];
$servers = metaconsole_get_servers();
// Avg of modules interval when modules have module_interval > 0.
$interval_avgs_modules = db_get_all_rows_sql(
'SELECT count(tagente_modulo.id_modulo) modules ,
tagente_modulo.id_modulo,
AVG(tagente_modulo.module_interval) avg_interval
FROM tagente_modulo, tagente_estado, tagente
WHERE tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo
AND tagente_modulo.disabled = 0
AND module_interval > 0
AND (utimestamp > 0 OR (
id_tipo_modulo = 100
OR (id_tipo_modulo > 21
AND id_tipo_modulo < 23
// Check if the group can be deleted or not.
if (isset($servers) === true
&& is_array($servers) === true
) {
foreach ($servers as $server) {
if (metaconsole_connect($server) == NOERR) {
// Avg of modules interval when modules have module_interval > 0.
$meta_interval_avgs_modules = db_get_all_rows_sql(
'SELECT count(tagente_modulo.id_modulo) modules ,
tagente_modulo.id_modulo,
AVG(tagente_modulo.module_interval) avg_interval
FROM tagente_modulo, tagente_estado, tagente
WHERE tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo
AND tagente_modulo.disabled = 0
AND module_interval > 0
AND (utimestamp > 0 OR (
id_tipo_modulo = 100
OR (id_tipo_modulo > 21
AND id_tipo_modulo < 23
)
)
)
AND delete_pending = 0
AND tagente.disabled = 0
AND tagente.id_agente = tagente_estado.id_agente
GROUP BY tagente_modulo.id_modulo'
);
foreach ($meta_interval_avgs_modules as $key => $val) {
if (array_key_exists($key, $interval_avgs_modules)) {
if ($meta_interval_avgs_modules[$key]['id_modulo'] == $interval_avgs_modules[$key]['id_modulo']) {
$interval_avgs_modules[$key]['modules'] += $meta_interval_avgs_modules[$key]['modules'];
$interval_avgs_modules[$key]['avg_interval'] += $meta_interval_avgs_modules[$key]['avg_interval'];
}
} else {
$interval_avgs_modules[$key] = $meta_interval_avgs_modules[$key];
}
}
}
metaconsole_restore_db();
}
}
} else {
// Avg of modules interval when modules have module_interval > 0.
$interval_avgs_modules = db_get_all_rows_sql(
'SELECT count(tagente_modulo.id_modulo) modules ,
tagente_modulo.id_modulo,
AVG(tagente_modulo.module_interval) avg_interval
FROM tagente_modulo, tagente_estado, tagente
WHERE tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo
AND tagente_modulo.disabled = 0
AND module_interval > 0
AND (utimestamp > 0 OR (
id_tipo_modulo = 100
OR (id_tipo_modulo > 21
AND id_tipo_modulo < 23
)
)
)
)
AND delete_pending = 0
AND tagente.disabled = 0
AND tagente.id_agente = tagente_estado.id_agente
GROUP BY tagente_modulo.id_modulo'
);
AND delete_pending = 0
AND tagente.disabled = 0
AND tagente.id_agente = tagente_estado.id_agente
GROUP BY tagente_modulo.id_modulo'
);
}
if (empty($interval_avgs_modules)) {
$interval_avgs_modules = [];

View File

@ -293,6 +293,21 @@ function tactical_get_data(
$list['_module_sanity_'] = 100;
}
$list['_monitors_alerts_'] = 0;
$servers = metaconsole_get_servers();
if (isset($servers) === true
&& is_array($servers) === true
) {
foreach ($servers as $server) {
if (metaconsole_connect($server) == NOERR) {
$list['_monitors_alerts_'] += tactical_monitor_alerts($user_strict, $user_groups_ids);
}
metaconsole_restore_db();
}
}
if (isset($list['_alerts_'])) {
if ($list['_monitors_alerts_fired_'] > 0 && $list['_alerts_'] > 0) {
$list['_alert_level_'] = format_numeric((100 - ($list['_monitors_alerts_fired_'] / ($list['_alerts_'] / 100))), 1);
@ -476,13 +491,12 @@ function tactical_get_data(
}
$list['_monitors_alerts_fired_'] = tactical_monitor_fired_alerts(explode(',', $user_groups_ids), $user_strict, explode(',', $user_groups_ids));
$list['_monitors_alerts_'] = tactical_monitor_alerts($user_strict);
$list['_monitors_alerts_'] = tactical_monitor_alerts($user_strict, $user_groups_ids);
$filter_agents = [];
if (users_is_admin() === false) {
// if (users_is_admin() === false) {
$filter_agents = ['id_grupo' => explode(',', $user_groups_ids)];
}
// }
$total_agentes = agents_get_agents(
$filter_agents,
['count(DISTINCT id_agente) as total_agents'],
@ -537,11 +551,15 @@ function tactical_status_modules_agents($id_user=false, $user_strict=false, $acc
}
function tactical_monitor_alerts($strict_user=false)
function tactical_monitor_alerts($strict_user=false, $groups_ids='')
{
global $config;
$groups = users_get_groups($config['id_user'], 'AR', false);
$id_groups = array_keys($groups);
if ($groups_ids === '') {
$groups = users_get_groups($config['id_user'], 'AR', false);
$id_groups = array_keys($groups);
} else {
$id_groups = explode(',', $groups_ids);
}
$where_clause = '';
if (empty($id_groups) === true) {

View File

@ -382,6 +382,10 @@ class TacticalWidget extends Widget
$data = [];
if (isset($all_data['_monitor_total_']) === false) {
$all_data['_monitor_total_'] = (int) $all_data['_monitor_checks_'];
}
$data['monitor_not_init'] = (int) $all_data['_monitors_not_init_'];
$data['monitor_unknown'] = (int) $all_data['_monitors_unknown_'];
$data['monitor_ok'] = (int) $all_data['_monitors_ok_'];
@ -393,6 +397,7 @@ class TacticalWidget extends Widget
$data['monitor_total'] = (int) $all_data['_monitor_total_'];
$data['total_agents'] = (int) $all_data['_total_agents_'];
$data['groups'] = $this->values['groupId'][0];
$data['monitor_checks'] = (int) $all_data['_monitor_checks_'];
@ -505,7 +510,7 @@ class TacticalWidget extends Widget
$table->data = [];
$table->style = [];
$table->data[0][0] = \reporting_get_stats_servers();
$table->data[0][0] = \reporting_get_stats_servers($data);
$output .= \html_print_table($table, true);
}