git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1201 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f

This commit is contained in:
guruevi 2008-10-29 20:03:42 +00:00
parent 7c866a3554
commit c35a1f33a8
3 changed files with 172 additions and 183 deletions

View File

@ -1,3 +1,11 @@
2008-10-29 Evi Vanoost <vanooste@rcbi.rochester.edu>
* operation/agentes/status_monitor.php: Made it a bit faster and fixed
some issues I had with it (flag). Uses new html functions now.
* include/functions.php: Made human_time_comparation accept both
Unixtime as well as other system timestamps
2008-10-28 Esteban Sanchez <estebans@artica.es> 2008-10-28 Esteban Sanchez <estebans@artica.es>
* godmode/modules/manage_network_components.php: Replaced parameters * godmode/modules/manage_network_components.php: Replaced parameters

View File

@ -475,8 +475,11 @@ function human_time_comparation ($timestamp) {
return "0 ".__('minutes'); return "0 ".__('minutes');
} }
$ahora = date ("Y/m/d H:i:s"); if (!is_numeric ($timestamp)) {
$seconds = strtotime ($ahora) - strtotime ($timestamp); $timestamp = strtotime ($timestamp);
}
$seconds = time () - $timestamp;
if ($seconds < 60) if ($seconds < 60)
return format_numeric ($seconds, 0)." ".__('seconds'); return format_numeric ($seconds, 0)." ".__('seconds');
@ -497,6 +500,7 @@ function human_time_comparation ($timestamp) {
if ($seconds < 15552000) if ($seconds < 15552000)
return format_numeric ($seconds / 2592000, 0)." ".__('months'); return format_numeric ($seconds / 2592000, 0)." ".__('months');
return " +6 ".__('months'); return " +6 ".__('months');
} }

View File

