#11494 Fix widget in metaconsole

This commit is contained in:
miguel angel rasteu 2023-09-14 15:28:54 +02:00
parent 750b318a2e
commit e727ea402b
2 changed files with 89 additions and 26 deletions

View File

@ -4782,9 +4782,27 @@ function service_level_module_data($datetime_from, $datetime_to, $id_agentmodule
$data['mtbf'] = false;
$data['mtrs'] = false;
$data['availability'] = false;
$data['critical_events'] = false;
$data['warning_events'] = false;
$data['last_status_change'] = false;
$data['module_name'] = false;
$availability = 0;
$type = '';
if ((bool) is_metaconsole() === true) {
if (enterprise_include_once('include/functions_metaconsole.php') !== ENTERPRISE_NOT_HOOK) {
$server_id = [];
$server_id['id'] = explode('|', $id_agentmodule)[0];
$id_agentmodule = explode('|', $id_agentmodule)[1];
$server_name = db_get_row_filter('tmetaconsole_setup', $server_id, 'server_name');
$connection = metaconsole_get_connection($server_name);
if (metaconsole_load_external_db($connection) !== NOERR) {
// Restore db connection.
metaconsole_restore_db();
return $data;
}
}
}
$uncompressed_data = db_uncompress_module_data(
$id_agentmodule,
@ -4815,6 +4833,24 @@ function service_level_module_data($datetime_from, $datetime_to, $id_agentmodule
ORDER BY utimestamp DESC';
$events_time = db_get_all_rows_sql($sql);
// Count events.
$sql = 'SELECT COUNT(*) as critical_events FROM tevento
WHERE id_agentmodule= '.$id_agentmodule.'
AND utimestamp >= '.$datetime_from.'
AND utimestamp <= '.$datetime_to.'
AND (event_type = "going_up_critical" OR event_type = "going_down_critical")';
$critical_events = db_get_sql($sql);
$sql = 'SELECT COUNT(*) as warning_events FROM tevento
WHERE id_agentmodule= '.$id_agentmodule.'
AND utimestamp >= '.$datetime_from.'
AND utimestamp <= '.$datetime_to.'
AND (event_type = "going_up_warning" OR event_type = "going_down_warning")';
$warning_events = db_get_sql($sql);
if ($events_time !== false && count($events_time) > 0) {
$failed_event = [];
$normal_event = [];
@ -4844,6 +4880,7 @@ function service_level_module_data($datetime_from, $datetime_to, $id_agentmodule
}
$mtbf_array = [];
if (!empty($failed_event) === true) {
if (count($failed_event) > 1) {
for ($i = 1; $i <= array_key_last($failed_event); $i++) {
@ -4866,9 +4903,8 @@ function service_level_module_data($datetime_from, $datetime_to, $id_agentmodule
$availability = round((($total_time_ok / $interval_time) * 100), 2);
}
// hd($availability, true);
if (count($mtbf_array) > 1) {
$mtbf = round(( $total_time_failed / count($mtbf_array)));
if ($critical_events > 1) {
$mtbf = round(( $total_time_failed / $critical_events));
} else {
$mtbf = false;
}
@ -4884,6 +4920,41 @@ function service_level_module_data($datetime_from, $datetime_to, $id_agentmodule
$data['mtbf'] = $mtbf;
$data['mtrs'] = $mtrs;
$data['availability'] = $availability;
} else {
$data['mtbf'] = false;
$data['mtrs'] = false;
$data['availability'] = false;
}
// Get last status change.
$sql = 'SELECT last_status_change FROM tagente_estado
WHERE id_agente_modulo = '.$id_agentmodule.' ';
$last_status_change = db_get_sql($sql);
// Get module name.
/*
$sql = 'SELECT nombre FROM tagente_modulo
WHERE id_agente_modulo = '.$id_agentmodule;*/
$sql = 'SELECT tagente_modulo.nombre as nombre, tagente.alias as alias
FROM tagente_modulo INNER JOIN tagente
ON tagente_modulo.id_agente = tagente.id_agente
WHERE id_agente_modulo = '.$id_agentmodule.' ';
$sql_query = db_get_all_rows_sql($sql);
$data['critical_events'] = $critical_events;
$data['warning_events'] = $warning_events;
$data['last_status_change'] = $last_status_change;
$data['module_name'] = $sql_query[0]['nombre'];
if ((bool) is_metaconsole() === true) {
$data['agent_alias'] = $server_name['server_name'].' » '.$sql_query[0]['alias'];
} else {
$data['agent_alias'] = $sql_query[0]['alias'];
}
if ((bool) is_metaconsole() === true) {
metaconsole_restore_db();
}
return $data;

View File

@ -461,7 +461,6 @@ class ServiceLevelWidget extends Widget
$visualData[$agent_id]['agent_name'] = $agent->name();
$visualData[$agent_id]['agent_alias'] = $agent->alias();
$visualData[$agent_id]['modules'] = [];
if (empty($allModules) === false) {
if (is_metaconsole() === true && $this->values['mShowCommonModules'] !== 'on') {
if (isset($reduceAllModules['modules_selected'][$tserver]) === true) {
@ -479,6 +478,11 @@ class ServiceLevelWidget extends Widget
}
$visualData[$agent_id]['modules'] = $allModules;
if ((bool) is_metaconsole() === true) {
metaconsole_restore_db();
}
foreach ($modules as $module) {
if ($module === null) {
continue;
@ -492,30 +496,19 @@ class ServiceLevelWidget extends Widget
// Mean Time Between Failure.
// Mean Time To Solution.
// Availability.
$module_data = service_level_module_data($interval_range['start'], $interval_range['end'], $data_module_array['id_agente_modulo']);
if ((bool) is_metaconsole() === true) {
$module_id = $tserver.'|'.$data_module_array['id_agente_modulo'];
} else {
$module_id = $data_module_array['id_agente_modulo'];
}
$module_data = service_level_module_data($interval_range['start'], $interval_range['end'], $module_id);
$visualData[$agent_id]['modules'][$module->name()]['mtrs'] = ($module_data['mtrs'] !== false) ? human_milliseconds_to_string(($module_data['mtrs'] * 100), 'short') : '-';
$visualData[$agent_id]['modules'][$module->name()]['mtbf'] = ($module_data['mtbf'] !== false) ? human_milliseconds_to_string(($module_data['mtbf'] * 100), 'short') : '-';
$visualData[$agent_id]['modules'][$module->name()]['availability'] = ($module_data['availability'] !== false) ? $module_data['availability'] : '100';
// Count events.
$sql = 'SELECT COUNT(*) as critical_events FROM tevento
WHERE id_agentmodule= '.$data_module_array['id_agente_modulo'].'
AND utimestamp >= '.$interval_range['start'].'
AND utimestamp <= '.$interval_range['end'].'
AND (event_type = "going_up_critical" OR event_type = "going_down_critical")';
$visualData[$agent_id]['modules'][$module->name()]['critical_events'] = db_get_sql($sql);
$sql = 'SELECT COUNT(*) as critical_events FROM tevento
WHERE id_agentmodule= '.$data_module_array['id_agente_modulo'].'
AND utimestamp >= '.$interval_range['start'].'
AND utimestamp <= '.$interval_range['end'].'
AND (event_type = "going_up_warning" OR event_type = "going_down_warning")';
$visualData[$agent_id]['modules'][$module->name()]['warning_events'] = db_get_sql($sql);
}
if ((bool) is_metaconsole() === true) {
metaconsole_restore_db();
$visualData[$agent_id]['modules'][$module->name()]['critical_events'] = ($module_data['critical_events'] !== false) ? $module_data['critical_events'] : '';
$visualData[$agent_id]['modules'][$module->name()]['warning_events'] = ($module_data['critical_events'] !== false) ? $module_data['critical_events'] : '';
$visualData[$agent_id]['modules'][$module->name()]['last_status_change'] = ($module_data['last_status_change'] !== false) ? $module_data['last_status_change'] : '';
}
} catch (\Exception $e) {
echo 'Error: ['.$agent_id.']'.$e->getMessage();
@ -558,7 +551,6 @@ class ServiceLevelWidget extends Widget
$table->data[$row][4] = $module_data['critical_events'];
$table->data[$row][5] = $module_data['warning_events'];
$table->data[$row][6] = date(TIME_FORMAT, $module_data['last_status_change']);
$table->colspan[][0] = 0;
}
$row++;