2008-10-21 Esteban Sanchez <estebans@artica.es>

* include/functions.php: Improved human_time_comparation() so it won't 
        return nothing like "1.7 minutes". Make enterprise_include use
        ENTERPRISE_DIR. Style correction.

        * operation/agentes/estado_agente.php: Uses generic functions. Reduce 
        one indent level by using continue on a loop. Fixes status flag to 
        check if agent is down with no monitors. Show the exact date on last 
        contact column title. Style corrections.



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1179 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
esanchezm 2008-10-21 12:57:03 +00:00
parent 25b26d9fe2
commit 5e5ecef789
3 changed files with 194 additions and 209 deletions

View File

@ -1,3 +1,14 @@
2008-10-21 Esteban Sanchez <estebans@artica.es>
* include/functions.php: Improved human_time_comparation() so it won't
return nothing like "1.7 minutes". Make enterprise_include use
ENTERPRISE_DIR. Style correction.
* operation/agentes/estado_agente.php: Uses generic functions. Reduce
one indent level by using continue on a loop. Fixes status flag to
check if agent is down with no monitors. Show the exact date on last
contact column title. Style corrections.
2008-10-21 Esteban Sanchez <estebans@artica.es> 2008-10-21 Esteban Sanchez <estebans@artica.es>
* godmode/profiles/profile_list.php: Rewritten be more consistent and * godmode/profiles/profile_list.php: Rewritten be more consistent and

View File

