2008-09-16 Evi Vanoost <vanooste@rcbi.rochester.edu>

* operation/agentes/estado_alertas.php: Fixed a few bugs and made it 
        faster by switching to the general functions. Style update

        * include/functions_db.php: Made get_agents_in_group() function accept 
        array or a comma delimited list. This will allow us to get agents in
        multiple groups. Backwards compatible (single value passed). Set an 
        output check on empty (array or false) for get_alerts_in_group().

        * include/functions.php: Made get_alert_days() output translatable. 
        Made the little columns with info on alerts give more text (it does
        fit). Made show_alert_show_view() use the internal functions to
        retrieve name and id's. Style updates, better HTML output (tags).

git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1097 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
guruevi 2008-09-16 18:16:09 +00:00
parent bcf966b451
commit 7db29da666
4 changed files with 250 additions and 315 deletions
pandora_console

View File

@ -1,3 +1,18 @@
2008-09-16 Evi Vanoost <vanooste@rcbi.rochester.edu>
* operation/agentes/estado_alertas.php: Fixed a few bugs and made it
faster by switching to the general functions. Style update
* include/functions_db.php: Made get_agents_in_group() function accept
array or a comma delimited list. This will allow us to get agents in
multiple groups. Backwards compatible (single value passed). Set an
output check on empty (array or false) for get_alerts_in_group().
* include/functions.php: Made get_alert_days() output translatable.
Made the little columns with info on alerts give more text (it does
fit). Made show_alert_show_view() use the internal functions to
retrieve name and id's. Style updates, better HTML output (tags).
2008-09-12 Evi Vanoost <vanooste@rcbi.rochester.edu>
* godmode/agentes/configurar_agente.php: Style updates for create agent

View File

