[Snapshots] Fixed snapshots in metaconsole. Changed functionallity but preserve all way to work

This commit is contained in:
fermin831 2018-03-12 15:17:59 +01:00
parent 3e90c3421a
commit 74f899736f
6 changed files with 93 additions and 39 deletions

View File

@ -1599,6 +1599,15 @@ class Tree {
'url' => $moduleGraphURL,
'handle' => $winHandle
);
// 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);
}
// Alerts fired image

View File

@ -268,21 +268,14 @@ function treeview_printModuleTable($id_module, $server_data = false, $no_head =
$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)) {
$handle = 'snapshot_' . $module['id_agente_modulo'];
$url = 'include/procesos.php?agente=' . $row['id_agente_modulo'];
$win_handle = dechex(crc32($handle));
if (! defined ('METACONSOLE')) {
$link = "winopeng_var('operation/agentes/snapshot_view.php?" .
"id=" . $module['id_agente_modulo'] .
"&refr=" . $module['current_interval'] .
"&label=" . rawurlencode(urlencode(io_safe_output($module['module_name']))) . "','" . $win_handle . "', 700,480)";
}
else{
$link = "winopeng_var('$last_data[datos]','',700,480)";
}
$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 . '">' .

View File

@ -3919,4 +3919,48 @@ function ui_print_tags_view($title = '', $tags = array()) {
$tv .= '</div>';
echo $tv;
}
/**
* @brief Get the link to open a snapshot into a new page
*
* @param Array Params to build the link (see $default_params)
* @param bool Flag to choose de return value:
* true: Get the four params required in the function of pandora.js winopen_var (js use)
* false: Get an inline winopen_var function call (php user)
*/
function ui_get_snapshot_link($params, $only_params = false) {
global $config;
$default_params = array(
'id_module' => 0, //id_agente_modulo
'module_name' => '',
'interval' => 300,
'last_data' => '',
'timestamp' => '0'
);
// Merge default params with passed params
$params = array_merge ($default_params, $params);
// First parameter of js winopeng_var
$page = $config['homeurl_static'] . "/operation/agentes/snapshot_view.php";
$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'])));
// Second parameter of js winopeng_var
$win_handle = dechex(crc32('snapshot_' . $params['id_module']));
$link_parts = array ($url, $win_handle, 700, 480);
// Return only the params to js execution
if ($only_params) return $link_parts;
// Return the function call to inline js execution
return "winopeng_var('" . implode("', '", $link_parts) . "')";
}
?>

View File

@ -402,16 +402,21 @@ var TreeController = {
else{
var $graphImage = $('<img src="'+(controller.baseURL.length > 0 ? controller.baseURL : '')
+'images/chart_curve.png" /> ');
+'images/chart_curve.png" /> ');
}
$graphImage
.addClass('module-graph')
.click(function (e) {
e.preventDefault();
if(element.statusImageHTML.indexOf('data:image')!=-1){
try {
winopeng_var(element.datos,'',700,480);
winopeng_var(
decodeURI(element.snapshot[0]),
element.snapshot[1],
element.snapshot[2],
element.snapshot[3]
);
}
catch (error) {
// console.log(error);

View File

@ -39,6 +39,16 @@ 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"];
}
// TODO - Put ACL here
?>
@ -61,15 +71,14 @@ $label = get_parameter ("label");
$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 $row["timestamp"];
echo $last_timestamp;
echo "</h2>";
$datos = io_safe_output($row["datos"]);
if (is_image_data($datos)) {
echo '<center><img src="' . $datos . '" alt="image" style="width:100%"/></center>';
if (is_image_data($last_data)) {
echo '<center><img src="' . $last_data . '" alt="image" style="width:100%"/></center>';
}
else {
$datos = preg_replace ('/</', '&lt;', $datos);
@ -77,7 +86,7 @@ $label = get_parameter ("label");
$datos = preg_replace ('/\n/i','<br>',$datos);
$datos = preg_replace ('/\s/i','&nbsp;',$datos);
echo "<div id='result_div' style='width: 100%; height: 100%; overflow: scroll; padding: 10px; font-size: 14px; line-height: 16px; font-family: mono,monospace; text-align: left'>";
echo $datos;
echo $last_data;
echo "</div>";
?>
<script type="text/javascript">
@ -88,16 +97,16 @@ $label = get_parameter ("label");
div.css('overflow-y', 'auto');
var w2 = $('div', div).innerWidth();
$(div).remove();
return (w1 - w2);
}
$(document).ready(function() {
width = $("#result_div").css("width");
width = width.replace("px", "");
width = parseInt(width);
$("#result_div").css("width", (width - getScrollbarWidth()) + "px");
height = $("#result_div").css("height");
height = height.replace("px", "");
height = parseInt(height);

View File

@ -1361,19 +1361,13 @@ if (!empty($result)) {
$is_snapshot = is_snapshot_data ( $module_value );
if (($config['command_snapshot']) && ($is_snapshot)) {
$handle = 'snapshot_' . $row['id_agente_modulo'];
$url = 'include/procesos.php?agente=' . $row['id_agente_modulo'];
$win_handle = dechex(crc32($handle));
if (! defined ('METACONSOLE')) {
$link = "winopeng_var('operation/agentes/snapshot_view.php?" .
"id=" . $row['id_agente_modulo'] .
"&refr=" . $row['current_interval'] .
"&label=" . rawurlencode(urlencode(io_safe_output($row['module_name']))) . "','" . $win_handle . "', 700,480)";
}
else{
$link = "winopeng_var('$row[datos]','',700,480)";
}
$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_image_data($row['datos'])){
$salida = '<a href="javascript:' . $link . '">' .