@ -19,7 +19,7 @@
// Load global vars // Load global vars
require ("include/config.php"); require_once ("include/config.php");
check_login(); check_login();
@ -30,8 +30,7 @@ if (! give_acl ($config['id_user'], 0, "AR") && ! give_acl ($config['id_user'],
exit; exit;
} }
echo "<h2>".__('Pandora Agents')." &gt; "; echo "<h2>".__('Pandora Agents')." &gt; ".__('Full list of Monitors')."</h2>";
echo __('Full list of Monitors')."</h2>";
$ag_freestring = get_parameter ("ag_freestring", ""); $ag_freestring = get_parameter ("ag_freestring", "");
$ag_modulename = get_parameter ("ag_modulename", ""); $ag_modulename = get_parameter ("ag_modulename", "");
@ -39,218 +38,196 @@ $ag_group = get_parameter ("ag_group", -1);
$offset = get_parameter ("offset", 0); $offset = get_parameter ("offset", 0);
$status = get_parameter ("status", 0); $status = get_parameter ("status", 0);
$URL = "index.php?sec=estado&sec2=operation/agentes/status_monitor&refr=60"; $url = '';
echo "<form method='post' action='"; if ($ag_group > 0) {
if ($ag_group != -1) $url .= "&ag_group=".$ag_group;
$URL .= "&ag_group=".$ag_group;
// Module name selector
// This code thanks for an idea from Nikum, nikun_h@hotmail.com
if ($ag_modulename != "")
$URL .= "&ag_modulename=".$ag_modulename;
// Freestring selector
if ($ag_freestring != "")
$URL .= "&ag_freestring=".$ag_freestring ;
// Status selector
$URL .= "&status=$status";
echo $URL;
// End FORM TAG
echo "'>";
echo "<table cellspacing='4' cellpadding='4' width='600' class='databox'>";
echo "<tr><td valign='middle'>".__('Group')."</td>";
echo "<td valign='middle'>";
echo "<select name='ag_group' onChange='javascript:this.form.submit();' class='w130'>";
if ( $ag_group > 1 ){
echo "<option value='".$ag_group."'>".dame_nombre_grupo($ag_group)."</option>";
} }
echo "<option value=1>".dame_nombre_grupo(1)."</option>"; if ($ag_modulename != "") {
list_group ($config['id_user']); $url .= "&ag_modulename=".$ag_modulename;
echo "</select>"; }
if ($ag_freestring != "") {
$url .= "&ag_freestring=".$ag_freestring;
}
if ($status != 0) {
$url .= "&status=".$status;
}
echo '<form method="post" action="index.php?sec=estado&sec2=operation/agentes/status_monitor&refr=60'.$url.'">';
echo '<table cellspacing="4" cellpadding="4" width="600" class="databox">';
echo '<tr><td valign="middle">'.__('Group').'</td>';
echo '<td valign="middle">';
print_select (get_user_groups (), "ag_group", $ag_group, 'this.form.submit();', '', '0', false, false, false, 'w130');
echo "</td>"; echo "</td>";
echo "<td>".__('Monitor status')."</td><td>";
echo "<td>"; $fields = array ();
echo __('Monitor status'); $fields[0] = __('Monitors down'); //default
echo "<td>"; $fields[1] = __('Monitors up');
echo "<select name='status'>"; $fields[2] = __('Monitors unknown');
if ($status == -1){
echo "<option value=-1>".__('All')."</option>";
echo "<option value=0>".__('Monitors down')."</option>";
echo "<option value=1>".__('Monitors up')."</option>";
echo "<option value=2>".__('Monitors unknown')."</option>";
} elseif ($status == 0){
echo "<option value=0>".__('Monitors down')."</option>";
echo "<option value=-1>".__('All')."</option>";
echo "<option value=1>".__('Monitors up')."</option>";
echo "<option value=2>".__('Monitors unknown')."</option>";
} elseif ($status == 2){
echo "<option value=2>".__('Monitors unknown')."</option>";
echo "<option value=0>".__('Monitors down')."</option>";
echo "<option value=-1>".__('All')."</option>";
echo "<option value=1>".__('Monitors up')."</option>";
} else {
echo "<option value=1>".__('Monitors up')."</option>";
echo "<option value=0>".__('Monitors down')."</option>";
echo "<option value=2>".__('Monitors unknown')."</option>";
echo "<option value=-1>".__('All')."</option>";
}
echo "</select>";
echo "</tr>"; print_select ($fields, "status", $status, 'this.form.submit();', __('All'), -1);
echo "<tr>";
echo "<td valign='middle'>".__('Module name')."</td>"; echo '</td></tr><tr><td valign="middle">'.__('Module name').'</td>';
echo "<td valign='middle'> echo '<td valign="middle">';
<select name='ag_modulename' onChange='javascript:this.form.submit();'>";
if ( isset($ag_modulename)){ $result = get_db_all_rows_sql ("SELECT DISTINCT(nombre) FROM tagente_modulo WHERE id_tipo_modulo IN (2, 6, 9, 18, 21, 100) ORDER BY nombre");
echo "<option>".$ag_modulename."</option>"; if ($result === false) {
$result = array ();
} }
echo "<option>".__('All')."</option>";
$sql='SELECT DISTINCT nombre $fields = array ();
FROM tagente_modulo foreach ($result as $row) {
WHERE id_tipo_modulo in (2, 6, 9, 18, 21, 100)'; $fields[$row["nombre"]] = $row["nombre"];
$result=mysql_query($sql);
while ($row=mysql_fetch_array($result)){
echo "<option>".$row['0']."</option>";
} }
echo "</select>";
echo "<td valign='middle'>"; print_select ($fields, "ag_modulename", $ag_modulename, 'this.form.submit();', __('All'), "");
echo __('Free text');
echo "<td valign='middle'>"; echo '</td><td valign="middle">'.__('Free text').'</td>';
echo "<input type=text name='ag_freestring' size=15 value='$ag_freestring'>";
echo "<td valign='middle'>"; echo '<td valign="middle">';
echo "<input name='uptbutton' type='submit' class='sub' value='".__('Show')."'"; print_input_text ("ag_freestring", $ag_freestring, '', 15);
echo '</td><td valign="middle">';
print_submit_button (__('Show'), "uptbutton", false, 'class="sub"');
echo "</form>"; echo "</form>";
echo "</table>"; echo "</table>";
// Begin Build SQL sentences // Begin Build SQL sentences
$sql = " FROM tagente, tagente_modulo, tagente_estado
$SQL_pre = "SELECT tagente_modulo.id_agente_modulo, tagente.nombre, tagente_modulo.nombre, tagente_modulo.descripcion, tagente.id_grupo, tagente.id_agente, tagente_modulo.id_tipo_modulo, tagente_modulo.module_interval, tagente_estado.datos, tagente_estado.utimestamp, tagente_estado.timestamp "; WHERE tagente.id_agente = tagente_modulo.id_agente
AND tagente_modulo.disabled = 0
$SQL_pre_count = "SELECT count(tagente_modulo.id_agente_modulo) "; AND tagente.disabled = 0
AND tagente_modulo.id_tipo_modulo IN (2, 9, 12, 18, 6, 100)
$SQL = " FROM tagente, tagente_modulo, tagente_estado WHERE tagente.id_agente = tagente_modulo.id_agente AND tagente_modulo.disabled = 0 AND tagente.disabled = 0 AND tagente_modulo.id_tipo_modulo in (2, 9, 12, 18, 6, 100) AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo "; AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo";
// Agent group selector // Agent group selector
if ($ag_group > 1) if ($ag_group > 1 && give_acl ($config["id_user"], $ag_group, "AR")) {
$SQL .=" AND tagente.id_grupo = ".$ag_group; $sql .= sprintf (" AND tagente.id_grupo = %d", $ag_group);
else { } else {
// User has explicit permission on group 1 ? // User has explicit permission on group 1 ?
$sql = sprintf ("SELECT COUNT(id_grupo) FROM tusuario_perfil WHERE id_usuario='%s' AND id_grupo = 1", $config['id_user']); $sql .= " AND tagente.id_grupo IN (".implode (",", array_keys (get_user_groups ())).")";
$all_group = get_db_sql ($sql);
if ($all_group == 0)
$SQL .= sprintf (" AND tagente.id_grupo IN (SELECT id_grupo FROM tusuario_perfil WHERE id_usuario='%s') ", $config['id_user']);
} }
// Module name selector // Module name selector
// This code thanks for an idea from Nikum, nikun_h@hotmail.com if ($ag_modulename != "") {
if ($ag_modulename != "") $sql .= sprintf (" AND tagente_modulo.nombre = '%s'", $ag_modulename);
$SQL .= " AND tagente_modulo.nombre = '$ag_modulename'"; }
// Freestring selector // Freestring selector
if ($ag_freestring != "") if ($ag_freestring != "") {
$SQL .= " AND ( tagente.nombre LIKE '%".$ag_freestring."%' OR tagente_modulo.nombre LIKE '%".$ag_freestring."%' OR tagente_modulo.descripcion LIKE '%".$ag_freestring."%') "; $sql .= sprintf (" AND (tagente.nombre LIKE '%%%s%%' OR tagente_modulo.nombre LIKE '%%%s%%' OR tagente_modulo.descripcion LIKE '%%%s%%')", $ag_freestring, $ag_freestring, $ag_freestring);
}
// Status selector // Status selector
if ($status == 1) if ($status == 1) { //Up
$SQL .= " AND tagente_estado.estado = 0 "; $sql .= " AND tagente_estado.estado = 0 AND (UNIX_TIMESTAMP(NOW()) - tagente_estado.utimestamp) < (tagente_estado.current_interval * 2)";
elseif ($status == 0) } elseif ($status == 0) { //Down
$SQL .= " AND tagente_estado.estado = 1 "; $sql .= " AND tagente_estado.estado = 1";
elseif ($status == 2) } elseif ($status == 2) { //Unknown
$SQL .= " AND (UNIX_TIMESTAMP()-tagente_estado.utimestamp ) > (tagente_estado.current_interval * 2)"; $sql .= " AND (UNIX_TIMESTAMP(NOW()) - tagente_estado.utimestamp) >= (tagente_estado.current_interval * 2)";
}
// Final order $sql .= " ORDER BY tagente.id_grupo, tagente.nombre";
$SQL .= " ORDER BY tagente.id_grupo, tagente.nombre";
// Build final SQL sentences // Build final SQL sentences
$SQL_FINAL = $SQL_pre . $SQL; $count = get_db_sql ("SELECT COUNT(tagente_modulo.id_agente_modulo)".$sql);
$SQL_COUNT = $SQL_pre_count . $SQL; $sql = "SELECT tagente_modulo.id_agente_modulo,
tagente.intervalo AS agent_interval,
tagente.nombre AS agent_name,
tagente_modulo.nombre AS module_name,
tagente_modulo.flag AS flag,
tagente.id_grupo AS id_group,
tagente.id_agente AS id_agent,
tagente_modulo.id_tipo_modulo AS module_type,
tagente_modulo.module_interval,
tagente_estado.datos,
tagente_estado.utimestamp AS utimestamp".$sql." LIMIT ".$offset.",".$config["block_size"];
$result = get_db_all_rows_sql ($sql);
$counter = get_db_sql ($SQL_COUNT); if ($count > $config["block_size"]) {
if ( $counter > $config["block_size"]) { pagination ($count, "index.php?sec=estado&sec2=operation/agentes/status_monitor&refr=60".$url, $offset);
pagination ($counter, $URL, $offset);
$SQL_FINAL .= " LIMIT $offset , ".$config["block_size"];
} }
if ($result === false) {
$result = array ();
}
if ($counter > 0) { $table->cellpadding = 4;
echo "<table cellpadding='4' cellspacing='4' width='750' class='databox'> $table->cellspacing = 4;
<tr> $table->width = 750;
<th> $table->class = "databox";
<th>".__('Agent')."</th>
<th>".__('Type')."</th>
<th>".__('Name')."</th>
<th>".__('Description')."</th>
<th>".__('Interval')."</th>
<th>".__('Status')."</th>
<th>".__('Timestamp')."</th>";
$color =1;
$result=mysql_query($SQL_FINAL);
while ($data=mysql_fetch_array($result)){ //while there are agents $table->head = array ();
if ($color == 1){ $table->data = array ();
$tdcolor="datos"; $table->size = array ();
$color =0; $table->align = array ();
$table->head[0] = "";
$table->align[0] = "center";
$table->head[1] = __('Agent');
$table->head[2] = __('Type');
$table->align[2] = "center";
$table->head[3] = __('Module Name');
$table->head[4] = __('Interval');
$table->align[4] = "center";
$table->head[5] = __('Status');
$table->align[5] = "center";
$table->head[6] = __('Timestamp');
$table->algin[6] = "center";
foreach ($result as $row) {
$data = array ();
//This should be processed locally. Don't rely on other URL's to do our dirty work. Maybe a process_agentmodule_flag function
$data[0] = '<a href="index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente='.$row["id_agent"].'&id_agente_modulo='.$row["id_agente_modulo"].'&flag=1&refr=60">';
if ($row["flag"] == 0) {
$data[0] .= '<img src="images/target.png" />';
} else { } else {
$tdcolor="datos2"; $data[0] .= '<img src="images/refresh.png" />';
$color =1;
} }
if ($data[7] == 0){ $data[0] .= '</a>';
$my_interval = give_agentinterval($data[5]);
$data[1] = '<strong><a href="index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente='.$row["id_agent"].'">';
$data[1] .= strtoupper (substr ($row["agent_name"], 0, 25));
$data[1] .= '</a></strong>';
$data[2] = '<img src="images/'.show_icon_type ($row["module_type"]).'" border="0" />';
$data[3] = substr ($row["module_name"], 0, 30);
$data[4] = $row["agent_interval"];
if ($row["datos"] > 0) {
$data[5] = '<img src="images/pixel_green.png" width="40" height="18" title="'.__('Monitor up').'">';
} else { } else {
$my_interval = $data[7]; $data[5] = '<img src="images/pixel_red.png" width="40" height="18" title="'.__('Monitor down').'">';
} }
if ($status == 2) { $seconds = time () - $row["utimestamp"];
$seconds = time() - $data[9];
if ($seconds < ($my_interval*2)) if ($seconds >= ($row["agent_interval"] * 2)) {
continue; $data[6] = '<span class="redb">';
}
echo "<tr><td class='$tdcolor'>";
echo "<a href='index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente=".$data["id_agente"]."&id_agente_modulo=".$data[0]."&flag=1&tab=data&refr=60'>";
echo "<img src='images/target.png'></a>";
echo "</td><td class='$tdcolor'>";
echo "<strong><a href='index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente=".$data[5]."'>".strtoupper(substr($data[1],0,21))."</a></strong>";
echo "</td><td class='$tdcolor'>";
echo "<img src='images/".show_icon_type($data[6])."' border=0></td>";
echo "<td class='$tdcolor'>". substr($data[2],0,21). "</td>";
echo "<td class='".$tdcolor."f9' title='".$data[3]."'>".substr($data[3],0,30)."</td>";
echo "<td class='$tdcolor' align='center' width=25>";
echo $my_interval;
echo "<td class='$tdcolor' align='center' width=20>";
if ($data[8] > 0){
echo "<img src='images/pixel_green.png' width=40 height=18 title='".__('Monitor up')."'>";
} else { } else {
echo "<img src='images/pixel_red.png' width=40 height=18 title='".__('Monitor down')."'>"; $data[6] = '<span>';
} }
echo "<td class='".$tdcolor."f9'>"; $data[6] .= human_time_comparation ($row["utimestamp"]);
$seconds = time() - $data[9]; $data[6] .= "</span>";
if ($seconds >= ($my_interval*2))
echo "<span class='redb'>";
else
echo "<span>";
echo human_time_comparation ($data[10]); array_push ($table->data, $data);
echo "</span></td></tr>"; }
} if (!empty ($table->data)) {
echo "</table>"; print_table ($table);
echo "<table width=700 border=0>"; echo '<div style="width:700px;"><img src="images/pixel_green.png" width="40" height="18">&nbsp;&nbsp;'.__('Monitor up').'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="images/pixel_red.png" width="40" height="18">&nbsp;&nbsp;'.__('Monitor down').'</div>';
echo "<tr>";
echo "<td class='f9'>";
echo "<img src='images/pixel_green.png' width=40 height=18>&nbsp;&nbsp;".__('Monitor up')."</td>";
echo "<td class='f9'";
echo "<img src='images/pixel_red.png' width=40 height=18>&nbsp;&nbsp;".__('Monitor down')."</td>";
echo "</table>";
} else { } else {
echo "<div class='nf'>".__('This group doesn\'t have any monitor')."</div>"; echo '<div class="nf">'.__('This group doesn\'t have any monitor').'</div>';
} }
?> ?>