diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index da9e6f9ff2..11bfc315a3 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,14 @@ +2008-10-07 Evi Vanoost + + * include/functions_reporting.php: Handle empty and zero values in + get_agent_module_sla. + + * include/config_process.php: SLA Period shouldn't be 0 (which is + apparently default in the database). If SLA is empty (NULL, 0, false + or '') then it get's reset to a default value. + + * godmode/setup/setup.php: SLA Period was hidden because of a miscount + 2008-10-06 Evi Vanoost * godmode/agentes/configurar_agente.php: Double values in query removed diff --git a/pandora_console/godmode/setup/setup.php b/pandora_console/godmode/setup/setup.php index bcbec1fe64..97380347ec 100644 --- a/pandora_console/godmode/setup/setup.php +++ b/pandora_console/godmode/setup/setup.php @@ -19,13 +19,12 @@ // Load global vars require("include/config.php"); -if (comprueba_login()) { - audit_db ($config['id_user'], $REMOTE_ADDR, "ACL Violation", "Trying to access Setup Management"); - require ("general/noaccess.php"); -} +check_login (); + if (! give_acl ($config['id_user'], 0, "PM") || ! dame_admin ($config['id_user'])) { audit_db ($config['id_user'], $REMOTE_ADDR, "ACL Violation", "Trying to access Setup Management"); require ("general/noaccess.php"); + exit; } $update_settings = (bool) get_parameter ('update_settings'); @@ -90,32 +89,32 @@ $table->data[4][1] = print_input_text ('graph_color2', $config["graph_color2"], $table->data[5][0] = __('Graph color (max)'); $table->data[5][1] = print_input_text ('graph_color3', $config["graph_color3"], '', 8, 8, true); -$table->data[6][0] = __('SLA period'); -$table->data[6][1] = print_input_text ('sla_period', $config["sla_period"], '', 5, 5, true); +$table->data[6][0] = __('SLA period (seconds)'); +$table->data[6][1] = print_input_text ('sla_period', $config["sla_period"], '', 8, 8, true); -$table->data[6][0] = __('Max. days before compact data'); -$table->data[6][1] = print_input_text ('days_compact', $config["days_compact"], '', 5, 5, true); +$table->data[7][0] = __('Max. days before compact data'); +$table->data[7][1] = print_input_text ('days_compact', $config["days_compact"], '', 5, 5, true); -$table->data[7][0] = __('Max. days before purge'); -$table->data[7][1] = print_input_text ('days_purge', $config["days_purge"], '', 5, 5, true); +$table->data[8][0] = __('Max. days before purge'); +$table->data[8][1] = print_input_text ('days_purge', $config["days_purge"], '', 5, 5, true); -$table->data[8][0] = __('Graphic resolution (1-low, 5-high)'); -$table->data[8][1] = print_input_text ('graph_res', $config["graph_res"], '', 5, 5, true); +$table->data[9][0] = __('Graphic resolution (1-low, 5-high)'); +$table->data[9][1] = print_input_text ('graph_res', $config["graph_res"], '', 5, 5, true); -$table->data[9][0] = __('Compact interpolation in hours (1 Fine-20 bad)'); -$table->data[9][1] = print_input_text ('step_compact', $config["step_compact"], '', 5, 5, true); +$table->data[10][0] = __('Compact interpolation in hours (1 Fine-20 bad)'); +$table->data[10][1] = print_input_text ('step_compact', $config["step_compact"], '', 5, 5, true); -$table->data[10][0] = __('Show unknown modules in global view'); -$table->data[10][1] = print_checkbox ('show_unknown', 1, $config["show_unknown"], true); +$table->data[11][0] = __('Show unknown modules in global view'); +$table->data[11][1] = print_checkbox ('show_unknown', 1, $config["show_unknown"], true); -$table->data[11][0] = __('Show last fired alerts in global view'); -$table->data[11][1] = print_checkbox ('show_lastalerts', 1, $config["show_lastalerts"], true); +$table->data[12][0] = __('Show last fired alerts in global view'); +$table->data[12][1] = print_checkbox ('show_lastalerts', 1, $config["show_lastalerts"], true); -$table->data[12][0] = __('Style template'); -$table->data[12][1] = print_select ($file_styles, 'style', $config["style"], '', '', '', true); +$table->data[13][0] = __('Style template'); +$table->data[13][1] = print_select ($file_styles, 'style', $config["style"], '', '', '', true); -$table->data[13][0] = __('Block size for pagination'); -$table->data[13][1] = print_input_text ('block_size', $config["block_size"], '', 5, 5, true); +$table->data[14][0] = __('Block size for pagination'); +$table->data[14][1] = print_input_text ('block_size', $config["block_size"], '', 5, 5, true); echo '
'; print_input_hidden ('update_settings', 1); diff --git a/pandora_console/include/config_process.php b/pandora_console/include/config_process.php index a42d73adf5..83a9a061ee 100644 --- a/pandora_console/include/config_process.php +++ b/pandora_console/include/config_process.php @@ -34,9 +34,6 @@ $config["fontpath"] = $config["homedir"]."/reporting/FreeSans.ttf"; // Style (pandora by default) $config["style"] = "pandora"; -// Default period (in secs) for auto SLA calculation (for monitors) -$config["sla_period"] = 604800; - // Read remaining config tokens from DB if (! mysql_connect ($config["dbhost"], $config["dbuser"], $config["dbpass"])) { //Non-persistent connection. If you want persistent conn change it to mysql_pconnect() @@ -122,4 +119,9 @@ if (isset ($config['homeurl']) && $config['homeurl'][0] != '/') { $config['homeurl'] = '/'.$config['homeurl']; } +if (!isset ($config["sla_period"]) || empty ($config["sla_period"])) { + // Default period (in secs) for auto SLA calculation (for monitors) + $config["sla_period"] = 604800; +} + ?> diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 65a9e68cd2..6adf1c9274 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -29,18 +29,33 @@ * @return SLA percentage of the requested module. */ function get_agent_module_sla ($id_agent_module, $period, $min_value, $max_value, $date = 0) { - require("config.php"); - if (! $date) + if (empty ($date)) $date = time (); - $datelimit = $date - $period; // limit date - $id_agent = get_db_value ('id_agente', 'tagente_modulo', 'id_agente_modulo', $id_agent_module); + + if (empty ($period)) + return false; //We can't calculate a 0 period (division by zero) + + + $datelimit = $date - $period; // start date + + $id_agent = get_db_value ('id_agente', 'tagente_modulo', 'id_agente_modulo', (int) $id_agent_module); + if (empty ($id_agent)) + return 0; + //No agent connected to this module. Something bad in the database + /* Get all the data in the interval */ - $sql = sprintf ('SELECT * FROM tagente_datos + $sql = sprintf ('SELECT datos, utimestamp FROM tagente_datos WHERE id_agente = %d AND id_agente_modulo = %d AND utimestamp > %d AND utimestamp <= %d ORDER BY utimestamp ASC', $id_agent, $id_agent_module, $datelimit, $date); $datas = get_db_all_rows_sql ($sql); + + if ($datas === false) { + //No data to calculate on so we return 0. + return 0; + } + $last_data = ""; $total_badtime = 0; $interval_begin = 0; @@ -49,14 +64,12 @@ function get_agent_module_sla ($id_agent_module, $period, $min_value, $max_value /* Get also the previous data before the selected interval. */ $previous_data = get_previous_data ($id_agent_module, $datelimit); + if ($previous_data) { /* Add data to the beginning */ array_unshift ($datas, $previous_data); $previous_data_timestamp = $previous_data['utimestamp']; } - if ($datas === false) { - return false; - } foreach ($datas as $data) { if ($data["datos"] > $max_value || $data["datos"] < $min_value) {