@ -391,7 +391,6 @@ function pagination ($count, $url, $offset) {
* @return * @return
*/ */
function format_datetime ($timestamp, $alt_format = "") { function format_datetime ($timestamp, $alt_format = "") {
global $config; global $config;
if ($alt_format == "") if ($alt_format == "")
@ -479,17 +478,25 @@ function human_time_comparation ($timestamp) {
$ahora = date ("Y/m/d H:i:s"); $ahora = date ("Y/m/d H:i:s");
$seconds = strtotime ($ahora) - strtotime ($timestamp); $seconds = strtotime ($ahora) - strtotime ($timestamp);
if ($seconds < 3600) if ($seconds < 60)
return format_numeric ($seconds / 60, 1)." ".__('minutes'); return format_numeric ($seconds, 0)." ".__('seconds');
if ($seconds >= 3600 && $seconds < 86400) if ($seconds < 3600) {
return format_numeric ($seconds / 3600, 1)." ".__('hours'); $minutes = format_numeric ($seconds / 60, 0);
$seconds = format_numeric ($seconds % 60, 0);
if ($seconds == 0)
return $minutes.' '.__('minutes');
$seconds = sprintf ("%02d", $seconds);
return $minutes.':'.$seconds.' '.__('minutes');
}
if ($seconds < 86400)
return format_numeric ($seconds / 3600, 0)." ".__('hours');
if ($seconds >= 86400 && $seconds < 2592000) if ($seconds < 2592000)
return format_numeric ($seconds / 86400, 1)." ".__('days'); return format_numeric ($seconds / 86400, 0)." ".__('days');
if ($seconds >= 2592000 && $seconds < 15552000) if ($seconds < 15552000)
return format_numeric ($seconds / 2592000, 1)." ".__('months'); return format_numeric ($seconds / 2592000, 0)." ".__('months');
return " +6 ".__('months'); return " +6 ".__('months');
} }
@ -1213,9 +1220,9 @@ function enterprise_hook ($function_name, $parameters = false) {
function enterprise_include ($filename) { function enterprise_include ($filename) {
global $config; global $config;
// Load enterprise extensions // Load enterprise extensions
$fullfilename = $config["homedir"]."/enterprise/" . $filename; $filepath = $config["homedir"].ENTERPRISE_DIR.'/'.$filename;
if (file_exists ($fullfilename)) { if (file_exists ($filepath)) {
include ($fullfilename); include ($filepath);
return true; return true;
} }
return ENTERPRISE_NOT_HOOK; return ENTERPRISE_NOT_HOOK;

View File

@ -16,8 +16,6 @@
// along with this program; if not, write to the Free Software // along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
// Load global vars // Load global vars
require ("include/config.php"); require ("include/config.php");
check_login (); check_login ();
@ -152,8 +150,9 @@ pagination ($total_events,
"index.php?sec=estado&sec2=operation/agentes/estado_agente&group_id=$ag_group&refr=60", "index.php?sec=estado&sec2=operation/agentes/estado_agente&group_id=$ag_group&refr=60",
$offset); $offset);
// Show data. // Show data.
$result=mysql_query($sql); $agents = get_db_all_rows_sql ($sql);
if (mysql_num_rows($result)){
if ($agents !== false) {
echo "<table cellpadding='4' cellspacing='4' width='700' class='databox' style='margin-top: 10px'>"; echo "<table cellpadding='4' cellspacing='4' width='700' class='databox' style='margin-top: 10px'>";
echo "<th>".__('Agent')."</th>"; echo "<th>".__('Agent')."</th>";
echo "<th>".__('OS')."</th>"; echo "<th>".__('OS')."</th>";
@ -165,30 +164,33 @@ if (mysql_num_rows($result)){
echo "<th>".__('Last contact')."</th>"; echo "<th>".__('Last contact')."</th>";
// For every agent defined in the agent table // For every agent defined in the agent table
$color = 1; $color = 1;
while ($row=mysql_fetch_array($result)){ foreach ($agents as $agent) {
$intervalo = $row["intervalo"]; // Interval in seconds $intervalo = $agent["intervalo"]; // Interval in seconds
$id_agente = $row['id_agente']; $id_agente = $agent['id_agente'];
$nombre_agente = substr(strtoupper($row["nombre"]),0,18); $nombre_agente = substr (strtoupper ($agent["nombre"]), 0, 18);
$direccion_agente =$row["direccion"]; $direccion_agente = $agent["direccion"];
$id_grupo=$row["id_grupo"]; $id_grupo = $agent["id_grupo"];
$id_os = $row["id_os"]; $id_os = $agent["id_os"];
$ultimo_contacto = $row["ultimo_contacto"]; $ultimo_contacto = $agent["ultimo_contacto"];
$biginterval = $intervalo; $biginterval = $intervalo;
$pertenece = 0;
foreach ($mis_grupos as $migrupo) { //Verifiy if the group this agent begins is one of the user groups foreach ($mis_grupos as $migrupo) { //Verifiy if the group this agent begins is one of the user groups
if (($migrupo ==1) || ($id_grupo==$migrupo)){ if ($migrupo || $id_grupo == $migrupo) {
$pertenece = 1; $pertenece = 1;
break; break;
} }
else
$pertenece = 0;
} }
if ($pertenece == 1) { // Si el agente pertenece a uno de los grupos que el usuario puede visualizar if (! $pertenece == 1)
continue;
// Obtenemos la lista de todos los modulos de cada agente // Obtenemos la lista de todos los modulos de cada agente
$sql_t="SELECT * FROM tagente_estado, tagente_modulo $sql = "SELECT * FROM tagente_estado, tagente_modulo
WHERE tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo AND WHERE tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo AND
tagente_modulo.disabled = 0 tagente_modulo.disabled = 0
AND tagente_modulo.id_agente=".$id_agente; AND tagente_modulo.id_agente=".$id_agente;
$result_t=mysql_query($sql_t); $modules = get_db_all_rows_sql ($sql);
if ($modules === false)
$modules = array ();
$estado_general = 0; $estado_general = 0;
$numero_modulos = 0; $numero_modulos = 0;
$numero_monitor = 0; $numero_monitor = 0;
@ -198,13 +200,15 @@ if (mysql_num_rows($result)){
$monitor_down = 0; $monitor_down = 0;
$numero_datamodules = 0; $numero_datamodules = 0;
$estado_cambio = 0; $estado_cambio = 0;
$ahora=date("Y/m/d H:i:s"); $agent_down = 0;
$now = time ();
// Calculate module/monitor totals for this agent // Calculate module/monitor totals for this agent
while ($row_t=mysql_fetch_array($result_t)){ foreach ($modules as $module) {
$est_modulo = $row_t["estado"]; $est_modulo = $module["estado"];
$ultimo_contacto_modulo = $row_t["timestamp"]; $ultimo_contacto_modulo = $module["timestamp"];
$module_interval = $row_t["module_interval"]; $module_interval = $module["module_interval"];
$module_type = $row_t["id_tipo_modulo"]; $module_type = $module["id_tipo_modulo"];
if ($module_interval > $biginterval) if ($module_interval > $biginterval)
$biginterval = $module_interval; $biginterval = $module_interval;
@ -212,25 +216,25 @@ if (mysql_num_rows($result)){
$intervalo_comp = $module_interval; $intervalo_comp = $module_interval;
else else
$intervalo_comp = $intervalo; $intervalo_comp = $intervalo;
if ($ultimo_contacto <> "") if ($ultimo_contacto != "")
$seconds = strtotime($ahora) - strtotime($ultimo_contacto_modulo); $seconds = $now - strtotime ($ultimo_contacto_modulo);
else else
$seconds = -1; $seconds = -1;
if (($module_type < 21) OR ($module_type == 100)){ if ($module_type < 21 || $module_type == 100) {
$async = 0; $async = 0;
} else { } else {
$async = 1; $async = 1;
} }
# Defines if Agent is down (interval x 2 > time last contact // Defines if Agent is down (interval x 2 > time last contact
if ($seconds >= ($intervalo_comp * 2)) { // If (intervalx2) secs. ago we don't get anything, show alert if ($seconds >= ($intervalo_comp * 2)) { // If (intervalx2) secs. ago we don't get anything, show alert
$agent_down = 1;
if ($est_modulo != 100) if ($est_modulo != 100)
$numero_monitor++; $numero_monitor++;
if ($async == 0) if ($async == 0)
$monitor_down++; $monitor_down++;
} } elseif ($est_modulo != 100) { // estado=100 are data modules
elseif ($est_modulo != 100) { // estado=100 are data modules
$estado_general = $estado_general + $est_modulo; $estado_general = $estado_general + $est_modulo;
$estado_cambio = $estado_cambio + $row_t["cambio"]; $estado_cambio = $estado_cambio + $module["cambio"];
$numero_monitor ++; $numero_monitor ++;
if ($est_modulo != 0) if ($est_modulo != 0)
$monitor_bad++; $monitor_bad++;
@ -282,44 +286,17 @@ echo '<img class="bot" src="images/groups_small/'.show_icon_group($id_grupo).'.p
echo "<td class='$tdcolor'> ". echo "<td class='$tdcolor'> ".
$numero_modulos." <b>/</b> ".$numero_monitor; $numero_modulos." <b>/</b> ".$numero_monitor;
if ($monitor_bad <> 0) { if ($monitor_bad != 0) {
echo " <b>/</b> <span class='red'>".$monitor_bad."</span>"; echo " <b>/</b> <span class='red'>".$monitor_bad."</span>";
} }
if ($monitor_down <> 0){ if ($monitor_down != 0){
echo " <b>/</b> <span class='grey'>".$monitor_down."</span>"; echo " <b>/</b> <span class='grey'>".$monitor_down."</span>";
} }
echo "</td>"; echo "</td>";
/*
if ($numero_monitor <> 0){
if ($estado_general <> 0){
if ($estado_cambio == 0){
// RED
echo "<td class='$tdcolor' align='center' style='background: #ff1d21'>";
} else {
// Yellow
echo "<td class='$tdcolor' align='center' style='background: #ffe100'>";
}
} elseif ($monitor_ok > 0) {
// Green
echo "<td class='$tdcolor' align='center' style='background: #5fff1b'>";
}
elseif ($numero_datamodules > 0) {
// Grey #1
echo "<td class='$tdcolor' align='center' style='background: #d5d5d5'>";
}
elseif ($monitor_down > 0) {
// Grey - Red
echo "<td class='$tdcolor' align='center' style='background: #d5b3b3'>";
}
} else {
// Blue
echo "<td class='$tdcolor' align='center' style='background: #4485d5'>";
}
*/
echo "<td class='$tdcolor' align='center'>"; echo "<td class='$tdcolor' align='center'>";
if ($numero_monitor <> 0){ if ($numero_monitor != 0){
if ($estado_general <> 0){ if ($estado_general != 0){
if ($estado_cambio == 0){ if ($estado_cambio == 0){
echo '<img src="images/pixel_red.png" width="40" height="18" title="'.__('At least one monitor fails').'" />'; echo '<img src="images/pixel_red.png" width="40" height="18" title="'.__('At least one monitor fails').'" />';
} else { } else {
@ -333,7 +310,9 @@ echo '<img class="bot" src="images/groups_small/'.show_icon_group($id_grupo).'.p
echo '<img src="images/pixel_blue.png" width="40" height="18" title="'.__('Agent without data').'" />'; echo '<img src="images/pixel_blue.png" width="40" height="18" title="'.__('Agent without data').'" />';
} }
} else { } else {
if ($numero_datamodules == 0) { if ($agent_down && $numero_datamodules == 0) {
echo '<img src="images/pixel_fucsia.png" width="40" height="18" title="'.__('Agent down').'" />';
} elseif ($numero_datamodules == 0) {
echo '<img src="images/pixel_blue.png" width="40" height="18" title="'.__('Agent without data').'" />'; echo '<img src="images/pixel_blue.png" width="40" height="18" title="'.__('Agent without data').'" />';
} else { } else {
echo '<img src="images/pixel_gray.png" width="40" height="18" title="'.__('Agent without monitors').'" />'; echo '<img src="images/pixel_gray.png" width="40" height="18" title="'.__('Agent without monitors').'" />';
@ -341,43 +320,31 @@ echo '<img class="bot" src="images/groups_small/'.show_icon_group($id_grupo).'.p
} }
// checks if an alert was fired recently // checks if an alert was fired recently
echo "<td class='$tdcolor' align='center'>"; echo "<td class='$tdcolor' align='center'>";
if (give_disabled_group($id_grupo) == 1) if (give_disabled_group ($id_grupo)) {
echo "<img src='images/pixel_gray.png' width=20 height=9>"; echo "<img src='images/pixel_gray.png' width=20 height=9>";
else { } else {
if (check_alert_fired ($id_agente) == 1) if (check_alert_fired ($id_agente) == 1)
echo "<img src='images/pixel_red.png' width=20 height=9 title='".__('Alert fired')."'>"; echo '<img src="images/pixel_red.png" width="20" height="9" title="'.__('Alert fired').'" />';
else else
echo "<img src='images/pixel_green.png' width=20 height=9 title='".__('Alert not fired')."'>"; echo '<img src="images/pixel_green.png" width="20" height="9" title="'.__('Alert not fired').'" />';
} }
echo "</td>"; echo "</td>";
echo "<td class='$tdcolor'>"; echo "<td class='$tdcolor'>";
if ($ultimo_contacto == "0000-00-00 00:00:00") { if ($ultimo_contacto == "0000-00-00 00:00:00") {
echo __('Never'); echo __('Never');
} else { } else {
$ultima = strtotime($ultimo_contacto); $last_time = strtotime ($ultimo_contacto);
$ahora = strtotime("now"); $diferencia = $now - $last_time;
$diferencia = $ahora - $ultima; $time = human_time_comparation ($ultimo_contacto);
$style = '';
if ($diferencia > ($biginterval * 2)) if ($diferencia > ($biginterval * 2))
echo "<font color='#ff0000'>"; $style = 'style="color: #ff0000"';
echo '<span '.$style.' title="'.format_datetime ($last_time).'">'.$time.'</span>';
echo human_time_comparation($ultimo_contacto);
/*
if ($biginterval > 0){
$percentil = round($diferencia/(($biginterval*2) / 100));
} else {
$percentil = -1;
} }
echo "<a href='#' class='info2'>
<img src='reporting/fgraph.php?tipo=progress&amp;percent=".
$percentil."&amp;height=18&amp;width=80' border='0'>
&nbsp;<span>$ultimo_contacto</span></a>";*/
}
} // If pertenece/belongs to group
} }
echo "<tr>"; echo "<tr>";
echo "</table><br>"; echo "</table><br>";
require "bulbs.php"; require ("bulbs.php");
} else { } else {
echo '</table><br><div class="nf">'.__('There are no agents included in this group').'</div>'; echo '</table><br><div class="nf">'.__('There are no agents included in this group').'</div>';
if (give_acl ($config['id_user'], 0, "LM") if (give_acl ($config['id_user'], 0, "LM")