From c22f0dfff2d9efe6fd2cb5cc0b955ebae49c3d6b Mon Sep 17 00:00:00 2001 From: guruevi Date: Fri, 21 Nov 2008 17:58:30 +0000 Subject: [PATCH] 2008-11-21 Evi Vanoost * godmode/setup/setup.php: Added prominent_time value to configuration. Also made setup.php available for singular GET requests. Implements feature request #2267582 * include/config_process.php: Added prominent_time to configuration. Also made sure some values are inserted into the database. Implements feature request #2267582 * include/functions.php: Removed give_human_time(). Fixed human_time_description_raw and human_time_comparation for 0 values * include/functions_db.php: Called safe_input in get_agentmodules * include/functions_html.php: Added print_timestamp for feature request #2267582. Timestamps should be printed using this function. * include/styles/pandora.css: Simplified CSS for f9 classes * operation/agentes/estado_monitores: Rewrite. Also implemented Glen Eustace's (from Godzone) feature request. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1254 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_console/ChangeLog | 23 +++ pandora_console/godmode/setup/setup.php | 42 ++-- pandora_console/include/config_process.php | 10 +- pandora_console/include/functions.php | 53 +----- pandora_console/include/functions_db.php | 11 +- pandora_console/include/functions_html.php | 51 ++++- pandora_console/include/styles/pandora.css | 8 +- .../operation/agentes/estado_monitores.php | 179 +++++++++--------- pandora_console/reporting/fgraph.php | 2 +- 9 files changed, 208 insertions(+), 171 deletions(-) diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 20d1911fff..a1c2c3e3ac 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,26 @@ +2008-11-21 Evi Vanoost + + * godmode/setup/setup.php: Added prominent_time value to configuration. + Also made setup.php available for singular GET requests. Implements + feature request #2267582 + + * include/config_process.php: Added prominent_time to configuration. Also + made sure some values are inserted into the database. Implements + feature request #2267582 + + * include/functions.php: Removed give_human_time(). Fixed + human_time_description_raw and human_time_comparation for 0 values + + * include/functions_db.php: Called safe_input in get_agentmodules + + * include/functions_html.php: Added print_timestamp for feature request + #2267582. Timestamps should be printed using this function. + + * include/styles/pandora.css: Simplified CSS for f9 classes + + * operation/agentes/estado_monitores: Rewrite. Also implemented + Glen Eustace's (from Godzone) feature request. + 2008-11-20 Evi Vanoost * operation/snmpconsole/snmp_view.php, godmode/snmpconsole/snmp_view.php: diff --git a/pandora_console/godmode/setup/setup.php b/pandora_console/godmode/setup/setup.php index 6edfe1d8b5..ff79b2944f 100644 --- a/pandora_console/godmode/setup/setup.php +++ b/pandora_console/godmode/setup/setup.php @@ -35,23 +35,24 @@ if (file_exists( $config["homedir"] . "/enterprise/godmode/setup/setup.php")) { $update_settings = (bool) get_parameter ('update_settings'); if ($update_settings) { - $config["block_size"] = (int) get_parameter ('block_size'); - $config["language"] = (string) get_parameter ('language_code'); - $config["days_compact"] = (int) get_parameter ('days_compact'); - $config["days_purge"] = (int) get_parameter ('days_purge'); - $config["graph_res"] = (int) get_parameter ('graph_res'); - $config["step_compact"] = (int) get_parameter ('step_compact'); - $config["show_unknown"] = (int) get_parameter ('show_unknown'); - $config["show_lastalerts"] = (int) get_parameter ('show_lastalerts'); - $config["style"] = (string) get_parameter ('style', 'pandora.css'); - $config["remote_config"] = (string) get_parameter ('remote_config'); - $config["graph_color1"] = (string) get_parameter ('graph_color1'); - $config["graph_color2"] = (string) get_parameter ('graph_color2'); - $config["graph_color3"] = (string) get_parameter ('graph_color3'); - $config["sla_period"] = (int) get_parameter ("sla_period"); - $config["date_format"] = (string) get_parameter ("date_format"); - $config["trap2agent"] = (string) get_parameter ("trap2agent"); - $config["autoupdate"] = (string) get_parameter ("autoupdate"); + $config["block_size"] = (int) get_parameter ('block_size', $config["block_size"]); + $config["language"] = (string) get_parameter ('language_code', $config["language"]); + $config["days_compact"] = (int) get_parameter ('days_compact', $config["days_compact"]); + $config["days_purge"] = (int) get_parameter ('days_purge', $config["days_purge"]); + $config["graph_res"] = (int) get_parameter ('graph_res', $config["graph_res"]); + $config["step_compact"] = (int) get_parameter ('step_compact', $config["step_compact"]); + $config["show_unknown"] = (int) get_parameter ('show_unknown', $config["show_unknown"]); + $config["show_lastalerts"] = (int) get_parameter ('show_lastalerts', $config["show_lastalerts"]); + $config["style"] = (string) get_parameter ('style', $config["style"]); + $config["remote_config"] = (string) get_parameter ('remote_config', $config["remote_config"]); + $config["graph_color1"] = (string) get_parameter ('graph_color1', $config["graph_color1"]); + $config["graph_color2"] = (string) get_parameter ('graph_color2', $config["graph_color2"]); + $config["graph_color3"] = (string) get_parameter ('graph_color3', $config["graph_color3"]); + $config["sla_period"] = (int) get_parameter ('sla_period', $config["sla_period"]); + $config["date_format"] = (string) get_parameter ('date_format', $config["date_format"]); + $config["trap2agent"] = (string) get_parameter ('trap2agent', $config["trap2agent"]); + $config["autoupdate"] = (string) get_parameter ('autoupdate', $config["autoupdate"]); + $config["prominent_time"] = (string) get_parameter ('prominent_time', $config["prominent_time"]); $config["style"] = substr ($config["style"], 0, strlen ($config["style"]) - 4); @@ -72,6 +73,7 @@ if ($update_settings) { process_sql ("UPDATE tconfig SET VALUE='".$config["date_format"]."' WHERE token = 'date_format'"); process_sql ("UPDATE tconfig SET VALUE='".$config["trap2agent"]."' WHERE token = 'trap2agent'"); process_sql ("UPDATE tconfig SET VALUE='".$config["autoupdate"]."' WHERE token = 'autoupdate'"); + process_sql ("UPDATE tconfig SET VALUE='".$config["prominent_time"]."' WHERE token = 'prominent_time'"); } echo "

