2008-09-30 Evi Vanoost <vanooste@rcbi.rochester.edu>

* reporting/fgraph.php: monitors_health_pipe was in an aesthetically 
        bad order. Moved for yellow to be bad and green to be good

        * operation/reporting/reporting_viewer.php,
        godmode/reporting/reporting_builder.php: Style updates. Use the
        updated database functions.

        * include/functions_reporting.php: monitor_health_reporting function 
        updated. There was a major bug; &not got translated into it's ASCII
        value and the graph didn't work. The graph was in a bad position as a
        float, it went over the table and if the table was not big enough,it
        would go over other data. So fixed all of it.

        * include/functions_html.php: print_select_from_sql updated to use SQL 
        functions

        * include/functions_db.php: get_monitors_in_group didn't work correctly 
        if the group was 1 (All). Removed quotes from get_db_value and 
        get_db_all_rows_field_filter

        * include/functions.php: get_report_type_data_source returned the wrong
        type for monitor_report (id 6) which made the jQuery not show the
        agent/module select box and subsequently the graph failed


git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1123 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
guruevi 2008-09-30 17:55:36 +00:00
parent 5a6d25232c
commit 5498a0e95b
8 changed files with 117 additions and 75 deletions

View File

@ -1,3 +1,30 @@
2008-09-30 Evi Vanoost <vanooste@rcbi.rochester.edu>
* reporting/fgraph.php: monitors_health_pipe was in an aesthetically
bad order. Moved for yellow to be bad and green to be good
* operation/reporting/reporting_viewer.php,
godmode/reporting/reporting_builder.php: Style updates. Use the
updated database functions.
* include/functions_reporting.php: monitor_health_reporting function
updated. There was a major bug; &not got translated into it's ASCII
value and the graph didn't work. The graph was in a bad position as a
float, it went over the table and if the table was not big enough,it
would go over other data. So fixed all of it.
* include/functions_html.php: print_select_from_sql updated to use SQL
functions
* include/functions_db.php: get_monitors_in_group didn't work correctly
if the group was 1 (All). Removed quotes from get_db_value and
get_db_all_rows_field_filter
* include/functions.php: get_report_type_data_source returned the wrong
type for monitor_report (id 6) which made the jQuery not show the
agent/module select box and subsequently the graph failed
2008-09-29 Evi Vanoost <vanooste@rcbi.rochester.edu>
* godmode/agentes/module_manager_editor_data.php,

View File

