Refactorized snapshot link on node

This commit is contained in:
fermin831 2018-08-02 13:02:33 +02:00
parent ca67bd632e
commit 18800feaae
8 changed files with 152 additions and 313 deletions

View File

@ -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);

View File

@ -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 = '<a href="javascript:' . $link . '">' .
html_print_image('images/default_list.png', true,
array('border' => '0',
'alt' => '',
'title' => __('Snapshot view'))) . '</a> &nbsp;&nbsp;';
}
else {
$salida = '<a href="javascript:' . $link . '">' .
html_print_image('images/photo.png', true,
array('border' => '0',
'alt' => '',
'title' => __('Snapshot view'))) . '</a> &nbsp;&nbsp;';
}
}
$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) . '&nbsp;&nbsp;';
}
$last_data_str .= $salida;
}
else {
$last_data_str = '<i>' . __('No data') . '</i>';

View File

@ -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) . '&nbsp;&nbsp;';
}
$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 = '<a href="javascript:' . $link . '">' .
html_print_image("images/photo.png", true,
array("border" => '0',
"alt" => "",
"title" => __("Snapshot view"))) . '</a> &nbsp;&nbsp;';
}
else {
$salida = '<a href="javascript:' . $link . '">' .
html_print_image("images/default_list.png", true,
array("border" => '0',
"alt" => "",
"title" => __("Snapshot view"))) . '</a> &nbsp;&nbsp;';
}
}
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) . '&nbsp;&nbsp;';
} 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'] .
"&timestamp=" . $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 .= "&timestamp=" . $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 = '<a href="javascript:' . $link . '">' .
html_print_image("images/$image_name", true,
array('border' => '0',
'alt' => '',
'title' => __('Snapshot view'))
) .
'</a>';
return $link;
}
function ui_get_using_system_timezone_warning ($tag = "h3", $return = true) {
global $config;

View File

@ -655,10 +655,9 @@ class Ui {
echo " <link rel='stylesheet' href='include/style/main.css' />\n";
echo " <link rel='stylesheet' href='include/style/jquery.mobile-1.3.1.css' />\n";
//echo " <link rel='stylesheet' href='http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.css' />\n";
echo " <script src='include/javascript/jquery.js'></script>\n";
echo " <script src='include/javascript/jquery.mobile-1.3.1.js'></script>\n";
//echo " <script src='http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.js'></script>\n";
echo " <script src='../include/javascript/pandora.js'></script>\n";
echo " </head>\n";
echo " <body>\n";

View File

@ -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')] = '<a href="javascript:' . $link . '">' .
html_print_image("images/photo.png", true,
array("border" => '0',
"alt" => "",
"title" => __("Snapshot view"))) . '</a> &nbsp;&nbsp;';
}
else {
$row[7] = $row[__('Data')] = '<a href="javascript:' . $link . '">' .
html_print_image("images/default_list.png", true,
array("border" => '0',
"alt" => "",
"title" => __("Snapshot view"))) . '</a> &nbsp;&nbsp;';
}
}
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) . '&nbsp;&nbsp;';
} else {
$row[7] = $row[__('Data')] = '<span style="white-space: nowrap;">' .
'<span style="display: none;" class="show_collapside">' .
$row[__('Status')] . '&nbsp;&nbsp;</span>' .
@ -626,18 +610,7 @@ class Modules {
$module['id_agente_modulo'] . '&id_agent=' .
$this->id_agent . '">' . $output . '</a>' . '</span>';
}
/*
'<span style="white-space: nowrap;">' .
'<span style="display: none;" class="show_collapside">' .
$row[__('Status')] . '&nbsp;&nbsp;</span>' .
'<a data-ajax="false" class="ui-link" ' .
'href="index.php?page=module_graph&id=' .
$module['id_agente_modulo'] . '&id_agent=' .
$this->id_agent . '">' . $output . '</a>' . '</span>';*/
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;
}
}

View File

@ -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 = '<a href="javascript:'.$link.'">' . html_print_image("images/default_list.png", true, array("border" => '0', "alt" => "", "title" => __("Snapshot view"))) . '</a> &nbsp;&nbsp;';
}
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) . '&nbsp;&nbsp;';
} else {
$value = ui_print_module_string_value(
$module_value, $module["id_agente_modulo"],
$module["current_interval"], $module["module_name"]);

View File

@ -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)) {
<head>
<?php
// Parsing the refresh before sending any header
$refresh = (int) get_parameter ("refr", -1);
if ($refresh > 0) {
$query = ui_get_url_refresh (false);
echo '<meta http-equiv="refresh" content="'.$refresh.'; URL='.$query.'" />';
@ -68,14 +78,8 @@ if (empty($last_data)) {
</head>
<body style='background:#000; color: #ccc;'>
<?php
$row = db_get_row_sql("SELECT *
FROM tagente_estado
WHERE id_agente_modulo = $id");
echo "<h2 style='text-align:center;' id='title_snapshot_view'>";
echo __("Current data at");
echo " ";
echo $last_timestamp;
echo __("Current data at %s", $last_timestamp);
echo "</h2>";
if (is_image_data($last_data)) {
echo '<center><img src="' . $last_data . '" alt="image" style="width:100%"/></center>';

View File

@ -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 = '<a href="javascript:' . $link . '">' .
html_print_image('images/default_list.png', true,
array('border' => '0',
'alt' => '',
'title' => __('Snapshot view'))) . '</a> &nbsp;&nbsp;';
}
else {
$salida = '<a href="javascript:' . $link . '">' .
html_print_image('images/photo.png', true,
array('border' => '0',
'alt' => '',
'title' => __('Snapshot view'))) . '</a> &nbsp;&nbsp;';
}
}
else {
$salida = ui_get_snapshot_image($link, $is_snapshot) . '&nbsp;&nbsp;';
} else {
$sub_string = substr(io_safe_output($row['datos']), 0, 12);
if ($module_value == $sub_string) {
if ($module_value == 0 && !$sub_string) {