".__('Pandora Setup')." > "; @@ -126,6 +128,12 @@ $table->data[13][1] = print_select ($file_styles, 'style', $config["style"], '', $table->data[14][0] = __('Block size for pagination'); $table->data[14][1] = print_input_text ('block_size', $config["block_size"], '', 5, 5, true); +$table->data[15][0] = __('Timestamp or time comparation'); +$table->data[15][1] = __('Comparation in rollover').' '; +$table->data[15][1] .= print_radio_button ('prominent_time', "timestamp", '', $config["prominent_time"], true); +$table->data[15][1] .= '
'.__('Timestamp in rollover').' '; +$table->data[15][1] .= print_radio_button ('prominent_time', "comparation", '', $config["prominent_time"], true); + enterprise_hook ('load_snmpforward_enterprise'); $table->data[16][0] = __('Automatic update check'); diff --git a/pandora_console/include/config_process.php b/pandora_console/include/config_process.php index a59deae116..7a73a60015 100644 --- a/pandora_console/include/config_process.php +++ b/pandora_console/include/config_process.php @@ -114,8 +114,9 @@ if (file_exists ('./include/languages/'.$config["language"].'.mo')) { $l10n->load_tables(); } -if (! isset ($config['date_format'])) { +if (!isset ($config['date_format'])) { $config['date_format'] = 'F j, Y, g:i a'; + process_sql ("INSERT INTO tconfig (token,value) VALUES ('date_format', '".$config['date_format']."')"); } if (isset ($config['homeurl']) && $config['homeurl'][0] != '/') { @@ -132,6 +133,13 @@ if (!isset($config["trap2agent"])){ if (!isset ($config["sla_period"]) || empty ($config["sla_period"])) { // Default period (in secs) for auto SLA calculation (for monitors) $config["sla_period"] = 604800; + process_sql ("INSERT INTO tconfig (token,value) VALUES ('sla_period',604800)"); +} + +if (!isset ($config["prominent_time"])) { + // Prominent time tells us what to show prominently when a timestamp is displayed. The comparation (... days ago) or the timestamp (full date) + $config["prominent_time"] == "comparation"; + process_sql ("INSERT INTO tconfig (token,value) VALUES ('prominent_time','comparation')"); } ?> diff --git a/pandora_console/include/functions.php b/pandora_console/include/functions.php index 916e3b41bc..d2814e58a7 100644 --- a/pandora_console/include/functions.php +++ b/pandora_console/include/functions.php @@ -163,48 +163,6 @@ function safe_url_extraclean ($string) { return preg_replace ('/[^a-z0-9_\/]/i', '', $string); } -/** - * Get a human readable string with a time threshold in seconds, - * minutes, days or weeks. - * - * @param int_seconds - * - * @return - */ -function give_human_time ($int_seconds) { - $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; - - // 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); - - // set flag to false, to allow 0's in lower periods - $flag_hide_zero = true; - } - - // 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); -} - /** * Add a help link to show help in a popup window. * @@ -502,10 +460,6 @@ function format_for_graph ($number , $decimals = 1, $dec_point = ".", $thousands * time and given timestamp. */ function human_time_comparation ($timestamp) { - if ($timestamp == "") { - return "0 ".__('minutes'); - } - if (!is_numeric ($timestamp)) { $timestamp = strtotime ($timestamp); } @@ -524,6 +478,10 @@ function human_time_comparation ($timestamp) { * @return A human readable translation of minutes. */ function human_time_description_raw ($seconds) { + if (empty ($seconds)) { + return __('Never'); + } + if ($seconds < 60) return format_numeric ($seconds, 0)." ".__('seconds'); @@ -535,6 +493,7 @@ function human_time_description_raw ($seconds) { $seconds = sprintf ("%02d", $seconds); return $minutes.':'.$seconds.' '.__('minutes'); } + if ($seconds < 86400) return format_numeric ($seconds / 3600, 0)." ".__('hours'); @@ -544,7 +503,7 @@ function human_time_description_raw ($seconds) { if ($seconds < 15552000) return format_numeric ($seconds / 2592000, 0)." ".__('months'); - return " +6 ".__('months'); + return "+6 ".__('months'); } /** diff --git a/pandora_console/include/functions_db.php b/pandora_console/include/functions_db.php index d7e96b4f15..e2117f911d 100644 --- a/pandora_console/include/functions_db.php +++ b/pandora_console/include/functions_db.php @@ -267,15 +267,18 @@ function get_agentmodules ($id_agent, $details = false) { if (empty ($details)) { $details = "nombre"; + } else { + $details = safe_input ($details); } $sql = "SELECT id_agente_modulo,".implode (",", (array) $details)." FROM tagente_modulo".$filter." ORDER BY nombre"; $result = get_db_all_rows_sql ($sql); //cast as array, that way a false will be converted into an array - if (empty ($result)) { - $result = array (); - } - $modules = array (); + if (empty ($result)) { + return array (); + } + + $modules = array (); foreach ($result as $row) { if (is_array ($details)) { $modules[$row["id_agente_modulo"]] = $row; //Just stack the information in array by ID diff --git a/pandora_console/include/functions_html.php b/pandora_console/include/functions_html.php index f4755b6a0c..1e816a1e08 100644 --- a/pandora_console/include/functions_html.php +++ b/pandora_console/include/functions_html.php @@ -611,10 +611,53 @@ function print_error_message ($result, $good = '', $bad = '', $attributes = '', $output = '<'.$tag.' class="suc" '.$attributes.'>'.$good.''; } - if ($return !== false) - return $output; + if ($return === false) + echo $output; - echo $output; + return $output; } -?> +/** + * Evaluates a unix timestamp and returns a span (or whatever tag specified) + * with as title the correctly formatted full timestamp and a time comparation + * in the tag + * + * @param int $unixtime: Any type of timestamp really, but we prefer unixtime + * @param string $attributes: Any additional attributes (class, script etc.) + * @param string $tag: If it should be in a different tag than span + * @param bool $return whether to output the string or return it + */ +function print_timestamp ($unixtime, $attributes, $tag = "span", $return = false) { + global $config; + + if (!is_numeric ($unixtime)) { + $unixtime = strtotime ($unixtime); + } + + //prominent_time is either timestamp or comparation + if ($config["prominent_time"] == "timestamp") { + $title = human_time_comparation ($unixtime); + $data = date ($config["date_format"], $unixtime); + } else { + $title = date ($config["date_format"], $unixtime); + $data = human_time_comparation ($unixtime); + } + + $output = '<'.$tag; + switch ($tag) { + default: + //Usually tags have title attributes, so by default we add, then fall through to add attributes and data + $output .= ' title="'.$title.'"'; + case "h1": + case "h2": + case "h3": + //Above tags don't have title attributes + $output .= ' '.$attributes.'>'.$data.''; + } + + if ($return === false) { + echo $output; + } + return $output; +} +?> \ No newline at end of file diff --git a/pandora_console/include/styles/pandora.css b/pandora_console/include/styles/pandora.css index f7502e2d8a..87ef55a4b6 100644 --- a/pandora_console/include/styles/pandora.css +++ b/pandora_console/include/styles/pandora.css @@ -327,7 +327,7 @@ td.datos_id { font-size: 7pt; text-align: center; } -.f9, .f9i, .f9b, td.f9, td.f9i, td.datosf9, td.datos2f9 { +.f9, .f9i, .f9b, .datos_greyf9, .datos_bluef9, .datos_greenf9, .datos_redf9, .datos_yellowf9, td.f9, td.f9i, td.datosf9, td.datos2f9 { font-size: 6.5pt; } .f9i, .redi { @@ -350,7 +350,7 @@ td.datos_id { background: url(../../images/err.png) no-repeat; padding: 4px 1px 6px 30px; } -.red , .redb, .redi, .error { +.red, .redb, .redi, .error { color: #f00; } .sep { @@ -660,10 +660,6 @@ span#logo_text2 { background-color: #E4E4E4; } -.datos_greyf9, .datos_bluef9, .datos_greenf9, .datos_redf9, .datos_yellowf9 { - font-size: 6.5pt; -} - td.datos_greyf9, td.datos_bluef9, td.datos_greenf9, td.datos_redf9, td.datos_yellowf9 { padding: 5px 5px 5px 5px; } diff --git a/pandora_console/operation/agentes/estado_monitores.php b/pandora_console/operation/agentes/estado_monitores.php index 8a1eb4d006..9aa26a2f5b 100644 --- a/pandora_console/operation/agentes/estado_monitores.php +++ b/pandora_console/operation/agentes/estado_monitores.php @@ -28,101 +28,98 @@ if (!isset ($id_agente)) { } // Get all module from agent -$sql_t='SELECT * FROM tagente_estado, tagente_modulo WHERE tagente_modulo.disabled = 0 AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo AND tagente_modulo.id_agente='.$id_agente.' AND tagente_estado.estado != 100 AND tagente_estado.utimestamp != 0 ORDER BY tagente_modulo.nombre'; -$result_t=mysql_query($sql_t); -if (mysql_num_rows ($result_t)) { - echo "

