From 18800feaae598ae5c1ce4e906cb0249c57cfd991 Mon Sep 17 00:00:00 2001 From: fermin831 Date: Thu, 2 Aug 2018 13:02:33 +0200 Subject: [PATCH] Refactorized snapshot link on node --- pandora_console/include/class/Tree.class.php | 2 - .../include/functions_treeview.php | 39 +--- pandora_console/include/functions_ui.php | 79 ++++--- pandora_console/mobile/include/ui.class.php | 3 +- pandora_console/mobile/operation/modules.php | 71 ++---- .../operation/agentes/estado_agente.php | 25 +-- .../operation/agentes/snapshot_view.php | 40 ++-- .../operation/agentes/status_monitor.php | 206 ++++-------------- 8 files changed, 152 insertions(+), 313 deletions(-) diff --git a/pandora_console/include/class/Tree.class.php b/pandora_console/include/class/Tree.class.php index 996eeaf07f..6d1a94ac66 100644 --- a/pandora_console/include/class/Tree.class.php +++ b/pandora_console/include/class/Tree.class.php @@ -1684,8 +1684,6 @@ class Tree { // Info to be able to open the snapshot image new page $module['snapshot'] = ui_get_snapshot_link(array( 'id_module' => $module['id'], - 'last_data' => $module['datos'], - 'timestamp' => $module['timestamp'], 'interval' => $module['current_interval'], 'module_name' => $module['name'] ), true); diff --git a/pandora_console/include/functions_treeview.php b/pandora_console/include/functions_treeview.php index 5c50f853b8..0315509b0f 100755 --- a/pandora_console/include/functions_treeview.php +++ b/pandora_console/include/functions_treeview.php @@ -266,35 +266,18 @@ function treeview_printModuleTable($id_module, $server_data = false, $no_head = $last_data_str .= " "; $last_data_str .= html_print_image('images/clock2.png', true, array('title' => $last_data["timestamp"], 'width' => '18px')); - - $is_snapshot = is_snapshot_data ( $last_data["datos"] ); - if (($config['command_snapshot']) && ($is_snapshot)) { - $link = ui_get_snapshot_link( array( - 'id_module' => $module['id_agente_modulo'], - 'last_data' => $last_data['datos'], - 'timestamp' => $last_data['timestamp'], - 'interval' => $module['current_interval'], - 'module_name' => $module['module_name'] - )); - if(!is_image_data($last_data["datos"])){ - $salida = '' . - html_print_image('images/default_list.png', true, - array('border' => '0', - 'alt' => '', - 'title' => __('Snapshot view'))) . '   '; - } - else { - $salida = '' . - html_print_image('images/photo.png', true, - array('border' => '0', - 'alt' => '', - 'title' => __('Snapshot view'))) . '   '; - } - } - - - $last_data_str .= $salida; + $is_snapshot = is_snapshot_data ( $last_data["datos"] ); + $is_large_image = is_text_to_black_string ($last_data["datos"]); + if (($config['command_snapshot']) && ($is_snapshot || $is_large_image)) { + $link = ui_get_snapshot_link( array( + 'id_module' => $module['id_agente_modulo'], + 'interval' => $module['current_interval'], + 'module_name' => $module['module_name'] + )); + $salida = ui_get_snapshot_image($link, $is_snapshot) . '  '; + } + $last_data_str .= $salida; } else { $last_data_str = '' . __('No data') . ''; diff --git a/pandora_console/include/functions_ui.php b/pandora_console/include/functions_ui.php index 0cb9e10cdd..279542edca 100755 --- a/pandora_console/include/functions_ui.php +++ b/pandora_console/include/functions_ui.php @@ -3791,36 +3791,27 @@ function ui_print_module_string_value($value, $id_agente_module, $value = io_safe_input($value); } + + $is_snapshot = is_snapshot_data ($module["datos"]); + $is_large_image = is_text_to_black_string ($module["datos"]); + if (($config['command_snapshot']) && ($is_snapshot || $is_large_image)) { + + + $row[7] = ui_get_snapshot_image($link, $is_snapshot) . '  '; + } + $is_snapshot = is_snapshot_data($value); $is_large_image = is_text_to_black_string ($value); - if (($config['command_snapshot']) && ($is_snapshot || $is_large_image)) { - $handle = "snapshot" . "_" . $id_agente_module; - $url = 'include/procesos.php?agente=' . $id_agente_module; - $win_handle = dechex(crc32($handle)); - - $link = "winopeng_var('operation/agentes/snapshot_view.php?" . - "id=" . $id_agente_module . - "&refr=" . $current_interval . - "&label=" . rawurlencode(urlencode(io_safe_output($module_name))) . "','" . $win_handle . "', 700,480)"; - if ($is_snapshot) { - $salida = '' . - html_print_image("images/photo.png", true, - array("border" => '0', - "alt" => "", - "title" => __("Snapshot view"))) . '   '; - } - else { - $salida = '' . - html_print_image("images/default_list.png", true, - array("border" => '0', - "alt" => "", - "title" => __("Snapshot view"))) . '   '; - - } - } - else { - + $link = ui_get_snapshot_link( array( + 'id_module' => $id_agente_module, + 'last_data' => $value, + 'interval' => $current_interval, + 'module_name' => $module_name, + 'timestamp' => db_get_value('timestamp', 'tagente_estado', 'id_agente_modulo', $id_agente_module) + )); + $salida = ui_get_snapshot_image($link, $is_snapshot) . '  '; + } else { $sub_string = substr(io_safe_output($value), 0, 12); if ($value == $sub_string) { if ($value == 0 && !$sub_string) { @@ -3921,8 +3912,8 @@ function ui_get_snapshot_link($params, $only_params = false) { 'id_module' => 0, //id_agente_modulo 'module_name' => '', 'interval' => 300, - 'last_data' => '', - 'timestamp' => '0' + 'timestamp' => 0, + 'id_node' => 0 ); // Merge default params with passed params @@ -3933,10 +3924,10 @@ function ui_get_snapshot_link($params, $only_params = false) { $url = "$page?" . "id=" . $params['id_module'] . - "&refr=" . $parms['interval'] . - "×tamp=" . $params['timestamp'] . - "&last_data=" . rawurlencode(urlencode(io_safe_output($params['last_data']))) . - "&label=" . rawurlencode(urlencode(io_safe_output($params['module_name']))); + "&label=" . rawurlencode(urlencode(io_safe_output($params['module_name']))). + "&id_node=" . $params['id_node']; + if ($params['timestamp'] != 0) $url .= "×tamp=" . $parms['timestamp']; + if ($params['timestamp'] != 0) $url .= "&refr=" . $parms['interval']; // Second parameter of js winopeng_var $win_handle = dechex(crc32('snapshot_' . $params['id_module'])); @@ -3950,6 +3941,28 @@ function ui_get_snapshot_link($params, $only_params = false) { return "winopeng_var('" . implode("', '", $link_parts) . "')"; } +/** + * @brief Get the snapshot image with the link to open a snapshot into a new page + * + * @param string Built link + * @param bool Picture image or list image + * + * @return string HTML anchor link with image + */ +function ui_get_snapshot_image ($link, $is_image) { + $image_name = $is_image ? 'photo.png' : 'default_list.png'; + + $link = '' . + html_print_image("images/$image_name", true, + array('border' => '0', + 'alt' => '', + 'title' => __('Snapshot view')) + ) . + ''; + + return $link; +} + function ui_get_using_system_timezone_warning ($tag = "h3", $return = true) { global $config; diff --git a/pandora_console/mobile/include/ui.class.php b/pandora_console/mobile/include/ui.class.php index c1525e8722..29505c8956 100755 --- a/pandora_console/mobile/include/ui.class.php +++ b/pandora_console/mobile/include/ui.class.php @@ -655,10 +655,9 @@ class Ui { echo " \n"; echo " \n"; - //echo " \n"; echo " \n"; echo " \n"; - //echo " \n"; + echo " \n"; echo " \n"; echo " \n"; diff --git a/pandora_console/mobile/operation/modules.php b/pandora_console/mobile/operation/modules.php index 5dd89b9aec..8971334eea 100644 --- a/pandora_console/mobile/operation/modules.php +++ b/pandora_console/mobile/operation/modules.php @@ -270,6 +270,7 @@ class Modules { } private function getListModules($page = 0, $ajax = false) { + global $config; $system = System::getInstance(); $user = User::getInstance(); @@ -590,34 +591,17 @@ class Modules { $output = $sub_string; } } - - - $is_snapshot = is_snapshot_data($module["datos"]); - - $handle = "snapshot" . "_" . $module["id_agente_modulo"]; - $url = 'include/procesos.php?agente=' . $module["id_agente_modulo"]; - - $link = "window.open('../operation/agentes/snapshot_view.php?" . - "id=" . $module["id_agente_modulo"] . - "&refr=" . $module["module_interval"]."','".$handle."','width=700, height=480')"; - - if ($is_snapshot) { - if (is_image_data($module["datos"])) { - $row[7] = $row[__('Data')] = '' . - html_print_image("images/photo.png", true, - array("border" => '0', - "alt" => "", - "title" => __("Snapshot view"))) . '   '; - } - else { - $row[7] = $row[__('Data')] = '' . - html_print_image("images/default_list.png", true, - array("border" => '0', - "alt" => "", - "title" => __("Snapshot view"))) . '   '; - } - } - else { + + $is_snapshot = is_snapshot_data ($module["datos"]); + $is_large_image = is_text_to_black_string ($module["datos"]); + if (($config['command_snapshot']) && ($is_snapshot || $is_large_image)) { + $link = ui_get_snapshot_link( array( + 'id_module' => $module['id_agente_modulo'], + 'module_name' => $module['module_name'] + )); + + $row[7] = ui_get_snapshot_image($link, $is_snapshot) . '  '; + } else { $row[7] = $row[__('Data')] = '' . '' . @@ -626,18 +610,7 @@ class Modules { $module['id_agente_modulo'] . '&id_agent=' . $this->id_agent . '">' . $output . '' . ''; } - - - /* - - '' . - '' . - '' . $output . '' . '';*/ - + if (!$ajax) { unset($row[0]); if ($this->columns['agent']) { @@ -814,23 +787,9 @@ class Modules { $filters_to_serialize[] = sprintf(__("Tag: %s"), $tag_name); } - + $string = '(' . implode(' - ', $filters_to_serialize) . ')'; - - - - //~ $status = $this->list_status[$this->status]; - //~ - //~ $group = groups_get_name($this->group, true); - //~ - //~ $module_group = db_get_value('name', - //~ 'tmodule_group', 'id_mg', $this->module_group); - //~ $module_group = io_safe_output($module_group); - //~ - //~ $string = sprintf( - //~ __("(Status: %s - Group: %s - Module group: %s - Free Search: %s)"), - //~ $status, $group, $module_group, $this->free_search); - + return $string; } } diff --git a/pandora_console/operation/agentes/estado_agente.php b/pandora_console/operation/agentes/estado_agente.php index 1632242dec..d37cc9396c 100644 --- a/pandora_console/operation/agentes/estado_agente.php +++ b/pandora_console/operation/agentes/estado_agente.php @@ -108,21 +108,18 @@ if (is_ajax ()) { $value = $module_value; } else{ - // If carriage returns present... then is a "Snapshot" data (full command output) - $is_snapshot = is_snapshot_data ( $module_value ); - $module = modules_get_agentmodule($id_module); - - if (($config['command_snapshot']) && ($is_snapshot)){ - $handle = "snapshot"."_".$module["id_agente_modulo"]; - $url = 'include/procesos.php?agente='.$module["id_agente_modulo"]; - $win_handle = dechex(crc32($handle)); - - $link ="winopeng_var('operation/agentes/snapshot_view.php?id=".$module["id_agente_modulo"]."&refr=".$module["current_interval"]."&label=".$module["nombre"]."','".$win_handle."', 700,480)"; - - $value = '' . html_print_image("images/default_list.png", true, array("border" => '0', "alt" => "", "title" => __("Snapshot view"))) . '   '; - } - else { + + $is_snapshot = is_snapshot_data ($module_value); + $is_large_image = is_text_to_black_string ($module_value); + if (($config['command_snapshot']) && ($is_snapshot || $is_large_image)) { + $link = ui_get_snapshot_link( array( + 'id_module' => $module["id_agente_modulo"], + 'interval' => $module["current_interval"], + 'module_name' => $module["nombre"] + )); + $value = ui_get_snapshot_image($link, $is_snapshot) . '  '; + } else { $value = ui_print_module_string_value( $module_value, $module["id_agente_modulo"], $module["current_interval"], $module["module_name"]); diff --git a/pandora_console/operation/agentes/snapshot_view.php b/pandora_console/operation/agentes/snapshot_view.php index c5d09a0f1c..07eda62a3e 100644 --- a/pandora_console/operation/agentes/snapshot_view.php +++ b/pandora_console/operation/agentes/snapshot_view.php @@ -28,6 +28,7 @@ require_once ($config['homedir'] . '/include/functions_graph.php'); require_once ($config['homedir'] . '/include/functions_modules.php'); require_once ($config['homedir'] . '/include/functions_agents.php'); require_once ($config['homedir'] . '/include/functions_tags.php'); +enterprise_include_once ('include/functions_metaconsole'); check_login (); @@ -38,17 +39,27 @@ if (file_exists ('../../include/languages/'.$user_language.'.mo')) { } $id = get_parameter('id'); -$label = get_parameter ("label"); -$last_data = get_parameter("last_data", ''); -$last_timestamp = get_parameter("timestamp", ''); -// FIXME: Support to old call snapshow_view calls. Remove it when all are migrated -if (empty($last_data)) { - $row = db_get_row_sql("SELECT * - FROM tagente_estado - WHERE id_agente_modulo = $id"); - $last_data = io_safe_output($row["datos"]); - $last_timestamp = $row["timestamp"]; +$id_node = get_parameter("id_node", 0); + +// Get the data +if ($id_node > 0) { + $connection = metaconsole_get_connection_by_id($server_name); + if (metaconsole_load_external_db($connection) != NOERR) { + echo "Node connection fail"; + exit; + } } +$row_module = modules_get_agentmodule($id); +$row_state = db_get_row('tagente_estado', 'id_agente_modulo', $id); +if ($id_node > 0) { + metaconsole_restore_db(); +} + +// Build the info +$label = get_parameter ("label", io_safe_output($row_module['module_name'])); +$last_timestamp = get_parameter("timestamp", $row_state['timestamp']); +$last_data = io_safe_output($row_state["datos"]); +$refresh = (int) get_parameter ("refr", $row_state['current_interval']); // TODO - Put ACL here ?> @@ -56,7 +67,6 @@ if (empty($last_data)) { 0) { $query = ui_get_url_refresh (false); echo ''; @@ -68,14 +78,8 @@ if (empty($last_data)) { "; - echo __("Current data at"); - echo " "; - echo $last_timestamp; + echo __("Current data at %s", $last_timestamp); echo ""; if (is_image_data($last_data)) { echo '
image
'; diff --git a/pandora_console/operation/agentes/status_monitor.php b/pandora_console/operation/agentes/status_monitor.php index 8d0a703584..e083cf4cc8 100644 --- a/pandora_console/operation/agentes/status_monitor.php +++ b/pandora_console/operation/agentes/status_monitor.php @@ -732,146 +732,50 @@ switch ($sortField) { break; } -switch ($config['dbtype']) { - case 'mysql': - $sql = 'SELECT - (SELECT GROUP_CONCAT(ttag.name SEPARATOR \',\') - FROM ttag - WHERE ttag.id_tag IN ( - SELECT ttag_module.id_tag - FROM ttag_module - WHERE ttag_module.id_agente_modulo = tagente_modulo.id_agente_modulo)) - AS tags, - tagente_modulo.id_agente_modulo, - tagente_modulo.id_modulo, - tagente.intervalo AS agent_interval, - tagente.alias AS agent_alias, - tagente.nombre AS agent_name, - tagente_modulo.nombre AS module_name, - tagente_modulo.history_data, - tagente_modulo.flag AS flag, - tagente.id_grupo AS id_group, - tagente.id_agente AS id_agent, - tagente_modulo.id_tipo_modulo AS module_type, - tagente_modulo.module_interval, - tagente_modulo.tcp_send, - tagente_modulo.ip_target, - tagente_modulo.snmp_community, - tagente_modulo.snmp_oid, - tagente_estado.datos, - tagente_estado.estado, - tagente_modulo.min_warning, - tagente_modulo.max_warning, - tagente_modulo.str_warning, - tagente_modulo.unit, - tagente_modulo.min_critical, - tagente_modulo.max_critical, - tagente_modulo.str_critical, - tagente_modulo.extended_info, - tagente_modulo.critical_inverse, - tagente_modulo.warning_inverse, - tagente_modulo.critical_instructions, - tagente_modulo.warning_instructions, - tagente_modulo.unknown_instructions, - tagente_estado.utimestamp AS utimestamp' . - $sql_from . $sql_conditions_all . ' - GROUP BY tagente_modulo.id_agente_modulo - ORDER BY ' . $order['field'] . " " . $order['order'] . ' - LIMIT '.$offset.",".$limit_sql; - break; - case 'postgresql': - if (strstr($config['dbversion'], "8.4") !== false) { - $string_agg = 'array_to_string(array_agg(ttag.name), \',\')'; - } - else { - $string_agg = 'STRING_AGG(ttag.name, \',\')'; - } - - $sql = 'SELECT - (SELECT ' . $string_agg . ' - FROM ttag - WHERE ttag.id_tag IN ( - SELECT ttag_module.id_tag - FROM ttag_module - WHERE ttag_module.id_agente_modulo = tagente_modulo.id_agente_modulo)) - AS tags, - tagente_modulo.id_agente_modulo, - tagente_modulo.id_modulo, - tagente.intervalo AS agent_interval, - tagente.alias AS agent_alias, - tagente.nombre AS agent_name, - tagente_modulo.nombre AS module_name, - tagente_modulo.history_data, - tagente_modulo.flag AS flag, - tagente.id_grupo AS id_group, - tagente.id_agente AS id_agent, - tagente_modulo.id_tipo_modulo AS module_type, - tagente_modulo.module_interval, - tagente_estado.datos, - tagente_estado.estado, - tagente_modulo.min_warning, - tagente_modulo.max_warning, - tagente_modulo.str_warning, - tagente_modulo.min_critical, - tagente_modulo.unit, - tagente_modulo.max_critical, - tagente_modulo.str_critical, - tagente_modulo.extended_info, - tagente_modulo.critical_inverse, - tagente_modulo.warning_inverse, - tagente_modulo.critical_instructions, - tagente_modulo.warning_instructions, - tagente_modulo.unknown_instructions, - tagente_estado.utimestamp AS utimestamp' . - $sql_from . - $sql_conditions_all . - ' LIMIT ' . $limit_sql . ' OFFSET ' . $offset; - break; - case 'oracle': - $set = array(); - $set['limit'] = $limit_sql; - $set['offset'] = $offset; - $sql = 'SELECT - (SELECT LISTAGG(ttag.name, \',\') WITHIN GROUP (ORDER BY ttag.name) - FROM ttag - WHERE ttag.id_tag IN ( - SELECT ttag_module.id_tag - FROM ttag_module - WHERE ttag_module.id_agente_modulo = tagente_modulo.id_agente_modulo)) - AS tags, - tagente_modulo.id_agente_modulo, - tagente_modulo.id_modulo, - tagente.intervalo AS agent_interval, - tagente.alias AS agent_alias, - tagente.nombre AS agent_name, - tagente_modulo.nombre AS module_name, - tagente_modulo.history_data, - tagente_modulo.flag AS flag, - tagente.id_grupo AS id_group, - tagente.id_agente AS id_agent, - tagente_modulo.id_tipo_modulo AS module_type, - tagente_modulo.module_interval, - tagente_estado.datos, - tagente_estado.estado, - tagente_modulo.min_warning, - tagente_modulo.max_warning, - tagente_modulo.str_warning, - tagente_modulo.unit, - tagente_modulo.min_critical, - tagente_modulo.max_critical, - tagente_modulo.str_critical, - tagente_modulo.extended_info, - tagente_modulo.critical_inverse, - tagente_modulo.warning_inverse, - tagente_modulo.critical_instructions, - tagente_modulo.warning_instructions, - tagente_modulo.unknown_instructions, - tagente_estado.utimestamp AS utimestamp' . - $sql_from . - $sql_conditions_all; - $sql = oracle_recode_query ($sql, $set); - break; -} +$sql = 'SELECT + (SELECT GROUP_CONCAT(ttag.name SEPARATOR \',\') + FROM ttag + WHERE ttag.id_tag IN ( + SELECT ttag_module.id_tag + FROM ttag_module + WHERE ttag_module.id_agente_modulo = tagente_modulo.id_agente_modulo)) + AS tags, + tagente_modulo.id_agente_modulo, + tagente_modulo.id_modulo, + tagente.intervalo AS agent_interval, + tagente.alias AS agent_alias, + tagente.nombre AS agent_name, + tagente_modulo.nombre AS module_name, + tagente_modulo.history_data, + tagente_modulo.flag AS flag, + tagente.id_grupo AS id_group, + tagente.id_agente AS id_agent, + tagente_modulo.id_tipo_modulo AS module_type, + tagente_modulo.module_interval, + tagente_modulo.tcp_send, + tagente_modulo.ip_target, + tagente_modulo.snmp_community, + tagente_modulo.snmp_oid, + tagente_estado.datos, + tagente_estado.estado, + tagente_modulo.min_warning, + tagente_modulo.max_warning, + tagente_modulo.str_warning, + tagente_modulo.unit, + tagente_modulo.min_critical, + tagente_modulo.max_critical, + tagente_modulo.str_critical, + tagente_modulo.extended_info, + tagente_modulo.critical_inverse, + tagente_modulo.warning_inverse, + tagente_modulo.critical_instructions, + tagente_modulo.warning_instructions, + tagente_modulo.unknown_instructions, + tagente_estado.utimestamp AS utimestamp' . + $sql_from . $sql_conditions_all . ' + GROUP BY tagente_modulo.id_agente_modulo + ORDER BY ' . $order['field'] . " " . $order['order'] . ' + LIMIT '.$offset.",".$limit_sql; if (! defined ('METACONSOLE')) { $result = db_get_all_rows_sql ($sql); @@ -1400,29 +1304,11 @@ if (!empty($result)) { if (($config['command_snapshot']) && ($is_snapshot || $is_large_image)) { $link = ui_get_snapshot_link( array( 'id_module' => $row['id_agente_modulo'], - 'last_data' => $row['datos'], - 'timestamp' => $row['timestamp'], 'interval' => $row['current_interval'], 'module_name' => $row['module_name'] )); - - if($is_large_image){ - $salida = '' . - html_print_image('images/default_list.png', true, - array('border' => '0', - 'alt' => '', - 'title' => __('Snapshot view'))) . '   '; - } - else { - $salida = '' . - html_print_image('images/photo.png', true, - array('border' => '0', - 'alt' => '', - 'title' => __('Snapshot view'))) . '   '; - } - } - else { - + $salida = ui_get_snapshot_image($link, $is_snapshot) . '  '; + } else { $sub_string = substr(io_safe_output($row['datos']), 0, 12); if ($module_value == $sub_string) { if ($module_value == 0 && !$sub_string) {