From 5498a0e95bdce7e5883a90a04cec8ce19fd92548 Mon Sep 17 00:00:00 2001 From: guruevi Date: Tue, 30 Sep 2008 17:55:36 +0000 Subject: [PATCH] 2008-09-30 Evi Vanoost * 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; ¬ 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 --- pandora_console/ChangeLog | 27 ++++++++ .../godmode/reporting/reporting_builder.php | 63 ++++++++++--------- pandora_console/include/functions.php | 4 +- pandora_console/include/functions_db.php | 26 +++++--- pandora_console/include/functions_html.php | 10 ++- .../include/functions_reporting.php | 16 ++--- .../operation/reporting/reporting_viewer.php | 38 +++++------ pandora_console/reporting/fgraph.php | 8 +-- 8 files changed, 117 insertions(+), 75 deletions(-) diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 8baf0df3bb..6e74fd3a6f 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,30 @@ +2008-09-30 Evi Vanoost + + * 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; ¬ 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 * godmode/agentes/module_manager_editor_data.php, diff --git a/pandora_console/godmode/reporting/reporting_builder.php b/pandora_console/godmode/reporting/reporting_builder.php index 163c3e3f96..9b03d0e2d7 100644 --- a/pandora_console/godmode/reporting/reporting_builder.php +++ b/pandora_console/godmode/reporting/reporting_builder.php @@ -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 "

".__('Deleted successfully')."

"; - else + } else { echo "

".__('Not deleted. Error deleting data')."

"; + } } // 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 "

".__('Reporting successfully deleted')."

"; 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 '

'.__('Reporting successfully created').'

'; $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 "

".__('Reporting successfully created')."

"; - else + } else { echo "

".__('There was a problem creating reporting')."

"; - $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 "

".__('Updated successfully')."

"; - else + } else { echo "

".__('Not updated. Error updating data')."

"; + } } 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 "

".__('SLA was successfully created')."

"; - else + } else { echo "

".__('There was a problem creating SLA')."

"; + } } else { echo "

".__('Module is not set')."

"; } @@ -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 "

".__('SLA was successfully delete')."

"; - else + } else { echo "

".__('There was a problem deleting SLA')."

"; + } } $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 ''; echo ''; -} 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 "

".__('Reporting')." > "; echo __('Custom reporting builder')."

"; diff --git a/pandora_console/include/functions.php b/pandora_console/include/functions.php index a62ef8e81c..14b1fe2eb4 100644 --- a/pandora_console/include/functions.php +++ b/pandora_console/include/functions.php @@ -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: diff --git a/pandora_console/include/functions_db.php b/pandora_console/include/functions_db.php index 7f4d630798..d35f068327 100644 --- a/pandora_console/include/functions_db.php +++ b/pandora_console/include/functions_db.php @@ -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); } diff --git a/pandora_console/include/functions_html.php b/pandora_console/include/functions_html.php index f04f95a44a..9f5dde8d3f 100644 --- a/pandora_console/include/functions_html.php +++ b/pandora_console/include/functions_html.php @@ -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]; } diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index c9945eae28..65a9e68cd2 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -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 .= ''; - $output .= ''.__('Total monitors').': '.sizeof ($monitors).'
'; - $output .= ''.__('Monitors down on period').': '.sizeof ($monitors_down).'
'; + $output .= ''.__('Total monitors').': '.count ($monitors).'
'; + $output .= ''.__('Monitors down on period').': '.count ($monitors_down).'
'; $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 .= ''; + if (!$return) echo $output; return $output; diff --git a/pandora_console/operation/reporting/reporting_viewer.php b/pandora_console/operation/reporting/reporting_viewer.php index 0d951f1b4e..7feecfeb10 100644 --- a/pandora_console/operation/reporting/reporting_viewer.php +++ b/pandora_console/operation/reporting/reporting_viewer.php @@ -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] = ''; -if ($report['description'] != '') +$table->data[0][0] = ''; +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 ''; echo '
'; -echo '
'; +echo '
'; echo ''.__('Loading').'...'; echo '
'; @@ -90,8 +91,8 @@ echo ''; - - + + @@ -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] = "

".human_time_description ($content['period'])."

"; 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] = ''.__('Ok').''; else $data[0] = ''.__('Fail').''; @@ -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] = '

'; - $data[0] .= $monitor_value.' %

'; + $data[0] .= $monitor_value.' %

'; $monitor_value2 = format_numeric (100 - $monitor_value, 2) ; - $data[1] = "

"; - $data[1] .= $monitor_value2.' %

'; + $data[1] = '

'; + $data[1] .= $monitor_value2.' %

'; array_push ($table->data, $data); break; diff --git a/pandora_console/reporting/fgraph.php b/pandora_console/reporting/fgraph.php index 1ff9842eee..7c8a7652fd 100644 --- a/pandora_console/reporting/fgraph.php +++ b/pandora_console/reporting/fgraph.php @@ -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;