".__('Full list of Monitors')."

"; - echo ""; - echo ""; - echo " - - - - - "; - $color=0; - while ($row_t=mysql_fetch_array($result_t)){ - # For evey module in the status table - $est_modulo = substr($row_t["nombre"],0,25); - $est_tipo = dame_nombre_tipo_modulo($row_t["id_tipo_modulo"]); - $est_description = $row_t["descripcion"]; - $est_timestamp = $row_t["timestamp"]; - $est_estado = $row_t["estado"]; - $est_datos = $row_t["datos"]; - $est_cambio = $row_t["cambio"]; - if ($row_t["module_interval"] > 0) { - $est_interval = $row_t["module_interval"]; +$sql = sprintf ("SELECT * FROM tagente_estado, tagente_modulo WHERE tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo + AND tagente_modulo.id_agente = %d + AND tagente_modulo.disabled = 0 + AND tagente_estado.utimestamp != 0 + ORDER BY tagente_modulo.nombre", $id_agente); + +$modules = get_db_all_rows_sql ($sql); + +$table->width = 750; +$table->cellpadding = 4; +$table->cellspacing = 4; +$table->class = "databox"; +$table->head = array (); +$table->data = array (); + +$table->head[0] = "X"; +$table->head[1] = __('Type'); +$table->head[2] = __('Module name'); +$table->head[3] = __('Description'); +$table->head[4] = __('Status'); +$table->head[5] = __('Interval'); +$table->head[6] = __('Last contact'); + +//Since PHP's Zend optimizer references $var2 in case you do $var = $var2, objects get referenced too so we can't do $table = $table_data +$table_data->head = $table->head; //Duplicate table for data modules +$table_data->class = $table->class; +$table_data->data = array (); +$table_data->cellspacing = $table->cellspacing; +$table_data->cellpadding = $table->cellpadding; +$table_data->width = $table->width; + +foreach ($modules as $module) { + $data = array (); + if (($module["id_modulo"] != 1) && ($module["id_tipo_modulo"] != 100)) { + if ($module["flag"] == 0) { + $data[0] = ''; } else { - $est_interval = get_module_interval ($row_t["module_interval"]); //This function will return the correct interval - } - - if ($est_estado <>100){ # si no es un modulo de tipo datos - # Determinamos si se ha caido el agente (tiempo de intervalo * 2 superado) - if ($color == 1){ - $tdcolor = "datos"; - $color = 0; - } - else { - $tdcolor = "datos2"; - $color = 1; - } - $seconds = time() - $row_t["utimestamp"]; - if ($seconds >= ($est_interval*2)) // If every interval x 2 secs. we get nothing, there's and alert - $agent_down = 1; - else - $agent_down = 0; - - - - - echo ""; - echo ""; + $data[0] = ''; } + } else { + $data[0] = ''; } - echo '
X".__('Type')."".__('Module name')."".__('Description')."".__('Status')."".__('Interval')."".__('Last contact')."
"; - - if (($row_t["id_modulo"] != 1) AND ($row_t["id_tipo_modulo"] < 100)) { - if ($row_t["flag"] == 0){ - echo ""; - } else { - echo ""; - } - } - echo ""; - echo ""; - echo "".$est_modulo.""; - echo substr($est_description,0,35); - echo ""; - if ($est_estado == 1){ - if ($est_cambio == 1) - echo ""; - else - echo ""; - } else - echo ""; - - echo ""; - if ($est_interval > 0) { - echo $est_interval; - } else { - echo "--"; - } - echo ""; - if ($agent_down == 1) { // If agent down, it's shown red and bold - echo ""; - } - else { - echo ""; - } - if ($row_t["timestamp"]=='0000-00-00 00:00:00') { - echo __('Never'); - } else { - echo human_time_comparation($row_t["timestamp"]); - } - echo "
'; + + $data[1] = ''; + $data[2] = substr ($module["nombre"], 0, 25); + $data[3] = substr ($module["descripcion"], 0, 35); + + if ($module["estado"] == 1 && $module["cambio"] == 1) { + $data[4] = ''; + } elseif ($module["estado"] == 1) { + $data[4] = ''; + } else { + $data[4] = ''; + } + + if ($module["module_interval"] > 0) { + $data[5] = $module["module_interval"]; + } else { + $data[5] = "--"; + } + + $seconds = time () - $module["utimestamp"]; + if ($module["current_interval"] > 0 && $module["utimestamp"] > 0 && $seconds >= ($module["current_interval"] * 2)) { + $data[6] = ''; + } else { + $data[6] = ''; + } + $data[6] .= print_timestamp ($module["utimestamp"], '', 'span', true); + $data[6] .= ''; + + if ($module["estado"] != 100) { + array_push ($table->data, $data); + //Monitor modules go on $table + } else { + array_push ($table_data->data, $data); + //Data modules go on $table_data + } +} +if (empty ($table->data)) { + echo '
'.__('This agent doesn\'t have any active monitors').'
'; } else { - echo "
".__('This agent doesn \'t have any monitor with data')."
"; + echo "

".__('Full list of Monitors')."

"; + print_table ($table); } -?> +if (empty ($table_data->data)) { + echo '
'.__('This agent doesn\'t have any active data modules').'
'; +} else { + echo "

".__('Full list of Data Modules')."

"; + print_table ($table_data); +} +unset ($table); +unset ($table_data); +?> \ No newline at end of file diff --git a/pandora_console/reporting/fgraph.php b/pandora_console/reporting/fgraph.php index 951af7cbac..8ffd7586f2 100644 --- a/pandora_console/reporting/fgraph.php +++ b/pandora_console/reporting/fgraph.php @@ -944,7 +944,7 @@ function graphic_string_data ($id_agent_module, $periodo, $width, $height, $pure $Graph->add( Image_Graph::vertical( Image_Graph::vertical( - $Title = Image_Graph::factory('title', array(' Pandora FMS Graph - '.strtoupper($nombre_agente)." - ".give_human_time ($periodo), 10)), + $Title = Image_Graph::factory('title', array(' Pandora FMS Graph - '.strtoupper($nombre_agente)." - ".human_time_description_raw ($periodo), 10)), $Subtitle = Image_Graph::factory('title', array(' '.__('Data occurrence for module ').$nombre_modulo, 7)), 90 ),