2012-07-18 Miguel de Dios <miguel.dedios@artica.es>

* include/javascript/pandora.js, include/functions_agents.php,
	include/functions_db.php, include/functions_html.php,
	include/db/postgresql.php, include/db/mysql.php,
	include/db/oracle.php: cleaned source code style and killed some
	unicorns and magical numbers.
	
	* operation/agentes/stat_win.php: a lot fixes, cleaned source code
	style, added magical widget for times for refresh. And yes I fixed
	the bug with jquery that failed with new graphs.
	
	Fixes: #3520966
	
	* operation/agentes/estado_ultimopaquete.php: fixed the links to
	window graph popup, now all the links have 10 minutes for the
	refresh.




git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6787 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
mdtrooper 2012-07-18 09:34:10 +00:00
parent 0a50fbcb1d
commit 8c3d85b507
10 changed files with 582 additions and 499 deletions

View File

@ -1,3 +1,21 @@
2012-07-18 Miguel de Dios <miguel.dedios@artica.es>
* include/javascript/pandora.js, include/functions_agents.php,
include/functions_db.php, include/functions_html.php,
include/db/postgresql.php, include/db/mysql.php,
include/db/oracle.php: cleaned source code style and killed some
unicorns and magical numbers.
* operation/agentes/stat_win.php: a lot fixes, cleaned source code
style, added magical widget for times for refresh. And yes I fixed
the bug with jquery that failed with new graphs.
Fixes: #3520966
* operation/agentes/estado_ultimopaquete.php: fixed the links to
window graph popup, now all the links have 10 minutes for the
refresh.
2012-07-17 Sergio Martin <sergio.martin@artica.es> 2012-07-17 Sergio Martin <sergio.martin@artica.es>
* include/javascript/jquery.scrollTo.js: Added jquery * include/javascript/jquery.scrollTo.js: Added jquery

View File

@ -690,7 +690,8 @@ function mysql_db_get_all_rows_filter ($table, $filter = array(), $fields = fals
$filter = ''; $filter = '';
} }
$sql = sprintf ('SELECT %s FROM %s %s', $fields, $table, $filter); $sql = sprintf ('SELECT %s
FROM %s %s', $fields, $table, $filter);
if ($returnSQL) if ($returnSQL)
return $sql; return $sql;
@ -1045,5 +1046,4 @@ function mysql_db_get_table_count($sql, $search_history_db = false) {
return $count; return $count;
} }
?> ?>

View File

@ -593,7 +593,6 @@ function oracle_db_format_array_where_clause_sql ($values, $join = 'AND', $prefi
} }
$i++; $i++;
continue; continue;
} }
else if (is_numeric ($field)) { else if (is_numeric ($field)) {
/* User provide the exact operation to do */ /* User provide the exact operation to do */

View File

@ -1658,28 +1658,27 @@ function agents_get_status($id_agent = 0, $noACLs = false) {
} }
if (! $status) if (! $status)
return -1; return AGENT_MODULE_STATUS_UNKNOW;
} }
// Status is 0 for normal, 1 for critical, 2 for warning and 3 for unknown. 4 for alert fired // Checking if any module has alert fired
// Checking if any module has alert fired (4) if (is_int(array_search(AGENT_MODULE_STATUS_CRITICAL_ALERT, $modules_status))) {
if (is_int(array_search(4,$modules_status))) { return AGENT_MODULE_STATUS_CRITICAL_ALERT;
return 4;
} }
// Checking if any module has critical status (1) // Checking if any module has critical status
elseif (is_int(array_search(1,$modules_status))) { elseif (is_int(array_search(AGENT_MODULE_STATUS_CRITICAL_BAD, $modules_status))) {
return 1; return AGENT_MODULE_STATUS_CRITICAL_BAD;
} }
// Checking if any module has warning status (2) // Checking if any module has warning status
elseif (is_int(array_search(2,$modules_status))) { elseif (is_int(array_search(AGENT_MODULE_STATUS_WARNING,$modules_status))) {
return 2; return AGENT_MODULE_STATUS_WARNING;
} }
// Checking if any module has unknown status (3) // Checking if any module has unknown status
elseif (is_int(array_search(3,$modules_status))) { elseif (is_int(array_search(AGENT_MODULE_STATUS_UNKNOW, $modules_status))) {
return 3; return AGENT_MODULE_STATUS_UNKNOW;
} }
else { else {
return 0; return AGENT_MODULE_STATUS_NORMAL;
} }
} }

