diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 5e1352e954..a8d91890e9 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,67 +1,111 @@ +2008-06-15 Esteban Sanchez + + * include/functions_html.php: Added to repository. Implements HTML + functions. + + * reporting/fgraph.php: Many style correction fixes, including those + regardings tabs and blank spaces, variable names and indentation + levels for checkings. Improved dame_fecha(). Added date support to + graphic_combined_module(), grafico_modulo_sparse(). The selection of + the graphic to show based on parameters has been replaced by a switch. + The parameters are parsed with get_parameter() + + * include/functions_db.php: Style correction of tabs and blanks + spaces. Use Pandora database functions on simple querying functions + such as dame_perfil(), give_disabled_group(), dame_grupo(), + give_note_author(), dame_agente_id(), dame_agente_modulo_id() and many + more, there are a lot more to change. Function comprueba_admin() + renamed to check_admin (wrap created for old function). Added some + checks to get_db_value(), get_db_row() so the SQL is build based on + the parameter types. Added get_db_all_rows_sqlfree(), + get_db_all_rows_in_table(), get_db_all_rows_field_filter(), + get_db_all_fields_in_table(). Added date support to + return_moduledata_avg_value(), return_moduledata_max_value(), + return_moduledata_min_value(). Added function + return_moduledata_sum_value() to get the sum of the values in a + module. + + * include/functions.php: If input is numeric on safe_input, do not + clean it, since it's safe by itself. Use mysql_escape_string() on + salida_sql(). Added get_report_types(), get_report_name(), + get_report_type_data_source() relatives to reports. Added also + is_module_data(), is_module_proc(), is_module_inc(), + is_module_data_string() to know if a module is from a type. Replaced + form_priority() with get_event_types() so the caller of this function + will print the select (using print_select). + + * operation/events/events.php: Replaced form_priorit() with + get_event_types(). + + * ChangeLog: Tab style correction with previous commit. + 2008-06-13 Sancho Lerena - * status_events: added to view new events in agentg view + * status_events: added to view new events in agentg view. + + * index.php: Added pure (Fullscreen). HTML code cleanup and user + session. + + * pandoradb.sql: talert_snmp: Added priority field. + + * pandoradb_data.sql: Changes default values in talerta. tconfig_os, + tgrupo and some links. + + * header.php: Fixed some user session management. + + * logon_ok.php: New design for welcome screen, odometer is over. + + * menu.php, godmode/menu.php: Some ACL improvements. + + * agent_disk_conf_editor.php: Minor fix in view link. + + * configurar_agente.php, agent_manager.php: Added parent combo and + better ACL checks. New remote configuration control for get timestamp + info of config file. + + * modify_alert.php: Changes to use new internal Mail alert. + + * config.php: Some items moved to config_process. (font, attachment + and default style). + + * functions.php: Added form_agent_combo(), form_event_type_combo(), + form_priority() and return_priority() functions. + + * functions_db.php: Added smal_event_table() to render a variable + table with latest events (filtered). + + * pandora.css: Added pure and priority colors. + + * estado_alertas.php: Fixed ACL problems. + + * stado_generalagente.php: Graph of modules now represents modules + that has generated events. Old graph is not used anymore. Also display + parent. + + * estado_grupo.php: Border of boxes is now thicker. + + * tactical.php: New screen, almost all code changed. Odometer is not + used anymore, added some new items, like module LAG meter, module + sanity, and other general metrics. + + * ver_agente.php: Now renders also event for each agent view. Alert + manual validation generate a new event. + + * events.php: New event system. 90% new code. A LOT of new features, + including full screen, coloured (by priority) and filters by six + fields. + + * snmp_alert.php: Added support for alert priority. + + * operation/users/user.php: No longer a user with UM privileges could + see any other user. + + * render_view.php: Added fullscreen support for visual maps. + + * fgraph.php: Added support for session checking in graphs (at + least!). New graphics for events (some changed it's function like + events by group), and feature added to progress GD implementation. - * index.php: Added pure (Fullscreen). HTML code cleanup and user session. - - * pandoradb.sql: talert_snmp: Added priority field. - - * pandoradb_data.sql: Changes default values in talerta. tconfig_os, tgrupo - and some links. - - * header.php: Fixed some user session management. - - * logon_ok.php: New design for welcome screen, odometer is over. - - * menu.php, godmode/menu.php: Some ACL improvements. - - * agent_disk_conf_editor.php: Minor fix in view link. - - * configurar_agente.php, agent_manager.php: Added parent combo and better - ACL checks. New remote configuration control for get timestamp info of - config file. - - * modify_alert.php: Changes to use new internal Mail alert. - - * config.php: Some items moved to config_process. (font, attachment and - default style). - - * functions.php: Added form_agent_combo(), form_event_type_combo(), - form_priority() and return_priority() functions. - - * functions_db.php: Added smal_event_table() to render a variable table - with latest events (filtered). - - * pandora.css. Added pure and priority colors. - - * estado_alertas.php: Fixed ACL problems. - - * stado_generalagente.php: Graph of modules now represents modules that - has generated events. Old graph is not used anymore. Also display parent. - - * estado_grupo.php: Border of boxes is now thicker. - - * tactical.php: New screen, almost all code changed. Odometer is not used - anymore, added some new items, like module LAG meter, module sanity, and - other general metrics. - - * ver_agente.php: Now renders also event for each agent view. Alert manual - validation generate a new event. - - * events.php: New event system. 90% new code. A LOT of new features, - including full screen, coloured (by priority) and filters by six fields. - - * snmp_alert.php: Added support for alert priority. - - * operation/users/user.php: No longer a user with UM privileges could - see any other user. - - * render_view.php: Added fullscreen support for visual maps. - - * fgraph.php: Added support for session checking in graphs (at least!). - New graphics for events (some changed it's function like events by group), - and feature added to progress GD implementation. - 2008-06-09 Sancho Lerena * operation/agentes/status_monitor.php, diff --git a/pandora_console/include/functions.php b/pandora_console/include/functions.php index a2fa849a85..a200454be9 100644 --- a/pandora_console/include/functions.php +++ b/pandora_console/include/functions.php @@ -16,13 +16,14 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +require ('functions_html.php'); function pandora_help ($id, $return = false) { - global $config; - $output = ''; - if ($return) - return $return; - echo $output; + global $config; + $output = ''; + if ($return) + return $return; + echo $output; } // --------------------------------------------------------------- // safe_output() @@ -31,7 +32,7 @@ function pandora_help ($id, $return = false) { // --------------------------------------------------------------- function safe_output ($string) { - return preg_replace('/[^\x09\x0A\x0D\x20-\x7F]/e', '"&#".ord($0).";"', $string); + return preg_replace('/[^\x09\x0A\x0D\x20-\x7F]/e', '"&#".ord($0).";"', $string); } // --------------------------------------------------------------- @@ -39,8 +40,10 @@ function safe_output ($string) { // Get parameter, using UTF8 encoding, and cleaning bad codes // --------------------------------------------------------------- -function safe_input ($string) { - return htmlentities(utf8_decode($string), ENT_QUOTES); +function safe_input ($value) { + if (is_numeric ($value)) + return $value; + return htmlentities (utf8_decode ($value), ENT_QUOTES); } // --------------------------------------------------------------- @@ -49,8 +52,7 @@ function safe_input ($string) { // --------------------------------------------------------------- function salida_sql ($string) { - $body = str_replace("\'", "'", $string); - return $body; + return mysql_escape_string ($string); } @@ -71,8 +73,8 @@ function midebug($var, $mesg){ function array_in($exampleArray, $item){ $result = 0; foreach ($exampleArray as $key => $value){ - if ($value == $item){ - $result = 1; + if ($value == $item){ + $result = 1; } } return $result; @@ -100,7 +102,6 @@ function salida_limpia ($string){ function clean_output_breaks ($string){ $myoutput = salida_limpia($string); return preg_replace ('/\n/',"
", $myoutput); - } @@ -131,7 +132,7 @@ function parametro_limpio($texto){ // Consiste en purgar los http:// de las cadenas $pos = strpos($texto,"://"); // quitamos la parte "fea" de http:// o ftp:// o telnet:// :-))) if ($pos <> 0) - $texto = substr_replace($texto,"",$pos,+3); + $texto = substr_replace($texto,"",$pos,+3); // limitamos la entrada de datos por parametros a 125 caracteres $texto = substr_replace($texto,"",125); $safe = preg_replace('/[^a-z0-9_\/]/i','',$texto); @@ -144,7 +145,7 @@ function parametro_limpio($texto){ // string closeOpenTags(string string [, string beginChar [, stringEndChar [, string CloseChar]]]); -function closeOpenTags($str, $open = "<", $close = ">", $end = "/", $tokens = "_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") +function closeOpenTags ($str, $open = "<", $close = ">", $end = "/", $tokens = "_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") { $chars = array(); for ($i = 0; $i < strlen($tokens); $i++) { $chars[] = substr($tokens, $i, 1); } @@ -193,41 +194,38 @@ function closeOpenTags($str, $open = "<", $close = ">", $end = "/", $tokens = "_ // --------------------------------------------------------------- function give_human_time ($int_seconds){ - $key_suffix = 's'; - $periods = array( - 'year' => 31556926, - 'month' => 2629743, - 'day' => 86400, - 'hour' => 3600, - 'minute' => 60, - 'second' => 1 - ); + $key_suffix = 's'; + $periods = array('year' => 31556926, + 'month' => 2629743, + 'day' => 86400, + 'hour' => 3600, + 'minute' => 60, + 'second' => 1 + ); - // used to hide 0's in higher periods - $flag_hide_zero = true; + // used to hide 0's in higher periods + $flag_hide_zero = true; - // do the loop thang - foreach( $periods as $key => $length ) - { - // calculate - $temp = floor( $int_seconds / $length ); + // do the loop thang + foreach( $periods as $key => $length ) { + // calculate + $temp = floor( $int_seconds / $length ); - // determine if temp qualifies to be passed to output - if( !$flag_hide_zero || $temp > 0 ) - { - // store in an array - $build[] = $temp.' '.$key.($temp!=1?'s':null); + // determine if temp qualifies to be passed to output + if( !$flag_hide_zero || $temp > 0 ) { + // store in an array + $build[] = $temp.' '.$key.($temp!=1?'s':null); - // set flag to false, to allow 0's in lower periods - $flag_hide_zero = false; - } + // set flag to false, to allow 0's in lower periods + $flag_hide_zero = false; + } - // get the remainder of seconds - $int_seconds = fmod($int_seconds, $length); - } + // get the remainder of seconds + $int_seconds = fmod($int_seconds, $length); + } - // return output, if !empty, implode into string, else output $if_reached - return ( !empty($build)?implode(', ', $build):$if_reached ); + // return output, if !empty, implode into string, else output $if_reached + return ( !empty($build)?implode(', ', $build):$if_reached ); } // --------------------------------------------------------------- @@ -261,54 +259,53 @@ function no_permission () { // --------------------------------------------------------------- function unmanaged_error ($error = "") { - require("config.php"); - require ("include/languages/language_".$config["language"].".php"); - echo "

".lang_string("Unmanaged error")."

"; - echo "error

"; - echo ""; - echo "
"; - echo lang_string("Unmanaged error_text"); - echo "
"; - echo $error; - echo "
"; - echo ""; - include "general/footer.php"; - exit; + require("config.php"); + require ("include/languages/language_".$config["language"].".php"); + echo "

".lang_string("Unmanaged error")."

"; + echo "error

"; + echo ""; + echo "
"; + echo lang_string("Unmanaged error_text"); + echo "
"; + echo $error; + echo "
"; + echo ""; + include "general/footer.php"; + exit; } function list_files($directory, $stringSearch, $searchHandler, $outputHandler) { - $errorHandler = false; - $result = array(); - if (! $directoryHandler = @opendir ($directory)) { - echo ("
\nerror: directory \"$directory\" doesn't exist!\n
\n"); - return $errorHandler = true; - } - if ($searchHandler == 0) { + $errorHandler = false; + $result = array(); + if (! $directoryHandler = @opendir ($directory)) { + echo ("
\nerror: directory \"$directory\" doesn't exist!\n
\n"); + return $errorHandler = true; + } + if ($searchHandler == 0) { while (false !== ($fileName = @readdir ($directoryHandler))) { @array_push ($result, $fileName); } - } - if ($searchHandler == 1) { - while(false !== ($fileName = @readdir ($directoryHandler))) { - if(@substr_count ($fileName, $stringSearch) > 0) { - @array_push ($result, $fileName); - } - } - } - if (($errorHandler == true) && (@count ($result) === 0)) { - echo ("
\nerror: no filetype \"$fileExtension\" found!\n
\n"); - } - else { - sort ($result); - if ($outputHandler == 0) { - return $result; - } - if ($outputHandler == 1) { - echo ("
\n");
-   			print_r ($result);
-   			echo ("
\n"); - } - } + } + if ($searchHandler == 1) { + while(false !== ($fileName = @readdir ($directoryHandler))) { + if(@substr_count ($fileName, $stringSearch) > 0) { + @array_push ($result, $fileName); + } + } + } + if (($errorHandler == true) && (@count ($result) === 0)) { + echo ("
\nerror: no filetype \"$fileExtension\" found!\n
\n"); + } else { + sort ($result); + if ($outputHandler == 0) { + return $result; + } + if ($outputHandler == 1) { + echo ("
\n");
+			print_r ($result);
+			echo ("
\n"); + } + } } @@ -417,7 +414,7 @@ function pagination ($count, $url, $offset ) { // --------------------------------------------------------------- // Render data in a fashion way :-) // --------------------------------------------------------------- -function format_numeric ( $number, $decimals=2, $dec_point=".", $thousands_sep=",") { +function format_numeric ($number, $decimals = 2, $dec_point = ".", $thousands_sep = ",") { if ($number == 0) return 0; // If has decimals @@ -444,9 +441,8 @@ function format_for_graph ( $number , $decimals=2, $dec_point=".", $thousands_se return number_format ($number/1000, 0, $dec_point, $thousands_sep )." K"; // If has decimals if (fmod ($number , 1)> 0) - return number_format ($number, $decimals, $dec_point, $thousands_sep); - else - return number_format ($number, 0, $dec_point, $thousands_sep); + return number_format ($number, $decimals, $dec_point, $thousands_sep); + return number_format ($number, 0, $dec_point, $thousands_sep); } function give_parameter_get ( $name, $default = "" ){ @@ -576,443 +572,565 @@ function render_time ($lapse) { } function get_parameter ($name, $default = '') { - // POST has precedence - if (isset($_POST[$name])) - return get_parameter_post ($name, $default); - - if (isset($_GET[$name])) - return get_parameter_get ($name, $default); - - return $default; + // POST has precedence + if (isset($_POST[$name])) + return get_parameter_post ($name, $default); + + if (isset($_GET[$name])) + return get_parameter_get ($name, $default); + + return $default; } function get_parameter_get ($name, $default = "") { - if ((isset ($_GET[$name])) && ($_GET[$name] != "")) - return safe_input ($_GET[$name]); - - return $default; + if ((isset ($_GET[$name])) && ($_GET[$name] != "")) + return safe_input ($_GET[$name]); + + return $default; } function get_parameter_post ( $name, $default = "" ){ - if ((isset ($_POST[$name])) && ($_POST[$name] != "")) - return safe_input ($_POST[$name]); - - return $default; + if ((isset ($_POST[$name])) && ($_POST[$name] != "")) + return safe_input ($_POST[$name]); + + return $default; } -function get_alert_priority ( $prio = 0){ - global $config; - switch ($prio){ - case 0: - $priority = lang_string("Maintenance"); - break; - case 1: - $priority = lang_string("Informational"); - break; - case 2: - $priority = lang_string("Normal"); - break; - case 3: - $priority = lang_string("Warning"); - break; - case 4: - $priority = lang_string("Critical"); - break; - } - return $priority; +function get_alert_priority ($priority = 0) { + global $config; + switch ($prio) { + case 0: + return lang_string("Maintenance"); + break; + case 1: + return lang_string("Informational"); + break; + case 2: + return lang_string("Normal"); + break; + case 3: + return lang_string("Warning"); + break; + case 4: + return lang_string("Critical"); + break; + } + return ''; } function get_alert_days ( $row ){ - global $config; - global $lang_label; - $days_output = ""; + global $config; + global $lang_label; + $days_output = ""; - $check = $row["monday"] + $row["tuesday"] + $row["wednesday"] + $row["thursday"]+ $row["friday"] + $row["saturday"] + $row["sunday"]; - - if ($row["monday"] != 0) - $days_output .= "Mo"; - if ($row["tuesday"] != 0) - $days_output .= "Tu"; - if ($row["wednesday"] != 0) - $days_output .= "We"; - if ($row["thursday"] != 0) - $days_output .= "Th"; - if ($row["friday"] != 0) - $days_output .= "Fr"; - if ($row["saturday"] != 0) - $days_output .= "Sa"; - if ($row["sunday"] != 0) - $days_output .= "Su"; - if ($days_output == "") - $days_output = lang_string ("none"); - if ($check == 7) - $days_output = lang_string ("all"); - return $days_output; + $check = $row["monday"] + $row["tuesday"] + $row["wednesday"] + $row["thursday"]+ $row["friday"] + $row["saturday"] + $row["sunday"]; + + if ($row["monday"] != 0) + return "Mo"; + if ($row["tuesday"] != 0) + return "Tu"; + if ($row["wednesday"] != 0) + return "We"; + if ($row["thursday"] != 0) + return "Th"; + if ($row["friday"] != 0) + return "Fr"; + if ($row["saturday"] != 0) + return "Sa"; + if ($row["sunday"] != 0) + return "Su"; + if ($check == 7) + return lang_string ("all"); + + return lang_string ("none"); } function get_alert_times ($row2){ - global $config; - global $lang_label; + global $config; + global $lang_label; - if ($row2["time_from"]){ - $time_from_table = $row2["time_from"]; - } else { - $time_from_table = lang_string("N/A"); - } - if ($row2["time_to"]){ - $time_to_table = $row2["time_to"]; - } else { - $time_to_table = lang_string("N/A"); - } - $string = ""; - if ($time_to_table == $time_from_table) - $string .= $lang_label["N/A"]; - else - $string .= substr($time_from_table,0,5)." - ".substr($time_to_table,0,5); - return $string; + if ($row2["time_from"]){ + $time_from_table = $row2["time_from"]; + } else { + $time_from_table = lang_string("N/A"); + } + if ($row2["time_to"]){ + $time_to_table = $row2["time_to"]; + } else { + $time_to_table = lang_string("N/A"); + } + $string = ""; + if ($time_to_table == $time_from_table) + $string .= $lang_label["N/A"]; + else + $string .= substr($time_from_table,0,5)." - ".substr($time_to_table,0,5); + return $string; } function show_alert_row_edit ($row2, $tdcolor = "datos", $id_tipo_modulo = 1, $combined = 0){ - global $config; - global $lang_label; + global $config; + global $lang_label; - $string = ""; - if ($row2["disable"] == 1){ - $string .= "".$lang_label["disabled"].""; - } elseif ($id_tipo_modulo != 0) { - $string .= ""; - } else { - $string .= "--"; - } - - if (isset($row2["operation"])){ - $string = $string."".$row2["operation"]; - } else { - $string = $string."".get_db_sql("SELECT nombre FROM talerta WHERE id_alerta = ".$row2["id_alerta"]); - } + $string = ""; + if ($row2["disable"] == 1){ + $string .= "".$lang_label["disabled"].""; + } elseif ($id_tipo_modulo != 0) { + $string .= ""; + } else { + $string .= "--"; + } - $string = $string."".human_time_description($row2["time_threshold"]); - if ($row2["dis_min"]!=0){ - $mytempdata = fmod($row2["dis_min"], 1); - if ($mytempdata == 0) - $mymin = intval($row2["dis_min"]); - else - $mymin = $row2["dis_min"]; - $mymin = format_for_graph($mymin ); - } else { - $mymin = 0; - } + if (isset($row2["operation"])){ + $string = $string."".$row2["operation"]; + } else { + $string = $string."".get_db_sql("SELECT nombre FROM talerta WHERE id_alerta = ".$row2["id_alerta"]); + } - if ($row2["dis_max"]!=0){ - $mytempdata = fmod($row2["dis_max"], 1); - if ($mytempdata == 0) - $mymax = intval($row2["dis_max"]); - else - $mymax = $row2["dis_max"]; - $mymax = format_for_graph($mymax ); - } else { - $mymax = 0; - } + $string = $string."".human_time_description($row2["time_threshold"]); + if ($row2["dis_min"]) { + $mytempdata = fmod($row2["dis_min"], 1); + if ($mytempdata == 0) + $mymin = intval($row2["dis_min"]); + else + $mymin = $row2["dis_min"]; + $mymin = format_for_graph($mymin ); + } else { + $mymin = 0; + } - if (($mymin == 0) && ($mymax == 0)){ - $mymin = lang_string ("N/A"); - $mymax = $mymin; - } + if ($row2["dis_max"]!=0){ + $mytempdata = fmod($row2["dis_max"], 1); + if ($mytempdata == 0) + $mymax = intval($row2["dis_max"]); + else + $mymax = $row2["dis_max"]; + $mymax = format_for_graph($mymax ); + } else { + $mymax = 0; + } - // We have alert text ? - if ($row2["alert_text"]!= "") { - $string = $string."".$lang_label["text"].""; - } else { - $string = $string."".$mymin.""; - $string = $string."".$mymax.""; - } + if (($mymin == 0) && ($mymax == 0)) { + $mymin = lang_string ("N/A"); + $mymax = $mymin; + } - // Alert times - $string = $string.""; - $string .= get_alert_times ($row2); + // We have alert text ? + if ($row2["alert_text"]!= "") { + $string = $string."".$lang_label["text"].""; + } else { + $string = $string."".$mymin.""; + $string = $string."".$mymax.""; + } - // Description - $string = $string."".salida_limpia ($row2["descripcion"]); + // Alert times + $string = $string.""; + $string .= get_alert_times ($row2); - // Has recovery notify activated ? - if ($row2["recovery_notify"] > 0) - $recovery_notify = lang_string("Yes"); - else - $recovery_notify = lang_string("No"); - - // calculate priority - $priority = get_alert_priority ($row2["priority"]); + // Description + $string = $string."".salida_limpia ($row2["descripcion"]); - // calculare firing conditions - if ($row2["alert_text"] != ""){ - $firing_cond = lang_string("text")."(".substr($row2["alert_text"],0,8).")"; - } else { - $firing_cond = $row2["min_alerts"]." / ".$row2["max_alerts"]; - } - // calculate days - $firing_days = get_alert_days ( $row2 ); + // Has recovery notify activated ? + if ($row2["recovery_notify"] > 0) + $recovery_notify = lang_string("Yes"); + else + $recovery_notify = lang_string("No"); - // More details EYE tooltip - $string = $string.""; - $string.= ""; + // calculate priority + $priority = get_alert_priority ($row2["priority"]); - // Add float info table - $string.= " - - - - - - - - - - -
". - lang_string("Recovery")."
$recovery_notify
". - lang_string("Priority")."
$priority
". - lang_string("Alert Ctrl.")."
".$firing_cond."
". - lang_string("Firing days")."
".$firing_days."
"; + // calculare firing conditions + if ($row2["alert_text"] != "") { + $firing_cond = lang_string("text")."(".substr($row2["alert_text"],0,8).")"; + } else { + $firing_cond = $row2["min_alerts"]." / ".$row2["max_alerts"]; + } + // calculate days + $firing_days = get_alert_days ( $row2 ); + // More details EYE tooltip + $string = $string.""; + $string.= ""; - return $string; + // Add float info table + $string.= " + + + + + + + + + + +
". + lang_string("Recovery")."
$recovery_notify
". + lang_string("Priority")."
$priority
". + lang_string("Alert Ctrl.")."
".$firing_cond."
". + lang_string("Firing days")."
".$firing_days."
"; + + return $string; } function show_alert_show_view ($data, $tdcolor = "datos", $combined = 0){ - global $config; - global $lang_label; + global $config; + global $lang_label; - if ($combined == 0){ - $module_name = get_db_sql ("SELECT nombre FROM tagente_modulo WHERE id_agente_modulo = ".$data["id_agente_modulo"]); - $agent_name = get_db_sql ("SELECT tagente.nombre FROM tagente_modulo, tagente WHERE tagente_modulo.id_agente = tagente.id_agente AND tagente_modulo.id_agente_modulo = ".$data["id_agente_modulo"]); - $id_agente = get_db_sql ("SELECT id_agente FROM tagente_modulo WHERE id_agente_modulo = ".$data["id_agente_modulo"]); - } else { - $agent_name = get_db_sql ("SELECT nombre FROM tagente WHERE id_agente =".$data["id_agent"]); - $id_agente = $data["id_agent"]; - } - $alert_name = get_db_sql ("SELECT nombre FROM talerta WHERE id_alerta = ".$data["id_alerta"]); + if ($combined == 0){ + $module_name = get_db_sql ("SELECT nombre FROM tagente_modulo WHERE id_agente_modulo = ".$data["id_agente_modulo"]); + $agent_name = get_db_sql ("SELECT tagente.nombre FROM tagente_modulo, tagente WHERE tagente_modulo.id_agente = tagente.id_agente AND tagente_modulo.id_agente_modulo = ".$data["id_agente_modulo"]); + $id_agente = get_db_sql ("SELECT id_agente FROM tagente_modulo WHERE id_agente_modulo = ".$data["id_agente_modulo"]); + } else { + $agent_name = get_db_sql ("SELECT nombre FROM tagente WHERE id_agente =".$data["id_agent"]); + $id_agente = $data["id_agent"]; + } + $alert_name = get_db_sql ("SELECT nombre FROM talerta WHERE id_alerta = ".$data["id_alerta"]); - echo "".$alert_name.""; - if ($combined == 0){ - echo "".substr($module_name,0,21).""; - } else { - echo ""; - // More details EYE tooltip (combined) - echo " "; - echo show_alert_row_mini ($data["id_aam"]); - echo " "; - echo substr($agent_name,0,21).""; - } + echo "".$alert_name.""; + if ($combined == 0) { + echo "".substr($module_name,0,21).""; + } else { + echo ""; + // More details EYE tooltip (combined) + echo " "; + echo show_alert_row_mini ($data["id_aam"]); + echo " "; + echo substr($agent_name,0,21).""; + } - // Description - echo "".$data["descripcion"].""; + // Description + echo "".$data["descripcion"].""; - // Extended info - echo ""; + // Extended info + echo ""; - // Has recovery notify activated ? - if ($data["recovery_notify"] > 0) - $recovery_notify = lang_string("Yes"); - else - $recovery_notify = lang_string("No"); - - // calculate priority - $priority = get_alert_priority ($data["priority"]); + // Has recovery notify activated ? + if ($data["recovery_notify"] > 0) + $recovery_notify = lang_string("Yes"); + else + $recovery_notify = lang_string("No"); - // calculare firing conditions - if ($data["alert_text"] != ""){ - $firing_cond = lang_string("text")."(".substr($data["alert_text"],0,8).")"; - } else { - $firing_cond = $data["min_alerts"]." / ".$data["max_alerts"]; - } - // calculate days - $firing_days = get_alert_days ($data); + // calculate priority + $priority = get_alert_priority ($data["priority"]); - // More details EYE tooltip - echo ""; + // calculare firing conditions + if ($data["alert_text"] != ""){ + $firing_cond = lang_string("text")."(".substr($data["alert_text"],0,8).")"; + } else { + $firing_cond = $data["min_alerts"]." / ".$data["max_alerts"]; + } + // calculate days + $firing_days = get_alert_days ($data); - // Add float info table - echo " - - - - - - - - - - -
". - lang_string("Recovery")."
$recovery_notify
". - lang_string("Priority")."
$priority
". - lang_string("Alert Ctrl.")."
".$firing_cond."
". - lang_string("Firing days")."
".$firing_days."
"; + // More details EYE tooltip + echo ""; - $mytempdata = fmod($data["dis_min"], 1); - if ($mytempdata == 0) - $mymin = intval($data["dis_min"]); - else - $mymin = $data["dis_min"]; - $mymin = format_for_graph($mymin ); + // Add float info table + echo " + + + + + + + + + +
". + lang_string("Recovery")."
$recovery_notify
". + lang_string("Priority")."
$priority
". + lang_string("Alert Ctrl.")."
".$firing_cond."
". + lang_string("Firing days")."
".$firing_days."
"; - $mytempdata = fmod($data["dis_max"], 1); - if ($mytempdata == 0) - $mymax = intval($data["dis_max"]); - else - $mymax = $data["dis_max"]; - $mymax = format_for_graph($mymax ); - // Text alert ? - if ($data["alert_text"] != "") - echo "".$lang_label["text"].""; - else { - echo "".$mymin.""; - echo "".$mymax.""; - } - echo "".human_time_description($data["time_threshold"]); - if ($data["last_fired"] == "0000-00-00 00:00:00") { - echo "".$lang_label["never"].""; - } - else { - echo "".human_time_comparation ($data["last_fired"]).""; - } - echo "".$data["times_fired"].""; - if ($data["times_fired"] <> 0){ - echo ""; - echo ""; - $id_grupo_alerta = get_db_value ("id_grupo", "tagente", "id_agente", $id_agente); - if (give_acl($config["id_user"], $id_grupo_alerta, "AW") == 1) { - echo ""; - echo ""; - echo ""; - } - } else - echo ""; + $mytempdata = fmod($data["dis_min"], 1); + if ($mytempdata == 0) + $mymin = intval($data["dis_min"]); + else + $mymin = $data["dis_min"]; + $mymin = format_for_graph($mymin ); + + $mytempdata = fmod($data["dis_max"], 1); + if ($mytempdata == 0) + $mymax = intval($data["dis_max"]); + else + $mymax = $data["dis_max"]; + $mymax = format_for_graph($mymax ); + // Text alert ? + if ($data["alert_text"] != "") + echo "".$lang_label["text"].""; + else { + echo "".$mymin.""; + echo "".$mymax.""; + } + echo "".human_time_description($data["time_threshold"]); + if ($data["last_fired"] == "0000-00-00 00:00:00") { + echo "".$lang_label["never"].""; + } else { + echo "".human_time_comparation ($data["last_fired"]).""; + } + echo "".$data["times_fired"].""; + if ($data["times_fired"] <> 0){ + echo ""; + echo ""; + $id_grupo_alerta = get_db_value ("id_grupo", "tagente", "id_agente", $id_agente); + if (give_acl($config["id_user"], $id_grupo_alerta, "AW") == 1) { + echo ""; + echo ""; + echo ""; + } + } else { + echo " + "; + } } function form_render_check ($name_form, $value_form = 1){ - echo ""; + echo ""; } +/** + * Get report types in an array. + * + * @return An array with all the possible reports in Pandora where the array index is the report id. + */ +function get_report_types () { + $types = array (); + $types['simple_graph'] = lang_string ('simple_graph'); + $types['custom_graph'] = lang_string ('custom_graph'); + $types['SLA'] = lang_string ('SLA'); + $types['event_report'] = lang_string ('event_report'); + $types['alert_report'] = lang_string ('alert_report'); + $types['monitor_report'] = lang_string ('monitor_report'); + $types['avg_value'] = lang_string ('avg_value'); + $types['max_value'] = lang_string ('max_value'); + $types['min_value'] = lang_string ('min_value'); + $types['sumatory'] = lang_string ('sumatory'); + $types['general_group_report'] = lang_string ('general_group_report'); -function form_event_type_combo ($name_form, $value_form = ""){ - echo ""; + return $types; } +/** + * Get report type name from type id. + * + * @param $type Type id of the report. + * + * @return Report type name. + */ +function get_report_name ($type) { + $types = get_report_types (); + if (! isset ($types[$type])) + return lang_string ('unknown'); + return $types[$type]; +} -function form_priority ($priority = 0, $form_name = "priority", $show_all = 0){ - global $config; - - echo '"; +/** + * Get report type name from type id. + * + * @param $type Type id of the report. + * + * @return Report type name. + */ +function get_report_type_data_source ($type) { + switch ($type) { + case 1: + case 'simple_graph': + case 7: + case 'avg_value': + case 8: + case 'max_value': + case 9: + case 'min_value': + case 10: + case 'sumatory': + return 'module'; + case 2: + case 'custom_graph': + return 'custom-graph'; + case 3: + case 'SLA': + case 4: + case 'event_report': + case 5: + case 'alert_report': + case 6: + case 'monitor_report': + case 11: + case 'general_group_report': + return 'agent-group'; + } + return 'unknown'; +} + +/** + * Checks if a module is of type "data" + * + * @param $module_name Module name to check. + * + * @return true if the module is of type "date" + */ +function is_module_data ($module_name) { + $result = ereg ("^(.*_data)$", $module_name); + if ($result === false) + return false; + return true; +} + +/** + * Checks if a module is of type "proc" + * + * @param $module_name Module name to check. + * + * @return true if the module is of type "proc" + */ +function is_module_proc ($module_name) { + $result = ereg ('^(.*_proc)$', $module_name); + if ($result === false) + return false; + return true; +} + +/** + * Checks if a module is of type "inc" + * + * @param $module_name Module name to check. + * + * @return true if the module is of type "inc" + */ +function is_module_inc ($module_name) { + $result = ereg ('^(.*_inc)$', $module_name); + if ($result === false) + return false; + return true; +} + +/** + * Checks if a module is of type "string" + * + * @param $module_name Module name to check. + * + * @return true if the module is of type "string" + */ +function is_module_data_string ($module_name) { + $result = ereg ('^(.*string)$', $module_name); + if ($result === false) + return false; + return true; +} + +function get_event_types () { + $types = array (); + $types['unknown'] = lang_string ('unknown'); + $types['monitor_up'] = lang_string ('monitor_up'); + $types['monitor_down'] = lang_string ('monitor_down'); + $types['alert_fired'] = lang_string ('alert_fired'); + $types['alert_recovered'] = lang_string ('alert_recovered'); + $types['alert_ceased'] = lang_string ('alert_ceased'); + $types['alert_manual_validation'] = lang_string ('alert_manual_validation'); + $types['recon_host_detected'] = lang_string ('recon_host_detected'); + $types['system'] = lang_string ('sytem'); + $types['error'] = lang_string ('error'); + + return $types; +} + +function form_priority ($priority = 0, $form_name = "priority", $show_all = 0) { + global $config; + + echo '"; } function return_priority ($priority){ - global $config; - - switch ($priority) { - case 0: - return lang_string("Maintenance"); - case 1: - return lang_string("Informational"); - case 2: - return lang_string("Normal"); - case 3: - return lang_string("Warning"); - case 4: - return lang_string("Critical"); - case -1: - return lang_string("All"); - } + global $config; + + switch ($priority) { + case 0: + return lang_string ("Maintenance"); + case 1: + return lang_string ("Informational"); + case 2: + return lang_string ("Normal"); + case 3: + return lang_string ("Warning"); + case 4: + return lang_string ("Critical"); + case -1: + return lang_string ("All"); + } } // Show combo with agents -function form_agent_combo ($id_agent = 0, $form_name = "id_agent"){ - global $config; - echo '"; +function form_agent_combo ($id_agent = 0, $form_name = "id_agent") { + global $config; + echo '"; } ?> diff --git a/pandora_console/include/functions_db.php b/pandora_console/include/functions_db.php index 1423c4b2f2..23c6d94141 100644 --- a/pandora_console/include/functions_db.php +++ b/pandora_console/include/functions_db.php @@ -15,25 +15,25 @@ function check_login() { - global $config; - if (!isset($config["homedir"])){ - // No exists $config. Exit inmediatly - include ("general/noaccess.php"); - exit; - } - if ((isset($_SESSION["id_usuario"])) AND ($_SESSION["id_usuario"] != "")) { - $id = $_SESSION["id_usuario"]; - $query1="SELECT id_usuario FROM tusuario WHERE id_usuario= '$id'"; - $resq1 = mysql_query($query1); - $rowdup = mysql_fetch_array($resq1); - $nombre = $rowdup[0]; - if ( $id == $nombre ){ - return 0 ; - } - } - audit_db("N/A", getenv("REMOTE_ADDR"), "No session", "Trying to access without a valid session"); - include ($config["homedir"]."/general/noaccess.php"); - exit; + global $config; + if (!isset($config["homedir"])){ + // No exists $config. Exit inmediatly + include ("general/noaccess.php"); + exit; + } + if ((isset($_SESSION["id_usuario"])) AND ($_SESSION["id_usuario"] != "")) { + $id = $_SESSION["id_usuario"]; + $query1="SELECT id_usuario FROM tusuario WHERE id_usuario= '$id'"; + $resq1 = mysql_query($query1); + $rowdup = mysql_fetch_array($resq1); + $nombre = $rowdup[0]; + if ( $id == $nombre ){ + return 0 ; + } + } + audit_db("N/A", getenv("REMOTE_ADDR"), "No session", "Trying to access without a valid session"); + include ($config["homedir"]."/general/noaccess.php"); + exit; } // --------------------------------------------------------------- @@ -136,30 +136,16 @@ function logoff_db($id,$ip){ // Returns profile given ID // --------------------------------------------------------------- -function dame_perfil($id){ - require("config.php"); - $query1="SELECT * FROM tperfil WHERE id_perfil =".$id; - $resq1=mysql_query($query1); - if ($rowdup=mysql_fetch_array($resq1)){ - $cat=$rowdup["name"]; - } - else $cat = ""; - return $cat; +function dame_perfil ($id_profile) { + return (string) get_db_value ('name', 'tperfil', 'id_perfil', (int) $id_profile); } // --------------------------------------------------------------- // Returns disabled from a given group_id // --------------------------------------------------------------- -function give_disabled_group($id){ - require("config.php"); - $query1="SELECT * FROM tgrupo WHERE id_grupo =".$id; - $resq1=mysql_query($query1); - if ($rowdup=mysql_fetch_array($resq1)){ - $cat=$rowdup["disabled"]; - } - else $cat = ""; - return $cat; +function give_disabled_group ($id_group) { + return (bool) get_db_value ('disabled', 'tgroup', 'id_grupo', (int) $id_group); } @@ -168,45 +154,24 @@ function give_disabled_group($id){ // Returns group given ID // --------------------------------------------------------------- -function dame_grupo($id){ - require("config.php"); - $query1="SELECT * FROM tgrupo WHERE id_grupo =".$id; - $resq1=mysql_query($query1); - if ($rowdup=mysql_fetch_array($resq1)){ - $cat=$rowdup["nombre"]; - } - else $cat = ""; - return $cat; +function dame_grupo ($id_group) { + return (string) get_db_value ('nombre', 'tgrupo', 'id_grupo', (int) $id_group); } // --------------------------------------------------------------- // Returns icon name given group ID // --------------------------------------------------------------- -function dame_grupo_icono($id){ - require("config.php"); - $query1="SELECT * FROM tgrupo WHERE id_grupo =".$id; - $resq1=mysql_query($query1); - if ($rowdup=mysql_fetch_array($resq1)){ - $cat=$rowdup["icon"]; - } - else $cat = ""; - return $cat; +function dame_grupo_icono ($id_group) { + return (string) get_db_value ('icon', 'tgrupo', 'id_grupo', (int) $id_group); } // --------------------------------------------------------------- // Return agent id given name of agent // --------------------------------------------------------------- -function dame_agente_id($nombre){ - require("config.php"); - $query1="SELECT * FROM tagente WHERE nombre = '".$nombre."'"; - $resq1=mysql_query($query1); - if ($rowdup=mysql_fetch_array($resq1)) - $pro=$rowdup["id_agente"]; - else - $pro = ""; - return $pro; +function dame_agente_id ($agent_name) { + return (int) get_db_value ('id_agente', 'tagente', 'nombre', $agent_name); } @@ -214,15 +179,8 @@ function dame_agente_id($nombre){ // Returns userid given name an note id // --------------------------------------------------------------- -function give_note_author ($id_note){ - require("config.php"); - $query1="SELECT * FROM tnota WHERE id_nota = ".$id_note; - $resq1=mysql_query($query1); - if ($rowdup=mysql_fetch_array($resq1)) - $pro=$rowdup["id_usuario"]; - else - $pro = ""; - return $pro; +function give_note_author ($id_note) { + return (int) get_db_value ('id_usuario', 'tnota', 'id_nota', (int) $id_note); } @@ -230,15 +188,12 @@ function give_note_author ($id_note){ // Returns agent id given name of agent // --------------------------------------------------------------- -function dame_agente_modulo_id($id_agente, $id_tipomodulo, $nombre){ - require("config.php"); - $query1="SELECT * FROM tagente_modulo WHERE id_agente = ".$id_agente." and id_tipo_modulo = ".$id_tipomodulo." and nombre = '".$nombre."'"; - $resq1=mysql_query($query1); - if ($rowdup=mysql_fetch_array($resq1)) - $pro=$rowdup["id_agente_modulo"]; - else - $pro = ""; - return $pro; +function dame_agente_modulo_id ($id_agente, $id_tipomodulo, $nombre) { + $sql = sprintf ('SELECT id_agente_modulo FROM tagente_modulo + WHERE id_agente = %d + AND id_tipo_modulo = %d AND nombre = "%s"', + $id_agent, $id_tipomodulo, $nombre); + return get_db_sql ($sql); } @@ -398,30 +353,18 @@ function giveme_module_type($id){ // Returns agent name, given a ID of agente_module table // --------------------------------------------------------------- -function dame_nombre_agente_agentemodulo($id_agente_modulo){ - require("config.php"); - $query1="SELECT * FROM tagente_modulo WHERE id_agente_modulo = ".$id_agente_modulo; - $resq1=mysql_query($query1); - if ($rowdup=mysql_fetch_array($resq1)) - $pro = dame_nombre_agente($rowdup["id_agente"]); - else - $pro = ""; - return $pro; +function dame_nombre_agente_agentemodulo ($id_agente_modulo) { + $id_agent = get_db_value ('id_agente', 'tagente_modulo', 'id_agente_modulo', $id_agente_modulo); + if ($id_agent) + return dame_nombre_agente ($id_agent); + return ''; } // --------------------------------------------------------------- // Return agent module name, given a ID of agente_module table // --------------------------------------------------------------- - -function dame_nombre_modulo_agentemodulo($id_agente_modulo){ - require("config.php"); - $query1="SELECT * FROM tagente_modulo WHERE id_agente_modulo = ".$id_agente_modulo; - $resq1=mysql_query($query1); - if ($rowdup=mysql_fetch_array($resq1)) - $pro = $rowdup["nombre"]; - else - $pro = ""; - return $pro; +function dame_nombre_modulo_agentemodulo ($id_agente_modulo) { + return get_db_value ('nombre', 'tagente_modulo', 'id_agente_modulo', $id_agente_modulo); } @@ -674,24 +617,10 @@ function dame_admin($id){ return $admin; } -// --------------------------------------------------------------- -// Gives error message and stops execution if user -//doesn't have an open session and this session is from an valid user -// --------------------------------------------------------------- +// Wrapper function since we change all functions to english function comprueba_login() { - if (isset($_SESSION["id_usuario"])){ - $id = $_SESSION["id_usuario"]; - require("config.php"); - $query1="SELECT * FROM tusuario WHERE id_usuario = '".$id."'"; - $resq1=mysql_query($query1); - $rowdup=mysql_fetch_array($resq1); - $nombre=$rowdup["id_usuario"]; - if ( $id == $nombre ){ - return 0 ; - } - } - return 1; + return check_login (); } // --------------------------------------------------------------- @@ -699,7 +628,7 @@ function comprueba_login() { //doesn't have an open session and this session is from an administrator // --------------------------------------------------------------- -function comprueba_admin() { +function check_admin () { if (isset($_SESSION["id_usuario"])){ $iduser=$_SESSION['id_usuario']; if (dame_admin($iduser)==1){ @@ -718,6 +647,9 @@ function comprueba_admin() { return 1; } +function comprueba_admin() { + return check_admin (); +} // --------------------------------------------------------------- // Returns number of alerts fired by this agent @@ -1144,44 +1076,111 @@ function give_agent_id_from_module_id ($id_module){ // Generic access to a field ($field) given a table // --------------------------------------------------------------- -function get_db_value ($field, $table, $field_search, $condition_value){ - $query = "SELECT $field FROM $table WHERE $field_search = '$condition_value' "; - $resq1 = mysql_query($query); - if ($rowdup = mysql_fetch_array($resq1)) - $pro = $rowdup[$field]; - else - $pro = ""; - return $pro; -} - -function give_db_value ($field, $table, $field_search, $condition_value){ - return get_db_value ($field, $table, $field_search, $condition_value); +function get_db_value ($field, $table, $field_search, $condition){ + if (is_int ($condition)) { + $sql = sprintf ('SELECT %s FROM %s WHERE %s = %d', $field, $table, $field_search, $condition); + } else if (is_float ($condition) || is_double ($condition)) { + $sql = sprintf ('SELECT %s FROM %s WHERE %s = %f', $field, $table, $field_search, $condition); + } else { + $sql = sprintf ('SELECT %s FROM %s WHERE %s = "%s"', $field, $table, $field_search, $condition); + } + + $result = mysql_query ($sql); + if (! $result) { + echo 'Error: get_db_value("'.$sql.'") :'. mysql_error ().'
'; + return NULL; + } + if ($row = mysql_fetch_array ($result)) + return $row[0]; + + return NULL; } // --------------------------------------------------------------- // Wrapper for old function name. Should be upgraded/renamed in next versions // --------------------------------------------------------------- +function give_db_value ($field, $table, $field_search, $condition) { + return get_db_value ($field, $table, $field_search, $condition); +} -function get_db_row ($table, $field_search, $condition_value){ - $query = "SELECT * FROM $table WHERE $field_search = '$condition_value' "; - $resq1 = mysql_query($query); - if ($rowdup = mysql_fetch_array($resq1)) - return $rowdup; - else - return 0; + +function get_db_row ($table, $field_search, $condition) { + global $config; + + if (is_int ($condition)) { + $sql = sprintf ('SELECT * FROM %s WHERE %s = %d', $table, $field_search, $condition); + } else if (is_float ($condition) || is_double ($condition)) { + $sql = sprintf ('SELECT * FROM %s WHERE %s = %f', $table, $field_search, $condition); + } else { + $sql = sprintf ('SELECT * FROM %s WHERE %s = "%s"', $table, $field_search, $condition); + } + + $result = mysql_query ($sql); + if (! $result) { + echo 'Error: get_db_row("'.$sql.'") :'. mysql_error ().'
'; + return NULL; + } + if ($row = mysql_fetch_array ($result)) + return $row; + + return NULL; } // --------------------------------------------------------------- // Generic access to single field using a free SQL sentence // --------------------------------------------------------------- -function get_db_sql ($sentence, $field = 0){ - if ($rowdup = mysql_fetch_array(mysql_query($sentence))) - return $rowdup[$field]; - else - return ""; +function get_db_sql ($sql, $field = 0){ + global $config; + + $result = mysql_query ($sql); + if (! $result) { + echo 'Error: get_db_sql ("'.$sql.'") :'. mysql_error ().'
'; + return NULL; + } + if ($row = mysql_fetch_array ($result)) + return $row[$field]; + + return NULL; } +function get_db_all_rows_sqlfree ($sql) { + global $config; + $retval = array (); + $result = mysql_query ($sql); + + if (! $result) { + echo mysql_error (); + return array(); + } + while ($row = mysql_fetch_array ($result)) { + array_push ($retval, $row); + } + return $retval; +} + +function get_db_all_rows_in_table ($table) { + return get_db_all_rows_sqlfree ('SELECT * FROM '.$table); +} + +function get_db_all_rows_field_filter ($table, $field, $condition) { + if (is_int ($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); + } else { + $sql = sprintf ('SELECT * FROM %s WHERE %s = "%s"', $table, $field, $condition); + } + + return get_db_all_rows_sqlfree ($sql); +} + +function get_db_all_fields_in_table ($table, $field) { + return get_db_all_rows_sqlfree ('SELECT '.$field.' FROM '. $table); +} + + + // --------------------------------------------------------------- // Return current status from a given agent module (1 alive, 0 down) // --------------------------------------------------------------- @@ -1287,172 +1286,228 @@ function return_coordinate_y_layoutdata ($id_layoutdata){ return (0); } -function return_moduledata_avg_value ($id_agent_module, $period){ - $datelimit = time() - $period; // limit date +function return_moduledata_avg_value ($id_agent_module, $period, $date = 0) { + if (! $date) + $date = time (); + $datelimit = $date - $period; // limit date $id_agent = get_db_value ("id_agente", "tagente_modulo", "id_agente_modulo", $id_agent_module); - $query1="SELECT AVG(datos) FROM tagente_datos WHERE id_agente = $id_agent AND id_agente_modulo = $id_agent_module AND utimestamp > $datelimit"; - $resq1=mysql_query($query1); - if ($resq1 != 0) { - $rowdup=mysql_fetch_array($resq1); - return ($rowdup[0]); - } else - return (0); + $sql = sprintf ("SELECT AVG(datos) FROM tagente_datos + WHERE id_agente = %d AND id_agente_modulo = %d + AND utimestamp > %d AND utimestamp <= %d", + $id_agent, $id_agent_module, $datelimit, $date); + return (float) get_db_sql ($sql); } -function return_moduledata_max_value ($id_agent_module, $period){ - $datelimit = time() - $period; // limit date +function return_moduledata_max_value ($id_agent_module, $period, $date = 0) { + if (! $date) + $date = time (); + $datelimit = $date - $period; // limit date $id_agent = get_db_value ("id_agente", "tagente_modulo", "id_agente_modulo", $id_agent_module); - $query1="SELECT MAX(datos) FROM tagente_datos WHERE id_agente = $id_agent AND id_agente_modulo = $id_agent_module AND utimestamp > $datelimit"; - $resq1=mysql_query($query1); - if ($resq1 != 0) { - $rowdup=mysql_fetch_array($resq1); - return ($rowdup[0]); - } else - return (0); + $sql = sprintf ("SELECT MAX(datos) FROM tagente_datos + WHERE id_agente = %d AND id_agente_modulo = %d + AND utimestamp > %d AND utimestamp <= %d", + $id_agent, $id_agent_module, $datelimit, $date); + return (float) get_db_sql ($sql); } - -function return_moduledata_min_value ($id_agent_module, $period){ - $datelimit = time() - $period; // limit date +function return_moduledata_min_value ($id_agent_module, $period, $date = 0) { + if (! $date) + $date = time (); + $datelimit = $date - $period; // limit date $id_agent = get_db_value ("id_agente", "tagente_modulo", "id_agente_modulo", $id_agent_module); - $query1="SELECT MIN(datos) FROM tagente_datos WHERE id_agente = $id_agent AND id_agente_modulo = $id_agent_module AND utimestamp > $datelimit"; - $resq1=mysql_query($query1); - if ($resq1 != 0) { - $rowdup=mysql_fetch_array($resq1); - return ($rowdup[0]); - } else - return (0); + $sql = sprintf ("SELECT MIN(datos) FROM tagente_datos + WHERE id_agente = %d AND id_agente_modulo = %d + AND utimestamp > %d AND utimestamp <= %d", + $id_agent, $id_agent_module, $datelimit, $date); + return (float) get_db_sql ($sql); } -function lang_string ($string){ - global $config; - require ($config["homedir"]."/include/languages/language_".$config["language"].".php"); - if (isset ($lang_label[$string])) - return $lang_label[$string]; - else - return $string; +function return_moduledata_sum_value ($id_agent_module, $period, $date = 0) { + if (! $date) + $date = time (); + $datelimit = $date - $period; // limit date + $agent_module = get_db_row ('tagente_modulo', 'id_agente_modulo', $id_agent_module); + $module_name = get_db_value ('nombre', 'ttipo_modulo', 'id_tipo', $agent_module['id_tipo_modulo']); + echo $module_name; + if (is_module_data_string ($module_name)) { + return lang_string ('wrong_module_type'); + } + $interval = get_db_value ('current_interval', 'tagente_estado', 'id_agente_modulo', $id_agent_module); + + // Get the whole interval of data + $sql = sprintf ('SELECT * FROM tagente_datos + WHERE id_agente = %d AND id_agente_modulo = %d + AND utimestamp > %d AND utimestamp <= %d', + $agent_module['id_agente'], $id_agent_module, $datelimit, $date); + $datas = get_db_all_rows_sqlfree ($sql); + $last_data = ""; + $total_badtime = 0; + $interval_begin = 0; + $interval_last = 0; + + if (sizeof ($datas) == 0) { + return 0; + } + $sum = 0; + $previous_data = 0; + foreach ($datas as $data) { + if ($interval_begin != 0) { + $interval_last = $data["utimestamp"]; + $elapsed = $interval_last - $interval_begin; + $times = intval ($elapsed / $interval); + } else { + $times = 1; + } + if (is_module_data_proc ($module_name)) { + $previous_data = $data['datos'] * $interval; + } else { + $previous_data = $data['datos']; + } + + $interval_begin = $data["utimestamp"]; + } + + /* The last interval value must be get from tagente_estado, but + it will count only if it's not older than date demanded + */ + $interval_last = give_db_value ('utimestamp', 'tagente_estado', 'id_agente_modulo', $id_agent_module); + if ($interval_last <= $datelimit) { + $elapsed = $interval_last - $interval_begin; + $times = intval ($elapsed / $interval); + $sum += $times * $previous_data; + } + + return (float) $sum; } -function check_server_status (){ - global $config; - // This check assumes that server_keepalive should be AT LEAST 15 MIN - $sql = "SELECT COUNT(id_server) FROM tserver WHERE status = 1 AND keepalive > NOW() - INTERVAL 15 MINUTE"; - $res = get_db_sql ($sql); - // Set servers to down - if ($res == 0){ - $res2 = mysql_query("UPDATE tserver SET status = 0"); - } - return $res; +function lang_string ($string) { + global $config; + require ($config["homedir"]."/include/languages/language_".$config["language"].".php"); + if (isset ($lang_label[$string])) + return $lang_label[$string]; + return $string; +} + +function check_server_status () { + global $config; + // This check assumes that server_keepalive should be AT LEAST 15 MIN + $sql = "SELECT COUNT(id_server) FROM tserver WHERE status = 1 AND keepalive > NOW() - INTERVAL 15 MINUTE"; + $res = get_db_sql ($sql); + // Set servers to down + if ($res == 0){ + $res2 = mysql_query ("UPDATE tserver SET status = 0"); + } + return $res; } function show_alert_row_mini ($id_combined_alert){ - global $config; - global $lang_label; - - $color=1; - $sql_com = "SELECT talerta_agente_modulo.*, tcompound_alert.operation FROM talerta_agente_modulo, tcompound_alert WHERE tcompound_alert.id_aam = talerta_agente_modulo.id_aam AND tcompound_alert.id = ".$id_combined_alert; - $result_com = mysql_query ($sql_com); - echo ""; - echo ""; - - if ($row2["disable"] == 1){ - $tdcolor = "datos3"; - } - echo ""; - } else { - echo ""; - } - - // Alert times - echo ""; + } else { + echo ""; + } + + // Alert times + echo ""; + else + echo ""; + + } + echo "
".lang_string("Name"); - echo "".lang_string("Oper"); - echo "".lang_string("Tt"); - echo "".lang_string("Firing"); - echo "".lang_string("Time"); - echo "".lang_string("Desc"); - echo "".lang_string("Recovery"); - echo "".lang_string("MinMax.Al"); - echo "".lang_string("Days"); - echo "".lang_string("Fired"); - while ($row2=mysql_fetch_array($result_com)){ + global $config; + global $lang_label; - if ($color == 1){ - $tdcolor = "datos"; - $color = 0; - } - else { - $tdcolor = "datos2"; - $color = 1; - } - echo "
".get_db_sql("SELECT nombre FROM tagente_modulo WHERE id_agente_modulo =".$row2["id_agente_modulo"]); - echo "".$row2["operation"]; - - echo "".human_time_description($row2["time_threshold"]); - - if ($row2["dis_min"]!=0){ - $mytempdata = fmod($row2["dis_min"], 1); - if ($mytempdata == 0) - $mymin = intval($row2["dis_min"]); - else - $mymin = $row2["dis_min"]; - $mymin = format_for_graph($mymin ); - } else { - $mymin = 0; - } - - if ($row2["dis_max"]!=0){ - $mytempdata = fmod($row2["dis_max"], 1); - if ($mytempdata == 0) - $mymax = intval($row2["dis_max"]); - else - $mymax = $row2["dis_max"]; - $mymax = format_for_graph($mymax ); - } else { - $mymax = 0; - } - - if (($mymin == 0) && ($mymax == 0)){ - $mymin = lang_string ("N/A"); - $mymax = $mymin; - } - - // We have alert text ? - if ($row2["alert_text"]!= "") { - echo "".$lang_label["text"]."".$mymin."/".$mymax.""; - echo get_alert_times ($row2); - - // Description - echo "".substr($row2["descripcion"],0,20); - - // Has recovery notify activated ? - if ($row2["recovery_notify"] > 0) - $recovery_notify = lang_string("Yes"); - else - $recovery_notify = lang_string("No"); - - echo "".$recovery_notify; - - // calculare firing conditions - if ($row2["alert_text"] != ""){ - $firing_cond = lang_string("text")."(".substr($row2["alert_text"],0,8).")"; - } else { - $firing_cond = $row2["min_alerts"]." / ".$row2["max_alerts"]; - } - echo "".$firing_cond; + $color=1; + $sql_com = "SELECT talerta_agente_modulo.*, tcompound_alert.operation FROM talerta_agente_modulo, tcompound_alert WHERE tcompound_alert.id_aam = talerta_agente_modulo.id_aam AND tcompound_alert.id = ".$id_combined_alert; + $result_com = mysql_query ($sql_com); + echo ""; + echo ""; - // Fired ? - if ($row2["times_fired"]>0) - echo ""; - else - echo ""; + if ($row2["disable"] == 1){ + $tdcolor = "datos3"; + } + echo "
".lang_string("Name"); + echo "".lang_string("Oper"); + echo "".lang_string("Tt"); + echo "".lang_string("Firing"); + echo "".lang_string("Time"); + echo "".lang_string("Desc"); + echo "".lang_string("Recovery"); + echo "".lang_string("MinMax.Al"); + echo "".lang_string("Days"); + echo "".lang_string("Fired"); + while ($row2=mysql_fetch_array($result_com)){ - // calculate days - $firing_days = get_alert_days ( $row2 ); - echo "".$firing_days; + if ($color == 1){ + $tdcolor = "datos"; + $color = 0; + } + else { + $tdcolor = "datos2"; + $color = 1; + } + echo "
".get_db_sql("SELECT nombre FROM tagente_modulo WHERE id_agente_modulo =".$row2["id_agente_modulo"]); + echo "".$row2["operation"]; - } - echo "
"; + echo "
".human_time_description($row2["time_threshold"]); + + if ($row2["dis_min"]!=0){ + $mytempdata = fmod($row2["dis_min"], 1); + if ($mytempdata == 0) + $mymin = intval($row2["dis_min"]); + else + $mymin = $row2["dis_min"]; + $mymin = format_for_graph($mymin ); + } else { + $mymin = 0; + } + + if ($row2["dis_max"]!=0){ + $mytempdata = fmod($row2["dis_max"], 1); + if ($mytempdata == 0) + $mymax = intval($row2["dis_max"]); + else + $mymax = $row2["dis_max"]; + $mymax = format_for_graph($mymax ); + } else { + $mymax = 0; + } + + if (($mymin == 0) && ($mymax == 0)){ + $mymin = lang_string ("N/A"); + $mymax = $mymin; + } + + // We have alert text ? + if ($row2["alert_text"]!= "") { + echo "".$lang_label["text"]."".$mymin."/".$mymax.""; + echo get_alert_times ($row2); + + // Description + echo "".substr($row2["descripcion"],0,20); + + // Has recovery notify activated ? + if ($row2["recovery_notify"] > 0) + $recovery_notify = lang_string("Yes"); + else + $recovery_notify = lang_string("No"); + + echo "".$recovery_notify; + + // calculare firing conditions + if ($row2["alert_text"] != ""){ + $firing_cond = lang_string("text")."(".substr($row2["alert_text"],0,8).")"; + } else { + $firing_cond = $row2["min_alerts"]." / ".$row2["max_alerts"]; + } + echo "".$firing_cond; + + // calculate days + $firing_days = get_alert_days ( $row2 ); + echo "".$firing_days; + + // Fired ? + if ($row2["times_fired"]>0) + echo "
"; } function smal_event_table ($filter = "", $limit = 10, $width=440){ global $config; diff --git a/pandora_console/include/functions_html.php b/pandora_console/include/functions_html.php new file mode 100644 index 0000000000..4f5ef42f2a --- /dev/null +++ b/pandora_console/include/functions_html.php @@ -0,0 +1,524 @@ +\n"; + + if ($nothing != '') { + $output .= ' \n"; + } + } + } + + $output .= "\n"; + + if ($return) + return $output; + + echo $output; +} + +/** + * Prints an array of fields in a popup menu of a form based on a SQL query. + * The first and second columns of the query will be used. + * + * Based on choose_from_menu() from Moodle + * + * $sql SQL sentence, the first field will be the identifier of the option. + * The second field will be the shown value in the dropdown. + * $name Select form name + * $selected Current selected value. + * $script Javascript onChange code. + * $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) { + + $fields = array (); + $result = mysql_query ($sql); + if (! $result) { + echo mysql_error (); + return ""; + } + + while ($row = mysql_fetch_array ($result)) { + $fields[$row[0]] = $row[1]; + } + + $output = print_select ($fields, $name, $selected, $script, $nothing, $nothing_value, true); + + if ($return) + return $output; + + echo $output; +} + +/** + * Render an input text element. Extended version, use print_input_text() to simplify. + * + * @param string $name Input name. + * @param string $value Input value. + * @param string $alt Alternative HTML string. + * @param int $size Size of the input. + * @param int $maxlength Maximum length allowed. + * @param bool $disabled Disable the button (optional, button enabled by default). + * @param string $alt Alternative HTML string. + * @param bool $return Whether to return an output string or echo now (optional, echo by default). + */ +function print_input_text_extended ($name, $value, $id, $alt, $size, $maxlength, $disabled, $script, $attributes, $return = false) { + static $idcounter = 0; + + ++$idcounter; + if (empty ($name)) { + $name = 'unnamed'; + } + + if (empty ($alt)) { + $alt = 'textfield'; + } + + if (! empty ($maxlength)) { + $maxlength = ' maxlength="'.$maxlength.'" '; + } + + $output = ''; + + if ($return) + return $output; + echo $output; +} + +function print_submit_button ($label = 'OK', $name = '', $disabled = false, $attributes = '', $return = false) { + $output = ''; + + $output .= ''; + $output .= $value; + $output .= ''; + + if ($return) + return $output; + echo $output; +} + +/** + * Print a nicely formatted table. Code taken from moodle. + * + * @param array $table is an object with several properties: + * $table->head - An array of heading names. + * $table->align - An array of column alignments + * $table->valign - An array of column alignments + * $table->size - An array of column sizes + * $table->wrap - An array of "nowrap"s or nothing + * $table->style - An array of personalized style for each column. + * $table->rowstyle - An array of personalized style of each row. + * $table->rowclass - An array of personalized classes of each row (odd-evens classes will be ignored). + * $table->colspan - An array of colspans of each column. + * $table->data[] - An array of arrays containing the data. + * $table->width - A percentage of the page + * $table->border - Border of the table. + * $table->tablealign - Align the whole table + * $table->cellpadding - Padding on each cell + * $table->cellspacing - Spacing between cells + * $table->class - CSS table class + * @param bool $return whether to return an output string or echo now + */ +function print_table ($table, $return = false) { + $output = ''; + static $table_count = 0; + + $table_count++; + if (isset ($table->align)) { + foreach ($table->align as $key => $aa) { + if ($aa) { + $align[$key] = ' text-align:'. $aa.';'; + } else { + $align[$key] = ''; + } + } + } + if (isset ($table->valign)) { + foreach ($table->valign as $key => $aa) { + if ($aa) { + $valign[$key] = ' vertical-align:'. $aa.';'; + } else { + $valign[$key] = ''; + } + } + } + if (isset ($table->size)) { + foreach ($table->size as $key => $ss) { + if ($ss) { + $size[$key] = ' width:'. $ss .';'; + } else { + $size[$key] = ''; + } + } + } + if (isset ($table->style)) { + foreach ($table->style as $key => $st) { + if ($st) { + $style[$key] = ' '. $st .';'; + } else { + $style[$key] = ''; + } + } + } + if (isset ($table->rowstyle)) { + foreach ($table->rowstyle as $key => $st) { + $rowstyle[$key] = ' '. $st .';'; + } + } + if (isset ($table->rowclass)) { + foreach ($table->rowclass as $key => $class) { + $rowclass[$key] = $st; + } + } + if (isset ($table->colspan)) { + foreach ($table->colspan as $keyrow => $colspan) { + foreach ($colspan as $key => $span) { + $colspan[$keyrow][$key] = ' colspan="'.$span.'"'; + } + } + } + if (empty ($table->width)) { + $table->width = '80%'; + } + + if (empty ($table->border)) { + $table->border = '0px'; + } + + if (empty ($table->tablealign)) { + $table->tablealign = 'center'; + } + + if (empty ($table->cellpadding)) { + $table->cellpadding = '4'; + } + + if (empty ($table->cellspacing)) { + $table->cellspacing = '4'; + } + + if (empty ($table->class)) { + $table->class = 'databox_color'; + } + + $tableid = empty ($table->id) ? 'table'.$table_count : $table->id; + + $output .= 'cellpadding\" cellspacing=\"$table->cellspacing\" "; + $output .= " border=\"$table->border\" 'class=\"$table->class\" id=\"$tableid\" >\n"; + $countcols = 0; + + if (!empty ($table->head)) { + $countcols = count ($table->head); + $output .= ''; + foreach ($table->head as $key => $heading) { + if (!isset ($size[$key])) { + $size[$key] = ''; + } + if (!isset ($align[$key])) { + $align[$key] = ''; + } + + $output .= ''; + } + $output .= ''."\n"; + } + if (!empty ($table->data)) { + $oddeven = 1; + foreach ($table->data as $keyrow => $row) { + + if (!isset ($rowstyle[$keyrow])) { + $rowstyle[$keyrow] = ''; + } + $oddeven = $oddeven ? 0 : 1; + $class = 'datos'.($oddeven ? "" : "2"); + if (isset ($rowclass[$keyrow])) { + $class = $rowclass[$keyrow]; + } + $output .= ''."\n"; + /* Special separator rows */ + if ($row == 'hr' and $countcols) { + $output .= ''; + continue; + } + /* It's a normal row */ + foreach ($row as $key => $item) { + if (!isset ($size[$key])) { + $size[$key] = ''; + } + if (!isset ($colspan[$key])) { + $colspan[$keyrow][$key] = ''; + } + if (!isset ($align[$key])) { + $align[$key] = ''; + } + if (!isset ($valign[$key])) { + $valign[$key] = ''; + } + if (!isset ($wrap[$key])) { + $wrap[$key] = ''; + } + if (!isset ($style[$key])) { + $style[$key] = ''; + } + + $output .= ''."\n"; + } + $output .= ''."\n"; + } + } + $output .= '
'. $heading .'
'. $item .'
'."\n"; + if ($return) + return $output; + + echo $output; +} + +/** + * Render a radio button input. Extended version, use print_radio_button() to simplify. + * + * @param string $name Input name. + * @param string $value Input value. + * @param string $checked Set the button to be marked (optional, unmarked by default). + * @param bool $disabled Disable the button (optional, button enabled by default). + * @param string $script Script to execute when onClick event is triggered (optional). + * @param string $attributes Optional HTML attributes. It's a free string which will be + inserted into the HTML tag, use it carefully (optional). + * @param bool $return Whether to return an output string or echo now (optional, echo by default). + */ +function print_radio_button_extended ($name, $value, $label, $checkedvalue, $disabled, $script, $attributes, $return = false) { + static $idcounter = 0; + + $output = ''; + + $output = ''. $label .'' . "\n"; + } + + if ($return) + return $output; + + echo $output; +} + +/** + * Render a radio button input. + * + * @param string $name Input name. + * @param string $value Input value. + * @param string $label Label to add after the radio button (optional). + * @param string $checkedvalue Checked and selected value, the button will be selected if it matches $value (optional). + * @param bool $return Whether to return an output string or echo now (optional, echo by default). + */ +function print_radio_button ($name, $value, $label = '', $checkedvalue = '', $return = false) { + $output = print_radio_button_extended ($name, $value, $label, $checkedvalue, false, '', '', true); + + if ($return) + return $output; + + echo $output; +} + +/** + * Render a checkbox button input. Extended version, use print_checkbox() to simplify. + * + * @param string $name Input name. + * @param string $value Input value. + * @param string $checked Set the button to be marked (optional, unmarked by default). + * @param bool $disabled Disable the button (optional, button enabled by default). + * @param string $script Script to execute when onClick event is triggered (optional). + * @param string $attributes Optional HTML attributes. It's a free string which will be + inserted into the HTML tag, use it carefully (optional). + * @param bool $return Whether to return an output string or echo now (optional, echo by default). + */ +function print_checkbox_extended ($name, $value, $checked, $disabled, $script, $attributes, $return = false) { + static $idcounter = 0; + + $htmlid = 'checkbox'.sprintf ('%04d', ++$idcounter); + $output = ''; + + if ($return) + return $output; + echo $output; +} + +?> diff --git a/pandora_console/operation/events/events.php b/pandora_console/operation/events/events.php index 52dfc1b4c6..88a2792778 100644 --- a/pandora_console/operation/events/events.php +++ b/pandora_console/operation/events/events.php @@ -218,7 +218,7 @@ echo ""; // Event type echo "".lang_string ("Event type").""; echo ""; -echo form_event_type_combo ("event_type", $event_type); +echo print_select (get_event_types (), 'event_type', $event_type, '', 'all', 0); echo ""; // Severity diff --git a/pandora_console/reporting/fgraph.php b/pandora_console/reporting/fgraph.php index cdbb9ace67..f73363562e 100644 --- a/pandora_console/reporting/fgraph.php +++ b/pandora_console/reporting/fgraph.php @@ -24,8 +24,8 @@ require ($config["homedir"].'/include/languages/language_'.$config['language'].' global $config; if (!isset($_SESSION["id_user"])){ - session_start(); - session_write_close(); + session_start(); + session_write_close(); } $config ["id_user"] = $_SESSION["id_usuario"]; @@ -51,15 +51,15 @@ function graphic_error () { * * @return string Formatted date string (YY-MM-DD hh:mm:ss) */ - -function dame_fecha($mh){ - $m_year = date("Y", time()-$mh*60); - $m_month = date("m", time()-$mh*60); - $m_day = date ("d", time()-$mh*60); - $m_hour = date ("H", time()-$mh*60); - $m_min = date ("i", time()-$mh*60); +function dame_fecha ($mh) { + $mh *= 60; + $m_year = date ("Y", time() - $mh); + $m_month = date ("m", time() - $mh); + $m_day = date ("d", time() - $mh); + $m_hour = date ("H", time() - $mh); + $m_min = date ("i", time() - $mh); $m = $m_year."-".$m_month."-".$m_day." ".$m_hour.":".$m_min.":00"; - return $m; + return $m; } /** @@ -87,17 +87,20 @@ function dame_fecha_grafico_timestamp ($timestamp) { * @param int Show events in graph (set to 1) * @param int Show alerts in graph (set to 1) * @param int Pure mode (without titles) (set to 1) + * @param int Date to start of getting info. */ - -function graphic_combined_module ( $module_list, $weight_list, $periodo, $width, $height, $title, $unit_name, $show_event=0, $show_alert=0, $pure =0, $stacked = 0){ +function graphic_combined_module ($module_list, $weight_list, $periodo, $width, $height, + $title, $unit_name, $show_event = 0, $show_alert = 0, $pure = 0, $stacked = 0, $date = 0) { include ("../include/config.php"); require ("../include/languages/language_".$config['language'].".php"); require_once 'Image/Graph.php'; $resolution = $config['graph_res'] * 50; // Number of "slices" we want in graph + if (! $date) + $date = time (); //$unix_timestamp = strtotime($mysql_timestamp) // Convert MYSQL format tio utime - $fechatope = time() - $periodo; // limit date + $fechatope = $date - $periodo; // limit date $horasint = $periodo / $resolution; // Each intervalo is $horasint seconds length $module_number = count($module_list); @@ -106,35 +109,35 @@ function graphic_combined_module ( $module_list, $weight_list, $periodo, // periodo - Gap of time, in seconds. This is now to (now-periodo) secs // Init tables - for ($y = 0; $y < $module_number; $y++){ - $real_data[$y] = array(); - $mod_data[$y] = 1; // Data multiplier to get the same scale on all modules + for ($i = 0; $i < $module_number; $i++){ + $real_data[$i] = array(); + $mod_data[$i] = 1; // Data multiplier to get the same scale on all modules if ($show_event == 1) - $real_event[$y] = array(); - if (isset($weight_list[$y])){ - if ($weight_list[$y] == 0) - $weight_list[$y] = 1; + $real_event[$i] = array(); + if (isset($weight_list[$i])){ + if ($weight_list[$i] == 0) + $weight_list[$i] = 1; } else - $weight_list[$y] = 1; + $weight_list[$i] = 1; } $max_value = 0; $min_value = 0; // FOR EACH MODULE IN module_list.... - for ($y = 0; $y < $module_number; $y++){ - $id_agente_modulo = $module_list[$y]; + for ($i = 0; $i < $module_number; $i++){ + $id_agente_modulo = $module_list[$i]; $nombre_agente = dame_nombre_agente_agentemodulo($id_agente_modulo); $id_agente = dame_agente_id($nombre_agente); $nombre_modulo = dame_nombre_modulo_agentemodulo($id_agente_modulo); - $module_list_name[$y] = substr($nombre_agente,0,9)." / ".substr($nombre_modulo,0,20); - for ($x = 0; $x <= $resolution; $x++) { - $valores[$x][0] = 0; // SUM of all values for this interval - $valores[$x][1] = 0; // counter - $valores[$x][2] = $fechatope + ($horasint * $x); // [2] Top limit for this range - $valores[$x][3] = $fechatope + ($horasint*($x+1)); // [3] Botom limit - $valores[$x][4] = 0; // MIN - $valores[$x][5] = 0; // MAX - $valores[$x][6] = 0; // Event + $module_list_name[$i] = substr($nombre_agente,0,9)." / ".substr($nombre_modulo,0,20); + for ($j = 0; $j <= $resolution; $j++) { + $valores[$j][0] = 0; // SUM of all values for this interval + $valores[$j][1] = 0; // counter + $valores[$j][2] = $fechatope + ($horasint * $j); // [2] Top limit for this range + $valores[$j][3] = $fechatope + ($horasint*($j+1)); // [3] Botom limit + $valores[$j][4] = 0; // MIN + $valores[$j][5] = 0; // MAX + $valores[$j][6] = 0; // Event } // Init other general variables @@ -166,13 +169,13 @@ function graphic_combined_module ( $module_list, $weight_list, $periodo, } $previous=0; // Get the first data outsite (to the left---more old) of the interval given - $sql1="SELECT datos, utimestamp FROM tagente_datos WHERE id_agente = $id_agente AND id_agente_modulo = $id_agente_modulo AND utimestamp < $fechatope ORDER BY utimestamp DESC LIMIT 1"; + $sql1="SELECT datos, utimestamp FROM tagente_datos WHERE id_agente = $id_agente AND id_agente_modulo = $id_agente_modulo AND utimestamp < $fechatope AND utimestamp >= $date ORDER BY utimestamp DESC LIMIT 1"; if ($result=mysql_query($sql1)){ - $row=mysql_fetch_array($result); + $row=mysql_fetch_array($result); $previous = $row[0]; - } + } - $sql1="SELECT datos,utimestamp FROM tagente_datos WHERE id_agente = $id_agente AND id_agente_modulo = $id_agente_modulo AND utimestamp >= $fechatope"; + $sql1="SELECT datos,utimestamp FROM tagente_datos WHERE id_agente = $id_agente AND id_agente_modulo = $id_agente_modulo AND utimestamp >= $fechatope AND utimestamp < $date"; if ($result=mysql_query($sql1)) while ($row=mysql_fetch_array($result)){ $datos = $row[0]; @@ -199,45 +202,44 @@ function graphic_combined_module ( $module_list, $weight_list, $periodo, // Calculate Average value for $valores[][0] - for ($x =0; $x <= $resolution; $x++) { - if ($valores[$x][1] > 0){ - $real_data[$y][$x] = $weight_list[$y] * ($valores[$x][0]/$valores[$x][1]); - $valores[$x][0] = $valores[$x][0]/$valores[$x][1]; + for ($j =0; $j <= $resolution; $j++) { + if ($valores[$j][1] > 0){ + $real_data[$i][$j] = $weight_list[$i] * ($valores[$j][0]/$valores[$j][1]); + $valores[$j][0] = $valores[$j][0]/$valores[$j][1]; } else { - $valores[$x][0] = $previous; - $real_data[$y][$x] = $previous * $weight_list[$y]; - $valores[$x][4] = $previous; - $valores[$x][5] = $previous; + $valores[$j][0] = $previous; + $real_data[$i][$j] = $previous * $weight_list[$i]; + $valores[$j][4] = $previous; + $valores[$j][5] = $previous; } // Get max value for all graph - if ($valores[$x][5] > $max_value ){ - $max_value = $valores[$x][5]; - } - // This stores in mod_data max values for each module - if ($mod_data[$y] < $valores[$x][5]){ - $mod_data[$y] = $valores[$x][5]; - } + if ($valores[$j][5] > $max_value ){ + $max_value = $valores[$j][5]; + } + // This stores in mod_data max values for each module + if ($mod_data[$i] < $valores[$j][5]){ + $mod_data[$i] = $valores[$j][5]; + } // Take prev. value // TODO: CHeck if there are more than 24hours between // data, if there are > 24h, module down. - $previous = $valores[$x][0]; + $previous = $valores[$j][0]; } } - for ($y = 0; $y < $module_number; $y++){ - // Disabled autoadjusment, is not working fine :( - // $weight_list[$y] = ($max_value / $mod_data[$y]) + ($weight_list[$y]-1); - if ($weight_list[$y] != 1) - $module_list_name[$y] .= " (x". format_numeric($weight_list[$y],1).")"; - $module_list_name[$y] = $module_list_name[$y]." (MAX: ".format_numeric($mod_data[$y]).")"; - } + for ($i = 0; $i < $module_number; $i++){ + // Disabled autoadjusment, is not working fine :( + // $weight_list[$i] = ($max_value / $mod_data[$i]) + ($weight_list[$i]-1); + if ($weight_list[$i] != 1) + $module_list_name[$i] .= " (x". format_numeric($weight_list[$i],1).")"; + $module_list_name[$i] = $module_list_name[$i]." (MAX: ".format_numeric($mod_data[$i]).")"; + } // Create graph // ************* $Graph =& Image_Graph::factory('graph', array($width, $height)); // add a TrueType font - if ($periodo == 86400) $title_period = "Last day"; elseif ($periodo == 604800) @@ -286,9 +288,9 @@ function graphic_combined_module ( $module_list, $weight_list, $periodo, // Merge data into a dataset object (sancho) // $Dataset =& Image_Graph::factory('dataset'); - for ($y = 0; $y < $module_number; $y++){ - $dataset[$y] = Image_Graph::factory('dataset'); - $dataset[$y] -> setName($module_list_name[$y]); + for ($i = 0; $i < $module_number; $i++){ + $dataset[$i] = Image_Graph::factory('dataset'); + $dataset[$i] -> setName($module_list_name[$i]); } if ($show_event == 1){ $dataset_event = Image_Graph::factory('dataset'); @@ -296,126 +298,118 @@ function graphic_combined_module ( $module_list, $weight_list, $periodo, } // ... and populated with data ... - for ($cc=0; $cc < $resolution; $cc++) { - $tdate = date('d/m', $valores[$cc][2])."\n".date('H:i', $valores[$cc][2]); - for ($y = 0; $y < $module_number; $y++){ - $dataset[$y]->addPoint($tdate, $real_data[$y][$cc]); - if (($show_event == 1) AND (isset($real_event[$cc]))) { + for ($i = 0; $i < $resolution; $i++) { + $tdate = date('d/m', $valores[$i][2])."\n".date('H:i', $valores[$i][2]); + for ($i = 0; $i < $module_number; $i++){ + $dataset[$i]->addPoint($tdate, $real_data[$i][$i]); + if (($show_event == 1) AND (isset($real_event[$i]))) { $dataset_event->addPoint($tdate, $max_value); } } } - if ($max_value > 0){ - // Show events ! - if ($show_event == 1){ - $Plot =& $Plotarea->addNew('Plot_Impulse', array($dataset_event)); - $Plot->setLineColor( 'black' ); - $Marker_event =& Image_Graph::factory('Image_Graph_Marker_Cross'); - $Plot->setMarker($Marker_event); - $Marker_event->setFillColor( 'red' ); - $Marker_event->setLineColor( 'red' ); - $Marker_event->setSize ( 5 ); - } - - // Show limits (for alert or whathever you want... - if ($show_alert == 1){ - $Plot =& $Plotarea->addNew('Image_Graph_Axis_Marker_Area', IMAGE_GRAPH_AXIS_Y); - $Plot->setFillColor( 'blue@0.1' ); - $Plot->setLowerBound( $alert_low); - $Plot->setUpperBound( $alert_high ); - } - - - // create the 1st plot as smoothed area chart using the 1st dataset - if ($stacked == 0){ - // Non-stacked - $Plot =& $Plotarea->addNew('area', array(&$dataset)); - } else { - // Stacked (> 2.0) - $Plot =& $Plotarea->addNew('Image_Graph_Plot_Area', array(&$dataset, 'stacked')); - } - $Plot->setLineColor('gray@0.4'); - $AxisX =& $Plotarea->getAxis(IMAGE_GRAPH_AXIS_X); - // $AxisX->Hide(); - $AxisY =& $Plotarea->getAxis(IMAGE_GRAPH_AXIS_Y); - $AxisY->setLabelOption("showtext",true); - $AxisY->setLabelInterval(ceil($max_value / 5)); - $AxisY->showLabel(IMAGE_GRAPH_LABEL_ZERO); - if ($unit_name != "") - $AxisY->setTitle($unit_name, 'vertical'); - $AxisX->setLabelInterval($resolution / 10); - //$AxisY->forceMinimum($minvalue); - //$AxisY->forceMaximum($max_value+($max_value/12)) ; - $GridY2 =& $Plotarea->addNew('bar_grid', IMAGE_GRAPH_AXIS_Y_SECONDARY); - $GridY2->setLineColor('gray'); - $GridY2->setFillColor('lightgray@0.05'); - // set line colors - $FillArray =& Image_Graph::factory('Image_Graph_Fill_Array'); - $Plot->setFillStyle($FillArray); - $FillArray->addColor('#BFFF51@0.6'); // Green - $FillArray->addColor('yellow@0.6'); // yellow - $FillArray->addColor('#FF5FDF@0.6'); // pink - $FillArray->addColor('orange@0.6'); // orange - $FillArray->addColor('#7D8AFF@0.6'); // blue - $FillArray->addColor('#FF302A@0.6'); // red - $FillArray->addColor('brown@0.6'); // brown - $FillArray->addColor('green@0.6'); - $AxisY_Weather =& $Plotarea->getAxis(IMAGE_GRAPH_AXIS_Y); - $Graph->done(); - } else + if ($max_value <= 0) { graphic_error (); + return; + } + // Show events ! + if ($show_event == 1) { + $Plot =& $Plotarea->addNew('Plot_Impulse', array($dataset_event)); + $Plot->setLineColor( 'black' ); + $Marker_event =& Image_Graph::factory('Image_Graph_Marker_Cross'); + $Plot->setMarker($Marker_event); + $Marker_event->setFillColor( 'red' ); + $Marker_event->setLineColor( 'red' ); + $Marker_event->setSize ( 5 ); + } + + // Show limits (for alert or whathever you want... + if ($show_alert == 1){ + $Plot =& $Plotarea->addNew('Image_Graph_Axis_Marker_Area', IMAGE_GRAPH_AXIS_Y); + $Plot->setFillColor( 'blue@0.1' ); + $Plot->setLowerBound( $alert_low); + $Plot->setUpperBound( $alert_high ); + } + + + // create the 1st plot as smoothed area chart using the 1st dataset + if ($stacked == 0) { + // Non-stacked + $Plot =& $Plotarea->addNew('area', array(&$dataset)); + } else { + // Stacked (> 2.0) + $Plot =& $Plotarea->addNew('Image_Graph_Plot_Area', array(&$dataset, 'stacked')); + } + $Plot->setLineColor('gray@0.4'); + $AxisX =& $Plotarea->getAxis(IMAGE_GRAPH_AXIS_X); + // $AxisX->Hide(); + $AxisY =& $Plotarea->getAxis(IMAGE_GRAPH_AXIS_Y); + $AxisY->setLabelOption("showtext",true); + $AxisY->setLabelInterval(ceil($max_value / 5)); + $AxisY->showLabel(IMAGE_GRAPH_LABEL_ZERO); + if ($unit_name != "") + $AxisY->setTitle($unit_name, 'vertical'); + $AxisX->setLabelInterval($resolution / 10); + //$AxisY->forceMinimum($minvalue); + //$AxisY->forceMaximum($max_value+($max_value/12)) ; + $GridY2 =& $Plotarea->addNew('bar_grid', IMAGE_GRAPH_AXIS_Y_SECONDARY); + $GridY2->setLineColor('gray'); + $GridY2->setFillColor('lightgray@0.05'); + // set line colors + $FillArray =& Image_Graph::factory('Image_Graph_Fill_Array'); + $Plot->setFillStyle($FillArray); + $FillArray->addColor('#BFFF51@0.6'); // Green + $FillArray->addColor('yellow@0.6'); // yellow + $FillArray->addColor('#FF5FDF@0.6'); // pink + $FillArray->addColor('orange@0.6'); // orange + $FillArray->addColor('#7D8AFF@0.6'); // blue + $FillArray->addColor('#FF302A@0.6'); // red + $FillArray->addColor('brown@0.6'); // brown + $FillArray->addColor('green@0.6'); + $AxisY_Weather =& $Plotarea->getAxis(IMAGE_GRAPH_AXIS_Y); + $Graph->done(); } -function grafico_modulo_sparse ( $id_agente_modulo, $periodo, $show_event, - $width, $height , $title, $unit_name, $show_alert, $avg_only = 0, $pure=0, $time_reference = "" ) { - +function grafico_modulo_sparse ($id_agente_modulo, $periodo, $show_event, + $width, $height , $title, $unit_name, $show_alert, $avg_only = 0, $pure = 0, $date = 0 ) { include ("../include/config.php"); require ("../include/languages/language_".$config['language'].".php"); - require_once 'Image/Graph.php'; + require_once 'Image/Graph.php'; + if (! $date) + $date = time (); $resolution = $config["graph_res"] * 50; // Number of "slices" we want in graph - - if ($time_reference != ""){ - $unix_timestamp = strtotime($time_reference); - $fechatope = $unix_timestamp - $periodo; - } - else - $fechatope = time() - $periodo; // limit date + $fechatope = $date - $periodo; $horasint = $periodo / $resolution; // Each intervalo is $horasint seconds length - $nombre_agente = dame_nombre_agente_agentemodulo($id_agente_modulo); - $id_agente = dame_agente_id($nombre_agente); - $nombre_modulo = dame_nombre_modulo_agentemodulo($id_agente_modulo); + $nombre_agente = dame_nombre_agente_agentemodulo ($id_agente_modulo); + $id_agente = dame_agente_id ($nombre_agente); + $nombre_modulo = dame_nombre_modulo_agentemodulo ($id_agente_modulo); - if ($show_event == 1){ - // If we want to show events in graphs - $sql1="SELECT utimestamp FROM tevento WHERE id_agentmodule = $id_agente_modulo AND utimestamp > $fechatope"; - $result=mysql_query($sql1); - while ($row=mysql_fetch_array($result)){ - $utimestamp = $row[0]; - for ($i=0; $i <= $resolution; $i++) { - if ( ($utimestamp <= $valores[$i][3]) && ($utimestamp >= $valores[$i][2]) ){ - $real_event[$i]=1; - } - } - } + if ($show_event) { + // If we want to show events in graphs + $sql1 = "SELECT utimestamp FROM tevento WHERE id_agentmodule = $id_agente_modulo AND utimestamp > $fechatope"; + $result = mysql_query($sql1); + while ($row=mysql_fetch_array($result)) { + $utimestamp = $row[0]; + for ($i=0; $i <= $resolution; $i++) { + if ($utimestamp <= $valores[$i][3] && $utimestamp >= $valores[$i][2]) { + $real_event[$i]=1; + } + } + } } - if ($show_alert == 1){ - $alert_high = 0; - $alert_low = 10000000; + if ($show_alert) { + $alert_high = false; + $alert_low = false; // If we want to show alerts limits - $sql1="SELECT * FROM talerta_agente_modulo where id_agente_modulo = ".$id_agente_modulo; - $result=mysql_query($sql1); - while ($row=mysql_fetch_array($result)){ - if ($row["dis_max"] > $alert_high) - $alert_high = $row["dis_max"]; - if ($row["dis_min"] < $alert_low) - $alert_low = $row["dis_min"]; - } + + $alert_high = get_db_value ('MAX(dis_max)', 'talerta_agente_modulo', 'id_agente_modulo', (int) $id_agente_modulo); + $alert_low = get_db_value ('MIN(dis_min)', 'talerta_agente_modulo', 'id_agente_modulo', (int) $id_agente_modulo); + // if no valid alert defined to render limits, disable it - if (($alert_low == 10000000) && ($alert_high == 0)){ + if (($alert_low === false) && ($alert_high === false)) { $show_alert = 0; } } @@ -425,26 +419,26 @@ function grafico_modulo_sparse ( $id_agente_modulo, $periodo, $show_event, // periodo - Gap of time, in seconds. This is now to (now-periodo) secs // Init tables - for ($x = 0; $x <= $resolution; $x++) { - $valores[$x][0] = 0; // SUM of all values for this interval - $valores[$x][1] = 0; // counter - $valores[$x][2] = $fechatope + ($horasint * $x); // [2] Top limit for this range - $valores[$x][3] = $fechatope + ($horasint*($x+1)); // [3] Botom limit - $valores[$x][4] = 0; // MIN - $valores[$x][5] = 0; // MAX - $valores[$x][6] = 0; // Event + for ($i = 0; $i <= $resolution; $i++) { + $valores[$i][0] = 0; // SUM of all values for this interval + $valores[$i][1] = 0; // counter + $valores[$i][2] = $fechatope + ($horasint * $i); // [2] Top limit for this range + $valores[$i][3] = $fechatope + ($horasint * ($i + 1)); // [3] Botom limit + $valores[$i][4] = 0; // MIN + $valores[$i][5] = 0; // MAX + $valores[$i][6] = 0; // Event } // Init other general variables - if ($show_event == 1){ + if ($show_event){ // If we want to show events in graphs - $sql1="SELECT utimestamp FROM tevento WHERE id_agente = $id_agente AND utimestamp > $fechatope"; - $result=mysql_query($sql1); - while ($row = mysql_fetch_array($result)){ + $sql = sprintf ('SELECT utimestamp FROM tevento WHERE id_agente = %d AND utimestamp > %d', $id_agente, $fechatope); + $eventos = get_db_all_rows_sqlfree ($sql); + foreach ($eventos as $row) { $utimestamp = $row[0]; - for ($i=0; $i <= $resolution; $i++) { - if ( ($utimestamp <= $valores[$i][3]) && ($utimestamp >= $valores[$i][2]) ){ - $real_event[$i]=1; + for ($i = 0; $i <= $resolution; $i++) { + if ($utimestamp <= $valores[$i][3] && $utimestamp >= $valores[$i][2]) { + $real_event[$i] = 1; } } } @@ -461,20 +455,21 @@ function grafico_modulo_sparse ( $id_agente_modulo, $periodo, $show_event, $row=mysql_fetch_array($result); $title=$title." [C] ".$row[0]; */ - $previous=0; // Get the first data outsite (to the left---more old) of the interval given - $sql1="SELECT datos,utimestamp FROM tagente_datos WHERE id_agente = $id_agente AND id_agente_modulo = $id_agente_modulo AND utimestamp < $fechatope ORDER BY utimestamp DESC LIMIT 1"; - $result=mysql_query($sql1); - if ($row=mysql_fetch_array($result)) - $previous=$row[0]; + $sql = sprintf ('SELECT datos, utimestamp FROM tagente_datos + WHERE id_agente = %d AND id_agente_modulo = %d + AND utimestamp < %d ORDER BY utimestamp DESC LIMIT 1', $id_agente, $id_agente_modulo, $fechatope); + $previous = (float) get_db_sql ($sql); - $sql1="SELECT datos,utimestamp FROM tagente_datos WHERE id_agente = $id_agente AND id_agente_modulo = $id_agente_modulo AND utimestamp > $fechatope"; - $result=mysql_query($sql1); - while ($row=mysql_fetch_array($result)){ + $sql = sprintf ('SELECT datos,utimestamp FROM tagente_datos + WHERE id_agente = %d AND id_agente_modulo = %d AND utimestamp > %d', + $id_agente, $id_agente_modulo, $fechatope); + $result = mysql_query ($sql); + while ($row = mysql_fetch_array ($result)) { $datos = $row[0]; $utimestamp = $row[1]; if ($datos >= 0) { - for ($i=0; $i <= $resolution; $i++) { + for ($i = 0; $i <= $resolution; $i++) { if ( ($utimestamp <= $valores[$i][3]) && ($utimestamp >= $valores[$i][2]) ){ $valores[$i][0]=$valores[$i][0]+$datos; $valores[$i][1]++; @@ -489,28 +484,28 @@ function grafico_modulo_sparse ( $id_agente_modulo, $periodo, $show_event, // Check max value if ($datos > $valores[$i][5]) $valores[$i][5] = $datos; - $i = $resolution+1; // BREAK FOR + break; } } } } // Calculate Average value for $valores[][0] - for ($x =0; $x <= $resolution; $x++) { - if ($valores[$x][1] > 0) - $valores[$x][0] = $valores[$x][0]/$valores[$x][1]; + for ($i =0; $i <= $resolution; $i++) { + if ($valores[$i][1] > 0) + $valores[$i][0] = $valores[$i][0]/$valores[$i][1]; else { - $valores[$x][0] = $previous; - $valores[$x][4] = $previous; - $valores[$x][5] = $previous; + $valores[$i][0] = $previous; + $valores[$i][4] = $previous; + $valores[$i][5] = $previous; } // Get max value for all graph - if ($valores[$x][5] > $max_value) - $max_value = $valores[$x][5]; + if ($valores[$i][5] > $max_value) + $max_value = $valores[$i][5]; // Take prev. value // TODO: CHeck if there are more than 24hours between // data, if there are > 24h, module down. - $previous = $valores[$x][0]; + $previous = $valores[$i][0]; } // Create graph @@ -572,17 +567,17 @@ function grafico_modulo_sparse ( $id_agente_modulo, $periodo, $show_event, $dataset_event -> setName("Event Fired"); } // ... and populated with data ... - for ($cc=0; $cc <= $resolution; $cc++) { - $tdate = date('d/m', $valores[$cc][2])."\n".date('H:i', $valores[$cc][2]); + for ($i = 0; $i <= $resolution; $i++) { + $tdate = date('d/m', $valores[$i][2])."\n".date('H:i', $valores[$i][2]); if ($avg_only == 0) { - $dataset[1]->addPoint($tdate, $valores[$cc][0]); - $dataset[0]->addPoint($tdate, $valores[$cc][5]); - $dataset[2]->addPoint($tdate, $valores[$cc][4]); + $dataset[1]->addPoint($tdate, $valores[$i][0]); + $dataset[0]->addPoint($tdate, $valores[$i][5]); + $dataset[2]->addPoint($tdate, $valores[$i][4]); } else { - $dataset[0]->addPoint($tdate, $valores[$cc][0]); + $dataset[0]->addPoint($tdate, $valores[$i][0]); } - if (($show_event == 1) AND (isset($real_event[$cc]))) { - $dataset_event->addPoint($tdate, $valores[$cc][5]); + if (($show_event == 1) AND (isset($real_event[$i]))) { + $dataset_event->addPoint($tdate, $valores[$i][5]); } } @@ -657,64 +652,65 @@ function grafico_modulo_sparse ( $id_agente_modulo, $periodo, $show_event, graphic_error (); } -function generic_pie_graph ($width=300, $height=200, $data, $legend) { +function generic_pie_graph ($width = 300, $height = 200, $data, $legend) { require ("../include/config.php"); require_once 'Image/Graph.php'; require ("../include/languages/language_".$config['language'].".php"); - if (sizeof($data) > 0){ - // create the graph - $driver=& Image_Canvas::factory('png',array('width'=>$width,'height'=>$height,'antialias' => 'native')); - $Graph = & Image_Graph::factory('graph', $driver); - // add a TrueType font - $Font =& $Graph->addNew('font', $config['fontpath']); - // set the font size to 7 pixels - $Font->setSize(7); - $Graph->setFont($Font); - // create the plotarea - $Graph->add( - Image_Graph::horizontal( - $Plotarea = Image_Graph::factory('plotarea'), - $Legend = Image_Graph::factory('legend'), - 50 - ) - ); - $Legend->setPlotarea($Plotarea); - // Create the dataset - // Merge data into a dataset object (sancho) - $Dataset1 =& Image_Graph::factory('dataset'); - for ($a=0;$a < sizeof($data); $a++){ - $Dataset1->addPoint(str_pad($legend[$a],15), $data[$a]); - } - $Plot =& $Plotarea->addNew('pie', $Dataset1); - $Plotarea->hideAxis(); - // create a Y data value marker - $Marker =& $Plot->addNew('Image_Graph_Marker_Value', IMAGE_GRAPH_PCT_Y_TOTAL); - // create a pin-point marker type - $PointingMarker =& $Plot->addNew('Image_Graph_Marker_Pointing_Angular', array(1, &$Marker)); - // and use the marker on the 1st plot - $Plot->setMarker($PointingMarker); - // format value marker labels as percentage values - $Marker->setDataPreprocessor(Image_Graph::factory('Image_Graph_DataPreprocessor_Formatted', '%0.1f%%')); - $Plot->Radius = 15; - $FillArray =& Image_Graph::factory('Image_Graph_Fill_Array'); - $Plot->setFillStyle($FillArray); - - $FillArray->addColor('green@0.7'); - $FillArray->addColor('yellow@0.7'); - $FillArray->addColor('red@0.7'); - $FillArray->addColor('orange@0.7'); - $FillArray->addColor('blue@0.7'); - $FillArray->addColor('purple@0.7'); - $FillArray->addColor('lightgreen@0.7'); - $FillArray->addColor('lightblue@0.7'); - $FillArray->addColor('lightred@0.7'); - $FillArray->addColor('grey@0.6', 'rest'); - $Plot->explode(6); - $Plot->setStartingAngle(0); - // output the Graph - $Graph->done(); - } else + if (sizeof($data) == 0) { graphic_error (); + return; + } + // create the graph + $driver=& Image_Canvas::factory('png',array('width'=>$width,'height'=>$height,'antialias' => 'native')); + $Graph = & Image_Graph::factory('graph', $driver); + // add a TrueType font + $Font =& $Graph->addNew('font', $config['fontpath']); + // set the font size to 7 pixels + $Font->setSize(7); + $Graph->setFont($Font); + // create the plotarea + $Graph->add( + Image_Graph::horizontal( + $Plotarea = Image_Graph::factory('plotarea'), + $Legend = Image_Graph::factory('legend'), + 50 + ) + ); + $Legend->setPlotarea($Plotarea); + // Create the dataset + // Merge data into a dataset object (sancho) + $Dataset1 =& Image_Graph::factory('dataset'); + for ($i = 0; $i < sizeof($data); $i++) { + $Dataset1->addPoint(str_pad($legend[$i],15), $data[$i]); + } + $Plot =& $Plotarea->addNew('pie', $Dataset1); + $Plotarea->hideAxis(); + // create a Y data value marker + $Marker =& $Plot->addNew('Image_Graph_Marker_Value', IMAGE_GRAPH_PCT_Y_TOTAL); + // create a pin-point marker type + $PointingMarker =& $Plot->addNew('Image_Graph_Marker_Pointing_Angular', array(1, &$Marker)); + // and use the marker on the 1st plot + $Plot->setMarker($PointingMarker); + // format value marker labels as percentage values + $Marker->setDataPreprocessor(Image_Graph::factory('Image_Graph_DataPreprocessor_Formatted', '%0.1f%%')); + $Plot->Radius = 15; + $FillArray =& Image_Graph::factory('Image_Graph_Fill_Array'); + $Plot->setFillStyle($FillArray); + + $FillArray->addColor('green@0.7'); + $FillArray->addColor('yellow@0.7'); + $FillArray->addColor('red@0.7'); + $FillArray->addColor('orange@0.7'); + $FillArray->addColor('blue@0.7'); + $FillArray->addColor('purple@0.7'); + $FillArray->addColor('lightgreen@0.7'); + $FillArray->addColor('lightblue@0.7'); + $FillArray->addColor('lightred@0.7'); + $FillArray->addColor('grey@0.6', 'rest'); + $Plot->explode(6); + $Plot->setStartingAngle(0); + // output the Graph + $Graph->done(); } @@ -725,22 +721,22 @@ function graphic_agentmodules($id_agent, $width, $height) { $sql1="SELECT * FROM ttipo_modulo"; $result=mysql_query($sql1); - $ax = 0; + $ntipos = 0; while ($row=mysql_fetch_array($result)){ - $data_label[$ax]=$row["nombre"]; - $data[$ax]=0; - $data_id[$ax] = $row["id_tipo"]; - $ax++; + $data_label[$ntipos]=$row["nombre"]; + $data[$ntipos]=0; + $data_id[$ntipos] = $row["id_tipo"]; + $ntipos++; } $cx=0; $sql1="SELECT * FROM tagente_modulo WHERE id_agente = ".$id_agent; $result=mysql_query($sql1); while ($row=mysql_fetch_array($result)){ $cx++; - for ($bx=0;$bx<=$ax;$bx++){ - if (isset($data_id[$bx])){ - if ($data_id[$bx] == $row["id_tipo_modulo"]){ - $data[$bx]++; + for ($i = 0; $i <= $ntipos; $i++){ + if (isset($data_id[$i])){ + if ($data_id[$i] == $row["id_tipo_modulo"]) { + $data[$i]++; } } } @@ -749,16 +745,16 @@ function graphic_agentmodules($id_agent, $width, $height) { $data_label2 = ""; $mayor = 0; $mayor_data =0; - for ($a=0;$a < sizeof($data); $a++) - if ($data[$a] > $mayor_data){ - $mayor = $a; - $mayor_data = $data[$a]; + for ($i = 0; $i < sizeof($data); $i++) + if ($data[$i] > $mayor_data){ + $mayor = $i; + $mayor_data = $data[$i]; } $bx=0; - for ($a=0;$a < sizeof($data_label); $a++){ - if ($data[$a] > 0){ - $data_label2[$bx] = $data_label[$a]; - $data2[$bx] = $data[$a]; + for ($i=0;$i < sizeof($data_label); $i++){ + if ($data[$i] > 0){ + $data_label2[$bx] = $data_label[$i]; + $data2[$bx] = $data[$i]; $bx++; } } @@ -766,7 +762,7 @@ function graphic_agentmodules($id_agent, $width, $height) { } -function graphic_agentaccess($id_agent, $periodo, $width, $height){ +function graphic_agentaccess ($id_agent, $periodo, $width, $height) { include ("../include/config.php"); require_once 'Image/Graph.php'; require ("../include/languages/language_".$config['language'].".php"); @@ -793,11 +789,11 @@ function graphic_agentaccess($id_agent, $periodo, $width, $height){ // esto acelera el tiempo de calculo al maximo, aunque complica el algoritmo :-) // Creamos la tabla (array) con los valores para el grafico. Inicializacion - for ($x = 0; $x <$intervalo; $x++) { - $valores[$x][0] = 0; // [0] Valor (contador) - $valores[$x][1] = 0; // [0] Valor (contador) - $valores[$x][2] = dame_fecha($horasint * $x); // [2] Rango superior de fecha para ese rango - $valores[$x][3] = dame_fecha($horasint*($x+1)); // [3] Rango inferior de fecha para ese rango + for ($i = 0; $i <$intervalo; $i++) { + $valores[$i][0] = 0; // [0] Valor (contador) + $valores[$i][1] = 0; // [0] Valor (contador) + $valores[$i][2] = dame_fecha($horasint * $i); // [2] Rango superior de fecha para ese rango + $valores[$i][3] = dame_fecha($horasint*($i+1)); // [3] Rango inferior de fecha para ese rango } $sql1="SELECT * FROM tagent_access WHERE id_agent = ".$id_agent." and timestamp > '".$fechatope."'"; @@ -834,8 +830,8 @@ function graphic_agentaccess($id_agent, $periodo, $width, $height){ // Create the dataset // Merge data into a dataset object (sancho) $Dataset =& Image_Graph::factory('dataset'); - for ($a=0;$a < sizeof($grafica); $a++){ - $Dataset->addPoint($a,$grafica[$a]); + for ($i = 0; $i < sizeof($grafica); $i++) { + $Dataset->addPoint ($i, $grafica[$i]); } // create the 1st plot as smoothed area chart using the 1st dataset $Plot =& $Plotarea->addNew('area', array(&$Dataset)); @@ -883,17 +879,17 @@ function grafico_incidente_estados() { } $mayor = 0; $mayor_data =0; - for ($a=0;$a < sizeof($data); $a++){ - if ($data[$a] > $mayor_data){ - $mayor = $a; - $mayor_data = $data[$a]; + for ($i = 0; $i < sizeof($data); $i++) { + if ($data[$i] > $mayor_data) { + $mayor = $i; + $mayor_data = $data[$i]; } } $legend = array ("Open Incident", "Closed Incident", "Outdated", "Invalid"); generic_pie_graph (370, 180,$data, $legend); } -function grafico_incidente_prioridad() { +function grafico_incidente_prioridad () { include ("../include/config.php"); require ("../include/languages/language_".$config['language'].".php"); @@ -921,10 +917,10 @@ function grafico_incidente_prioridad() { $mayor = 0; $mayor_data =0; - for ($a=0;$a < sizeof($data); $a++) - if ($data[$a] > $mayor_data){ - $mayor = $a; - $mayor_data = $data[$a]; + for ($i = 0;$i < sizeof($data); $i++) + if ($data[$i] > $mayor_data){ + $mayor = $i; + $mayor_data = $data[$i]; } $legend = array ("Informative","Low","Medium","Serious", "Very serious", "Maintance"); generic_pie_graph (320, 200, $data, $legend); @@ -947,23 +943,23 @@ function graphic_incident_group() { } // Sort array by bubble method (yes, I study more methods in university, but if you want more speed, please, submit a patch :) // or much better, pay me to do a special version for you, highly optimized :-)))) - for ($a=0;$a < sizeof($data);$a++){ - for ($b=$a; $b $data[$a]){ - $temp = $data[$a]; - $temp_label = $legend[$a]; - $data[$a] = $data[$b]; - $legend[$a] = $legend[$b]; - $data[$b] = $temp; - $legend[$b] = $temp_label; + for ($i = 0; $i < sizeof($data); $i++) { + for ($j = $i; $j $data[$i]) { + $temp = $data[$i]; + $temp_label = $legend[$i]; + $data[$i] = $data[$j]; + $legend[$i] = $legend[$j]; + $data[$j] = $temp; + $legend[$j] = $temp_label; } } $mayor = 0; $mayor_data =0; - for ($a=0;$a < sizeof($data); $a++){ - if ($data[$a] > $mayor_data){ - $mayor = $a; - $mayor_data = $data[$a]; + for ($i = 0; $i < sizeof($data); $i++) { + if ($data[$i] > $mayor_data) { + $mayor = $i; + $mayor_data = $data[$i]; } } generic_pie_graph (320, 200, $data, $legend); @@ -986,23 +982,23 @@ function graphic_incident_user() { } // Sort array by bubble method (yes, I study more methods in university, but if you want more speed, please, submit a patch :) // or much better, pay me to do a special version for you, highly optimized :-)))) - for ($a=0;$a < sizeof($data);$a++){ - for ($b=$a; $b $data[$a]){ - $temp = $data[$a]; - $temp_label = $legend[$a]; - $data[$a] = $data[$b]; - $legend[$a] = $legend[$b]; - $data[$b] = $temp; - $legend[$b] = $temp_label; + for ($i = 0; $i < sizeof($data); $i++) { + for ($j = $i; $j $data[$i]) { + $temp = $data[$i]; + $temp_label = $legend[$i]; + $data[$i] = $data[$j]; + $legend[$i] = $legend[$j]; + $data[$j] = $temp; + $legend[$j] = $temp_label; } } $mayor = 0; $mayor_data =0; - for ($a=0;$a < sizeof($data); $a++){ - if ($data[$a] > $mayor_data){ - $mayor = $a; - $mayor_data = $data[$a]; + for ($i = 0; $i < sizeof($data); $i++) { + if ($data[$i] > $mayor_data) { + $mayor = $i; + $mayor_data = $data[$i]; } } generic_pie_graph (320, 200, $data, $legend); @@ -1027,23 +1023,23 @@ function graphic_user_activity($width=350, $height=230) { // Sort array by bubble method (yes, I study more methods in university, but if you want more speed, please, submit a patch :) // or much better, pay me to do a special version for you, highly optimized :-)))) - for ($a=0;$a < sizeof($data);$a++){ - for ($b=$a; $b $data[$a]){ - $temp = $data[$a]; - $temp_label = $legend[$a]; - $data[$a] = $data[$b]; - $legend[$a] = $legend[$b]; - $data[$b] = $temp; - $legend[$b] = $temp_label; + for ($i = 0; $i < sizeof($data); $i++) { + for ($j = $i; $j $data[$i]) { + $temp = $data[$i]; + $temp_label = $legend[$i]; + $data[$i] = $data[$j]; + $legend[$i] = $legend[$j]; + $data[$j] = $temp; + $legend[$j] = $temp_label; } } // Take only the first 5 items if (sizeof($data) >= 5){ - for ($a=0;$a < 5;$a++){ - $legend2[]= $legend[$a]; - $data2[] = $data[$a]; + for ($i = 0; $i < 5; $i++) { + $legend2[]= $legend[$i]; + $data2[] = $data[$i]; } generic_pie_graph ($width, $height, $data2, $legend2); } else @@ -1067,22 +1063,22 @@ function graphic_incident_source ($width=320, $height=200) { } // Sort array by bubble method (yes, I study more methods in university, but if you want more speed, please, submit a patch :) // or much better, pay me to do a special version for you, highly optimized :-)))) - for ($a=0;$a < sizeof($data);$a++){ - for ($b=$a; $b $data[$a]){ - $temp = $data[$a]; - $temp_label = $legend[$a]; - $data[$a] = $data[$b]; - $legend[$a] = $legend[$b]; - $data[$b] = $temp; - $legend[$b] = $temp_label; + for ($i = 0; $i < sizeof($data); $i++) { + for ($j = $i; $j $data[$i]) { + $temp = $data[$i]; + $temp_label = $legend[$i]; + $data[$i] = $data[$j]; + $legend[$i] = $legend[$j]; + $data[$j] = $temp; + $legend[$j] = $temp_label; } } // Take only the first 5 items if (sizeof($data) >= 5){ - for ($a=0;$a < 5;$a++){ - $legend2[]= $legend[$a]; - $data2[] = $data[$a]; + for ($i = 0; $i < 5; $i++) { + $legend2[]= $legend[$i]; + $data2[] = $data[$i]; } generic_pie_graph ($width, $height, $data2, $legend2); } else @@ -1106,15 +1102,15 @@ function grafico_db_agentes_modulos($width, $height) { } // Sort array by bubble method (yes, I study more methods in university, but if you want more speed, please, submit a patch :) // or much better, pay me to do a special version for you, highly optimized :-)))) - for ($a=0;$a < sizeof($data);$a++){ - for ($b=$a; $b $data[$a]){ - $temp = $data[$a]; - $temp_label = $legend[$a]; - $data[$a] = $data[$b]; - $legend[$a] = $legend[$b]; - $data[$b] = $temp; - $legend[$b] = $temp_label; + for ($i = 0; $i < sizeof($data); $i++) { + for ($j = $i; $j $data[$i]) { + $temp = $data[$i]; + $temp_label = $legend[$i]; + $data[$i] = $data[$j]; + $legend[$i] = $legend[$j]; + $data[$j] = $temp; + $legend[$j] = $temp_label; } } generic_bar_graph ($width, $height, $data, $legend); @@ -1139,31 +1135,32 @@ function grafico_eventos_usuario( $width=420, $height=200) { } // Sort array by bubble method (yes, I study more methods in university, but if you want more speed, please, submit a patch :) // or much better, pay me to do a special version for you, highly optimized :-)))) - for ($a=0;$a < sizeof($data);$a++){ - for ($b=$a; $b $data[$a]){ - $temp = $data[$a]; - $temp_label = $legend[$a]; - $data[$a] = $data[$b]; - $legend[$a] = $legend[$b]; - $data[$b] = $temp; - $legend[$b] = $temp_label; + for ($i = 0; $i < sizeof($data); $i++) { + for ($j = $i; $j $data[$i]) { + $temp = $data[$i]; + $temp_label = $legend[$i]; + $data[$i] = $data[$j]; + $legend[$i] = $legend[$j]; + $data[$j] = $temp; + $legend[$j] = $temp_label; } } // Take only the first 5 items if (sizeof($data) >= 5){ - for ($a=0;$a < 5;$a++){ - $legend2[]= $legend[$a]; - $data2[] = $data[$a]; + for ($i = 0; $i < 5; $i++) { + $legend2[]= $legend[$i]; + $data2[] = $data[$i]; } generic_pie_graph ($width, $height, $data2, $legend2); } else generic_pie_graph ($width, $height, $data, $legend); } -function grafico_eventos_total( $filter = "") { +function grafico_eventos_total ($filter = "") { require ("../include/config.php"); require ("../include/languages/language_".$config['language'].".php"); + $filter = str_replace ( "\\" , "", $filter); $data = array(); $legend = array(); @@ -1183,139 +1180,137 @@ function grafico_eventos_total( $filter = "") { $total = $total + $row[0]; $legend[] = lang_string("Informational")."( $row[0] )"; - $sql1="SELECT COUNT(id_evento) FROM tevento WHERE criticity = 2 $filter"; - $result=mysql_query($sql1); - $row=mysql_fetch_array($result); - $data[] = $row[0]; - $total = $total + $row[0]; - $legend[] = lang_string("Normal")." ( $row[0] )"; + $sql1="SELECT COUNT(id_evento) FROM tevento WHERE criticity = 2 $filter"; + $result=mysql_query($sql1); + $row=mysql_fetch_array($result); + $data[] = $row[0]; + $total = $total + $row[0]; + $legend[] = lang_string("Normal")." ( $row[0] )"; - $sql1="SELECT COUNT(id_evento) FROM tevento WHERE criticity = 3 $filter"; - $result=mysql_query($sql1); - $row=mysql_fetch_array($result); - $data[] = $row[0]; - $total = $total + $row[0]; - $legend[] = lang_string("Warning")." ( $row[0] )"; + $sql1="SELECT COUNT(id_evento) FROM tevento WHERE criticity = 3 $filter"; + $result=mysql_query($sql1); + $row=mysql_fetch_array($result); + $data[] = $row[0]; + $total = $total + $row[0]; + $legend[] = lang_string("Warning")." ( $row[0] )"; - $sql1="SELECT COUNT(id_evento) FROM tevento WHERE criticity = 4 $filter"; - $result=mysql_query($sql1); - $row=mysql_fetch_array($result); - $data[] = $row[0]; - $total = $total + $row[0]; - $legend[] = lang_string("Critical")." ( $row[0] )"; + $sql1="SELECT COUNT(id_evento) FROM tevento WHERE criticity = 4 $filter"; + $result=mysql_query($sql1); + $row=mysql_fetch_array($result); + $data[] = $row[0]; + $total = $total + $row[0]; + $legend[] = lang_string("Critical")." ( $row[0] )"; // Sort array by bubble method (yes, I study more methods in university, but if you want more speed, please, submit a patch :) // or much better, pay me to do a special version for you, highly optimized :-)))) - for ($a=0;$a < sizeof($data);$a++){ - for ($b=$a; $b $data[$a]){ - $temp = $data[$a]; - $temp_label = $legend[$a]; - $data[$a] = $data[$b]; - $legend[$a] = $legend[$b]; - $data[$b] = $temp; - $legend[$b] = $temp_label; + for ($i = 0; $i < sizeof($data); $i++) { + for ($j = $i; $j $data[$i]){ + $temp = $data[$i]; + $temp_label = $legend[$i]; + $data[$i] = $data[$j]; + $legend[$i] = $legend[$j]; + $data[$j] = $temp; + $legend[$j] = $temp_label; } } generic_pie_graph (320, 200, $data, $legend); } +function graph_event_module ($width = 300, $height = 200, $id_agent) { + include ("../include/config.php"); + require ("../include/languages/language_".$config['language'].".php"); + global $config; - -function graph_event_module ($width = 300, $height = 200, $id_agent ) { - include ("../include/config.php"); - require ("../include/languages/language_".$config['language'].".php"); - global $config; - - // Need ACL check - $data = array(); - $legend = array(); - $sql1="SELECT * FROM tagente_modulo WHERE id_agente = $id_agent AND disabled = 0"; - $result=mysql_query($sql1); - while ($row=mysql_fetch_array($result)){ - $sql1="SELECT COUNT(*) FROM tevento WHERE id_agentmodule = ".$row["id_agente_modulo"]; - if ($result2=mysql_query($sql1)) - $row2=mysql_fetch_array($result2); - if ($row2[0] > 0){ - $data[] = $row2[0]; - $legend[] = substr($row["nombre"],0,15)." ( $row2[0] )"; - } - } - // Sort array by bubble method (yes, I study more methods in university, but if you want more speed, please, submit a patch :) - // or much better, pay me to do a special version for you, highly optimized :-)))) - for ($a=0;$a < sizeof($data);$a++){ - for ($b=$a; $b $data[$a]){ - $temp = $data[$a]; - $temp_label = $legend[$a]; - $data[$a] = $data[$b]; - $legend[$a] = $legend[$b]; - $data[$b] = $temp; - $legend[$b] = $temp_label; - } - } - $max_items = 6; - // Take only the first x items - if (sizeof($data) >= $max_items){ - for ($a=0;$a < $max_items;$a++){ - $legend2[]= $legend[$a]; - $data2[] = $data[$a]; - } - generic_pie_graph ($width, $height, $data2, $legend2); - } else - generic_pie_graph ($width, $height, $data, $legend); + // Need ACL check + $data = array(); + $legend = array(); + $sql1="SELECT * FROM tagente_modulo WHERE id_agente = $id_agent AND disabled = 0"; + $result=mysql_query($sql1); + while ($row=mysql_fetch_array($result)){ + $sql1="SELECT COUNT(*) FROM tevento WHERE id_agentmodule = ".$row["id_agente_modulo"]; + if ($result2=mysql_query($sql1)) + $row2=mysql_fetch_array($result2); + if ($row2[0] > 0) { + $data[] = $row2[0]; + $legend[] = substr($row["nombre"],0,15)." ( $row2[0] )"; + } + } + // Sort array by bubble method (yes, I study more methods in university, but if you want more speed, please, submit a patch :) + // or much better, pay me to do a special version for you, highly optimized :-)))) + for ($i = 0; $i < sizeof ($data); $i++) { + for ($j = $i; $j $data[$i]) { + $temp = $data[$i]; + $temp_label = $legend[$i]; + $data[$i] = $data[$j]; + $legend[$i] = $legend[$j]; + $data[$j] = $temp; + $legend[$j] = $temp_label; + } + } + $max_items = 6; + // Take only the first x items + if (sizeof($data) >= $max_items) { + for ($i = 0; $i < $max_items; $i++) { + $legend2[] = $legend[$i]; + $data2[] = $data[$i]; + } + generic_pie_graph ($width, $height, $data2, $legend2); + } else + generic_pie_graph ($width, $height, $data, $legend); } -function grafico_eventos_grupo ($width = 300, $height = 200, $url = "" ) { +function grafico_eventos_grupo ($width = 300, $height = 200, $url = "") { include ("../include/config.php"); require ("../include/languages/language_".$config['language'].".php"); - global $config; - $url = str_replace ( "\\" , "", $url); + + global $config; + $url = str_replace ( "\\" , "", $url); $data = array(); $legend = array(); $sql1="SELECT * FROM tagente"; $result=mysql_query($sql1); while ($row=mysql_fetch_array($result)){ - if (give_acl($config["id_user"], $row["id_grupo"], "AR") == 1){ - $sql1="SELECT COUNT(id_evento) FROM tevento WHERE 1=1 $url AND id_agente = ".$row["id_agente"]; - if ($result2=mysql_query($sql1)) - $row2=mysql_fetch_array($result2); - if ($row2[0] > 0){ - $data[] = $row2[0]; - $legend[] = substr($row["nombre"],0,15)." ( $row2[0] )"; - } - } + if (give_acl($config["id_user"], $row["id_grupo"], "AR") == 1) { + $sql1="SELECT COUNT(id_evento) FROM tevento WHERE 1=1 $url AND id_agente = ".$row["id_agente"]; + if ($result2=mysql_query($sql1)) + $row2=mysql_fetch_array($result2); + if ($row2[0] > 0) { + $data[] = $row2[0]; + $legend[] = substr($row["nombre"],0,15)." ( $row2[0] )"; + } + } + } + // System events + $sql1="SELECT COUNT(id_evento) FROM tevento WHERE 1=1 $url AND id_agente = 0"; + if ($result2 = mysql_query($sql1)) + $row2=mysql_fetch_array($result2); + if ($row2[0] > 0){ + $data[] = $row2[0]; + $legend[] = "SYSTEM"." ( $row2[0] )"; } - - // System events - $sql1="SELECT COUNT(id_evento) FROM tevento WHERE 1=1 $url AND id_agente = 0"; - if ($result2=mysql_query($sql1)) - $row2=mysql_fetch_array($result2); - if ($row2[0] > 0){ - $data[] = $row2[0]; - $legend[] = "SYSTEM"." ( $row2[0] )"; - } // Sort array by bubble method (yes, I study more methods in university, but if you want more speed, please, submit a patch :) // or much better, pay me to do a special version for you, highly optimized :-)))) - for ($a=0;$a < sizeof($data);$a++){ - for ($b=$a; $b $data[$a]){ - $temp = $data[$a]; - $temp_label = $legend[$a]; - $data[$a] = $data[$b]; - $legend[$a] = $legend[$b]; - $data[$b] = $temp; - $legend[$b] = $temp_label; + for ($i=0;$i < sizeof($data);$i++){ + for ($j=$i; $j $data[$i]) { + $temp = $data[$i]; + $temp_label = $legend[$i]; + $data[$i] = $data[$j]; + $legend[$i] = $legend[$j]; + $data[$j] = $temp; + $legend[$j] = $temp_label; } } $max_items = 6; // Take only the first x items if (sizeof($data) >= $max_items){ - for ($a=0;$a < $max_items;$a++){ - $legend2[]= $legend[$a]; - $data2[] = $data[$a]; + for ($i = 0; $i < $max_items; $i++){ + $legend2[]= $legend[$i]; + $data2[] = $data[$i]; } generic_pie_graph ($width, $height, $data2, $legend2); } else @@ -1328,9 +1323,9 @@ function generic_bar_graph ( $width =380, $height = 200, $data, $legend) { require_once 'Image/Graph.php'; require ("../include/languages/language_".$config['language'].".php"); - if (sizeof($data) > 10){ - $height = sizeof($legend) * 20; - } + if (sizeof($data) > 10){ + $height = sizeof($legend) * 20; + } // create the graph $Graph =& Image_Graph::factory('graph', array($width, $height)); @@ -1350,8 +1345,8 @@ function generic_bar_graph ( $width =380, $height = 200, $data, $legend) { // Create the dataset // Merge data into a dataset object (sancho) $Dataset1 =& Image_Graph::factory('dataset'); - for ($a=0;$a < sizeof($data); $a++){ - $Dataset1->addPoint(substr($legend[$a],0,22), $data[$a]); + for ($i = 0; $i < sizeof($data); $i++) { + $Dataset1->addPoint(substr($legend[$i], 0, 22), $data[$i]); } $Plot =& $Plotarea->addNew('bar', $Dataset1); $GridY2 =& $Plotarea->addNew('bar_grid', IMAGE_GRAPH_AXIS_Y_SECONDARY); @@ -1385,15 +1380,15 @@ function grafico_db_agentes_paquetes ($width = 380, $height = 300) { } // Sort array by bubble method (yes, I study more methods in university, but if you want more speed, please, submit a patch :) // or much better, pay me to do a special version for you, highly optimized :-)))) - for ($a=0;$a < sizeof($data);$a++){ - for ($b=$a; $b $data[$a]){ - $temp = $data[$a]; - $temp_label = $legend[$a]; - $data[$a] = $data[$b]; - $legend[$a] = $legend[$b]; - $data[$b] = $temp; - $legend[$b] = $temp_label; + for ($i=0;$i < sizeof($data);$i++){ + for ($j=$i; $j $data[$i]){ + $temp = $data[$i]; + $temp_label = $legend[$i]; + $data[$i] = $data[$j]; + $legend[$i] = $legend[$j]; + $data[$j] = $temp; + $legend[$j] = $temp_label; } } generic_bar_graph ($width, $height, $data, $legend); @@ -1404,8 +1399,8 @@ function grafico_db_agentes_purge ($id_agent, $width, $height) { require_once 'Image/Graph.php'; require ("../include/languages/language_".$config['language'].".php"); - if ($id_agent == 0) - $id_agent = -1; + if ($id_agent == 0) + $id_agent = -1; // All data (now) $purge_all=date("Y-m-d H:i:s",time()); @@ -1420,28 +1415,28 @@ function grafico_db_agentes_purge ($id_agent, $width, $height) { $fechas_label = array("30-90 days","7-30 days","This week","Today"); // Calc. total packets - $sql1="SELECT COUNT(id_agente_datos) FROM tagente_datos";; - $result2=mysql_query($sql1); - $row2=mysql_fetch_array($result2); - $total = $row2[0]; + $sql1 = "SELECT COUNT(id_agente_datos) FROM tagente_datos"; + $result2 = mysql_query ($sql1); + $row2 = mysql_fetch_array ($result2); + $total = $row2[0]; - for ($a=0; $a < sizeof ($fechas); $a++){ + for ($i = 0; $i < sizeof ($fechas); $i++){ // 4 x intervals will be enought, increase if your database is very very fast :) - if ($a==3){ + if ($i == 3) { if ($id_agent == -1) - $sql1="SELECT COUNT(id_agente_datos) FROM tagente_datos WHERE utimestamp >= ".$fechas[$a]; + $sql1="SELECT COUNT(id_agente_datos) FROM tagente_datos WHERE utimestamp >= ".$fechas[$i]; else - $sql1="SELECT COUNT(id_agente_datos) FROM tagente_datos WHERE id_agente = $id_agent AND utimestamp >= ".$fechas[$a]; + $sql1="SELECT COUNT(id_agente_datos) FROM tagente_datos WHERE id_agente = $id_agent AND utimestamp >= ".$fechas[$i]; } else { if ($id_agent == -1) - $sql1="SELECT COUNT(id_agente_datos) FROM tagente_datos WHERE utimestamp >= ".$fechas[$a]." AND utimestamp < ".$fechas[$a+1]; + $sql1="SELECT COUNT(id_agente_datos) FROM tagente_datos WHERE utimestamp >= ".$fechas[$i]." AND utimestamp < ".$fechas[$i+1]; else - $sql1="SELECT COUNT(id_agente_datos) FROM tagente_datos WHERE id_agente = $id_agent AND utimestamp >= ".$fechas[$a]." AND utimestamp < ".$fechas[$a+1]; + $sql1="SELECT COUNT(id_agente_datos) FROM tagente_datos WHERE id_agente = $id_agent AND utimestamp >= ".$fechas[$i]." AND utimestamp < ".$fechas[$i+1]; } $result=mysql_query($sql1); $row=mysql_fetch_array($result); $data[] = $row[0]; - $legend[]=$fechas_label[$a]." ( ".format_for_graph($row[0],0)." )"; + $legend[]=$fechas_label[$i]." ( ".format_for_graph($row[0],0)." )"; } generic_pie_graph ($width, $height, $data, $legend); } @@ -1477,84 +1472,84 @@ function drawWarning($width,$height) { // *************************************************************************** function progress_bar ($progress, $width, $height, $mode = 1) { - // Copied from the PHP manual: - // http://us3.php.net/manual/en/function.imagefilledrectangle.php - // With some adds from sdonie at lgc dot com - // Get from official documentation PHP.net website. Thanks guys :-) - function drawRating($rating, $width, $height, $mode) { - include ("../include/config.php"); - require ("../include/languages/language_".$config["language"].".php"); - $rating = format_numeric($rating,1); - if ($width == 0) { - $width = 150; - } - if ($height == 0) { - $height = 20; - } + // Copied from the PHP manual: + // http://us3.php.net/manual/en/function.imagefilledrectangle.php + // With some adds from sdonie at lgc dot com + // Get from official documentation PHP.net website. Thanks guys :-) + function drawRating($rating, $width, $height, $mode) { + include ("../include/config.php"); + require ("../include/languages/language_".$config["language"].".php"); + $rating = format_numeric($rating,1); + if ($width == 0) { + $width = 150; + } + if ($height == 0) { + $height = 20; + } - //$rating = $_GET['rating']; - $ratingbar = (($rating/100)*$width)-2; + //$rating = $_GET['rating']; + $ratingbar = (($rating/100)*$width)-2; - $image = imagecreate($width,$height); - //colors - $back = ImageColorAllocate($image,255,255,255); - $border = ImageColorAllocate($image,140,140,140); - $textcolor = ImageColorAllocate($image,60,60,60); - $red = ImageColorAllocate($image,255,60,75); + $image = imagecreate($width,$height); + //colors + $back = ImageColorAllocate($image,255,255,255); + $border = ImageColorAllocate($image,140,140,140); + $textcolor = ImageColorAllocate($image,60,60,60); + $red = ImageColorAllocate($image,255,60,75); - if ($mode == 0){ - if ($rating > 70) - $fill = ImageColorAllocate($image,176,255,84); // Green - elseif ($rating > 50) - $fill = ImageColorAllocate($image,255,230,84); // Yellow - elseif ($rating > 30) - $fill = ImageColorAllocate($image,255,154,83); // Orange - else - $fill = ImageColorAllocate($image,255,0,0); // Red - } - else - $fill = ImageColorAllocate($image,44,81,150); - + if ($mode == 0){ + if ($rating > 70) + $fill = ImageColorAllocate($image,176,255,84); // Green + elseif ($rating > 50) + $fill = ImageColorAllocate($image,255,230,84); // Yellow + elseif ($rating > 30) + $fill = ImageColorAllocate($image,255,154,83); // Orange + else + $fill = ImageColorAllocate($image,255,0,0); // Red + } + else + $fill = ImageColorAllocate($image,44,81,150); - $grey = ImageColorAllocate($image,230,230,210); - if ($mode == 1){ - ImageFilledRectangle($image,0,0,$width-1,$height-1,$back); - } else { - ImageFilledRectangle($image,0,0,$width-1,$height-1,$grey); - } - if ($rating > 100) - ImageFilledRectangle($image,1,1,$ratingbar,$height-1,$red); - else - ImageFilledRectangle($image,1,1,$ratingbar,$height-1,$fill); - if ($mode == 1){ - ImageRectangle($image,0,0,$width-1,$height-1,$border); - } - if ($mode == 1){ - if ($rating > 50) - if ($rating > 100) - ImageTTFText($image, 8, 0, ($width/4), ($height/2)+($height/5), $back, $config["fontpath"], lang_string ("out_of_limits")); - else - ImageTTFText($image, 8, 0, ($width/2)-($width/10), ($height/2)+($height/5), $back, $config["fontpath"], $rating."%"); - else - ImageTTFText($image, 8, 0, ($width/2)-($width/10), ($height/2)+($height/5), $textcolor, $config["fontpath"], $rating."%"); - } - imagePNG($image); - imagedestroy($image); - } - Header("Content-type: image/png"); - if ($progress > 100 || $progress < 0){ - // HACK: This report a static image... will increase render in about 200% :-) useful for - // high number of realtime statusbar images creation (in main all agents view, for example - $imgPng = imageCreateFromPng("../images/outof.png"); - imageAlphaBlending($imgPng, true); - imageSaveAlpha($imgPng, true); - imagePng($imgPng); - } else - drawRating($progress,$width,$height,$mode); + $grey = ImageColorAllocate($image,230,230,210); + + if ($mode == 1){ + ImageFilledRectangle($image,0,0,$width-1,$height-1,$back); + } else { + ImageFilledRectangle($image,0,0,$width-1,$height-1,$grey); + } + if ($rating > 100) + ImageFilledRectangle($image,1,1,$ratingbar,$height-1,$red); + else + ImageFilledRectangle($image,1,1,$ratingbar,$height-1,$fill); + if ($mode == 1){ + ImageRectangle($image,0,0,$width-1,$height-1,$border); + } + if ($mode == 1){ + if ($rating > 50) + if ($rating > 100) + ImageTTFText($image, 8, 0, ($width/4), ($height/2)+($height/5), $back, $config["fontpath"], lang_string ("out_of_limits")); + else + ImageTTFText($image, 8, 0, ($width/2)-($width/10), ($height/2)+($height/5), $back, $config["fontpath"], $rating."%"); + else + ImageTTFText($image, 8, 0, ($width/2)-($width/10), ($height/2)+($height/5), $textcolor, $config["fontpath"], $rating."%"); + } + imagePNG($image); + imagedestroy($image); + } + Header("Content-type: image/png"); + if ($progress > 100 || $progress < 0){ + // HACK: This report a static image... will increase render in about 200% :-) useful for + // high number of realtime statusbar images creation (in main all agents view, for example + $imgPng = imageCreateFromPng("../images/outof.png"); + imageAlphaBlending($imgPng, true); + imageSaveAlpha($imgPng, true); + imagePng($imgPng); + } else + drawRating($progress,$width,$height,$mode); } -function odo_tactic ($value1, $value2, $value3){ +function odo_tactic ($value1, $value2, $value3) { require_once 'Image/Graph.php'; include ("../include/config.php"); @@ -1567,13 +1562,12 @@ function odo_tactic ($value1, $value2, $value3){ $Font->setSize(8); $Graph->setFont($Font); - // create the plotarea $Graph->add( Image_Graph::vertical( $Plotarea = Image_Graph::factory('plotarea'), $Legend = Image_Graph::factory('legend'), - 80 + 80 ) ); @@ -1582,9 +1576,9 @@ function odo_tactic ($value1, $value2, $value3){ if ($value1 <0) $value1=0; if ($value2 <0) - $value2=0; + $value2=0; if ($value3 <0) - $value3=0; + $value3=0; /***************************Arrows************************/ $Arrows = & Image_Graph::factory('dataset'); $Arrows->addPoint('Global Health', $value1, 'GLOBAL'); @@ -1696,14 +1690,14 @@ function grafico_modulo_boolean ( $id_agente_modulo, $periodo, $show_event, // periodo - Gap of time, in seconds. This is now to (now-periodo) secs // Init tables - for ($x = 0; $x <= $resolution; $x++) { - $valores[$x][0] = 0; // SUM of all values for this interval - $valores[$x][1] = 0; // counter - $valores[$x][2] = $fechatope + ($horasint * $x); // [2] Top limit for this range - $valores[$x][3] = $fechatope + ($horasint*($x+1)); // [3] Botom limit - $valores[$x][4] = -1; // MIN - $valores[$x][5] = -1; // MAX - $valores[$x][6] = -1; // Event + for ($i = 0; $i <= $resolution; $i++) { + $valores[$i][0] = 0; // SUM of all values for this interval + $valores[$i][1] = 0; // counter + $valores[$i][2] = $fechatope + ($horasint * $i); // [2] Top limit for this range + $valores[$i][3] = $fechatope + ($horasint*($i+1)); // [3] Botom limit + $valores[$i][4] = -1; // MIN + $valores[$i][5] = -1; // MAX + $valores[$i][6] = -1; // Event } // Init other general variables if ($show_event == 1){ @@ -1773,32 +1767,32 @@ function grafico_modulo_boolean ( $id_agente_modulo, $periodo, $show_event, $last = $previous; // Calculate Average value for $valores[][0] - for ($x =0; $x <= $resolution; $x++) { - //echo $valores[$x][6] . ", (" . $valores[$x][4] . ", " . $valores[$x][5] . ") : "; + for ($i =0; $i <= $resolution; $i++) { + //echo $valores[$i][6] . ", (" . $valores[$i][4] . ", " . $valores[$i][5] . ") : "; - if ($valores[$x][6] == -1) - $valores[$x][6] = $last; + if ($valores[$i][6] == -1) + $valores[$i][6] = $last; else - $valores[$x][6] = $valores[$x][4]; // min + $valores[$i][6] = $valores[$i][4]; // min - $last = $valores[$x][5] != -1 ? $valores[$x][5] : $valores[$x][6]; // max + $last = $valores[$i][5] != -1 ? $valores[$i][5] : $valores[$i][6]; // max - if ($valores[$x][1] > 0) - $valores[$x][0] = $valores[$x][0]/$valores[$x][1]; + if ($valores[$i][1] > 0) + $valores[$i][0] = $valores[$i][0]/$valores[$i][1]; else { - $valores[$x][0] = $previous; - $valores[$x][4] = $previous; - $valores[$x][5] = $previous; + $valores[$i][0] = $previous; + $valores[$i][4] = $previous; + $valores[$i][5] = $previous; } // Get max value for all graph - if ($valores[$x][5] > $max_value) - $max_value = $valores[$x][5]; + if ($valores[$i][5] > $max_value) + $max_value = $valores[$i][5]; // Take prev. value // TODO: CHeck if there are more than 24hours between // data, if there are > 24h, module down. - $previous = $valores[$x][0]; + $previous = $valores[$i][0]; - //echo $valores[$x][6]; + //echo $valores[$i][6]; //echo "
"; } //exit; @@ -1866,21 +1860,21 @@ function grafico_modulo_boolean ( $id_agente_modulo, $periodo, $show_event, $dataset_event -> setName("Event Fired"); } // ... and populated with data ... - for ($cc=0; $cc <= $resolution; $cc++) { - $tdate = date('d/m', $valores[$cc][2])."\n".date('H:i', $valores[$cc][2]); + for ($i = 0; $i <= $resolution; $i++) { + $tdate = date('d/m', $valores[$i][2])."\n".date('H:i', $valores[$i][2]); /* if ($avg_only == 0) { - $dataset[1]->addPoint($tdate, $valores[$cc][0]); - $dataset[0]->addPoint($tdate, $valores[$cc][5]); - $dataset[2]->addPoint($tdate, $valores[$cc][4]); + $dataset[1]->addPoint($tdate, $valores[$i][0]); + $dataset[0]->addPoint($tdate, $valores[$i][5]); + $dataset[2]->addPoint($tdate, $valores[$i][4]); } else { - $dataset[0]->addPoint($tdate, $valores[$cc][6]); // 0:average 4:min 5:max 6:event + $dataset[0]->addPoint($tdate, $valores[$i][6]); // 0:average 4:min 5:max 6:event } */ - $dataset[0]->addPoint($tdate, $valores[$cc][6]); + $dataset[0]->addPoint($tdate, $valores[$i][6]); - if (($show_event == 1) AND (isset($real_event[$cc]))) { - $dataset_event->addPoint($tdate, $valores[$cc][5]); + if (($show_event == 1) AND (isset($real_event[$i]))) { + $dataset_event->addPoint($tdate, $valores[$i][5]); } } @@ -1967,174 +1961,113 @@ function grafico_modulo_boolean ( $id_agente_modulo, $periodo, $show_event, // Generic parameter handling // ************************** -if (isset($_GET["tipo"])) - $tipo = entrada_limpia($_GET["tipo"]); -else - $tipo = ""; // 1 day default period - -// Pure (Without title and legend) -if ( isset($_GET["pure"])) - $pure = $_GET["pure"]; -else - $pure = 0; - - -if (isset($_GET["period"])) - $period = entrada_limpia($_GET["period"]); -else - $period = 86400; // 1 day default period - -if (isset($_GET["intervalo"])) - $intervalo = entrada_limpia($_GET["intervalo"]); -else - $intervalo = 300; // 1 day default period - -if (isset($_GET["id"])) - $id = entrada_limpia($_GET["id"]); -else - $id = 0; - -if (isset($_GET["weight_l"])) - $weight_l = entrada_limpia($_GET["weight_l"]); -else - $weight_l = 0; - -if (isset($_GET["width"])) - $width = entrada_limpia($_GET["width"]); -else - $width = 450; - -if (isset($_GET["height"])) - $height = entrada_limpia ($_GET["height"]); -else - $height = 200; - -if (isset($_GET["label"])) - $label = entrada_limpia ($_GET["label"]); -else - $label = ""; - -if (isset($_GET["color"])) - $color = entrada_limpia ($_GET["color"]); -else - $color = "#226677"; - -if (isset($_GET["percent"])) - $percent = entrada_limpia ($_GET["percent"]); -else - $percent = "100"; - -// Zoom -if (isset($_GET['zoom']) and - is_numeric($_GET['zoom']) and - $_GET['zoom']>100) - $zoom = $_GET['zoom'] / 100 ; -else +$tipo = (string) get_parameter ('tipo'); +$pure = (bool) get_parameter ('pure'); +$period = (int) get_parameter ('period', 86400); +$intervalo = (int) get_parameter ('intervalo', 300); +$id = (string) get_parameter ('id'); +$weight_l = (string) get_parameter ('weight_l'); +$width = (int) get_parameter ('width', 450); +$height = (int) get_parameter ('height', 200); +$label = (string) get_parameter ('label', ''); +$color = (string) get_parameter ('color', '#226677'); +$percent = (int) get_parameter ('percent', 100); +$zoom = (int) get_parameter ('zoom', 100); +$zoom /= 100; +if ($zoom <= 0 || $zoom > 1) $zoom = 1; - -// Unit_name -if (isset($_GET["unit_name"])) - $unit_name = entrada_limpia ($_GET["unit_name"]); -else - $unit_name = ""; - - -// Draw Events ? -if ( isset($_GET["draw_events"])) - $draw_events = $_GET["draw_events"]; -else - $draw_events = 0; - -// Average values only -if ( isset($_GET["avg_only"])) - $avg_only = $_GET["avg_only"]; -else - $avg_only = 0; - -// Draw alert limits ? -if ( isset($_GET["draw_alerts"])) - $draw_alerts = $_GET["draw_alerts"]; -else - $draw_alerts = 0; - -// Values 1 2 and 3 -if ( isset($_GET["value1"])) - $value1 = $_GET["value1"]; -else - $value1 = 0; -if ( isset($_GET["value2"])) - $value2 = $_GET["value2"]; -else - $value2 = 0; - -$mode = get_parameter ("mode", 1); // Progress - -$value3 = get_parameter("value3",0); +$unit_name = (string) get_parameter ('unit_name'); +$draw_events = (int) get_parameter ('draw_events'); +$avg_only = (int) get_parameter ('avg_only'); +$draw_alerts = (int) get_parameter ('draw_alerts'); +$value1 = get_parameter ('value1'); +$value2 = get_parameter ('value2'); +$value3 = get_parameter("value3", 0); $stacked = get_parameter ("stacked", 0); -$time_reference = get_parameter ("time_reference", ""); -$url = get_parameter ("url", ""); -$id_agent = get_parameter ("id_agent", ""); -// Image handler -// ***************** +$date = get_parameter ("date"); +$graphic_type = (string) get_parameter ('tipo'); - -if (isset($_GET["tipo"])){ - if ($_GET["tipo"] == "sparse"){ - grafico_modulo_sparse ($id, $period, $draw_events, $width, $height , $label, $unit_name, $draw_alerts, $avg_only, $pure, $time_reference); - } - elseif ($_GET["tipo"] =="boolean") +if ($graphic_type) { + switch ($graphic_type) { + case 'sparse': + grafico_modulo_sparse ($id, $period, $draw_events, $width, $height , $label, $unit_name, $draw_alerts, $avg_only, $pure, $date); + break; + case "boolean": grafico_modulo_boolean ($id, $period, $draw_events, $width, $height , $label, $unit_name, $draw_alerts, 1, $pure); - elseif ($_GET["tipo"] =="estado_incidente") - grafico_incidente_estados(); - elseif ($_GET["tipo"] =="prioridad_incidente") - grafico_incidente_prioridad(); - elseif ($_GET["tipo"]=="db_agente_modulo") + break; + case "estado_incidente": + grafico_incidente_estados (); + break; + case "prioridad_incidente": + grafico_incidente_prioridad (); + break; + case "db_agente_modulo": grafico_db_agentes_modulos($width, $height); - elseif ($_GET["tipo"]=="db_agente_paquetes") + break; + case "db_agente_paquetes": grafico_db_agentes_paquetes($width, $height); - elseif ($_GET["tipo"] =="db_agente_purge") + break; + case "db_agente_purge": grafico_db_agentes_purge($id, $width, $height); - elseif ($_GET["tipo"] =="group_events") - grafico_eventos_grupo($width, $height, $url); - elseif ($_GET["tipo"] =="user_events") + break; + case "group_events": + grafico_eventos_grupo($width, $height); + break; + case "user_events": grafico_eventos_usuario($width, $height); - elseif ($_GET["tipo"] =="total_events") - grafico_eventos_total($url); - elseif ($_GET["tipo"] =="group_incident") + break; + case "total_events": + grafico_eventos_total(); + break; + case "group_incident": graphic_incident_group(); - elseif ($_GET["tipo"] =="user_incident") + break; + case "user_incident": graphic_incident_user(); - elseif ($_GET["tipo"] =="source_incident") - graphic_incident_source(); - elseif ($_GET["tipo"] =="user_activity") - graphic_user_activity($width,$height); - elseif ($_GET["tipo"] == "agentaccess") - graphic_agentaccess($_GET["id"], $_GET["periodo"], $width, $height); - elseif ($_GET["tipo"] == "agentmodules") + break; + case "source_incident": + graphic_incident_source(); + break; + case "user_activity": + graphic_user_activity($width,$height); + break; + case "agentaccess": + graphic_agentaccess ($_GET["id"], $_GET["periodo"], $width, $height); + break; + case "agentmodules": graphic_agentmodules($_GET["id"], $width, $height); - + break; //elseif ($_GET["tipo"] == "gdirect") // graphic_test ($id, $period, $intervalo, $label, $width, $height); - elseif ( $_GET["tipo"] =="progress"){ - $percent= $_GET["percent"]; - progress_bar($percent,$width,$height,$mode); - } - elseif ( $_GET["tipo"] == "odo_tactic"){ + case "progress": + $percent = $_GET["percent"]; + progress_bar($percent,$width,$height); + break; + case "odo_tactic": odo_tactic ( $value1, $value2, $value3 ); - } - elseif ( $_GET["tipo"] == "event_module"){ - graph_event_module ($width, $height, $id_agent); - } - elseif ( $_GET["tipo"] =="combined"){ + break; + case "combined": // Split id to get all parameters $module_list = array(); - $module_list = split ( ",", $id); + $module_list = split (",", $id); $weight_list = array(); - $weight_list = split ( ",", $weight_l); - graphic_combined_module ($module_list, $weight_list, $period, $width, $height , $label, $unit_name, $draw_events, $draw_alerts, $pure, $stacked); - } - else + $weight_list = split (",", $weight_l); + graphic_combined_module ($module_list, $weight_list, $period, $width, $height, + $label, $unit_name, $draw_events, $draw_alerts, $pure, $stacked, $date); + break; + case "alerts_fired_pipe": + $data = array (); + $data[0] = get_parameter ('fired'); + $data[1] = get_parameter ('not_fired'); + $legends = array (); + $legends[0] = lang_string ('fired_alerts'); + $legends[1] = lang_string ('not_fired_alerts'); + generic_pie_graph ($width, $height, $data, $legends); + break; + default: graphic_error (); -} else + } +} else { graphic_error (); +} ?>