From f46626e120d341c13652146c7032165b19f8b8fc Mon Sep 17 00:00:00 2001 From: daniel Date: Thu, 21 Sep 2023 10:21:45 +0200 Subject: [PATCH] refactor cluster view pandora_enterprise#12032 --- .../godmode/agentes/configurar_agente.php | 3 - .../godmode/agentes/modificar_agente.php | 16 +- .../godmode/alerts/alert_list.builder.php | 3 +- .../godmode/alerts/alert_list.list.php | 16 +- pandora_console/godmode/alerts/alert_list.php | 5 + pandora_console/include/ajax/module.php | 132 +++++- pandora_console/include/class/HTML.class.php | 47 ++ pandora_console/include/functions_agents.php | 338 ++++++++++++++- pandora_console/include/functions_events.php | 3 - pandora_console/include/functions_ui.php | 52 +++ .../include/javascript/datatablesFunction.js | 9 +- pandora_console/include/lib/Cluster.php | 86 ++++ .../lib/ClusterViewer/ClusterManager.php | 87 +++- .../lib/ClusterViewer/ClusterWizard.php | 34 +- pandora_console/include/styles/pandora.css | 87 +++- .../operation/agentes/alerts_status.php | 12 +- .../operation/agentes/estado_agente.php | 7 +- .../agentes/estado_generalagente.php | 409 ++---------------- .../operation/agentes/estado_monitores.php | 29 ++ pandora_console/views/cluster/edit.php | 3 + pandora_console/views/cluster/view.php | 383 ++++------------ 21 files changed, 1001 insertions(+), 760 deletions(-) diff --git a/pandora_console/godmode/agentes/configurar_agente.php b/pandora_console/godmode/agentes/configurar_agente.php index de42b8b6c3..96837b876d 100644 --- a/pandora_console/godmode/agentes/configurar_agente.php +++ b/pandora_console/godmode/agentes/configurar_agente.php @@ -2092,7 +2092,6 @@ if ($create_module) { if ($disable_module) { - hd($disable_module, true); $result = modules_change_disabled($disable_module, 1); $module_name = modules_get_agentmodule_name($disable_module); @@ -2116,13 +2115,11 @@ if ($create_module) { if ($result === NOERR) { - hd($disable_module, true); db_pandora_audit( AUDIT_LOG_MODULE_MANAGEMENT, 'Disable #'.$disable_module.' | '.$module_name.' | '.io_safe_output($agent['alias']) ); } else { - hd($disable_module, true); db_pandora_audit( AUDIT_LOG_MODULE_MANAGEMENT, 'Fail to disable #'.$disable_module.' | '.$module_name.' | '.io_safe_output($agent['alias']) diff --git a/pandora_console/godmode/agentes/modificar_agente.php b/pandora_console/godmode/agentes/modificar_agente.php index a14bff4b92..487fe54e07 100644 --- a/pandora_console/godmode/agentes/modificar_agente.php +++ b/pandora_console/godmode/agentes/modificar_agente.php @@ -751,6 +751,10 @@ if ($agents !== false) { 'index.php?sec=reporting&sec2=operation/cluster/cluster&op=view&id=%s', $cluster->id() ); + $agentAlertUrl = sprintf( + 'index.php?sec=estado&sec2=operation/cluster/cluster&op=update&id=%s&page=6', + $cluster->id() + ); } else { $main_tab = ($check_aw === true) ? 'main' : 'module'; $agentNameUrl = sprintf( @@ -762,6 +766,10 @@ if ($agents !== false) { 'index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente=%s', $agent['id_agente'] ); + $agentAlertUrl = sprintf( + 'index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&tab=alert&id_agente=%s', + $agent['id_agente'] + ); } if (empty($agent['alias']) === true) { @@ -825,7 +833,7 @@ if ($agents !== false) { ); } - if ((int) $agent['id_os'] !== 100) { + if ((int) $agent['id_os'] != CLUSTER_OS_ID) { $additionalOptionsAgentName[] = html_print_anchor( [ 'href' => ui_get_full_url('index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&tab=module&id_agente='.$agent['id_agente']), @@ -837,7 +845,7 @@ if ($agents !== false) { $additionalOptionsAgentName[] = html_print_anchor( [ - 'href' => ui_get_full_url('index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&tab=alert&id_agente='.$agent['id_agente']), + 'href' => ui_get_full_url($agentAlertUrl), 'content' => __('Alerts'), ], true @@ -942,7 +950,7 @@ if ($agents !== false) { $os ) ), - 'onClick' => ($agent['id_os'] === CLUSTER_OS_ID) ? sprintf('if (!confirm(\'%s\')) return false', $agentDisableEnableCaption) : 'return true;', + 'onClick' => ($agent['id_os'] == CLUSTER_OS_ID) ? sprintf('if (!confirm(\'%s\')) return false', $agentDisableEnableCaption) : 'return true;', 'image' => sprintf('images/%s', $agentDisableEnableIcon), 'title' => $agentDisableEnableTitle, ], @@ -950,7 +958,7 @@ if ($agents !== false) { ); if ($check_aw === true && is_management_allowed() === true) { - if ($agent['id_os'] !== CLUSTER_OS_ID) { + if ($agent['id_os'] != CLUSTER_OS_ID) { $onClickActionDeleteAgent = 'if (!confirm(\' '.__('Are you sure?').'\')) return false;'; } else { $onClickActionDeleteAgent = 'if (!confirm(\' '.__('WARNING! - You are going to delete a cluster agent. Are you sure?').'\')) return false;'; diff --git a/pandora_console/godmode/alerts/alert_list.builder.php b/pandora_console/godmode/alerts/alert_list.builder.php index de07bce961..34242a8fa3 100644 --- a/pandora_console/godmode/alerts/alert_list.builder.php +++ b/pandora_console/godmode/alerts/alert_list.builder.php @@ -206,9 +206,10 @@ $table->data[2][0] = html_print_label_input_block( if (isset($step) === false) { echo '
'; - html_print_table($table); } +html_print_table($table); + if (isset($step) === false) { $output = ''; diff --git a/pandora_console/godmode/alerts/alert_list.list.php b/pandora_console/godmode/alerts/alert_list.list.php index fa848c845d..5d71895ecd 100644 --- a/pandora_console/godmode/alerts/alert_list.list.php +++ b/pandora_console/godmode/alerts/alert_list.list.php @@ -620,7 +620,21 @@ foreach ($simple_alerts as $alert) { $main_tab = 'module'; } - $data[0] = ''; + if ((int) agents_get_os($id_agent) === CLUSTER_OS_ID) { + $cluster = PandoraFMS\Cluster::loadFromAgentId($id_agent); + $agentAlertUrl = sprintf( + 'index.php?sec=estado&sec2=operation/cluster/cluster&op=update&id=%s&page=6', + $cluster->id() + ); + } else { + $agentAlertUrl = sprintf( + 'index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&tab=%s&id_agente=%s', + $main_tab, + $id_agent + ); + } + + $data[0] = ''; if ($alert['disabled']) { $data[0] .= ''; diff --git a/pandora_console/godmode/alerts/alert_list.php b/pandora_console/godmode/alerts/alert_list.php index 17669ab248..1dc32ba086 100644 --- a/pandora_console/godmode/alerts/alert_list.php +++ b/pandora_console/godmode/alerts/alert_list.php @@ -650,6 +650,11 @@ if ($id_agente) { echo $messageAction; include_once 'godmode/alerts/alert_list.list.php'; + + if (isset($step) === true && $step === true) { + return; + } + $all_groups = agents_get_all_groups_agent($id_agente, $agent['id_grupo']); if (check_acl_one_of_groups($config['id_user'], $all_groups, 'LW') || check_acl_one_of_groups($config['id_user'], $all_groups, 'LM')) { include_once 'godmode/alerts/alert_list.builder.php'; diff --git a/pandora_console/include/ajax/module.php b/pandora_console/include/ajax/module.php index 1e529c487c..78daacb0a0 100755 --- a/pandora_console/include/ajax/module.php +++ b/pandora_console/include/ajax/module.php @@ -80,6 +80,7 @@ if (check_login()) { $save_monitor_filter = get_parameter('save_monitor_filter', 0); $update_monitor_filter = get_parameter('update_monitor_filter', 0); $delete_monitor_filter = get_parameter('delete_monitor_filter', 0); + $get_cluster_module_detail = (bool) get_parameter('get_cluster_module_detail', 0); if ($get_agent_modules_json_by_name === true) { $agent_name = get_parameter('agent_name'); @@ -742,13 +743,6 @@ if (check_login()) { include_once $config['homedir'].'/include/functions_tags.php'; include_once $config['homedir'].'/include/functions_clippy.php'; - - // Disable module edition in cluster module list. - $cluster_view = (bool) preg_match( - '/operation\/cluster\/cluster/', - $_SERVER['HTTP_REFERER'] - ); - $agent_a = (bool) check_acl($config['id_user'], 0, 'AR'); $agent_w = (bool) check_acl($config['id_user'], 0, 'AW'); $access = ($agent_a === true) ? 'AR' : (($agent_w === true) ? 'AW' : 'AR'); @@ -758,7 +752,19 @@ if (check_login()) { $cluster_list = (int) get_parameter('cluster_list'); $sortField = (string) get_parameter('sort_field'); $sort = (string) get_parameter('sort', 'none'); + + // Disable module edition in cluster module list. + $cluster_view = false; $url = 'index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente='.$id_agent; + if ((int) agents_get_os($id_agent) === CLUSTER_OS_ID) { + $cluster = PandoraFMS\Cluster::loadFromAgentId($id_agent); + $url = sprintf( + 'index.php?sec=estado&sec2=operation/cluster/cluster&op=view&id=%s', + $cluster->id() + ); + $cluster_view = true; + } + $selectTypeUp = false; $selectTypeDown = false; $selectNameUp = false; @@ -1248,7 +1254,6 @@ if (check_login()) { $graph_type = return_graphtype($module['id_tipo_modulo']); $nombre_tipo_modulo = modules_get_moduletype_name($module['id_tipo_modulo']); $handle = 'stat'.$nombre_tipo_modulo.'_'.$module['id_agente_modulo']; - $url = 'include/procesos.php?agente='.$module['id_agente_modulo']; $win_handle = dechex(crc32($module['id_agente_modulo'].$module['nombre'])); // Show events for boolean modules by default. $draw_events = ($graph_type === 'boolean') ? 1 : 0; @@ -1314,6 +1319,23 @@ if (check_login()) { true ); + if ($cluster_view === true) { + $graphButtons[] = html_print_anchor( + [ + 'href' => 'javascript: show_cluster_module_detail('.$cluster->id().', \''.$modules_get_agentmodule_name.'\')', + 'content' => html_print_image( + 'images/plus@svg.svg', + true, + [ + 'title' => __('Module cluster detail'), + 'class' => 'main_menu_icon forced_title', + ] + ), + ], + true + ); + } + $data[8] = html_print_div( [ 'class' => 'table_action_buttons', @@ -1340,7 +1362,7 @@ if (check_login()) { $moduleActionButtons[] = html_print_anchor( [ - 'href' => 'index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente='.$id_agente.'&id_agente_modulo='.$module['id_agente_modulo'].'&refr=60'.$additionalLinkAction.'"', + 'href' => $url.'&id_agente_modulo='.$module['id_agente_modulo'].'&refr=60'.$additionalLinkAction.'"', 'content' => html_print_image( $imgaction, true, @@ -1756,14 +1778,75 @@ if (check_login()) { return; } + if ($get_cluster_module_detail === true) { + global $config; + $data = []; + + $cluster_id = get_parameter('cluster_id', 0); + $cluster = new PandoraFMS\Cluster($cluster_id); + $modules_ids = $cluster->getIdsModulesInvolved(); + $module_name = get_parameter('module_name', ''); + + try { + $column_names = [ + __('Module name'), + __('Agent'), + __('Last status change'), + __('Status'), + ]; + + $columns = [ + 'nombre', + 'alias', + 'last_status_change', + 'estado', + ]; + + $tableId = 'ModuleByStatus'; + // Load datatables user interface. + ui_print_datatable( + [ + 'id' => $tableId, + 'class' => 'info_table align-left-important', + 'style' => 'width: 100%', + 'columns' => $columns, + 'column_names' => $column_names, + 'ajax_url' => 'include/ajax/module', + 'ajax_data' => [ + 'get_data_ModulesByStatus' => 1, + 'table_id' => $tableId, + 'module_name' => $module_name, + 'modules_ids' => $modules_ids, + 'search' => '', + ], + 'default_pagination' => 5, + 'order' => [ + 'field' => 'last_status_change', + 'direction' => 'desc', + ], + 'csv' => 0, + 'dom_elements' => 'frtip', + 'no_move_elements_to_action' => true, + 'mini_pagination' => true, + ] + ); + } catch (\Exception $e) { + echo $e->getMessage(); + } + + return; + } + if ($get_data_ModulesByStatus === true) { global $config; $data = []; $table_id = get_parameter('table_id', ''); $search = get_parameter('search', ''); + $module_name = get_parameter('module_name', ''); $status = get_parameter('status', ''); $start = get_parameter('start', 0); + $modules_ids = get_parameter('modules_ids', []); $length = get_parameter('length', $config['block_size']); // There is a limit of (2^32)^2 (18446744073709551615) rows in a MyISAM table, show for show all use max nrows. $length = ($length != '-1') ? $length : '18446744073709551615'; @@ -1771,12 +1854,11 @@ if (check_login()) { $nodes = get_parameter('nodes', 0); $disabled_modules = (bool) get_parameter('disabled_modules', false); - $where = ''; + $where = '1=1'; $recordsTotal = 0; - if (empty($search) === false) { - $where = 'tagente_modulo.nombre LIKE "%%'.$search.'%%" AND '; + $where .= ' AND tagente_modulo.nombre LIKE "%%'.$search.'%%"'; } if (str_contains($status, '6') === true) { @@ -1791,16 +1873,32 @@ if (check_login()) { $status = implode(',', $expl); } - $where .= sprintf( - 'tagente_estado.estado IN (%s) - AND tagente_modulo.delete_pending = 0', - $status, - ); + if (empty($status) === false) { + $where .= sprintf( + ' AND tagente_estado.estado IN (%s) + AND tagente_modulo.delete_pending = 0', + $status, + ); + } if ($disabled_modules === false) { $where .= ' AND tagente_modulo.disabled = 0'; } + if (empty($modules_ids) === false && is_array($modules_ids) === true) { + $where .= sprintf( + ' AND tagente_modulo.id_agente_modulo IN (%s)', + implode(',', $modules_ids) + ); + } + + if (empty($module_name) === false) { + $where .= sprintf( + ' AND tagente_modulo.nombre = "%s"', + $module_name + ); + } + if (is_metaconsole() === false) { $order_by = ''; switch ($order['field']) { diff --git a/pandora_console/include/class/HTML.class.php b/pandora_console/include/class/HTML.class.php index cb04097f33..5020538e26 100644 --- a/pandora_console/include/class/HTML.class.php +++ b/pandora_console/include/class/HTML.class.php @@ -1261,4 +1261,51 @@ var simTree_'.$target.'; } + /** + * Build Steps. + * + * @param array $steps Steps. + * @param null|boolean $return Output mode. + * + * @return string. + */ + public static function printSteps(array $steps, ?bool $return=false) + { + $i = 1; + + $count = count($steps); + $output = '
    '; + foreach ($steps as $step) { + $class = ''; + if ((int) $step['selected'] === 1) { + $class = 'current'; + } + + if ($i === 1) { + $class .= ' first'; + } + + if ($i === $count) { + $class .= ' last'; + } + + $output .= '
  1. '; + $output .= ''; + $output .= __('Step').' '.$i.' » '; + $output .= ''.$step['label'].''; + $output .= ''; + $output .= '
  2. '; + $i++; + } + + $output .= '
'; + + if ($return === true) { + return $output; + } + + echo $output; + } + + } diff --git a/pandora_console/include/functions_agents.php b/pandora_console/include/functions_agents.php index 2a14579bc6..f74e9dbaaf 100644 --- a/pandora_console/include/functions_agents.php +++ b/pandora_console/include/functions_agents.php @@ -3179,6 +3179,38 @@ function agents_detail_view_status_img($critical, $warning, $unknown, $total, $n } +// Returns the status div to display agent detail view +function agents_detail_view_status_div($critical, $warning, $unknown, $total, $notinit) +{ + if ($total == 0 || $total == $notinit) { + return ui_print_status_agent_div( + AGENT_STATUS_NOT_INIT, + __('No Monitors') + ); + } else if ($critical > 0) { + return ui_print_status_agent_div( + AGENT_STATUS_CRITICAL, + __('At least one module in CRITICAL status') + ); + } else if ($warning > 0) { + return ui_print_status_agent_div( + AGENT_STATUS_WARNING, + __('At least one module in WARNING status') + ); + } else if ($unknown > 0) { + return ui_print_status_agent_div( + AGENT_STATUS_UNKNOWN, + __('At least one module is in UKNOWN status') + ); + } else { + return ui_print_status_agent_div( + AGENT_STATUS_NORMAL, + __('All Monitors OK') + ); + } +} + + function agents_update_gis( $idAgente, $latitude, @@ -4386,23 +4418,26 @@ function agents_get_offspring(int $id_agent) } -function agents_get_starmap(int $id_agent, float $width=0, float $height=0) -{ +function agents_get_starmap( + int $id_agent, + float $width=0, + float $height=0, + ?array $all_modules=null +) { ui_require_css_file('heatmap'); - $all_modules = agents_get_modules($id_agent, 'id_agente_modulo', ['disabled' => 0]); - if (empty($all_modules)) { - return null; + if (empty($all_modules) === true) { + $all_modules = agents_get_modules($id_agent, 'id_agente_modulo', ['disabled' => 0]); + if (empty($all_modules)) { + return null; + } } $total_modules = count($all_modules); if ($width !== 0 && $height !== 0) { - $measuresProvided = false; $width = 200; $height = 50; - } else { - $measuresProvided = true; } // Best square. @@ -4421,7 +4456,6 @@ function agents_get_starmap(int $id_agent, float $width=0, float $height=0) $square_length = min(($width / floor($width / $low)), ($height / floor($height / $low))); - // $measureSymbol = ($measuresProvided === true) ? '' : '%'; // Print starmap. $html = sprintf( '', @@ -4544,4 +4578,290 @@ function agents_get_starmap(int $id_agent, float $width=0, float $height=0) function hash_agent_name(string $alias, string $nombre_agente) { return hash('sha256', $alias.'|'.$nombre_agente.'|'.time().'|'.sprintf('%04d', rand(0, 10000))); +} + + +function get_resume_agent_status_header($agent) +{ + global $config; + + $agentCaptionAddedMessage = []; + $agentCaption = ''.ucfirst(agents_get_alias($agent['id_agente'])).''; + $in_planned_downtime = (bool) db_get_sql( + 'SELECT executed FROM tplanned_downtime + INNER JOIN tplanned_downtime_agents + ON tplanned_downtime.id = tplanned_downtime_agents.id_downtime + WHERE tplanned_downtime_agents.id_agent = '.$agent['id_agente'].' AND tplanned_downtime.executed = 1' + ); + + if ((bool) $agent['disabled'] === true) { + $agentCaptionAddedMessage[] = __('Disabled'); + } else if ((bool) $agent['quiet'] === true) { + $agentCaptionAddedMessage[] = __('Quiet'); + } + + if ($in_planned_downtime === true) { + $agentCaptionAddedMessage[] = __('In scheduled downtime'); + } + + if (empty($agentCaptionAddedMessage) === false) { + $agentCaption .= ' ('.implode(' - ', $agentCaptionAddedMessage).')'; + } + + $agentIconGroup = ((bool) $config['show_group_name'] === false) ? ui_print_group_icon( + $agent['id_grupo'], + true, + '', + 'padding-right: 6px;', + true, + false, + false, + '', + true + ) : ''; + + $agentIconStatus = agents_detail_view_status_img( + $agent['critical_count'], + $agent['warning_count'], + $agent['unknown_count'], + $agent['total_count'], + $agent['notinit_count'] + ); + + $agent_details_agent_caption = html_print_div( + [ + 'class' => 'agent_details_agent_caption', + 'content' => $agentCaption, + ], + true + ); + + $agent_details_agent_data = html_print_div( + [ + 'class' => 'agent_details_agent_data', + 'content' => $agentIconGroup, + ], + true + ); + + $agent_details_agent_status_image = html_print_div( + [ + 'class' => 'icono_right', + 'content' => $agentIconStatus, + ], + true + ); + + $agentStatusHeader = html_print_div( + [ + 'class' => 'agent_details_header', + 'content' => $agent_details_agent_caption.$agent_details_agent_data.$agent_details_agent_status_image, + ], + true + ); + + return $agentStatusHeader; +} + + +function get_status_agent_chart_pie($id_agente, $graph_width, $data=null) +{ + // Fixed width non interactive charts. + $agentStatusGraph = html_print_div( + [ + 'id' => 'status_pie', + 'style' => 'width: '.$graph_width.'px;', + 'content' => graph_agent_status( + $id_agente, + $graph_width, + $graph_width, + true, + true, + (empty($data) === true) ? false : $data, + true + ), + ], + true + ); + + return $agentStatusGraph; +} + + +function get_resume_agent_concat($id_agente, $all_groups, $agent) +{ + global $config; + + $table_contact = new stdClass(); + $table_contact->id = 'agent_contact_main'; + $table_contact->width = '100%'; + $table_contact->cellspacing = 0; + $table_contact->cellpadding = 0; + $table_contact->class = 'floating_form'; + $table_contact->style[0] = 'height: 32px; width: 30%; padding-right: 5px; text-align: end; vertical-align: top'; + $table_contact->style[1] = 'height: 32px; width: 70%; padding-left: 5px; font-weight: lighter; vertical-align: top'; + + $agentContactCaption = html_print_div( + [ + 'class' => 'agent_details_agent_caption', + 'content' => ''.__('Agent contact').'', + ], + true + ); + + if ($agent['id_os'] == CLUSTER_OS_ID) { + $cluster = PandoraFMS\Cluster::loadFromAgentId( + $agent['id_agente'] + ); + $url = 'index.php?sec=reporting&sec2='; + $url .= 'operation/cluster/cluster'; + $url .= '&op=view&id='.$cluster->id(); + } else { + $url = 'index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente='.$agent['id_agente']; + } + + $buttonsRefreshAgent = html_print_button( + __('Refresh data'), + 'refresh_data', + false, + 'window.location.assign("'.$url.'&refr=60")', + [ 'mode' => 'link' ], + true + ); + + if (check_acl_one_of_groups($config['id_user'], $all_groups, 'AW') === true) { + $buttonsRefreshAgent .= html_print_button( + __('Force checks'), + 'force_checks', + false, + 'window.location.assign("'.$url.'&flag_agent=1")', + [ 'mode' => 'link' ], + true + ); + } + + $buttons_refresh_agent_view = html_print_div( + [ + 'class' => 'buttons_agent_view', + 'content' => $buttonsRefreshAgent, + ], + true + ); + + // Data for agent contact. + $intervalHumanTime = human_time_description_raw($agent['intervalo']); + $lastContactDate = ui_print_timestamp($agent['ultimo_contacto'], true); + $remoteContactDate = ($agent['ultimo_contacto_remoto'] === '01-01-1970 00:00:00') ? __('Never') : date_w_fixed_tz($agent['ultimo_contacto_remoto']); + $lastAndRemoteContact = sprintf('%s / %s', $lastContactDate, $remoteContactDate); + $progress = agents_get_next_contact($id_agente); + $tempTimeToShow = ($agent['intervalo'] - (strtotime('now') - strtotime($agent['ultimo_contacto']))); + $progressCaption = ($tempTimeToShow >= 0) ? sprintf('%d s', $tempTimeToShow) : __('Out of bounds'); + $ajaxNextContactInterval = (empty($agent['intervalo']) === true) ? 0 : (100 / $agent['intervalo']); + $secondary_groups = enterprise_hook('agents_get_secondary_groups', [$id_agente]); + $secondaryLinks = []; + if (empty($secondary_groups['for_select']) === true) { + $secondaryLinks[] = ''.__('N/A').''; + } else { + foreach ($secondary_groups['for_select'] as $id => $name) { + $secondaryLinks[] = html_print_anchor( + [ + 'href' => 'index.php?sec=estado&sec2=operation/agentes/estado_agente&refr=60&group_id='.$id, + 'content' => $name, + ], + true + ); + } + } + + $last_status_change_agent = agents_get_last_status_change($agent['id_agente']); + $time_elapsed = (empty($last_status_change_agent) === false) ? human_time_comparation($last_status_change_agent) : ''.__('N/A').''; + + // Agent Interval. + $data = []; + $data[0] = __('Interval'); + $data[1] = $intervalHumanTime; + $table_contact->data[] = $data; + + // Last & Remote contact. + $data = []; + $data[0] = __('Last contact').' / '.__('Remote'); + $data[1] = $lastAndRemoteContact; + $table_contact->data[] = $data; + + // Next contact progress. + $data = []; + $data[0] = __('Next contact'); + $data[1] = ui_progress( + $progress, + '80%', + '1.2', + '#ececec', + true, + $progressCaption, + [ + 'page' => 'operation/agentes/ver_agente', + 'interval' => $ajaxNextContactInterval, + 'data' => [ + 'id_agente' => $id_agente, + 'refresh_contact' => 1, + ], + + ] + ); + $table_contact->data[] = $data; + + // Group line. + $data = []; + $data[0] = ''.__('Group').''; + $data[1] = html_print_anchor( + [ + 'href' => 'index.php?sec=gagente&sec2=godmode/groups/tactical&id_group='.$agent['id_grupo'], + 'content' => groups_get_name($agent['id_grupo']), + ], + true + ); + $table_contact->data[] = $data; + + // Secondary groups. + $data = []; + $data[0] = ''.__('Secondary groups').''; + $data[1] = implode(', ', $secondaryLinks); + $table_contact->data[] = $data; + + // Parent agent line. + if (enterprise_installed() === true) { + $data = []; + $data[0] = ''.__('Parent').''; + if ((int) $agent['id_parent'] === 0) { + $data[1] = ''.__('N/A').''; + } else { + $data[1] = html_print_anchor( + [ + 'href' => 'index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente='.$agent['id_parent'], + 'content' => agents_get_alias($agent['id_parent']), + ], + true + ); + } + + $table_contact->data[] = $data; + } + + // Last status change line. + $data = []; + $data[0] = ''.__('Last status change').''; + $data[1] = $time_elapsed; + $table_contact->data[] = $data; + + $agent_contact = html_print_div( + [ + 'class' => 'agent_details_header', + 'content' => $agentContactCaption.$buttons_refresh_agent_view, + ], + true + ); + + $agent_contact .= html_print_table($table_contact, true); + + return $agent_contact; } \ No newline at end of file diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index 7068d554e6..069b91f125 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -5019,9 +5019,6 @@ function events_page_general($event) } $data[1] = $user_ack.' ( '; - // hd($config['date_format'], true); - // hd($event['ack_utimestamp_raw'], true); - // TODO: mirar en el manage y en la api que este ack de venir vacio lo herede del anterior que hubiera. if ($event['ack_utimestamp_raw'] !== false && $event['ack_utimestamp_raw'] !== 'false' && empty($event['ack_utimestamp_raw']) === false diff --git a/pandora_console/include/functions_ui.php b/pandora_console/include/functions_ui.php index 6e5aaef69a..ce7a548f4b 100755 --- a/pandora_console/include/functions_ui.php +++ b/pandora_console/include/functions_ui.php @@ -4011,6 +4011,10 @@ function ui_print_datatable(array $parameters) $parameters['csv'] = 1; } + if (isset($parameters['no_move_elements_to_action']) === false) { + $parameters['no_move_elements_to_action'] = false; + } + $filter = ''; // Datatable filter. if (isset($parameters['form']) && is_array($parameters['form'])) { @@ -7981,6 +7985,54 @@ function ui_print_status_div($status) } +function ui_print_div(?string $class='', ?string $title='') +{ + $return = '
'; + $return .= ' '; + $return .= '
'; + + return $return; +} + + +function ui_print_status_agent_div(int $status, ?string $title=null) +{ + $return = ''; + $class = 'status_rounded_rectangles forced_title'; + switch ((int) $status) { + case AGENT_STATUS_CRITICAL: + $return = ui_print_div('group_view_crit '.$class, $title); + break; + + case AGENT_STATUS_NORMAL: + $return = ui_print_div('group_view_ok '.$class, $title); + break; + + case AGENT_STATUS_NOT_INIT: + $return = ui_print_div('group_view_not_init '.$class, $title); + break; + + case AGENT_STATUS_UNKNOWN: + $return = ui_print_div('group_view_unk '.$class, $title); + break; + + case AGENT_STATUS_WARNING: + $return = ui_print_div('group_view_warn '.$class, $title); + break; + + case AGENT_STATUS_ALERT_FIRED: + $return = ui_print_div('group_view_alrm '.$class, $title); + break; + + default: + // Not posible. + break; + } + + return $return; +} + + function ui_print_fav_menu($id_element, $url, $label, $section) { global $config; diff --git a/pandora_console/include/javascript/datatablesFunction.js b/pandora_console/include/javascript/datatablesFunction.js index 6c9dc6a3f4..34fe301f41 100644 --- a/pandora_console/include/javascript/datatablesFunction.js +++ b/pandora_console/include/javascript/datatablesFunction.js @@ -131,6 +131,11 @@ if (dt.startDisabled === true) { startDisabled = true; } +var noMoveElementsToAction = false; +if (dt.no_move_elements_to_action === true) { + noMoveElementsToAction = true; +} + $(document).ready(function() { function checkPages() { if (dt_table.page.info().pages > 1) { @@ -226,7 +231,9 @@ $(document).ready(function() { ] : [], initComplete: function(settings, json) { - moveElementsToActionButtons(); + if (noMoveElementsToAction === false) { + moveElementsToActionButtons(); + } checkPages(); diff --git a/pandora_console/include/lib/Cluster.php b/pandora_console/include/lib/Cluster.php index 9a01eea428..b7bd21d929 100644 --- a/pandora_console/include/lib/Cluster.php +++ b/pandora_console/include/lib/Cluster.php @@ -205,6 +205,92 @@ class Cluster extends Entity } + /** + * Counters modules involved status. + * + * @return array + */ + public function getCounters() :array + { + $id_agent_modules = $this->getIdsModulesInvolved(); + $sql = sprintf( + 'SELECT SUM( IF(estado = 1, 1, 0) ) AS critical, + SUM( IF(estado = 2, 1, 0) ) AS warning, + SUM( IF(estado = 0, 1, 0) ) AS normal, + SUM( IF(estado = 3, 1, 0) ) AS unknown, + SUM( IF(estado = 4 OR estado = 5, 1, 0) ) AS not_init, + COUNT(id_agente_modulo) AS total + FROM tagente_estado + WHERE id_agente_modulo IN (%s)', + implode(',', $id_agent_modules) + ); + + $counters = db_get_row_sql($sql); + if ($counters === false) { + $counters = []; + } + + return $counters; + } + + + /** + * Return Ids modules involved. + * + * @return array + */ + public function getIdsModulesInvolved(): array + { + $members = $this->getMembers(); + $modules_ids = []; + $modules_names = $this->getItemNames(); + if (empty($members) === false) { + foreach ($members as $agent) { + $modules_filtered = $agent->searchModules(['nombre' => $modules_names], 0); + if (empty($modules_filtered) === false) { + foreach ($modules_filtered as $idAgent => $module) { + $modules_ids[] = $module->id_agente_modulo(); + } + } + } + } + + return $modules_ids; + } + + + /** + * Return names modules involved. + * + * @return array + */ + public function getItemNames(): array + { + $result = []; + if (empty($this->getItems()) === false) { + $result = array_keys($this->getItems()); + } + + return $result; + } + + + /** + * Return name type. + * + * @return string + */ + public function getStringTypeName(): string + { + $result = __('Active').' / '.__('Active'); + if ($this->cluster_type() === 'AP') { + $result = __('Active').' / '.__('Pasive'); + } + + return $result; + } + + /** * Cleans members from cluster object. * diff --git a/pandora_console/include/lib/ClusterViewer/ClusterManager.php b/pandora_console/include/lib/ClusterViewer/ClusterManager.php index 3afff1adb3..7ee9a96ba1 100644 --- a/pandora_console/include/lib/ClusterViewer/ClusterManager.php +++ b/pandora_console/include/lib/ClusterViewer/ClusterManager.php @@ -216,15 +216,27 @@ class ClusterManager $err = ''; $id = get_parameter('id', null); - - try { - $cluster = new Cluster($id); - } catch (\Exception $e) { - $err = ui_print_error_message( - __('Cluster not found: '.$e->getMessage()), - '', - true - ); + if (empty($id) === true) { + $id_agente = get_parameter('id_agente', null); + try { + $cluster = Cluster::loadFromAgentId($id_agente, true); + } catch (\Exception $e) { + $err = ui_print_error_message( + __('Cluster not found: '.$e->getMessage()), + '', + true + ); + } + } else { + try { + $cluster = new Cluster($id); + } catch (\Exception $e) { + $err = ui_print_error_message( + __('Cluster not found: '.$e->getMessage()), + '', + true + ); + } } if ($cluster->agent()->id_agente() === null) { @@ -237,15 +249,60 @@ class ClusterManager $critical = true; } + $allGroups = agents_get_all_groups_agent( + $cluster->agent()->id_agente(), + $cluster->agent()->id_grupo() + ); + + $flag = (int) get_parameter('flag', 0); + if ($flag === 1 && check_acl_one_of_groups($config['id_user'], $allGroups, 'AW') === true) { + $id_agent_module = get_parameter('id_agente_modulo'); + db_process_sql_update( + 'tagente_modulo', + ['flag' => 1], + ['id_agente_modulo' => $id_agent_module] + ); + } + + $flag_agent = (int) get_parameter('flag_agent', 0); + if ($flag_agent === 1 && check_acl_one_of_groups($config['id_user'], $allGroups, 'AW') === true) { + db_process_sql_update( + 'tagente_modulo', + ['flag' => 1], + ['id_agente' => $cluster->agent()->id_agente()] + ); + } + + $counters = $cluster->getCounters(); + $counters_chart = []; + $counters_bullet = []; + foreach ($counters as $key => $value) { + if ($key === 'not_init') { + $counters_chart['Not init'] = $value; + } else { + $counters_chart[ucfirst($key)] = $value; + } + + $counters_bullet[$key.'_count'] = $value; + } + + unset($counters_chart['Total']); + + $module_involved_ids = $cluster->getIdsModulesInvolved(); + View::render( 'cluster/view', [ - 'message' => $msg, - 'error' => $err, - 'config' => $config, - 'model' => $this, - 'cluster' => $cluster, - 'critical' => $critical, + 'message' => $msg, + 'error' => $err, + 'config' => $config, + 'model' => $this, + 'cluster' => $cluster, + 'critical' => $critical, + 'allGroups' => $allGroups, + 'counters_chart' => $counters_chart, + 'counters_bullet' => $counters_bullet, + 'module_involved_ids' => array_combine($module_involved_ids, $module_involved_ids), ] ); } diff --git a/pandora_console/include/lib/ClusterViewer/ClusterWizard.php b/pandora_console/include/lib/ClusterViewer/ClusterWizard.php index 03e13d0f36..3c4c4eb293 100644 --- a/pandora_console/include/lib/ClusterViewer/ClusterWizard.php +++ b/pandora_console/include/lib/ClusterViewer/ClusterWizard.php @@ -725,14 +725,11 @@ class ClusterWizard extends \HTML } if ($this->page === 7) { - /* - * - * PARSE ALERTS - * - */ - - // There is no need to parse anything. Already managed by alert - // builder. + global $config; + $step = true; + $id_agente = $this->cluster->agent()->id_agente(); + $dont_display_alert_create_bttn = true; + include_once $config['homedir'].'/godmode/alerts/alert_list.php'; header('Location: '.$this->url.'&op=view&id='.$this->cluster->id()); } @@ -1212,26 +1209,15 @@ class ClusterWizard extends \HTML 'block_content' => $inputs, ]; } else if ($this->page === 6) { - /* - * - * Page: Alerts. - * - */ - - ob_start(); global $config; - + $step = true; $id_agente = $this->cluster->agent()->id_agente(); $dont_display_alert_create_bttn = true; - include_once $config['homedir'].'/godmode/alerts/alert_list.php'; + ob_start(); include_once $config['homedir'].'/godmode/alerts/alert_list.builder.php'; - - // XXX: Please do not use this kind of thing never more. - $hack = ob_get_clean(); - - // TODO: Alert form. - $form['pre-content'] = $hack; - + html_print_input_hidden('create_alert', 1); + $hack_form = ob_get_clean(); + $form['inputs'][] = ['extra' => $hack_form]; $final = true; } diff --git a/pandora_console/include/styles/pandora.css b/pandora_console/include/styles/pandora.css index 8d6fa524d4..5a8beaa6ab 100644 --- a/pandora_console/include/styles/pandora.css +++ b/pandora_console/include/styles/pandora.css @@ -6215,19 +6215,18 @@ div#status_pie { padding: 15px; } -/* .agent_details_content { display: flex; align-items: flex-start; padding: 20px; padding-bottom: 0; } -*/ -.agent_details_content { + +.agent_details_content_cluster { display: flex; + flex-direction: row; + justify-content: space-between; align-items: flex-start; - padding: 20px; - padding-bottom: 0; } .agent_details_content .agent_details_graph { @@ -6240,10 +6239,69 @@ div#status_pie { justify-content: center; } -.agent_details_content .agent_details_info { - flex: 1 1 70%; - overflow: hidden; - padding-left: 15px; +.agent_details_content_cluster .agent_details_graph { + display: flex; + flex-direction: column; + margin-left: 10px; + min-width: 35%; + max-width: 50%; +} + +.agent_details_content_cluster .agent_details_graph > div { + display: flex; + flex-direction: row; + justify-content: space-around; + align-items: center; + width: 100%; + margin-bottom: 5px; +} + +.agent_details_content_cluster div#status_pie { + margin: 0px; +} + +.agent_details_content_cluster .agent_details_info { + display: flex; + flex-direction: column; + margin-right: 10px; + min-width: 35%; + max-width: 50%; + justify-content: space-between; + align-items: center; + height: 180px; +} + +.agent_details_content_cluster .agent_details_info > div { + display: flex; + flex-direction: column; + justify-content: space-around; + align-items: flex-end; + width: 100%; + margin-bottom: 5px; +} + +.agent_details_content_cluster .agent_details_info { + display: flex; + flex-direction: column; + margin-left: 10px; + min-width: 35%; + max-width: 50%; + justify-content: space-around; + align-items: flex-end; + margin-right: 20px; +} + +.agent_event_chart_cluster { + margin-left: 10px; + margin-bottom: 10px; +} + +.agent_event_chart_cluster div b { + margin-left: 0px; +} + +.agent_event_chart_cluster .white-table-graph-content { + height: auto; } .agent_details_info { @@ -6280,6 +6338,17 @@ div#status_pie { justify-content: flex-start; } +.agent_details_bullets_cluster #bullets_modules { + display: flex; + justify-content: flex-start; + flex-direction: column; +} + +.agent_details_bullets_cluster #bullets_modules > div { + padding: 0px; + margin-bottom: 10px; +} + .agent_details_bullets #bullets_modules > div { display: flex; align-items: center; diff --git a/pandora_console/operation/agentes/alerts_status.php b/pandora_console/operation/agentes/alerts_status.php index 176ac6bce8..a7ce53646c 100755 --- a/pandora_console/operation/agentes/alerts_status.php +++ b/pandora_console/operation/agentes/alerts_status.php @@ -109,6 +109,7 @@ $sec = safe_url_extraclean($sec); $flag_alert = (bool) get_parameter('force_execution', 0); $alert_validate = (bool) get_parameter('alert_validate', 0); $tab = get_parameter_get('tab', null); +$op = get_parameter('op', null); $refr = (int) get_parameter('refr', 0); $pure = get_parameter('pure', 0); @@ -119,8 +120,11 @@ if ($flag_alert == 1 && check_acl($config['id_user'], $id_group, 'AW')) { forceExecution($id_group); } - -$idAgent = get_parameter_get('id_agente', 0); +if (isset($id_agente) === false || empty($id_agente) === true) { + $idAgent = get_parameter_get('id_agente', 0); +} else { + $idAgent = $id_agente; +} // Show alerts for specific agent. if ($idAgent != 0) { @@ -207,6 +211,10 @@ if ($idAgent != 0) { $alerts = []; +if ($op != null) { + $url = $url.'&op='.$op; +} + if ($tab != null) { $url = $url.'&tab='.$tab; } diff --git a/pandora_console/operation/agentes/estado_agente.php b/pandora_console/operation/agentes/estado_agente.php index 44d64fddaf..75b1c6222a 100644 --- a/pandora_console/operation/agentes/estado_agente.php +++ b/pandora_console/operation/agentes/estado_agente.php @@ -1153,11 +1153,8 @@ foreach ($agents as $agent) { $cluster = PandoraFMS\Cluster::loadFromAgentId( $agent['id_agente'] ); - $url = 'index.php?sec=reporting&sec2='; - $url .= 'operation/cluster/cluster'; - $url = ui_get_full_url( - $url.'&op=view&id='.$cluster->id() - ); + $url_cluster = 'index.php?sec=reporting&sec2=operation/cluster/cluster'; + $url = $url_cluster.'&op=view&id='.$cluster->id(); } else { $url = 'index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente='.$agent['id_agente']; } diff --git a/pandora_console/operation/agentes/estado_generalagente.php b/pandora_console/operation/agentes/estado_generalagente.php index 641f58c714..e51d53597f 100755 --- a/pandora_console/operation/agentes/estado_generalagente.php +++ b/pandora_console/operation/agentes/estado_generalagente.php @@ -79,215 +79,11 @@ $alive_animation = agents_get_starmap($id_agente, 200, 50); /* * START: TABLE AGENT BUILD. */ -$agentCaptionAddedMessage = []; -$agentCaption = ''.ucfirst(agents_get_alias($agent['id_agente'])).''; -$in_planned_downtime = (bool) db_get_sql( - 'SELECT executed FROM tplanned_downtime - INNER JOIN tplanned_downtime_agents - ON tplanned_downtime.id = tplanned_downtime_agents.id_downtime - WHERE tplanned_downtime_agents.id_agent = '.$agent['id_agente'].' AND tplanned_downtime.executed = 1' -); -if ((bool) $agent['disabled'] === true) { - $agentCaptionAddedMessage[] = __('Disabled'); -} else if ((bool) $agent['quiet'] === true) { - $agentCaptionAddedMessage[] = __('Quiet'); -} - -if ($in_planned_downtime === true) { - $agentCaptionAddedMessage[] = __('In scheduled downtime'); -} - -if (empty($agentCaptionAddedMessage) === false) { - $agentCaption .= ' ('.implode(' - ', $agentCaptionAddedMessage).')'; -} - -$agentIconGroup = ((bool) $config['show_group_name'] === false) ? ui_print_group_icon( - $agent['id_grupo'], - true, - '', - 'padding-right: 6px;', - true, - false, - false, - '', - true -) : ''; - -$agentIconStatus = agents_detail_view_status_img( - $agent['critical_count'], - $agent['warning_count'], - $agent['unknown_count'], - $agent['total_count'], - $agent['notinit_count'] -); - -$agent_details_agent_caption = html_print_div( - [ - 'class' => 'agent_details_agent_caption', - 'content' => $agentCaption, - ], - true -); - -$agent_details_agent_data = html_print_div( - [ - 'class' => 'agent_details_agent_data', - 'content' => $agentIconGroup, - ], - true -); - -$agent_details_agent_status_image = html_print_div( - [ - 'class' => 'icono_right', - 'content' => $agentIconStatus, - ], - true -); - -$agentStatusHeader = html_print_div( - [ - 'class' => 'agent_details_header', - 'content' => $agent_details_agent_caption.$agent_details_agent_data.$agent_details_agent_status_image, - ], - true -); +$agentStatusHeader = get_resume_agent_status_header($agent); // Fixed width non interactive charts. -$status_chart_width = 150; -$graph_width = 150; - -$table_status = new stdClass(); -$table_status->id = 'agent_status_main'; -$table_status->width = '100%'; -$table_status->cellspacing = 0; -$table_status->cellpadding = 0; -$table_status->class = 'floating_form'; -$table_status->style[0] = 'height: 32px; width: 30%; padding-right: 5px; text-align: end; vertical-align: top'; -$table_status->style[1] = 'height: 32px; width: 70%; padding-left: 5px; font-weight: lighter; vertical-align: top'; - -$agentStatusGraph = html_print_div( - [ - 'id' => 'status_pie', - 'style' => 'width: '.$graph_width.'px;', - 'content' => graph_agent_status( - $id_agente, - $graph_width, - $graph_width, - true, - false, - false, - true - ), - ], - true -); - -/* - $table_agent_graph = '
'; - $table_agent_graph .= graph_agent_status( - $id_agente, - $graph_width, - $graph_width, - true, - false, - false, - true - ); -$table_agent_graph .= '
';*/ - -/* - $table_agent_os = '

'.ui_print_os_icon( - $agent['id_os'], - false, - true, - true, - false, - false, - false, - [ - 'title' => get_os_name($agent['id_os']), - 'width' => '20px;', - ] - ); -*/ - -$table_status->data['agent_os'][0] = __('OS'); -$agentOS = []; -$agentOS[] = html_print_div([ 'content' => (empty($agent['os_version']) === true) ? get_os_name((int) $agent['id_os']) : $agent['os_version']], true); -$agentOS[] = html_print_div([ 'style' => 'width: 16px;padding-left: 5px', 'content' => ui_print_os_icon($agent['id_os'], false, true, true, false, false, false, ['width' => '16px'])], true); -$table_status->data['agent_os'][1] = html_print_div(['class' => 'agent_details_agent_data', 'content' => implode('', $agentOS)], true); - -// $table_agent_os .= (empty($agent['os_version']) === true) ? get_os_name((int) $agent['id_os']) : $agent['os_version'].'

'; -$addresses = agents_get_addresses($id_agente); -$address = agents_get_address($id_agente); - -foreach ($addresses as $k => $add) { - if ($add == $address) { - unset($addresses[$k]); - } -} - -if (empty($address) === false) { - $table_status->data['ip_address'][0] = __('IP address'); - $table_status->data['ip_address'][1] = (empty($address) === true) ? ''.__('N/A').'' : $address; - /* - $table_agent_ip = '

'.html_print_image( - 'images/world.png', - true, - [ - 'title' => __('IP address'), - 'class' => 'invert_filter', - ] - ); - $table_agent_ip .= ''; - $table_agent_ip .= (empty($address) === true) ? ''.__('N/A').'' : $address; - $table_agent_ip .= '

'; - */ -} - -$table_status->data['agent_version'][0] = __('Agent Version'); -$table_status->data['agent_version'][1] = (empty($agent['agent_version']) === true) ? ''.__('N/A').'' : $agent['agent_version']; - -$table_status->data['description'][0] = __('Description'); -$table_status->data['description'][1] = (empty($agent['comentarios']) === true) ? ''.__('N/A').'' : $agent['comentarios']; - -/* - $table_agent_version = '

'.html_print_image( - 'images/version.png', - true, - [ - 'title' => __('Agent Version'), - 'class' => 'invert_filter', - ] - ); - $table_agent_version .= ''; - $table_agent_version .= (empty($agent['agent_version']) === true) ? ''.__('N/A').'' : $agent['agent_version']; - $table_agent_version .= '

'; - - $table_agent_description = '

'.html_print_image( - 'images/list.png', - true, - [ - 'title' => __('Description'), - 'class' => 'invert_filter', - ] - ); - $table_agent_description .= ''; - $table_agent_description .= (empty($agent['comentarios']) === true) ? ''.__('N/A').'' : $agent['comentarios']; - $table_agent_description .= '

'; -*/ - -/* - $table_agent_count_modules = reporting_tiny_stats( - $agent, - true, - 'agent', - // Useless. - ':', - true -);*/ +$agentStatusGraph = get_status_agent_chart_pie($id_agente, 150); $agentCountModules = html_print_div( [ @@ -304,6 +100,40 @@ $agentCountModules = html_print_div( true ); +$table_status = new stdClass(); +$table_status->id = 'agent_status_main'; +$table_status->width = '100%'; +$table_status->cellspacing = 0; +$table_status->cellpadding = 0; +$table_status->class = 'floating_form'; +$table_status->style[0] = 'height: 32px; width: 30%; padding-right: 5px; text-align: end; vertical-align: top'; +$table_status->style[1] = 'height: 32px; width: 70%; padding-left: 5px; font-weight: lighter; vertical-align: top'; +$table_status->data['agent_os'][0] = __('OS'); +$agentOS = []; +$agentOS[] = html_print_div([ 'content' => (empty($agent['os_version']) === true) ? get_os_name((int) $agent['id_os']) : $agent['os_version']], true); +$agentOS[] = html_print_div([ 'style' => 'width: 16px;padding-left: 5px', 'content' => ui_print_os_icon($agent['id_os'], false, true, true, false, false, false, ['width' => '16px'])], true); +$table_status->data['agent_os'][1] = html_print_div(['class' => 'agent_details_agent_data', 'content' => implode('', $agentOS)], true); + +$addresses = agents_get_addresses($id_agente); +$address = agents_get_address($id_agente); + +foreach ($addresses as $k => $add) { + if ($add == $address) { + unset($addresses[$k]); + } +} + +if (empty($address) === false) { + $table_status->data['ip_address'][0] = __('IP address'); + $table_status->data['ip_address'][1] = (empty($address) === true) ? ''.__('N/A').'' : $address; +} + +$table_status->data['agent_version'][0] = __('Agent Version'); +$table_status->data['agent_version'][1] = (empty($agent['agent_version']) === true) ? ''.__('N/A').'' : $agent['agent_version']; + +$table_status->data['description'][0] = __('Description'); +$table_status->data['description'][1] = (empty($agent['comentarios']) === true) ? ''.__('N/A').'' : $agent['comentarios']; + $has_remote_conf = enterprise_hook( 'config_agents_has_remote_configuration', [$agent['id_agente']] @@ -347,163 +177,6 @@ $table_agent = $agentStatusHeader.' * END: TABLE AGENT BUILD. */ -/* - *START: TABLE CONTACT BUILD. - */ - -$table_contact = new stdClass(); -$table_contact->id = 'agent_contact_main'; -$table_contact->width = '100%'; -$table_contact->cellspacing = 0; -$table_contact->cellpadding = 0; -$table_contact->class = 'floating_form'; -$table_contact->style[0] = 'height: 32px; width: 30%; padding-right: 5px; text-align: end; vertical-align: top'; -$table_contact->style[1] = 'height: 32px; width: 70%; padding-left: 5px; font-weight: lighter; vertical-align: top'; - -$agentContactCaption = html_print_div( - [ - 'class' => 'agent_details_agent_caption', - 'content' => ''.__('Agent contact').'', - ], - true -); - -$buttonsRefreshAgent = html_print_button( - __('Refresh data'), - 'refresh_data', - false, - 'window.location.assign("index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente='.$id_agente.'&refr=60")', - [ 'mode' => 'link' ], - true -); - -if (check_acl_one_of_groups($config['id_user'], $all_groups, 'AW') === true) { - $buttonsRefreshAgent .= html_print_button( - __('Force checks'), - 'force_checks', - false, - 'window.location.assign("index.php?sec=estado&sec2=operation/agentes/ver_agente&flag_agent=1&id_agente='.$id_agente.'")', - [ 'mode' => 'link' ], - true - ); -} - -$buttons_refresh_agent_view = html_print_div( - [ - 'class' => 'buttons_agent_view', - 'content' => $buttonsRefreshAgent, - ], - true -); - -// Data for agent contact. -$intervalHumanTime = human_time_description_raw($agent['intervalo']); -$lastContactDate = ui_print_timestamp($agent['ultimo_contacto'], true); -$remoteContactDate = ($agent['ultimo_contacto_remoto'] === '01-01-1970 00:00:00') ? __('Never') : date_w_fixed_tz($agent['ultimo_contacto_remoto']); -$lastAndRemoteContact = sprintf('%s / %s', $lastContactDate, $remoteContactDate); -$progress = agents_get_next_contact($id_agente); -$tempTimeToShow = ($agent['intervalo'] - (strtotime('now') - strtotime($agent['ultimo_contacto']))); -$progressCaption = ($tempTimeToShow >= 0) ? sprintf('%d s', $tempTimeToShow) : __('Out of bounds'); -$ajaxNextContactInterval = (empty($agent['intervalo']) === true) ? 0 : (100 / $agent['intervalo']); -$secondary_groups = enterprise_hook('agents_get_secondary_groups', [$id_agente]); -$secondaryLinks = []; -if (empty($secondary_groups['for_select']) === true) { - $secondaryLinks[] = ''.__('N/A').''; -} else { - foreach ($secondary_groups['for_select'] as $id => $name) { - $secondaryLinks[] = html_print_anchor( - [ - 'href' => 'index.php?sec=estado&sec2=operation/agentes/estado_agente&refr=60&group_id='.$id, - 'content' => $name, - ], - true - ); - } -} - -$last_status_change_agent = agents_get_last_status_change($agent['id_agente']); -$time_elapsed = (empty($last_status_change_agent) === false) ? human_time_comparation($last_status_change_agent) : ''.__('N/A').''; - -// Agent Interval. -$data = []; -$data[0] = __('Interval'); -$data[1] = $intervalHumanTime; -$table_contact->data[] = $data; - -// Last & Remote contact. -$data = []; -$data[0] = __('Last contact').' / '.__('Remote'); -$data[1] = $lastAndRemoteContact; -$table_contact->data[] = $data; - -// Next contact progress. -$data = []; -$data[0] = __('Next contact'); -$data[1] = ui_progress( - $progress, - '80%', - '1.2', - '#ececec', - true, - $progressCaption, - [ - 'page' => 'operation/agentes/ver_agente', - 'interval' => $ajaxNextContactInterval, - 'data' => [ - 'id_agente' => $id_agente, - 'refresh_contact' => 1, - ], - - ] -); -$table_contact->data[] = $data; - -// Group line. -$data = []; -$data[0] = ''.__('Group').''; -$data[1] = html_print_anchor( - [ - 'href' => 'index.php?sec=gagente&sec2=godmode/groups/tactical&id_group='.$agent['id_grupo'], - 'content' => groups_get_name($agent['id_grupo']), - ], - true -); -$table_contact->data[] = $data; - -// Secondary groups. -$data = []; -$data[0] = ''.__('Secondary groups').''; -$data[1] = implode(', ', $secondaryLinks); -$table_contact->data[] = $data; - -// Parent agent line. -if (enterprise_installed() === true) { - $data = []; - $data[0] = ''.__('Parent').''; - if ((int) $agent['id_parent'] === 0) { - $data[1] = ''.__('N/A').''; - } else { - $data[1] = html_print_anchor( - [ - 'href' => 'index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente='.$agent['id_parent'], - 'content' => agents_get_alias($agent['id_parent']), - ], - true - ); - } - - $table_contact->data[] = $data; -} - -// Last status change line. -$data = []; -$data[0] = ''.__('Last status change').''; -$data[1] = $time_elapsed; -$table_contact->data[] = $data; - -/* - * END: TABLE CONTACT BUILD - */ /* * START: TABLE DATA BUILD @@ -881,15 +554,7 @@ if (empty($network_interfaces) === false) { }); 'agent_details_header', - 'content' => $agentContactCaption.$buttons_refresh_agent_view, - ], - true -); - -$agent_contact .= html_print_table($table_contact, true); +$agent_contact = get_resume_agent_concat($id_agente, $all_groups, $agent); $agentDetails = html_print_div( [ diff --git a/pandora_console/operation/agentes/estado_monitores.php b/pandora_console/operation/agentes/estado_monitores.php index 43255d226f..372a636044 100755 --- a/pandora_console/operation/agentes/estado_monitores.php +++ b/pandora_console/operation/agentes/estado_monitores.php @@ -371,6 +371,7 @@ ui_require_css_file('cluetip', 'include/styles/js/'); ui_require_jquery_file('cluetip'); echo "
"; +echo "
"; ui_include_time_picker(); ui_require_jquery_file('ui.datepicker-'.get_user_language(), 'include/javascript/i18n/'); @@ -453,6 +454,34 @@ ui_require_jquery_file('ui.datepicker-'.get_user_language(), 'include/javascript } }); } + + // Show the modal window of an module + function show_cluster_module_detail(cluster_id, module_name) { + title = ; + $.ajax({ + type: "POST", + url: "", + data: "page=include/ajax/module&get_cluster_module_detail=1&cluster_id="+cluster_id+"&module_name="+module_name, + dataType: "html", + success: function(data) { + $("#cluster_module_detail").hide () + .empty () + .append (data) + .dialog ({ + resizable: true, + draggable: true, + modal: true, + title: title + module_name, + overlay: { + opacity: 0.5, + background: "black" + }, + width: "auto" + }).css({"min-width": "650px"}) + .show (); + } + }); + } function datetime_picker_callback() { $("#text-time_from, #text-time_to").timepicker({ diff --git a/pandora_console/views/cluster/edit.php b/pandora_console/views/cluster/edit.php index 03c9d27bcd..2c417b0f75 100644 --- a/pandora_console/views/cluster/edit.php +++ b/pandora_console/views/cluster/edit.php @@ -126,6 +126,9 @@ if (empty($form) === false) { $submit = $form['submit-external-input']; unset($form['submit-external-input']); + unset($bc[0]); + $wizard->printSteps($bc); + HTML::printForm($form, false, ($wizard->page < 6)); $buttons_input .= HTML::printInput($submit); } diff --git a/pandora_console/views/cluster/view.php b/pandora_console/views/cluster/view.php index af33475c4a..32bcdb0736 100644 --- a/pandora_console/views/cluster/view.php +++ b/pandora_console/views/cluster/view.php @@ -115,260 +115,17 @@ if ($critical === true) { return; } - -/* - * - * All this block has been retrieved from 'estado_generalagente.php' as - * described in issue #5755. - * - */ - - - -/* - * - * - * CLUSTER AGENT DETAILS. - * - */ - -// Prepare information for view. -$alive_animation = agents_get_status_animation( - agents_get_interval_status($cluster->agent()->toArray(), false) -); - - -$agent_name = ui_print_agent_name( - $cluster->agent()->id_agente(), - true, - 500, - 'font-size: medium;font-weight:bold', - true, - '', - '', - false, - false -); -$in_planned_downtime = db_get_sql( - 'SELECT executed FROM tplanned_downtime - INNER JOIN tplanned_downtime_agents - ON tplanned_downtime.id = tplanned_downtime_agents.id_downtime - WHERE tplanned_downtime_agents.id_agent = '.$cluster->agent()->id_agente().' AND tplanned_downtime.executed = 1' -); - -if ($cluster->agent()->disabled()) { - if ($in_planned_downtime) { - $agent_name = ''.$agent_name.ui_print_help_tip(__('Disabled'), true); - } else { - $agent_name = ''.$agent_name.''.ui_print_help_tip(__('Disabled'), true); - } -} else if ($cluster->agent()->quiet()) { - if ($in_planned_downtime) { - $agent_name = "".$agent_name.' '.html_print_image('images/dot_blue.png', true, ['border' => '0', 'title' => __('Quiet'), 'alt' => '']); - } else { - $agent_name = "".$agent_name.' '.html_print_image('images/dot_blue.png', true, ['border' => '0', 'title' => __('Quiet'), 'alt' => '']).''; - } -} else { - $agent_name = $agent_name; -} - -if ($in_planned_downtime && !$cluster->agent()->disabled() && !$cluster->agent()->quiet()) { - $agent_name .= ' '.ui_print_help_tip( - __('Agent in scheduled downtime'), - true, - 'images/minireloj-16.png' - ).''; -} else if (($in_planned_downtime && !$cluster->agent()->disabled()) - || ($in_planned_downtime && !$cluster->agent()->quiet()) -) { - $agent_name .= ' '.ui_print_help_tip( - __('Agent in scheduled downtime'), - true, - 'images/clock.svg' - ).''; -} - - -$table_agent_header = '
'; -$table_agent_header .= $agent_name; -$table_agent_header .= '
'; -$table_agent_header .= '
'; -if (!$config['show_group_name']) { - $table_agent_header .= ui_print_group_icon( - $cluster->agent()->id_grupo(), - true, - 'groups_small', - 'padding-right: 6px;' - ); -} - -$table_agent_header .= '
'; - -$status_img = agents_detail_view_status_img( - $cluster->agent()->critical_count(), - $cluster->agent()->warning_count(), - $cluster->agent()->unknown_count(), - $cluster->agent()->total_count(), - $cluster->agent()->notinit_count() -); - -$table_agent_header .= '
'.$status_img.'
'; -$table_agent_header .= '  '; -$table_agent_header .= ''.html_print_image( - 'images/force@svg.svg', - true, - [ - 'title' => __('Force cluster status calculation'), - 'alt' => '', - 'class' => 'main_menu_icon invert_filter', - - ] -).''; -// Fixed width non interactive charts. -$status_chart_width = 180; -$graph_width = 180; - -$table_agent_graph = '
'; -$table_agent_graph .= graph_agent_status( - $cluster->agent()->id_agente(), - $graph_width, - $graph_width, - true, - false, - false, - true -); -$table_agent_graph .= '
'; - -$table_agent_os = '

'.ui_print_os_icon( - $cluster->agent()->id_os(), - false, - true, - true, - false, - false, - false, - ['title' => __('OS').': '.get_os_name($cluster->agent()->id_os())] -); -$table_agent_os .= (empty($cluster->agent()->os_version()) === true) ? get_os_name((int) $cluster->agent()->id_os()) : $cluster->agent()->os_version().'

'; - - - -$addresses = agents_get_addresses($cluster->agent()->id_agente()); -$address = agents_get_address($cluster->agent()->id_agente()); - -foreach ($addresses as $k => $add) { - if ($add == $address) { - unset($addresses[$k]); - } -} - -if (empty($address) === false) { - $table_agent_ip = '

'.html_print_image( - 'images/web@groups.svg', - true, - [ - 'title' => __('IP address'), - 'class' => 'main_menu_icon invert_filter', - ] - ); - $table_agent_ip .= ''; - $table_agent_ip .= empty($address) ? ''.__('N/A').'' : $address; - $table_agent_ip .= '

'; -} - -$table_agent_description = '

'.html_print_image( - 'images/logs@svg.svg', - true, - [ - 'title' => __('Description'), - 'class' => 'main_menu_icon invert_filter', - ] -); -$table_agent_description .= ''; -$table_agent_description .= empty( - $cluster->description() -) ? ''.__('N/A').'' : $cluster->description(); -$table_agent_description .= '

'; - -$table_agent_count_modules = reporting_tiny_stats( - $cluster->agent()->toArray(), - true, - 'agent', - // Useless. - ':', - true -); - -$table_agent_version = '

'.html_print_image( - 'images/version.png', - true, - [ - 'title' => __('Agent Version'), - 'class' => 'invert_filter', - ] -); -$table_agent_version .= ''; -$table_agent_version .= empty($cluster->agent()->agent_version()) ? ''.__('Cluster agent').'' : $cluster->agent()->agent_version(); -$table_agent_version .= '

'; - -/* - * - * MAP - * - */ - -$nodes = $cluster->getNodes(); - -$font_size = 20; -$width = '45%'; -$height = '500'; -$node_radius = 40; - -// Generate map. -$map_manager = new NetworkMap( - [ - 'nodes' => $nodes, - 'no_pandora_node' => 1, - 'pure' => 1, - 'map_options' => [ - 'generation_method' => LAYOUT_SPRING1, - 'font_size' => $font_size, - 'node_radius' => $node_radius, - 'height' => $height, - 'width' => '100%', - 'tooltip' => true, - 'size_image' => 50, - 'z_dash' => 0.5, - 'map_filter' => [ - 'node_sep' => 7, - 'node_radius' => 50, - 'x_offs' => 130, - 'y_offs' => -70, - ], - ], - ] -); - - -/* - * - * EVENTS 24h - * - */ - -$table_events = '
'; -$table_events .= '
'; -$table_events .= ''; +$table_events = '
'; +$table_events .= '
'; +$table_events .= ''; $table_events .= __('Events (Last 24h)'); -$table_events .= ''; +$table_events .= ''; $table_events .= '
'; $table_events .= '
'; $table_events .= graph_graphic_agentevents( $cluster->agent()->id_agente(), 95, - 70, + 50, SECONDS_1DAY, '', true, @@ -378,53 +135,89 @@ $table_events .= graph_graphic_agentevents( $table_events .= '
'; $table_events .= '
'; -?> -
-
-
-
- -
-
-
- -
- -
-
-
- -
-
-
-
- -
-
-
-
- printMap(); ?> -
-
-
+$agentCountModules = html_print_div( + [ + 'class' => 'agent_details_bullets_cluster', + 'content' => reporting_tiny_stats( + $counters_bullet, + true, + 'modules', + // Useless. + ':', + true + ), + ], + true +); -
-'; + +$output .= '
'; +$output .= '
'; +$output .= get_resume_agent_status_header($cluster->agent()->toArray()); +$output .= '
'; +$output .= '
'; +$output .= '
'; +$output .= get_status_agent_chart_pie($cluster->agent()->id_agente(), 150, $counters_chart); +$output .= $agentCountModules; +$output .= '
'; +$output .= '
'; +$output .= '
'.__('Cluster Status').'
'; +$output .= '
'; +$output .= agents_detail_view_status_div( + $cluster->agent()->critical_count(), + $cluster->agent()->warning_count(), + $cluster->agent()->unknown_count(), + $cluster->agent()->total_count(), + $cluster->agent()->notinit_count() +); +$output .= '
'; +$output .= '
'; +$output .= '
'; +$output .= '
'; +$output .= $alive_animation; +$output .= '
'; +$output .= '
'.__('Cluster Mode').' : '.$cluster->getStringTypeName().'
'; +$output .= '
'.$cluster->name().'
'; +$output .= '
'; +$output .= '
'; +$output .= '
'; + +$output .= $table_events; + +$output .= '
'; + +$output .= '
'; +$output .= get_resume_agent_concat( + $cluster->agent()->id_agente(), + $allGroups, + $cluster->agent()->toArray() +); +$output .= '
'; + +$output .= '
'; +$output .= '
'; +echo $output; + +echo '
'; $id_agente = $cluster->agent()->id_agente(); +$id_cluster = $cluster->id(); +$agent = $cluster->agent()->toArray(); require_once $config['homedir'].'/operation/agentes/estado_monitores.php'; -?> -
+echo '
'; +require_once $config['homedir'].'/operation/agentes/alerts_status.php'; -url.'&op=view&id='.$cluster->id().'" method="POST">'; +$reload .= html_print_submit_button( __('Reload'), 'submit', false, @@ -434,12 +227,14 @@ $buttons[] = html_print_submit_button( ], true ); -echo ''; +$reload .= ''; + +$buttons[] = $reload; + +// Print always go back button. +$buttons[] = HTML::printForm($model->getGoBackForm(), true); + html_print_action_buttons( implode('', $buttons), ['type' => 'form_action'] ); -echo ''; - -// Print always go back button. -HTML::printForm($model->getGoBackForm(), false);