2008-11-21 Evi Vanoost <vanooste@rcbi.rochester.edu>

* 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
This commit is contained in:
guruevi 2008-11-21 17:58:30 +00:00
parent 65d81fa325
commit 5e8d3fa275
9 changed files with 208 additions and 171 deletions

View File

@ -1,3 +1,26 @@
2008-11-21 Evi Vanoost <vanooste@rcbi.rochester.edu>
* 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 <vanooste@rcbi.rochester.edu>
* operation/snmpconsole/snmp_view.php, godmode/snmpconsole/snmp_view.php:

View File

@ -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 "<h2>".__('Pandora Setup')." &gt; ";
@ -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] .= '<br />'.__('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');

View File

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

View File

@ -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');
}
/**

View File

@ -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

View File

@ -611,10 +611,53 @@ function print_error_message ($result, $good = '', $bad = '', $attributes = '',
$output = '<'.$tag.' class="suc" '.$attributes.'>'.$good.'</'.$tag.'>';
}
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.'</'.$tag.'>';
}
if ($return === false) {
echo $output;
}
return $output;
}
?>

View File

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

View File

@ -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 "<h3>".__('Full list of Monitors')."</h3>";
echo "<table width='750' cellpadding=4 cellspacing=4 class='databox'>";
echo "<tr><th>X</th>";
echo "<th>".__('Type')."</th>
<th>".__('Module name')."</th>
<th>".__('Description')."</th>
<th>".__('Status')."</th>
<th>".__('Interval')."</th>
<th>".__('Last contact')."</th>";
$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] = '<a href="index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente='.$id_agente.'&id_agente_modulo='.$module["id_agente_modulo"].'&flag=1&refr=60"><img src="images/target.png" border="0" /></a>';
} 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 "<tr><td class='".$tdcolor."'>";
if (($row_t["id_modulo"] != 1) AND ($row_t["id_tipo_modulo"] < 100)) {
if ($row_t["flag"] == 0){
echo "<a href='index.php?sec=estado& sec2=operation/agentes/ver_agente& id_agente=".$id_agente."&id_agente_modulo=".$row_t["id_agente_modulo"]."&flag=1& tab=main&refr=60'><img src='images/target.png' border='0'></a>";
} else {
echo "<a href='index.php?sec=estado& sec2=operation/agentes/ver_agente&id_agente=".$id_agente."&id_agente_modulo=".$row_t["id_agente_modulo"]."&tab=main&refr=60'><img src='images/refresh.png' border='0'></a>";
}
}
echo "<td class='".$tdcolor."'>";
echo "<img src='images/".show_icon_type($row_t["id_tipo_modulo"])."' border=0>";
echo "<td class='".$tdcolor."'>".$est_modulo."</td>";
echo "<td class='".$tdcolor."f9'>";
echo substr($est_description,0,35);
echo "<td class='".$tdcolor."' align='center'>";
if ($est_estado == 1){
if ($est_cambio == 1)
echo "<img src='images/pixel_yellow.png' width=40 height=18 title='".__('Change between Green/Red state')."'>";
else
echo "<img src='images/pixel_red.png' width=40 height=18 title='".__('At least one monitor fails')."'>";
} else
echo "<img src='images/pixel_green.png' width=40 height=18 title='".__('All Monitors OK')."'>";
echo "<td align='center' class='".$tdcolor."'>";
if ($est_interval > 0) {
echo $est_interval;
} else {
echo "--";
}
echo "</td><td class='".$tdcolor."f9'>";
if ($agent_down == 1) { // If agent down, it's shown red and bold
echo "<span class='redb'>";
}
else {
echo "<span>";
}
if ($row_t["timestamp"]=='0000-00-00 00:00:00') {
echo __('Never');
} else {
echo human_time_comparation($row_t["timestamp"]);
}
echo "</span></td>";
$data[0] = '<a href="index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente='.$id_agente.'&id_agente_modulo='.$module["id_agente_modulo"].'&refr=60"><img src="images/refresh.png" border="0"></a>';
}
} else {
$data[0] = '';
}
echo '</table>';
$data[1] = '<img src="images/'.show_icon_type ($module["id_tipo_modulo"]).'" border="0">';
$data[2] = substr ($module["nombre"], 0, 25);
$data[3] = substr ($module["descripcion"], 0, 35);
if ($module["estado"] == 1 && $module["cambio"] == 1) {
$data[4] = '<img src="images/pixel_yellow.png" width="40" height="18" title="'.__('Change between Green/Red state').'">';
} elseif ($module["estado"] == 1) {
$data[4] = '<img src="images/pixel_red.png" width="40" height="18" title="'.__('At least one monitor fails').'">';
} else {
$data[4] = '<img src="images/pixel_green.png" width="40" height="18" title="'.__('All Monitors OK').'">';
}
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] = '<span class="redb">';
} else {
$data[6] = '<span>';
}
$data[6] .= print_timestamp ($module["utimestamp"], '', 'span', true);
$data[6] .= '</span>';
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 '<div class="nf">'.__('This agent doesn\'t have any active monitors').'</div>';
} else {
echo "<div class='nf'>".__('This agent doesn \'t have any monitor with data')."</div>";
echo "<h3>".__('Full list of Monitors')."</h3>";
print_table ($table);
}
?>
if (empty ($table_data->data)) {
echo '<div class="nf">'.__('This agent doesn\'t have any active data modules').'</div>';
} else {
echo "<h3>".__('Full list of Data Modules')."</h3>";
print_table ($table_data);
}
unset ($table);
unset ($table_data);
?>

View File

@ -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
),