@ -66,13 +66,14 @@ if ($delete_report_content) {
$id_report_content = (int) get_parameter ('id_report_content');
$order = get_db_value ('`order`', 'treport_content', 'id_rc', $id_report_content);
$sql = sprintf ('UPDATE treport_content SET `order` = `order` -1 WHERE id_report = %d AND `order` > %d', $id_report, $order);
mysql_query ($sql);
process_sql ($sql);
$sql = sprintf ('DELETE FROM treport_content WHERE id_rc = %d', $id_report_content);
$result = mysql_query ($sql);
if ($result)
$result = process_sql ($sql);
if ($result !== false) {
echo "<h3 class='suc'>".__('Deleted successfully')."</h3>";
else
} else {
echo "<h3 class='error'>".__('Not deleted. Error deleting data')."</h3>";
}
}
// Move content up
@ -82,9 +83,9 @@ if ($content_up) {
/* Set the previous element order to the current of the content we want to change */
$sql = sprintf ('UPDATE treport_content SET `order` = `order` + 1 WHERE id_report = %d AND `order` = %d',
$id_report, $order - 1);
$result = mysql_query ($sql);
$result = process_sql ($sql);
$sql = sprintf ('UPDATE treport_content SET `order` = `order` - 1 WHERE id_rc = %d', $id_report_content);
$result = mysql_query ($sql);
$result = process_sql ($sql);
}
// Move content down
@ -94,17 +95,17 @@ if ($content_down) {
/* Set the previous element order to the current of the content we want to change */
$sql = sprintf ('UPDATE treport_content SET `order` = `order` - 1 WHERE id_report = %d AND `order` = %d',
$id_report, $order + 1);
$result = mysql_query ($sql);
$result = process_sql ($sql);
$sql = sprintf ('UPDATE treport_content SET `order` = `order` + 1 WHERE id_rc = %d', $id_report_content);
$result = mysql_query ($sql);
$result = process_sql ($sql);
}
// Delete report SQL code
if ($delete_report) {
$sql = sprintf ('DELETE FROM treport_content WHERE id_report = %d', $id_report);
$sql2 = sprintf ('DELETE FROM treport WHERE id_report = %d', $id_report);
$res = mysql_query ($sql);
$res2 = mysql_query ($sql2);
$res = process_sql ($sql);
$res2 = process_sql ($sql2);
if ($res AND $res2)
echo "<h3 class=suc>".__('Reporting successfully deleted')."</h3>";
else
@ -132,7 +133,9 @@ if ($add_content) {
$id_report, $id_custom_graph ? $id_custom_graph : "NULL",
$id_agent_module ? $id_agent_module : "NULL",
$order, $type, $period * 3600);
if ($result = mysql_query($sql)) {
$result = process_sql ($sql);
if ($result !== false) {
echo '<h3 class="suc">'.__('Reporting successfully created').'</h3>';
$id_agent = 0;
$id_agent_module = 0;
@ -154,12 +157,12 @@ if ($create_report) {
$sql = sprintf ('INSERT INTO treport (name, description, id_user, private, id_group)
VALUES ("%s", "%s", "%s", %d, %d)',
$report_name, $report_description, $config['id_user'], $report_private, $report_id_group);
$result = mysql_query ($sql);
if ($result)
$id_report = process_sql ($sql, "insert_id");
if ($id_report !== false) {
echo "<h3 class=suc>".__('Reporting successfully created')."</h3>";
else
} else {
echo "<h3 class=error>".__('There was a problem creating reporting')."</h3>";
$id_report = mysql_insert_id ();
}
}
// Update report
@ -169,11 +172,12 @@ if ($update_report) {
WHERE id_report = %d',
$report_name, $report_description,
$report_private, $id_report);
$result = mysql_query ($sql);
if ($result)
$result = process_sql ($sql);
if ($result) {
echo "<h3 class=suc>".__('Updated successfully')."</h3>";
else
} else {
echo "<h3 class=error>".__('Not updated. Error updating data')."</h3>";
}
}
if ($id_report) {
@ -214,11 +218,12 @@ if ($edit_sla_report_content) {
$id_report_content, $id_module, $sla_max, $sla_min, $sla_limit);
if ($id_module) {
$result = mysql_query ($sql);
if ($result)
$result = process_sql ($sql);
if ($result !== false) {
echo "<h3 class=suc>".__('SLA was successfully created')."</h3>";
else
} else {
echo "<h3 class=error>".__('There was a problem creating SLA')."</h3>";
}
} else {
echo "<h3 class=error>".__('Module is not set')."</h3>";
}
@ -226,11 +231,12 @@ if ($edit_sla_report_content) {
if ($delete_sla) {
$id_sla = (int) get_parameter ('id_sla');
$sql = sprintf ('DELETE FROM treport_content_sla_combined WHERE id = %d', $id_sla);
$result = mysql_query ($sql);
if ($result)
$result = process_sql ($sql);
if ($result !== false) {
echo "<h3 class=suc>".__('SLA was successfully delete')."</h3>";
else
} else {
echo "<h3 class=error>".__('There was a problem deleting SLA')."</h3>";
}
}
$report_content = get_db_row ('treport_content', 'id_rc', $id_report_content);
@ -255,7 +261,7 @@ if ($edit_sla_report_content) {
$table->head[5] = __('Delete');
$slas = get_db_all_rows_field_filter ('treport_content_sla_combined', 'id_report_content', $id_report_content);
if ($slas){
if ($slas) {
foreach ($slas as $sla) {
$data = array ();
@ -309,12 +315,9 @@ if ($edit_sla_report_content) {
echo '</div>';
echo '</form>';
} else if ($edit_report || $id_report) {
} elseif ($edit_report || $id_report) {
/* Edit and creation report form */
if (isset($_POST["id_agent"]))
$id_agent = $_POST["id_agent"];
else
$id_agent = 0;
$id_agent = get_parameter_post ("id_agent",0);
echo "<h2>".__('Reporting')." &gt; ";
echo __('Custom reporting builder')."</h2>";

View File

@ -1033,6 +1033,8 @@ function get_report_type_data_source ($type) {
switch ($type) {
case 1:
case 'simple_graph':
case 6:
case 'monitor_report':
case 7:
case 'avg_value':
case 8:
@ -1051,8 +1053,6 @@ function get_report_type_data_source ($type) {
case 'event_report':
case 5:
case 'alert_report':
case 6:
case 'monitor_report':
case 11:
case 'general_group_report':
case 12:

View File

@ -551,11 +551,21 @@ function get_monitor_last_down_timestamp_in_period ($id_agent_module, $period, $
* @return An array with all the monitors defined in the group (tagente_modulo).
*/
function get_monitors_in_group ($id_group) {
if ($id_group <= 1) {
//We select all groups the user has access to if it's 0, -1 or 1
global $config;
$id_group = array_keys (get_user_groups ($config['id_user']));
}
if (is_array ($id_group)) {
$id_group = implode (",",$id_group);
}
$sql = sprintf ("SELECT `tagente_modulo`.* FROM `tagente_modulo`, `ttipo_modulo`, `tagente` WHERE
`id_tipo_modulo` = `id_tipo`
AND `tagente`.`id_agente` = `tagente_modulo`.`id_agente`
AND `ttipo_modulo`.`nombre` LIKE '%%_proc'
AND `tagente`.`id_grupo` = %d", $id_group);
AND `tagente`.`id_grupo` IN (%s) ORDER BY `tagente`.`nombre`", $id_group);
return get_db_all_rows_sql ($sql);
}
@ -589,12 +599,12 @@ function get_monitors_in_agent ($id_agent) {
*/
function get_monitors_down ($monitors, $period = 0, $date = 0) {
$monitors_down = array ();
if (! $monitors)
if (empty ($monitors))
return $monitors_down;
foreach ($monitors as $monitor) {
$down = get_monitor_downs_in_period ($monitor['id_agente_modulo'], $period, $date);
if ($down)
if ($down > 0)
array_push ($monitors_down, $monitor);
}
return $monitors_down;
@ -1302,13 +1312,13 @@ $sql_cache = array ('saved' => 0);
*/
function get_db_value ($field, $table, $field_search = 1, $condition = 1) {
if (is_int ($condition)) {
$sql = sprintf ("SELECT %s FROM `%s` WHERE %s = %d LIMIT 1",
$sql = sprintf ("SELECT %s FROM %s WHERE %s = %d LIMIT 1",
$field, $table, $field_search, $condition);
} else if (is_float ($condition) || is_double ($condition)) {
$sql = sprintf ("SELECT %s FROM `%s` WHERE `%s` = %f LIMIT 1",
$sql = sprintf ("SELECT %s FROM %s WHERE %s = %f LIMIT 1",
$field, $table, $field_search, $condition);
} else {
$sql = sprintf ("SELECT %s FROM `%s` WHERE `%s` = '%s' LIMIT 1",
$sql = sprintf ("SELECT %s FROM %s WHERE %s = '%s' LIMIT 1",
$field, $table, $field_search, $condition);
}
$result = get_db_all_rows_sql ($sql);
@ -1473,9 +1483,9 @@ function get_db_all_rows_in_table ($table, $order_field = "") {
*/
function get_db_all_rows_field_filter ($table, $field, $condition, $order_field = "") {
if (is_int ($condition)) {
$sql = sprintf ("SELECT * FROM `%s` WHERE `%s` = '%d'", $table, $field, $condition);
$sql = sprintf ("SELECT * FROM `%s` WHERE `%s` = %d", $table, $field, $condition);
} else if (is_float ($condition) || is_double ($condition)) {
$sql = sprintf ("SELECT * FROM `%s` WHERE `%s` = '%f'", $table, $field, $condition);
$sql = sprintf ("SELECT * FROM `%s` WHERE `%s` = %f", $table, $field, $condition);
} else {
$sql = sprintf ("SELECT * FROM `%s` WHERE `%s` = '%s'", $table, $field, $condition);
}

View File

@ -99,16 +99,14 @@ function print_select ($fields, $name, $selected = '', $script = '', $nothing =
* $nothing Label when nothing is selected.
* $nothing_value Value when nothing is selected
*/
function print_select_from_sql ($sql, $name, $selected = '', $script = '', $nothing = 'select', $nothing_value = '0', $return = false, $multiple = false, $sort = true) {
function print_select_from_sql ($sql, $name, $selected = '', $script = '', $nothing = '', $nothing_value = '0', $return = false, $multiple = false, $sort = true) {
$fields = array ();
$result = mysql_query ($sql);
if (! $result) {
echo mysql_error ();
$result = get_db_all_rows_sql ($sql);
if ($result === false)
return "";
}
while ($row = mysql_fetch_array ($result)) {
foreach ($result as $row) {
$fields[$row[0]] = $row[1];
}

View File

@ -374,22 +374,21 @@ function alert_reporting ($id_group, $period = 0, $date = 0, $return = false) {
* @param $return Flag to return or echo the report (by default).
*/
function monitor_health_reporting ($id_group, $period = 0, $date = 0, $return = false) {
if (! $date)
if (empty ($date)) //If date is 0, false or empty
$date = time ();
$datelimit = $date - $period;
$output = '';
$monitors = get_monitors_in_group ($id_group);
if (sizeof ($monitors) == 0)
if (empty ($monitors)) //If monitors has returned false or an empty array
return;
$monitors_down = get_monitors_down ($monitors, $period, $date);
$down_percentage = round (sizeof ($monitors_down) / sizeof ($monitors) * 100, 2);
$down_percentage = round (count ($monitors_down) / count ($monitors) * 100, 2);
$not_down_percentage = 100 - $down_percentage;
$output .= '<img src="reporting/fgraph.php?tipo=monitors_health_pipe&height=150&width=280&down='.
$down_percentage.'&not_down='.$not_down_percentage.'" style="float: right; border: 1px solid black">';
$output .= '<strong>'.__('Total monitors').': '.sizeof ($monitors).'</strong><br />';
$output .= '<strong>'.__('Monitors down on period').': '.sizeof ($monitors_down).'</strong><br />';
$output .= '<strong>'.__('Total monitors').': '.count ($monitors).'</strong><br />';
$output .= '<strong>'.__('Monitors down on period').': '.count ($monitors_down).'</strong><br />';
$table = get_monitors_down_reporting_table ($monitors_down);
$table->width = '100%';
@ -404,6 +403,9 @@ function monitor_health_reporting ($id_group, $period = 0, $date = 0, $return =
$output .= print_table ($table, true);
//Floating it was ugly, moved it to the bottom
$output .= '<img src="reporting/fgraph.php?tipo=monitors_health_pipe&height=150&width=280&down='.$down_percentage.'&amp;not_down='.$not_down_percentage.'" style="border: 1px solid black">';
if (!$return)
echo $output;
return $output;

View File

@ -34,7 +34,7 @@ if (! $id_report) {
$report = get_db_row ('treport', 'id_report', $id_report);
if (! give_acl ($config['id_user'], $report['id_group'], "AR")) {
audit_db ($config['id_user'], $REMOTE_ADDR, "ACL Violation","Trying to access graph builder");
audit_db ($config['id_user'], $REMOTE_ADDR, "ACL Violation","Trying to access graph reader");
include ("general/noaccess.php");
exit;
}
@ -60,11 +60,12 @@ $table->style[0] = 'font-weight: bold';
$table->size = array ();
$table->size[0] = '50px';
$table->data = array ();
$table->data[0][0] = '<img src="images/reporting.png" width="32" height="32">';
if ($report['description'] != '')
$table->data[0][0] = '<img src="images/reporting.png" width="32" height="32" />';
if ($report['description'] != '') {
$table->data[0][1] = $report['description'];
else
} else {
$table->data[0][1] = $report['name'];
}
$table->data[1][0] = __('Date');
$table->data[1][1] = print_input_text ('date', $date, '', 10, 10, true). ' ';
$table->data[1][1] .= print_input_text ('time', $time, '', 7, 7, true). ' ';
@ -76,7 +77,7 @@ print_input_hidden ('id_report', $id_report);
echo '</form>';
echo '<div id="loading">';
echo '<img src="images/wait.gif" border="0"><br />';
echo '<img src="images/wait.gif" border="0" /><br />';
echo '<strong>'.__('Loading').'...</strong>';
echo '</div>';
@ -90,8 +91,8 @@ echo '</div>';
<script src="include/javascript/jquery.ui.core.js"></script>
<script src="include/javascript/jquery.ui.datepicker.js"></script>
<script src="include/javascript/jquery.timeentry.js"></script>
<script src="include/languages/date_<?= $config['language'] ?>.js"></script>
<script src="include/languages/time_<?= $config['language'] ?>.js"></script>
<script src="include/languages/date_<?php echo $config['language']; ?>.js"></script>
<script src="include/languages/time_<?php echo $config['language']; ?>.js"></script>
<script language="javascript" type="text/javascript">
@ -99,7 +100,7 @@ $(document).ready (function () {
$("#loading").slideUp ();
$("#text-time").timeEntry ({spinnerImage: 'images/time-entry.png', spinnerSize: [20, 20, 0]});
$("#text-date").datepicker ();
$.datepicker.regional["<?= $config['language'] ?>"];
$.datepicker.regional["<?php echo $config['language']; ?>"];
});
</script>
@ -124,8 +125,7 @@ $table->rowclass = array ();
$table->rowclass[0] = 'datos3';
$group_name = dame_grupo ($report['id_group']);
$sql = sprintf ('SELECT * FROM treport_content WHERE id_report = %d ORDER BY `order`', $id_report);
$contents = get_db_all_rows_sql ($sql);
$contents = get_db_all_rows_field_filter ("treport_content","id_report",$id_report,"order");
if ($contents === false) {
return;
};
@ -163,11 +163,13 @@ foreach ($contents as $content) {
$data[2] = "<h4>".human_time_description ($content['period'])."</h4>";
array_push ($table->data, $data);
$sql2 = sprintf ('SELECT * FROM tgraph_source WHERE id_graph = %d', $content['id_gs']);
$res2 = mysql_query($sql2);
$result = get_db_all_rows_field_filter ("tgraph_source","id_graph",$content['id_gs']);
$modules = array ();
$weights = array ();
while ($content2 = mysql_fetch_array($res2)) {
if ($result === false)
$result = array();
foreach ($result as $content2) {
array_push ($modules, $content2['id_agent_module']);
array_push ($weights, $content2["weight"]);
}
@ -229,9 +231,9 @@ foreach ($contents as $content) {
$n = array_push ($table->data, $data);
}
if (sizeof ($slas)) {
if (!empty ($slas)) {
$data = array ();
if (! $sla_failed)
if ($sla_failed !== false)
$data[0] = '<span style="font: bold 3em Arial, Sans-serif; color: #000000;">'.__('Ok').'</span>';
else
$data[0] = '<span style="font: bold 3em Arial, Sans-serif; color: #ff0000;">'.__('Fail').'</span>';
@ -284,10 +286,10 @@ foreach ($contents as $content) {
$data = array ();
$monitor_value = format_numeric (get_agent_module_sla ($content['id_agent_module'], $content['period'], 1, 1, $datetime));
$data[0] = '<p style="font: bold 3em Arial, Sans-serif; color: #000000;">';
$data[0] .= $monitor_value.' % <img src="images/b_green.png" height="32" width="32"></p>';
$data[0] .= $monitor_value.' % <img src="images/b_green.png" height="32" width="32" /></p>';
$monitor_value2 = format_numeric (100 - $monitor_value, 2) ;
$data[1] = "<p style='font: bold 3em Arial, Sans-serif; color: #ff0000;'>";
$data[1] .= $monitor_value2.' % <img src="images/b_red.png" height="32" width="32"></p>';
$data[1] = '<p style="font: bold 3em Arial, Sans-serif; color: #ff0000;">';
$data[1] .= $monitor_value2.' % <img src="images/b_red.png" height="32" width="32" /></p>';
array_push ($table->data, $data);
break;

View File

@ -2133,11 +2133,11 @@ if ($graphic_type) {
break;
case 'monitors_health_pipe':
$data = array ();
$data[0] = (float) get_parameter ('down');
$data[1] = (float) get_parameter ('not_down');
$data[1] = (float) get_parameter ('down');
$data[0] = (float) get_parameter ('not_down');
$legends = array ();
$legends[0] = __('Monitors BAD');
$legends[1] = __('Monitors OK');
$legends[1] = __('Monitors BAD');
$legends[0] = __('Monitors OK');
generic_pie_graph ($width, $height, $data, $legends);
break;