@ -700,28 +700,32 @@ function get_alert_days ($row) {
$days_output = "";
$check = $row["monday"] + $row["tuesday"] + $row["wednesday"] + $row["thursday"] + $row["friday"] + $row["saturday"] + $row["sunday"];
if ($check == 7) {
return __('All');
} elseif ($check == 0) {
return __('None');
}
if ($row["monday"] != 0)
$days_output .= "Mo ";
$days_output .= __('Mon')." ";
if ($row["tuesday"] != 0)
$days_output .= "Tu ";
$days_output .= __('Tue')." ";
if ($row["wednesday"] != 0)
$days_output .= "We ";
$days_output .= __('Wed')." ";
if ($row["thursday"] != 0)
$days_output .= "Th ";
$days_output .= __('Thu')." ";
if ($row["friday"] != 0)
$days_output .= "Fr ";
$days_output .= __('Fri')." ";
if ($row["saturday"] != 0)
$days_output .= "Sa ";
$days_output .= __('Sat')." ";
if ($row["sunday"] != 0)
$days_output .= "Su ";
$days_output .= __('Sun');
if ($check > 1) {
return str_replace (" ",", ",$days_output);
}
return rtrim ($days_output);
}
@ -829,7 +833,7 @@ function show_alert_row_edit ($row2, $tdcolor = "datos", $id_tipo_modulo = 1, $c
// calculare firing conditions
if ($row2["alert_text"] != "") {
$firing_cond = __('Text')."(".substr($row2["alert_text"],0,8).")";
$firing_cond = __('Text')." (".substr($row2["alert_text"],0,12).")";
} else {
$firing_cond = $row2["min_alerts"]." / ".$row2["max_alerts"];
}
@ -846,19 +850,15 @@ function show_alert_row_edit ($row2, $tdcolor = "datos", $id_tipo_modulo = 1, $c
<span>
<table cellspacing='2' cellpadding='0'
style='margin-left:2px;'>
<tr><th colspan='2' width='91'>".
__('Recovery')."</th></tr>
<tr><th colspan='2' width='91'>".__('Recovery')."</th></tr>
<tr><td colspan='2' class='datos' align='center'><b>$recovery_notify</b></td></tr>
<tr><th colspan='2' width='91'>".
__('Priority')."</th></tr>
<tr><th colspan='2' width='91'>".__('Priority')."</th></tr>
<tr><td colspan='2' class='datos' align='center'><b>$priority</b></td></tr>
<tr><th colspan='2' width='91'>".
__('Alert Ctrl.')."</th></tr>
<tr><th colspan='2' width='91'>".__('Alert Ctrl.')."</th></tr>
<tr><td colspan='2' class='datos' align='center'><b>".$firing_cond."</b></td></tr>
<tr><th colspan='2' width='91'>".
__('Firing days')."</th></tr>
<tr><th colspan='2' width='91'>".__('Firing days')."</th></tr>
<tr><td colspan='2' class='datos' align='center'><b>".$firing_days."</b></td></tr>
</table></span></A>";
</table></span></a>";
return $string;
}
@ -877,116 +877,116 @@ function show_alert_show_view ($data, $tdcolor = "datos", $combined = 0) {
global $lang_label;
if ($combined == 0) {
$sql = sprintf ("SELECT tagente.nombre AS agent_name, tagente_modulo.nombre AS module_name, tagente_modulo.id_agente FROM `tagente_modulo`, `tagente` WHERE `tagente_modulo`.`id_agente` = `tagente`.`id_agente` AND `tagente_modulo`.`id_agente_modulo` = '%d'",$data["id_agente_modulo"]);
$result = get_db_all_rows_sql ($sql);
$agent_name = $result[0]["agent_name"];
$id_agente = $result[0]["id_agente"];
$module_name = $result[0]["module_name"];
$id_agente = give_agent_id_from_module_id ($data["id_agente_modulo"]);
$agent_name = dame_nombre_agente ($id_agente);
$module_name = dame_nombre_modulo_agentemodulo ($data["id_agente_modulo"]);
} else {
$sql = sprintf ("SELECT `nombre` FROM `tagente` WHERE `id_agente` = '%d'",$data["id_agent"]);
$agent_name = get_db_sql ($sql);
$id_agente = $data["id_agent"];
$agent_name = dame_nombre_agente ($id_agente);
}
$alert_name = get_db_sql ("SELECT nombre FROM talerta WHERE id_alerta = ".$data["id_alerta"]);
$alert_name = dame_nombre_alerta ($data["id_alerta"]);
echo "<td class='".$tdcolor."f9' title='$alert_name'>".substr($alert_name,0,15)."</td>";
echo '<td class="'.$tdcolor.'f9" title="'.$alert_name.'">'.substr($alert_name,0,15).'</td>';
if ($combined == 0) {
echo "<td class='".$tdcolor."'>".substr($module_name,0,12)."</td>";
echo '<td class="'.$tdcolor.'">'.substr ($module_name,0,12).'</td>';
} else {
echo "<td class='".$tdcolor."'>";
echo '<td class="'.$tdcolor.'">';
// More details EYE tooltip (combined)
echo " <a href='#' class='info_table'><img class='top' src='images/eye.png' alt=''><span>";
echo '<a href="#" class="info_table"><img class="top" src="images/eye.png" alt=""><span>';
echo show_alert_row_mini ($data["id_aam"]);
echo "</span></a> ";
echo substr($agent_name,0,16)."</td>";
echo '</span></a>';
echo substr($agent_name,0,16).'</td>';
}
// Description
echo "<td class='".$tdcolor."'>".$data["descripcion"]."</td>";
echo '<td class="'.$tdcolor.'">'.$data["descripcion"].'</td>';
// Extended info
echo "<td class='".$tdcolor."'>";
echo '<td class="'.$tdcolor.'">';
// Has recovery notify activated ?
if ($data["recovery_notify"] > 0)
if ($data["recovery_notify"] > 0) {
$recovery_notify = __('Yes');
else
} else {
$recovery_notify = __('No');
}
// calculate priority
$priority = get_alert_priority ($data["priority"]);
// calculare firing conditions
if ($data["alert_text"] != ""){
$firing_cond = __('Text')."(".substr($data["alert_text"],0,8).")";
$firing_cond = __('Text')." (".substr($data["alert_text"],0,12).")";
} else {
$firing_cond = $data["min_alerts"]." / ".$data["max_alerts"];
}
// calculate days
$firing_days = get_alert_days ($data);
// More details EYE tooltip
echo "<a href='#' class='info'><img class='top'
src='images/eye.png' alt=''>";
echo '<a href="#" class="info"><img class="top" src="images/eye.png" alt="">';
// Add float info table
echo "<span>
<table cellspacing='2' cellpadding='0'
style='margin-left:2px;'>
<tr><th colspan='2' width='91'>".
__('Recovery')."</th></tr>
<tr><td colspan='2' class='datos' align='center'><b>$recovery_notify</b></td></tr>
<tr><th colspan='2' width='91'>".
__('Priority')."</th></tr>
<tr><td colspan='2' class='datos' align='center'><b>$priority</b></td></tr>
<tr><th colspan='2' width='91'>".
__('Alert Ctrl.')."</th></tr>
<tr><td colspan='2' class='datos' align='center'><b>".$firing_cond."</b></td></tr>
<tr><th colspan='2' width='91'>".
__('Firing days')."</th></tr>
<tr><td colspan='2' class='datos' align='center'><b>".$firing_days."</b></td></tr>
</table></span></a>";
echo '<span>
<table cellspacing="2" cellpadding="0" style="margin-left:2px;">
<tr><th colspan="2" width="91">'.__('Recovery').'</th></tr>
<tr><td colspan="2" class="datos" align="center"><b>'.$recovery_notify.'</b></td></tr>
<tr><th colspan="2" width="91">'.__('Priority').'</th></tr>
<tr><td colspan="2" class="datos" align="center"><b>'.$priority.'</b></td></tr>
<tr><th colspan="2" width="91">'.__('Alert Ctrl.').'</th></tr>
<tr><td colspan="2" class="datos" align="center"><b>'.$firing_cond.'</b></td></tr>
<tr><th colspan="2" width="91">'.__('Firing days').'</th></tr>
<tr><td colspan="2" class="datos" align="center"><b>'.$firing_days.'</b></td></tr>
</table></span></a>';
$mytempdata = fmod($data["dis_min"], 1);
if ($mytempdata == 0)
$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 "<td class='".$tdcolor."' colspan=2>".__('Text')."</td>";
else {
echo "<td class='".$tdcolor."'>".$mymin."</td>";
echo "<td class='".$tdcolor."'>".$mymax."</td>";
}
echo "<td align='center' class='".$tdcolor."'>".human_time_description($data["time_threshold"]);
if ($data["last_fired"] == "0000-00-00 00:00:00") {
echo "<td align='center' class='".$tdcolor."f9'>".__('Never')."</td>";
} else {
echo "<td align='center' class='".$tdcolor."f9'>".human_time_comparation ($data["last_fired"])."</td>";
$mymin = $data["dis_min"];
}
echo "<td align='center' class='".$tdcolor."'>".$data["times_fired"]."</td>";
if ($data["times_fired"] <> 0){
echo "<td class='".$tdcolor."' align='center'><img width='20' height='9' src='images/pixel_red.png' title='".__('Alert fired')."'>";
echo "</td>";
$id_grupo_alerta = get_db_value ("id_grupo", "tagente", "id_agente", $id_agente);
$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 '<td class="'.$tdcolor.'" colspan="2">'.__('Text').'</td>';
} else {
echo '<td class="'.$tdcolor.'">'.$mymin.'</td>';
echo '<td class="'.$tdcolor.'">'.$mymax.'</td>';
}
echo '<td align="center" class="'.$tdcolor.'">'.human_time_description ($data["time_threshold"]).'</td>';
if ($data["last_fired"] == "0000-00-00 00:00:00") {
echo '<td align="center" class="'.$tdcolor.'f9">'.__('Never').'</td>';
} else {
echo '<td align="center" class="'.$tdcolor.'f9">'.human_time_comparation ($data["last_fired"]).'</td>';
}
echo '<td align="center" class="'.$tdcolor.'">'.$data["times_fired"].'</td>';
if ($data["times_fired"] != 0) {
echo '<td class="'.$tdcolor.'" align="center"><img width="20" height="9" src="images/pixel_red.png" title="'.__('Alert fired').'"></td>';
$id_grupo_alerta = dame_id_grupo ($id_agente);
if (give_acl($config["id_user"], $id_grupo_alerta, "AW") == 1) {
echo "<td align='center' class='".$tdcolor."'>";
echo "<a href='index.php?sec=estado&sec2=operation/agentes/ver_agente&
id_agente=$id_agente&validate_alert=".$data["id_aam"]."'><img src='images/ok.png'></a>";
echo "</td>";
echo '<td align="center" class="'.$tdcolor.'">';
echo '<a href="index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente='.$id_agente.'&validate_alert='.$data["id_aam"].'"><img src="images/ok.png"></a>';
echo '</td>';
}
} else {
echo "<td class='".$tdcolor."' align='center'>
<img width='20' height='9' src='images/pixel_green.png' title='".__('Alert not fired')."'></td>";
echo '<td class="'.$tdcolor.'" align="center"><img width="20" height="9" src="images/pixel_green.png" title="'.__('Alert not fired').'"></td>';
}
}

View File

@ -192,12 +192,17 @@ function give_disabled_group ($id_group) {
/**
* Get all the agents in a group.
*
* @param id_group Group id
* @param id_group Group id or a comma delimited list of id_groups or an array
* of ID's
*
* @param disabled Add disabled agents to agents. Default: False.
*
* @return An array with all agents in the group.
*/
function get_agents_in_group ($id_group, $disabled = false) {
if (is_array ($id_group)) //If id_group is an array, then
$id_group = implode (",", $id_group);
/* 'All' group must return all agents */
if ($id_group == 1) {
if ($disabled) {
@ -206,9 +211,10 @@ function get_agents_in_group ($id_group, $disabled = false) {
return get_db_all_rows_field_filter ('tagente', 'disabled', 0, 'nombre');
}
} elseif ($disabled && $id_group != 1) {
return get_db_all_rows_field_filter ('tagente', 'id_grupo', (int) $id_group, 'nombre');
$sql = sprintf ("SELECT * FROM tagente WHERE id_grupo IN (%s) ORDER BY nombre",$id_group);
return get_db_all_rows_sql ($sql);
} else {
$sql = sprintf ("SELECT * FROM tagente WHERE id_grupo = %d AND disabled = 0 ORDER BY nombre",$id_group);
$sql = sprintf ("SELECT * FROM tagente WHERE id_grupo IN (%s) AND disabled = 0 ORDER BY nombre",$id_group);
return get_db_all_rows_sql ($sql);
}
}
@ -628,8 +634,9 @@ function get_alert_fires_in_period ($id_agent_module, $period, $date = 0) {
function get_alerts_in_group ($id_group) {
$alerts = array ();
$agents = get_agents_in_group ($id_group);
if (!$agents)
return;
if (empty ($agents))
return $alerts;
foreach ($agents as $agent) {
$agent_alerts = get_alerts_in_agent ($agent["id_agente"]);
$alerts = array_merge ($alerts, $agent_alerts);

View File

@ -16,12 +16,9 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
// Load global vars
require ("include/config.php");
check_login ();
if (! give_acl ($config["id_user"], 0, "AR") && ! give_acl ($config["id_user"], 0, "AW")) {
@ -33,74 +30,80 @@ if (! give_acl ($config["id_user"], 0, "AR") && ! give_acl ($config["id_user"],
// Show alerts for specific agent
if (isset($_GET["id_agente"])){
$id_agente = $_GET["id_agente"];
$id_agente = get_parameter_get ("id_agente");
$id_grupo_alerta = get_db_value ("id_grupo", "tagente", "id_agente", $id_agente);
if (give_acl($config["id_user"], $id_grupo_alerta, "AR") == 0) {
audit_db($config["id_user"], $REMOTE_ADDR, "ACL Violation","Trying to access alert view");
$id_grupo_alerta = dame_id_grupo ($id_agente);
if (give_acl ($config["id_user"], $id_grupo_alerta, "AR") == 0) {
audit_db ($config["id_user"], $REMOTE_ADDR, "ACL Violation","Trying to access alert view");
include ("general/noaccess.php");
exit;
}
if (isset($_GET["tab"])){
if (isset ($_GET["tab"])){
echo "<h2>".__('Pandora Agents')." &gt; ".__('Full list of Alerts')."</h2>";
}
$query_gen='SELECT talerta_agente_modulo.* FROM talerta_agente_modulo, tagente_modulo WHERE talerta_agente_modulo.id_agente_modulo = tagente_modulo.id_agente_modulo AND tagente_modulo.id_agente ='.$id_agente;
$result_gen=mysql_query($query_gen);
if (mysql_num_rows ($result_gen)) {
$query = sprintf ("SELECT talerta_agente_modulo.* FROM talerta_agente_modulo, tagente_modulo WHERE
talerta_agente_modulo.id_agente_modulo = tagente_modulo.id_agente_modulo AND
tagente_modulo.id_agente = %d",$id_agente);
$result = get_db_all_rows_sql ($query);
if ($result !== false) {
if (!isset($_GET["tab"])) {
if (!isset ($_GET["tab"])) {
echo "<h3>".__('Full list of Alerts')."</h3>";
}
echo "<table cellpadding='4' cellspacing='4' width=750 border=0 class='databox'>";
echo "<tr>
<th>".__('Type')."<th>".__('Name')."</th>
<th>".__('Description')."</th>
echo '<table cellpadding="4" cellspacing="4" width="750" border="0" class="databox">';
echo "<tr><th>".__('Type')."</th>
<th>".__('Name')."</th>
<th>".__('Description')."</th>
<th>".__('Info')."</th>
<th>".__('Min.')."</th>
<th>".__('Max.')."</th>
<th>".__('Time threshold')."</th>
<th>".__('Last fired')."</th>
<th>".__('Times Fired')."</th>
<th>".__('Status')."</th>
<th>".__('Validate')."</th>";
$color=1;
while ($data=mysql_fetch_array($result_gen)){
<th>".__('Min.')."</th>
<th>".__('Max.')."</th>
<th>".__('Time threshold')."</th>
<th>".__('Last fired')."</th>
<th>".__('Times Fired')."</th>
<th>".__('Status')."</th>
<th>".__('Validate')."</th></tr>";
$color = 1;
foreach ($result as $data) {
if ($color == 1){
$tdcolor = "datos";
$color = 0;
}
else {
} else {
$tdcolor = "datos2";
$color = 1;
}
echo "<tr>";
show_alert_show_view ($data, $tdcolor, 0);
echo "</tr>";
}
// Show combined alerts for this agent
$result_com = mysql_query("SELECT * FROM talerta_agente_modulo WHERE id_agent = $id_agente");
if (mysql_num_rows ($result_com)) {
echo "<tr><td colspan=11 class='datos3'><center>".__('Combined alerts')."</center>";
}
while ($data_com=mysql_fetch_array($result_com)){
if ($color == 1){
$tdcolor = "datos";
$color = 0;
} else {
$tdcolor = "datos2";
$color = 1;
$sql = sprintf ("SELECT * FROM talerta_agente_modulo WHERE id_agent = %d",$id_agente);
$result = get_db_all_rows_sql ($sql);
if ($result !== false) {
echo '<tr><td colspan="11" class="datos3"><center>'.__('Combined alerts').'</center>';
foreach ($result as $data) {
//$color comes from the previous one
if ($color == 1) {
$tdcolor = "datos";
$color = 0;
} else {
$tdcolor = "datos2";
$color = 1;
}
echo "<tr>";
show_alert_show_view ($data, $tdcolor, 1);
echo "</tr>";
}
echo "<tr>";
show_alert_show_view ($data_com, $tdcolor, 1);
}
echo '</table>';
echo '</table>';
} else {
echo "<div class='nf'>".__('This agent doesn\'t have any alert')."</div>";
echo '<div class="nf">'.__('This agent doesn\'t have any alert').'</div>';
}
// Show alert for no defined agent
@ -109,194 +112,104 @@ if (isset($_GET["id_agente"])){
// SHOW ALL ALERTS (GENERAL PAGE)
// -------------------------------
echo "<h2>".__('Pandora Agents')." &gt; ";
echo __('Full list of Alerts')."</h2>";
$iduser_temp=$_SESSION['id_usuario'];
echo "<h2>".__('Pandora Agents')." &gt; ".__('Full list of Alerts')."</h2>";
$iduser_temp = $config["id_user"];
$ag_group = get_parameter ("ag_group", -1);
if ($ag_group != -1)
echo "<form method='post' action='index.php?sec=estado&sec2=operation/agentes/estado_alertas&refr=60&ag_group=".$ag_group."'>";
else
echo "<form method='post' action='index.php?sec=estado&sec2=operation/agentes/estado_alertas&refr=60'>";
if (give_acl ($config["id_user"], $ag_group, "AR") == 0) {
audit_db ($config["id_user"], $REMOTE_ADDR, "ACL Violation","Trying to access alert view");
require ("general/noaccess.php");
exit;
}
if ($ag_group != -1) {
echo '<form method="post" action="index.php?sec=estado&sec2=operation/agentes/estado_alertas&refr=60&ag_group='.$ag_group.'">';
} else {
echo '<form method="post" action="index.php?sec=estado&sec2=operation/agentes/estado_alertas&refr=60">';
}
echo '<table cellpadding="4" cellspacing="4" class="databox">';
echo '<tr><td>'.__('Group').'</td><td valign="middle">';
//Select box
$fields = get_user_groups ($iduser_temp);
print_select ($fields, "ag_group", $ag_group, 'javascript:this.form.submit();" class="w150','');
//And submit button
echo '</td><td valign="middle"><noscript><input name="uptbutton" type="submit" class="sub" value="'.__('Show').'"></noscript></td>';
//And finish the table here
echo '<td class="f9" style="padding-left:30px;"><img src="images/pixel_red.png" width="18" height="18">&nbsp;'.__('Alert fired').'</td>';
echo '<td class="f9" style="padding-left:30px;"><img src="images/pixel_green.png" width="18" height="18">&nbsp;'.__('Alert not fired').'</td>';
echo '<td class="f9" style="padding-left:30px; vertical-align:bottom;">(*) '.__('Combined alert').'</tr></table></form>';
echo "<table cellpadding='4' cellspacing='4' class='databox'>";
echo "<tr>";
echo "<td>".__('Group')."</td>";
echo "<td valign='middle'>";
echo "<select name='ag_group' onChange='javascript:this.form.submit();' class='w150'>";
if ( $ag_group > 1 ){
echo "<option value='".$ag_group."'>".dame_nombre_grupo($ag_group).
"</option>";
}
echo "<option value=1>".dame_nombre_grupo(1)."</option>";
list_group ($config["id_user"]);
echo "</select></td>";
echo "<td valign='middle'>
<noscript>
<input name='uptbutton' type='submit' class='sub' value='".__('Show')."'>
</noscript></td></form>";
// Display single alerts
if ($ag_group > 1)
$sql='SELECT id_agente, nombre, disabled FROM tagente WHERE id_grupo='.$ag_group.' ORDER BY nombre';
else
$sql='SELECT id_agente, nombre, disabled FROM tagente ORDER BY id_grupo, nombre';
$sql = "SELECT id_agente, nombre, disabled FROM tagente WHERE tagente.disabled = 0 ";
// Agent group selector
if ($ag_group > 1)
$sql .=" AND tagente.id_grupo = ".$ag_group;
else {
// User has explicit permission on group 1 ?
$all_group = get_db_sql ("SELECT COUNT(id_grupo) FROM tusuario_perfil WHERE id_usuario='".$config["id_user"]."' AND id_grupo = 1");
if ($all_group == 0)
$sql .=" AND tagente.id_grupo IN (SELECT id_grupo FROM tusuario_perfil WHERE id_usuario='".$config["id_user"]."')";
if ($ag_group > 1) {
$result = get_agents_in_group ($ag_group);
} else {
//Fields is an array with all the groups the user has access to
$result = get_agents_in_group (array_keys ($fields));
}
$color = 1;
$string = '';
$color=1; $string = '';
$result=mysql_query($sql);
if ($result)
while ($row=mysql_fetch_array($result)) { //while there are agents
$id_agente = $row['id_agente'];
$nombre_agente = strtoupper($row["nombre"]);
$query_gen='SELECT talerta_agente_modulo.id_alerta,
talerta_agente_modulo.descripcion,
talerta_agente_modulo.last_fired,
talerta_agente_modulo.times_fired,
talerta_agente_modulo.id_agente_modulo,
tagente_modulo.id_agente_modulo
FROM tagente_modulo, talerta_agente_modulo
WHERE tagente_modulo.id_agente = '.$id_agente.'
AND tagente_modulo.id_agente_modulo = talerta_agente_modulo.id_agente_modulo
AND talerta_agente_modulo.disable = 0 ';
$result_gen=mysql_query($query_gen);
while ($data=mysql_fetch_array($result_gen)){
if ($color == 1){
$tdcolor = "datos";
$color = 0;
}
else {
$tdcolor = "datos2";
$color = 1;
}
$string .= "<tr><td class='".$tdcolor."'>
<a href='index.php?sec=estado&
sec2=operation/agentes/ver_agente&
id_agente=".$id_agente."'>
<b>".$nombre_agente."</b>";
$string .= "<td class='$tdcolor' align='center'>";
if ($data["times_fired"] <> 0)
$string .= "<img src='images/pixel_red.png' width=40 height=18 title='".__('Alert fired')."'>";
else
$string .= "<img src='images/pixel_green.png' width=40 height=18 title='".__('Alert not fired')."'>";
$string = $string."<td class='".$tdcolor."'>"
.dame_nombre_alerta($data["id_alerta"])."</td>";
$string=$string."<td class='".$tdcolor."'>".
$data["descripcion"]."</td>";
if ($data["last_fired"] == "0000-00-00 00:00:00") {
$string=$string."<td class='".$tdcolor."'>".
__('Never')."</td>";
} else {
$string=$string."<td class='".$tdcolor."'>".
human_time_comparation($data["last_fired"])."</td>";
}
$string=$string."<td class='".$tdcolor."'>".
$data["times_fired"]."</td>";
}
} //end while
// Display combined alerts
// =======================
$sql = "SELECT id_agente, nombre, disabled FROM tagente WHERE tagente.disabled = 0 ";
// Agent group selector
if ($ag_group > 1)
$sql .=" AND tagente.id_grupo = ".$ag_group;
else {
// User has explicit permission on group 1 ?
$all_group = get_db_sql ("SELECT COUNT(id_grupo) FROM tusuario_perfil WHERE id_usuario='".$config["id_user"]."' AND id_grupo = 1");
if ($all_group == 0)
$sql .=" AND tagente.id_grupo IN (SELECT id_grupo FROM tusuario_perfil WHERE id_usuario='".$config["id_user"]."')";
if ($result === false) {
$result = array();
} else {
$table->head = array(); //Reset table head
$table->head[0] = __('Agent');
$table->head[1] = __('Status');
$table->head[2] = __('Type');
$table->head[3] = __('Description');
$table->head[4] = __('Last fired');
$table->head[5] = __('Times Fired');
$table->align = array();
$table->align[1] = "center";
$table->cellpadding = 4;
$table->cellspacing = 4;
$table->width = 700;
$table->class = "databox";
$table->data = array(); //Reset table data
$idx = 0; //row index
}
$result=mysql_query($sql);
$color=1;
if ($result)
while ($row=mysql_fetch_array($result)){ //while there are agents
$id_agente = $row['id_agente'];
$nombre_agente = strtoupper($row["nombre"]);
$query_gen='SELECT talerta_agente_modulo.id_alerta,
talerta_agente_modulo.descripcion,
talerta_agente_modulo.last_fired,
talerta_agente_modulo.times_fired,
talerta_agente_modulo.id_agent
FROM talerta_agente_modulo
WHERE talerta_agente_modulo.id_agent = '.$id_agente.' AND talerta_agente_modulo.disable = 0 ';
$result_gen=mysql_query($query_gen);
if (mysql_num_rows ($result_gen)) {
while ($data=mysql_fetch_array($result_gen)){
if ($color == 1){
$tdcolor = "datos";
$color = 0;
}
else {
$tdcolor = "datos2";
$color = 1;
}
if (!isset($string)) {
$string='';
}
$string = $string."<tr><td class='".$tdcolor."'>
<a href='index.php?sec=estado&
sec2=operation/agentes/ver_agente&
id_agente=".$id_agente."'>
<b>".$nombre_agente."</b> (*)";
$string .= "<td class='$tdcolor' align='center'>";
if ($data["times_fired"] <> 0)
$string .= "<img src='images/pixel_red.png' width=40 height=18 title='".__('Alert fired')."'>";
else
$string .= "<img src='images/pixel_green.png' width=40 height=18 title='".__('Alert not fired')."'>";
//This result is the array with agents
foreach ($result as $row) {
$id_agente = $row["id_agente"];
$nombre_agente = strtoupper ($row["nombre"]);
$result_alerts = get_alerts_in_agent ($id_agente);
if ($result_alerts === false)
$result_alerts = array();
foreach ($result_alerts as $data) {
$table->data[$idx] = array(); //init array
$table->data[$idx][0] = '<a href="index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente='.$id_agente.'"><b>'.$nombre_agente.'</b>';
$string = $string."<td class='".$tdcolor."'>"
.dame_nombre_alerta($data["id_alerta"])."</td>";
$string=$string."<td class='".$tdcolor."'>".
$data["descripcion"]."</td>";
if ($data["last_fired"] == "0000-00-00 00:00:00") {
$string=$string."<td class='".$tdcolor."'>".
__('Never')."</td>";
} else {
$string=$string."<td class='".$tdcolor."'>".
human_time_comparation($data["last_fired"])."</td>";
}
$string=$string."<td class='".$tdcolor."'>".
$data["times_fired"]."</td>";
if ($data["times_fired"] != 0) {
$table->data[$idx][1] = '<img src="images/pixel_red.png" width="40" height="18" title="'.__('Alert fired').'">';
} else {
$table->data[$idx][1] = '<img src="images/pixel_green.png" width="40" height="18" title="'.__('Alert not fired').'">';
}
}
} //end while
if ($string != "") {
echo "<td class='f9' style='padding-left: 30px;'>";
echo "<img src='images/pixel_red.png' width=18 height=18> ".__('Alert fired')."</td>";
echo "<td class='f9' style='padding-left: 30px;'>";
echo "<img src='images/pixel_green.png' width=18 height=18> ".__('Alert not fired');
echo "</td><td class='f9' valign='bottom' style='padding-left: 10px;'>(*) ".__('Combined alert')."</tr></table>";
echo "<br>";
echo "<table cellpadding='4' cellspacing='4' width='700' class='databox'>";
echo "<tr>
<th>".__('Agent')."</th>
<th>".__('Status')."</th>
<th>".__('Type')."</th>
<th>".__('Description')."</th>
<th>".__('Last fired')."</th>
<th>".__('Times Fired')."</th>";
echo $string; //built table of alerts
echo "</table>";
}
else {
echo "</table><br><div class='nf'>".
__('No agent included in this group has any assigned alert')."</div>";
$table->data[$idx][2] = dame_nombre_alerta ($data["id_alerta"]);
$table->data[$idx][3] = $data["descripcion"];
if ($data["last_fired"] == "0000-00-00 00:00:00") {
$table->data[$idx][4] = __('Never');
} else {
$table->data[$idx][4] = human_time_comparation ($data["last_fired"]);
}
$table->data[$idx][5] = $data["times_fired"];
$tbl_idx++; //increment the index counter
} //end foreach (data)
} //end foreach (agent)
if (!empty ($result) && !empty ($table->data)) {
print_table ($table);
} else {
echo '<div class="nf">'.__('No agent included in this group has any assigned alert').'</div>';
}
unset ($table); //throw away table
} // Main alert view
?>