View File

@ -843,7 +843,8 @@ function db_process_delete_temp ($table, $row, $value) {
$result = db_process_sql_delete ($table, $row.' = '.$value); $result = db_process_sql_delete ($table, $row.' = '.$value);
break; break;
case "oracle": case "oracle":
if (is_int ($value) || is_bool ($value) || is_float ($value) || is_double ($value)) { if (is_int ($value) || is_bool ($value) ||
is_float ($value) || is_double ($value)) {
$result = oracle_db_process_sql_delete_temp ($table, $row . ' = ' . $value); $result = oracle_db_process_sql_delete_temp ($table, $row . ' = ' . $value);
} }
else { else {
@ -1152,6 +1153,4 @@ function db_get_table_count($table, $search_history_db = false) {
break; break;
} }
} }
?> ?>

View File

@ -266,8 +266,10 @@ function html_print_select_groups($id_user = false, $privilege = "AR", $returnAl
* *
* @return string HTML code if return parameter is true. * @return string HTML code if return parameter is true.
*/ */
function html_print_select ($fields, $name, $selected = '', $script = '', $nothing = '', $nothing_value = 0, $return = false, function html_print_select ($fields, $name, $selected = '', $script = '',
$multiple = false, $sort = true, $class = '', $disabled = false, $style = false, $option_style = false, $size = false) { $nothing = '', $nothing_value = 0, $return = false, $multiple = false,
$sort = true, $class = '', $disabled = false, $style = false,
$option_style = false, $size = false) {
$output = "\n"; $output = "\n";
@ -346,7 +348,8 @@ function html_print_select ($fields, $name, $selected = '', $script = '', $nothi
if (is_array ($selected) && in_array ($value, $selected)) { if (is_array ($selected) && in_array ($value, $selected)) {
$output .= ' selected="selected"'; $output .= ' selected="selected"';
} }
elseif (is_numeric ($value) && is_numeric ($selected) && $value == $selected) { elseif (is_numeric ($value) && is_numeric ($selected) &&
$value == $selected) {
//This fixes string ($value) to int ($selected) comparisons //This fixes string ($value) to int ($selected) comparisons
$output .= ' selected="selected"'; $output .= ' selected="selected"';
} }
@ -354,7 +357,8 @@ function html_print_select ($fields, $name, $selected = '', $script = '', $nothi
//Needs type comparison otherwise if $selected = 0 and $value = "string" this would evaluate to true //Needs type comparison otherwise if $selected = 0 and $value = "string" this would evaluate to true
$output .= ' selected="selected"'; $output .= ' selected="selected"';
} }
if (is_array ($option_style) && in_array ($value, array_keys($option_style))) { if (is_array ($option_style) &&
in_array ($value, array_keys($option_style))) {
$output .= ' style="'.$option_style[$value].'"'; $output .= ' style="'.$option_style[$value].'"';
} }
if ($optlabel === '') { if ($optlabel === '') {
@ -527,10 +531,13 @@ function html_print_input_text_extended ($name, $value, $id, $alt, $size, $maxle
++$idcounter; ++$idcounter;
$valid_attrs = array ("accept", "disabled", "maxlength", "name", "readonly", "size", "value", $valid_attrs = array ("accept", "disabled", "maxlength",
"accesskey", "class", "dir", "id", "lang", "style", "tabindex", "title", "xml:lang", "name", "readonly", "size", "value", "accesskey",
"onfocus", "onblur", "onselect", "onchange", "onclick", "ondblclick", "onmousedown", "class", "dir", "id", "lang", "style", "tabindex",
"onmouseup", "onmouseover", "onmousemove", "onmouseout", "onkeypress", "onkeydown", "onkeyup"); "title", "xml:lang", "onfocus", "onblur", "onselect",
"onchange", "onclick", "ondblclick", "onmousedown",
"onmouseup", "onmouseover", "onmousemove", "onmouseout",
"onkeypress", "onkeydown", "onkeyup");
$output = '<input '.($password ? 'type="password" ' : 'type="text" '); $output = '<input '.($password ? 'type="password" ' : 'type="text" ');
@ -680,9 +687,10 @@ function html_print_input_image ($name, $src, $value, $style = '', $return = fal
$output = '<input id="image-'.$name.$idcounter.'" src="'.$src.'" style="'.$style.'" name="'.$name.'" type="image"'; $output = '<input id="image-'.$name.$idcounter.'" src="'.$src.'" style="'.$style.'" name="'.$name.'" type="image"';
//Valid attributes (invalid attributes get skipped) //Valid attributes (invalid attributes get skipped)
$attrs = array ("alt", "accesskey", "lang", "tabindex", "title", "xml:lang", $attrs = array ("alt", "accesskey", "lang", "tabindex",
"onclick", "ondblclick", "onmousedown", "onmouseup", "onmouseover", "onmousemove", "title", "xml:lang", "onclick", "ondblclick", "onmousedown",
"onmouseout", "onkeypress", "onkeydown", "onkeyup"); "onmouseup", "onmouseover", "onmousemove", "onmouseout",
"onkeypress", "onkeydown", "onkeyup");
foreach ($attrs as $attribute) { foreach ($attrs as $attribute) {
if (isset ($options[$attribute])) { if (isset ($options[$attribute])) {
@ -816,6 +824,7 @@ function html_print_textarea ($name, $rows, $columns, $value = '', $attributes =
if ($return) if ($return)
return $output; return $output;
echo $output; echo $output;
} }
@ -861,7 +870,8 @@ function html_print_table (&$table, $return = false) {
foreach ($table->align as $key => $aa) { foreach ($table->align as $key => $aa) {
if ($aa) { if ($aa) {
$align[$key] = ' text-align:'. $aa.';'; $align[$key] = ' text-align:'. $aa.';';
} else { }
else {
$align[$key] = ''; $align[$key] = '';
} }
} }
@ -879,7 +889,8 @@ function html_print_table (&$table, $return = false) {
foreach ($table->size as $key => $ss) { foreach ($table->size as $key => $ss) {
if ($ss) { if ($ss) {
$size[$key] = ' width:'. $ss .';'; $size[$key] = ' width:'. $ss .';';
} else { }
else {
$size[$key] = ''; $size[$key] = '';
} }
} }
@ -888,7 +899,8 @@ function html_print_table (&$table, $return = false) {
foreach ($table->style as $key => $st) { foreach ($table->style as $key => $st) {
if ($st) { if ($st) {
$style[$key] = ' '. $st .';'; $style[$key] = ' '. $st .';';
} else { }
else {
$style[$key] = ''; $style[$key] = '';
} }
} }
@ -934,7 +946,8 @@ function html_print_table (&$table, $return = false) {
if (empty ($table->tablealign) || $table->tablealign != 'left' || $table->tablealign != 'right') { if (empty ($table->tablealign) || $table->tablealign != 'left' || $table->tablealign != 'right') {
$table->tablealign = ''; $table->tablealign = '';
} else { }
else {
$table->tablealign = 'style="float:'.$table->tablealign.';"'; //Align is deprecated. Use float instead $table->tablealign = 'style="float:'.$table->tablealign.';"'; //Align is deprecated. Use float instead
} }
@ -1150,7 +1163,8 @@ function html_print_checkbox_extended ($name, $value, $checked, $disabled, $scri
//If duplicate names exist, it will start numbering. Otherwise it won't //If duplicate names exist, it will start numbering. Otherwise it won't
if (isset ($idcounter[$name])) { if (isset ($idcounter[$name])) {
$idcounter[$name]++; $idcounter[$name]++;
} else { }
else {
$idcounter[$name] = 0; $idcounter[$name] = 0;
} }

View File

@ -462,18 +462,18 @@ foreach ($modules as $module) {
$graph_label = io_safe_output($module["nombre"]); $graph_label = io_safe_output($module["nombre"]);
echo "<a href='javascript:" . echo "<a href='javascript:" .
"winopeng(\"operation/agentes/stat_win.php?type=$graph_type&period=" . (28 * SECONDS_1DAY) . "&id=".$module["id_agente_modulo"]."&label=".base64_encode($graph_label)."&refresh=180000\", \"month_".$win_handle."\")'>" . html_print_image('images/grafica_m.png' , true, array("border" => '0', "alt" => '')) . "</a>&nbsp;"; "winopeng(\"operation/agentes/stat_win.php?type=$graph_type&period=" . SECONDS_1MONTH . "&id=".$module["id_agente_modulo"]."&label=".base64_encode($graph_label)."&refresh=" . SECONDS_10MINUTES . "\", \"month_".$win_handle."\")'>" . html_print_image('images/grafica_m.png' , true, array("border" => '0', "alt" => '')) . "</a>&nbsp;";
$link ="winopeng(" . $link ="winopeng(" .
"'operation/agentes/stat_win.php?type=$graph_type&period=" . SECONDS_1WEEK . "&id=".$module["id_agente_modulo"]."&label=".base64_encode($graph_label)."&refresh=6000','week_".$win_handle."')"; "'operation/agentes/stat_win.php?type=$graph_type&period=" . SECONDS_1WEEK . "&id=".$module["id_agente_modulo"]."&label=".base64_encode($graph_label)."&refresh=" . SECONDS_10MINUTES . "','week_".$win_handle."')";
echo '<a href="javascript:'.$link.'">' . html_print_image("images/grafica_w.png", true, array("border" => '0', "alt" => '')) . '</a>&nbsp;'; echo '<a href="javascript:'.$link.'">' . html_print_image("images/grafica_w.png", true, array("border" => '0', "alt" => '')) . '</a>&nbsp;';
$link ="winopeng(" . $link ="winopeng(" .
"'operation/agentes/stat_win.php?type=$graph_type&period=" . SECONDS_1DAY . "&id=".$module["id_agente_modulo"]."&label=".base64_encode($graph_label)."&refresh=600','day_".$win_handle."')"; "'operation/agentes/stat_win.php?type=$graph_type&period=" . SECONDS_1DAY . "&id=".$module["id_agente_modulo"]."&label=".base64_encode($graph_label)."&refresh=" . SECONDS_10MINUTES . "','day_".$win_handle."')";
echo '<a href="javascript:'.$link.'">' . html_print_image("images/grafica_d.png", true, array("border" => '0', "alt" => '')) . '</a>&nbsp;'; echo '<a href="javascript:'.$link.'">' . html_print_image("images/grafica_d.png", true, array("border" => '0', "alt" => '')) . '</a>&nbsp;';
$link ="winopeng(" . $link ="winopeng(" .
"'operation/agentes/stat_win.php?type=$graph_type&period=" . SECONDS_1HOUR . "&id=".$module["id_agente_modulo"]."&label=".base64_encode($graph_label)."&refresh=60','hour_".$win_handle."')"; "'operation/agentes/stat_win.php?type=$graph_type&period=" . SECONDS_1HOUR . "&id=".$module["id_agente_modulo"]."&label=".base64_encode($graph_label)."&refresh=" . SECONDS_10MINUTES . "','hour_".$win_handle."')";
echo '<a href="javascript:'.$link.'">' . html_print_image("images/grafica_h.png", true, array("border" => '0', "alt" => "")) . '</a>'; echo '<a href="javascript:'.$link.'">' . html_print_image("images/grafica_h.png", true, array("border" => '0', "alt" => "")) . '</a>';
} }

View File

@ -61,8 +61,9 @@ if ($refresh > 0) {
<script type='text/javascript' src='../../include/javascript/x_event.js'></script> <script type='text/javascript' src='../../include/javascript/x_event.js'></script>
<script type='text/javascript' src='../../include/javascript/x_slide.js'></script> <script type='text/javascript' src='../../include/javascript/x_slide.js'></script>
<script type='text/javascript' src='../../include/javascript/pandora.js'></script> <script type='text/javascript' src='../../include/javascript/pandora.js'></script>
<script type='text/javascript' src='../../include/javascript/jquery.js'></script> <script type='text/javascript' src='../../include/javascript/jquery-1.7.1.js'></script>
<script type='text/javascript'><!-- <script type='text/javascript'>
<!--
var defOffset = 2; var defOffset = 2;
var defSlideTime = 220; var defSlideTime = 220;
var tnActive = 0; var tnActive = 0;
@ -98,16 +99,13 @@ window.onload = function() {
$("#graph_menu_arrow").attr("src", <?php echo '"' . $config['homeurl'] . '"'; ?> + "/images/graphmenu_arrow.png"); $("#graph_menu_arrow").attr("src", <?php echo '"' . $config['homeurl'] . '"'; ?> + "/images/graphmenu_arrow.png");
} }
}); });
}; };
function docOnMousemoveIn(evt) { function docOnMousemoveIn(evt) {
var e = new xEvent(evt); var e = new xEvent(evt);
var d = getTermEle(e.target); var d = getTermEle(e.target);
// if (!tnActive) { // no def is active // mouse is over a term, activate its def
// if (d) { // mouse is over a term, activate its def
if (showed == 0) { if (showed == 0) {
xSlideTo('divmenu', 0, xPageY(d), defSlideTime); xSlideTo('divmenu', 0, xPageY(d), defSlideTime);
showed = 1; showed = 1;
@ -116,8 +114,6 @@ function docOnMousemoveIn(evt) {
xSlideTo('divmenu', visibleMargin - menuW, xPageY(d), defSlideTime); xSlideTo('divmenu', visibleMargin - menuW, xPageY(d), defSlideTime);
showed = 0; showed = 0;
} }
// }
// }
} }
function docOnMousemove(evt) { function docOnMousemove(evt) {
@ -163,7 +159,9 @@ function show_others() {
// Get input parameters // Get input parameters
$label = get_parameter ("label",""); $label = get_parameter ("label","");
if (!isset($_GET["period"]) OR (!isset($_GET["id"]))) { if (!isset($_GET["period"]) OR (!isset($_GET["id"]))) {
echo "<h3 class='error'>".__('There was a problem locating the source of the graph')."</h3>"; echo "<h3 class='error'>" .
__('There was a problem locating the source of the graph') .
"</h3>";
exit; exit;
} }
@ -250,9 +248,17 @@ switch ($graph_type) {
echo '</div>'; echo '</div>';
//z-index is 1 because 2 made the calendar show under the divmenu. //z-index is 1 because 2 made the calendar show under the divmenu.
echo '<div id="divmenu" class="menu" style="z-index:1; height: 98%;"><b>'.__('Pandora FMS Graph configuration menu').'</b><br /><br />'.__('Please, make your changes and apply with the <i>Reload</i> button'); ?>
echo '<div style="float: left">'; <div id="divmenu" class="menu" style="z-index:1; height: 98%;">
echo '<form method="get" action="stat_win.php">'; <b> <?php echo __('Pandora FMS Graph configuration menu');?></b>
<br />
<br />
<?php
echo __('Please, make your changes and apply with the <i>Reload</i> button');
?>
<div style="float: left; width: 80%;">
<form method="get" action="stat_win.php">
<?php
html_print_input_hidden ("id", $id); html_print_input_hidden ("id", $id);
html_print_input_hidden ("label", $label); html_print_input_hidden ("label", $label);
@ -260,61 +266,109 @@ if (isset($_GET["type"])) {
$type = get_parameter_get ("type"); $type = get_parameter_get ("type");
html_print_input_hidden ("type", $type); html_print_input_hidden ("type", $type);
} }
echo '<table class="databox_frame" cellspacing="5">'; ?>
echo '<tr><td>'.__('Refresh time').'</td><td colspan="2">'; <table class="databox_frame" cellspacing="5" width="100%">
<tr>
html_print_input_text ("refresh", $refresh, '', 5); <td><?php echo __('Refresh time');?></td>
<td>
echo '&nbsp;&nbsp;&nbsp;'.__('Avg. Only'); <?php
html_print_extended_select_for_time(
"refresh", $refresh, '', '', 0, 7);
?>
</td>
</tr>
<tr>
<td><?php echo __('Avg. Only'); ?></td>
<td>
<?php
html_print_checkbox ("avg_only", 1, (bool) $avg_only, false, false, 'show_others()'); html_print_checkbox ("avg_only", 1, (bool) $avg_only, false, false, 'show_others()');
html_print_input_hidden('show_other', 0); html_print_input_hidden('show_other', 0);
?>
echo '<tr><td>'.__('Begin date').'</td><td>'; </td>
</tr>
<tr>
<td><?php echo __('Begin date'); ?></td>
<td>
<?php
html_print_input_text ("start_date", substr ($start_date, 0, 10),'', 10); html_print_input_text ("start_date", substr ($start_date, 0, 10),'', 10);
html_print_image ("images/calendar_view_day.png", false, array ("onclick" => "scwShow(scwID('text-start_date'),this);")); html_print_image ("images/calendar_view_day.png", false, array ("onclick" => "scwShow(scwID('text-start_date'),this);"));
?>
echo '</td></tr><tr><td>'.__('Zoom factor').'</td>'; </td>
echo '<td>'; </tr>
<tr>
<td><?php echo __('Zoom factor');?></td>
<td>
<?php
$options = array (); $options = array ();
$options[$zoom] = 'x'.$zoom; $options[$zoom] = 'x'.$zoom;
$options[1] = 'x1'; $options[1] = 'x1';
$options[2] = 'x2'; $options[2] = 'x2';
$options[3] = 'x3'; $options[3] = 'x3';
$options[4] = 'x4'; $options[4] = 'x4';
html_print_select ($options, "zoom", $zoom); html_print_select ($options, "zoom", $zoom);
echo '</td></tr><tr><td>'.__('Time range').'</td><td>';
html_print_extended_select_for_time('period', $period, '', '', 0, 7);
echo '</td></tr><tr><td>'.__('Show events').'</td><td>';
html_print_checkbox ("draw_events", 1, (bool) $draw_events);
echo '</td></tr><tr><td>'.__('Show alerts').'</td><td>';
html_print_checkbox ("draw_alerts", 1, (bool) $draw_alerts);
if ($config['enterprise_installed'] && $graph_type == "sparse") {
echo '</td></tr><tr><td>'.__('Draw baseline').'</td><td>';
html_print_checkbox ("baseline", 1, (bool) $baseline);
}
echo '</td><td>';
echo '</td></tr><tr><td>'.__('Show event graph').'</td><td>';
html_print_checkbox ("show_events_graph", 1, (bool) $show_events_graph);
echo '</td></tr>';
echo '<tr><td></td><td style="text-align: right">';
html_print_submit_button (__('Reload'), "submit", false, 'class="sub next"');
echo '</td></tr></table></form></div><div id="show_menu" style="position: relative; border:1px solid #FFF; float: right; height: 50px; width: 50px;">' . html_print_image("images/graphmenu_arrow.png", true, array('id' => 'graph_menu_arrow')) . '<div></div></body></html>';
?> ?>
</td>
</tr>
<tr>
<td><?php echo __('Time range'); ?></td>
<td>
<?php
html_print_extended_select_for_time('period',
$period, '', '', 0, 7);
?>
</td>
</tr>
<tr>
<td><?php echo __('Show events');?></td>
<td>
<?php
html_print_checkbox ("draw_events", 1, (bool) $draw_events);
?>
</td>
</tr>
<tr>
<td><?php echo __('Show alerts');?></td>
<td>
<?php
html_print_checkbox ("draw_alerts", 1, (bool) $draw_alerts);
?>
</td>
</tr>
<?php
if ($config['enterprise_installed'] && $graph_type == "sparse") {
echo '<tr>';
echo '<td>' . __('Draw baseline') . '</td>';
echo '<td>';
html_print_checkbox ("baseline", 1, (bool) $baseline);
echo '</td>';
echo '</tr>';
}
?>
<tr>
<td><?php echo __('Show event graph');?></td>
<td>
<?php
html_print_checkbox ("show_events_graph",
1, (bool) $show_events_graph);
?>
</td>
</tr>
<tr>
<td></td>
<td style="text-align: right">
<?php
html_print_submit_button (__('Reload'), "submit", false, 'class="sub next"');
?>
</td>
</tr>
</table>
</form>
</div>
<div id="show_menu" style="position: relative; border:1px solid #FFF; float: right; height: 50px; width: 50px;">
<?php
html_print_image("images/graphmenu_arrow.png", false, array('id' => 'graph_menu_arrow'));
?>
<div>
</div>
</body> </body>
</html> </html>