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 feb1c42743
commit 3b338a5c2d
4 changed files with 250 additions and 315 deletions

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> 2008-09-12 Evi Vanoost <vanooste@rcbi.rochester.edu>
* godmode/agentes/configurar_agente.php: Style updates for create agent * godmode/agentes/configurar_agente.php: Style updates for create agent

View File

@ -700,28 +700,32 @@ function get_alert_days ($row) {
$days_output = ""; $days_output = "";
$check = $row["monday"] + $row["tuesday"] + $row["wednesday"] + $row["thursday"] + $row["friday"] + $row["saturday"] + $row["sunday"]; $check = $row["monday"] + $row["tuesday"] + $row["wednesday"] + $row["thursday"] + $row["friday"] + $row["saturday"] + $row["sunday"];
if ($check == 7) { if ($check == 7) {
return __('All'); return __('All');
} elseif ($check == 0) { } elseif ($check == 0) {
return __('None'); return __('None');
} }
if ($row["monday"] != 0) if ($row["monday"] != 0)
$days_output .= "Mo "; $days_output .= __('Mon')." ";
if ($row["tuesday"] != 0) if ($row["tuesday"] != 0)
$days_output .= "Tu "; $days_output .= __('Tue')." ";
if ($row["wednesday"] != 0) if ($row["wednesday"] != 0)
$days_output .= "We "; $days_output .= __('Wed')." ";
if ($row["thursday"] != 0) if ($row["thursday"] != 0)
$days_output .= "Th "; $days_output .= __('Thu')." ";
if ($row["friday"] != 0) if ($row["friday"] != 0)
$days_output .= "Fr "; $days_output .= __('Fri')." ";
if ($row["saturday"] != 0) if ($row["saturday"] != 0)
$days_output .= "Sa "; $days_output .= __('Sat')." ";
if ($row["sunday"] != 0) if ($row["sunday"] != 0)
$days_output .= "Su "; $days_output .= __('Sun');
if ($check > 1) { if ($check > 1) {
return str_replace (" ",", ",$days_output); return str_replace (" ",", ",$days_output);
} }
return rtrim ($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 // calculare firing conditions
if ($row2["alert_text"] != "") { if ($row2["alert_text"] != "") {
$firing_cond = __('Text')."(".substr($row2["alert_text"],0,8).")"; $firing_cond = __('Text')." (".substr($row2["alert_text"],0,12).")";
} else { } else {
$firing_cond = $row2["min_alerts"]." / ".$row2["max_alerts"]; $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> <span>
<table cellspacing='2' cellpadding='0' <table cellspacing='2' cellpadding='0'
style='margin-left:2px;'> style='margin-left:2px;'>
<tr><th colspan='2' width='91'>". <tr><th colspan='2' width='91'>".__('Recovery')."</th></tr>
__('Recovery')."</th></tr>
<tr><td colspan='2' class='datos' align='center'><b>$recovery_notify</b></td></tr> <tr><td colspan='2' class='datos' align='center'><b>$recovery_notify</b></td></tr>
<tr><th colspan='2' width='91'>". <tr><th colspan='2' width='91'>".__('Priority')."</th></tr>
__('Priority')."</th></tr>
<tr><td colspan='2' class='datos' align='center'><b>$priority</b></td></tr> <tr><td colspan='2' class='datos' align='center'><b>$priority</b></td></tr>
<tr><th colspan='2' width='91'>". <tr><th colspan='2' width='91'>".__('Alert Ctrl.')."</th></tr>
__('Alert Ctrl.')."</th></tr>
<tr><td colspan='2' class='datos' align='center'><b>".$firing_cond."</b></td></tr> <tr><td colspan='2' class='datos' align='center'><b>".$firing_cond."</b></td></tr>
<tr><th colspan='2' width='91'>". <tr><th colspan='2' width='91'>".__('Firing days')."</th></tr>
__('Firing days')."</th></tr>
<tr><td colspan='2' class='datos' align='center'><b>".$firing_days."</b></td></tr> <tr><td colspan='2' class='datos' align='center'><b>".$firing_days."</b></td></tr>
</table></span></A>"; </table></span></a>";
return $string; return $string;
} }
@ -877,116 +877,116 @@ function show_alert_show_view ($data, $tdcolor = "datos", $combined = 0) {
global $lang_label; global $lang_label;
if ($combined == 0) { 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"]); $id_agente = give_agent_id_from_module_id ($data["id_agente_modulo"]);
$result = get_db_all_rows_sql ($sql); $agent_name = dame_nombre_agente ($id_agente);
$agent_name = $result[0]["agent_name"]; $module_name = dame_nombre_modulo_agentemodulo ($data["id_agente_modulo"]);
$id_agente = $result[0]["id_agente"];
$module_name = $result[0]["module_name"];
} else { } 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"]; $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"]);
echo "<td class='".$tdcolor."f9' title='$alert_name'>".substr($alert_name,0,15)."</td>"; $alert_name = dame_nombre_alerta ($data["id_alerta"]);
echo '<td class="'.$tdcolor.'f9" title="'.$alert_name.'">'.substr($alert_name,0,15).'</td>';
if ($combined == 0) { if ($combined == 0) {
echo "<td class='".$tdcolor."'>".substr($module_name,0,12)."</td>"; echo '<td class="'.$tdcolor.'">'.substr ($module_name,0,12).'</td>';
} else { } else {
echo "<td class='".$tdcolor."'>"; echo '<td class="'.$tdcolor.'">';
// More details EYE tooltip (combined) // 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 show_alert_row_mini ($data["id_aam"]);
echo "</span></a> "; echo '</span></a>';
echo substr($agent_name,0,16)."</td>"; echo substr($agent_name,0,16).'</td>';
} }
// Description // Description
echo "<td class='".$tdcolor."'>".$data["descripcion"]."</td>"; echo '<td class="'.$tdcolor.'">'.$data["descripcion"].'</td>';
// Extended info // Extended info
echo "<td class='".$tdcolor."'>"; echo '<td class="'.$tdcolor.'">';
// Has recovery notify activated ? // Has recovery notify activated ?
if ($data["recovery_notify"] > 0) if ($data["recovery_notify"] > 0) {
$recovery_notify = __('Yes'); $recovery_notify = __('Yes');
else } else {
$recovery_notify = __('No'); $recovery_notify = __('No');
}
// calculate priority // calculate priority
$priority = get_alert_priority ($data["priority"]); $priority = get_alert_priority ($data["priority"]);
// calculare firing conditions // calculare firing conditions
if ($data["alert_text"] != ""){ if ($data["alert_text"] != ""){
$firing_cond = __('Text')."(".substr($data["alert_text"],0,8).")"; $firing_cond = __('Text')." (".substr($data["alert_text"],0,12).")";
} else { } else {
$firing_cond = $data["min_alerts"]." / ".$data["max_alerts"]; $firing_cond = $data["min_alerts"]." / ".$data["max_alerts"];
} }
// calculate days // calculate days
$firing_days = get_alert_days ($data); $firing_days = get_alert_days ($data);
// More details EYE tooltip // More details EYE tooltip
echo "<a href='#' class='info'><img class='top' echo '<a href="#" class="info"><img class="top" src="images/eye.png" alt="">';
src='images/eye.png' alt=''>";
// Add float info table // Add float info table
echo "<span> echo '<span>
<table cellspacing='2' cellpadding='0' <table cellspacing="2" cellpadding="0" style="margin-left:2px;">
style='margin-left:2px;'> <tr><th colspan="2" width="91">'.__('Recovery').'</th></tr>
<tr><th colspan='2' width='91'>". <tr><td colspan="2" class="datos" align="center"><b>'.$recovery_notify.'</b></td></tr>
__('Recovery')."</th></tr> <tr><th colspan="2" width="91">'.__('Priority').'</th></tr>
<tr><td colspan='2' class='datos' align='center'><b>$recovery_notify</b></td></tr> <tr><td colspan="2" class="datos" align="center"><b>'.$priority.'</b></td></tr>
<tr><th colspan='2' width='91'>". <tr><th colspan="2" width="91">'.__('Alert Ctrl.').'</th></tr>
__('Priority')."</th></tr> <tr><td colspan="2" class="datos" align="center"><b>'.$firing_cond.'</b></td></tr>
<tr><td colspan='2' class='datos' align='center'><b>$priority</b></td></tr> <tr><th colspan="2" width="91">'.__('Firing days').'</th></tr>
<tr><th colspan='2' width='91'>". <tr><td colspan="2" class="datos" align="center"><b>'.$firing_days.'</b></td></tr>
__('Alert Ctrl.')."</th></tr> </table></span></a>';
<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); $mytempdata = fmod ($data["dis_min"], 1);
if ($mytempdata == 0) if ($mytempdata == 0) {
$mymin = intval($data["dis_min"]); $mymin = intval($data["dis_min"]);
else } else {
$mymin = $data["dis_min"]; $mymin = $data["dis_min"];
}
$mymin = format_for_graph ($mymin); $mymin = format_for_graph ($mymin);
$mytempdata = fmod ($data["dis_max"], 1); $mytempdata = fmod ($data["dis_max"], 1);
if ($mytempdata == 0) if ($mytempdata == 0) {
$mymax = intval($data["dis_max"]); $mymax = intval($data["dis_max"]);
else } else {
$mymax = $data["dis_max"]; $mymax = $data["dis_max"];
}
$mymax = format_for_graph($mymax); $mymax = format_for_graph($mymax);
// Text alert ? // Text alert ?
if ($data["alert_text"] != "") if ($data["alert_text"] != "") {
echo "<td class='".$tdcolor."' colspan=2>".__('Text')."</td>"; echo '<td class="'.$tdcolor.'" colspan="2">'.__('Text').'</td>';
else { } else {
echo "<td class='".$tdcolor."'>".$mymin."</td>"; echo '<td class="'.$tdcolor.'">'.$mymin.'</td>';
echo "<td class='".$tdcolor."'>".$mymax."</td>"; echo '<td class="'.$tdcolor.'">'.$mymax.'</td>';
} }
echo "<td align='center' class='".$tdcolor."'>".human_time_description($data["time_threshold"]);
echo '<td align="center" class="'.$tdcolor.'">'.human_time_description ($data["time_threshold"]).'</td>';
if ($data["last_fired"] == "0000-00-00 00:00:00") { if ($data["last_fired"] == "0000-00-00 00:00:00") {
echo "<td align='center' class='".$tdcolor."f9'>".__('Never')."</td>"; echo '<td align="center" class="'.$tdcolor.'f9">'.__('Never').'</td>';
} else { } else {
echo "<td align='center' class='".$tdcolor."f9'>".human_time_comparation ($data["last_fired"])."</td>"; 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 align="center" class="'.$tdcolor.'">'.$data["times_fired"].'</td>';
echo "<td class='".$tdcolor."' align='center'><img width='20' height='9' src='images/pixel_red.png' title='".__('Alert fired')."'>";
echo "</td>"; if ($data["times_fired"] != 0) {
$id_grupo_alerta = get_db_value ("id_grupo", "tagente", "id_agente", $id_agente); 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) { if (give_acl($config["id_user"], $id_grupo_alerta, "AW") == 1) {
echo "<td align='center' class='".$tdcolor."'>"; echo '<td align="center" class="'.$tdcolor.'">';
echo "<a href='index.php?sec=estado&sec2=operation/agentes/ver_agente& 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>';
id_agente=$id_agente&validate_alert=".$data["id_aam"]."'><img src='images/ok.png'></a>"; echo '</td>';
echo "</td>";
} }
} else { } else {
echo "<td class='".$tdcolor."' align='center'> echo '<td class="'.$tdcolor.'" align="center"><img width="20" height="9" src="images/pixel_green.png" title="'.__('Alert not fired').'"></td>';
<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. * 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. * @param disabled Add disabled agents to agents. Default: False.
* *
* @return An array with all agents in the group. * @return An array with all agents in the group.
*/ */
function get_agents_in_group ($id_group, $disabled = false) { 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 */ /* 'All' group must return all agents */
if ($id_group == 1) { if ($id_group == 1) {
if ($disabled) { 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'); return get_db_all_rows_field_filter ('tagente', 'disabled', 0, 'nombre');
} }
} elseif ($disabled && $id_group != 1) { } 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 { } 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); 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) { function get_alerts_in_group ($id_group) {
$alerts = array (); $alerts = array ();
$agents = get_agents_in_group ($id_group); $agents = get_agents_in_group ($id_group);
if (!$agents) if (empty ($agents))
return; return $alerts;
foreach ($agents as $agent) { foreach ($agents as $agent) {
$agent_alerts = get_alerts_in_agent ($agent["id_agente"]); $agent_alerts = get_alerts_in_agent ($agent["id_agente"]);
$alerts = array_merge ($alerts, $agent_alerts); $alerts = array_merge ($alerts, $agent_alerts);

View File

@ -16,12 +16,9 @@
// 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 ();
if (! give_acl ($config["id_user"], 0, "AR") && ! give_acl ($config["id_user"], 0, "AW")) { if (! give_acl ($config["id_user"], 0, "AR") && ! give_acl ($config["id_user"], 0, "AW")) {
@ -33,9 +30,9 @@ if (! give_acl ($config["id_user"], 0, "AR") && ! give_acl ($config["id_user"],
// Show alerts for specific agent // Show alerts for specific agent
if (isset($_GET["id_agente"])){ 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); $id_grupo_alerta = dame_id_grupo ($id_agente);
if (give_acl ($config["id_user"], $id_grupo_alerta, "AR") == 0) { 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"); audit_db ($config["id_user"], $REMOTE_ADDR, "ACL Violation","Trying to access alert view");
include ("general/noaccess.php"); include ("general/noaccess.php");
@ -46,17 +43,19 @@ if (isset($_GET["id_agente"])){
echo "<h2>".__('Pandora Agents')." &gt; ".__('Full list of Alerts')."</h2>"; 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; $query = sprintf ("SELECT talerta_agente_modulo.* FROM talerta_agente_modulo, tagente_modulo WHERE
$result_gen=mysql_query($query_gen); talerta_agente_modulo.id_agente_modulo = tagente_modulo.id_agente_modulo AND
if (mysql_num_rows ($result_gen)) { 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 "<h3>".__('Full list of Alerts')."</h3>";
} }
echo "<table cellpadding='4' cellspacing='4' width=750 border=0 class='databox'>"; echo '<table cellpadding="4" cellspacing="4" width="750" border="0" class="databox">';
echo "<tr> echo "<tr><th>".__('Type')."</th>
<th>".__('Type')."<th>".__('Name')."</th> <th>".__('Name')."</th>
<th>".__('Description')."</th> <th>".__('Description')."</th>
<th>".__('Info')."</th> <th>".__('Info')."</th>
<th>".__('Min.')."</th> <th>".__('Min.')."</th>
@ -65,27 +64,29 @@ if (isset($_GET["id_agente"])){
<th>".__('Last fired')."</th> <th>".__('Last fired')."</th>
<th>".__('Times Fired')."</th> <th>".__('Times Fired')."</th>
<th>".__('Status')."</th> <th>".__('Status')."</th>
<th>".__('Validate')."</th>"; <th>".__('Validate')."</th></tr>";
$color = 1; $color = 1;
while ($data=mysql_fetch_array($result_gen)){ foreach ($result as $data) {
if ($color == 1){ if ($color == 1){
$tdcolor = "datos"; $tdcolor = "datos";
$color = 0; $color = 0;
} } else {
else {
$tdcolor = "datos2"; $tdcolor = "datos2";
$color = 1; $color = 1;
} }
echo "<tr>"; echo "<tr>";
show_alert_show_view ($data, $tdcolor, 0); show_alert_show_view ($data, $tdcolor, 0);
echo "</tr>";
} }
// Show combined alerts for this agent // Show combined alerts for this agent
$result_com = mysql_query("SELECT * FROM talerta_agente_modulo WHERE id_agent = $id_agente"); $sql = sprintf ("SELECT * FROM talerta_agente_modulo WHERE id_agent = %d",$id_agente);
if (mysql_num_rows ($result_com)) { $result = get_db_all_rows_sql ($sql);
echo "<tr><td colspan=11 class='datos3'><center>".__('Combined alerts')."</center>";
} if ($result !== false) {
while ($data_com=mysql_fetch_array($result_com)){ echo '<tr><td colspan="11" class="datos3"><center>'.__('Combined alerts').'</center>';
foreach ($result as $data) {
//$color comes from the previous one
if ($color == 1) { if ($color == 1) {
$tdcolor = "datos"; $tdcolor = "datos";
$color = 0; $color = 0;
@ -94,13 +95,15 @@ if (isset($_GET["id_agente"])){
$color = 1; $color = 1;
} }
echo "<tr>"; echo "<tr>";
show_alert_show_view ($data_com, $tdcolor, 1); show_alert_show_view ($data, $tdcolor, 1);
echo "</tr>";
}
} }
echo '</table>'; echo '</table>';
} else { } 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 // Show alert for no defined agent
@ -109,194 +112,104 @@ if (isset($_GET["id_agente"])){
// SHOW ALL ALERTS (GENERAL PAGE) // SHOW ALL ALERTS (GENERAL PAGE)
// ------------------------------- // -------------------------------
echo "<h2>".__('Pandora Agents')." &gt; "; echo "<h2>".__('Pandora Agents')." &gt; ".__('Full list of Alerts')."</h2>";
echo __('Full list of Alerts')."</h2>";
$iduser_temp=$_SESSION['id_usuario']; $iduser_temp = $config["id_user"];
$ag_group = get_parameter ("ag_group", -1); $ag_group = get_parameter ("ag_group", -1);
if ($ag_group != -1) if (give_acl ($config["id_user"], $ag_group, "AR") == 0) {
echo "<form method='post' action='index.php?sec=estado&sec2=operation/agentes/estado_alertas&refr=60&ag_group=".$ag_group."'>"; audit_db ($config["id_user"], $REMOTE_ADDR, "ACL Violation","Trying to access alert view");
else require ("general/noaccess.php");
echo "<form method='post' action='index.php?sec=estado&sec2=operation/agentes/estado_alertas&refr=60'>"; exit;
}
echo "<table cellpadding='4' cellspacing='4' class='databox'>"; if ($ag_group != -1) {
echo "<tr>"; echo '<form method="post" action="index.php?sec=estado&sec2=operation/agentes/estado_alertas&refr=60&ag_group='.$ag_group.'">';
echo "<td>".__('Group')."</td>"; } else {
echo "<td valign='middle'>"; echo '<form method="post" action="index.php?sec=estado&sec2=operation/agentes/estado_alertas&refr=60">';
echo "<select name='ag_group' onChange='javascript:this.form.submit();' class='w150'>"; }
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>';
// Agent group selector
if ($ag_group > 1) { if ($ag_group > 1) {
echo "<option value='".$ag_group."'>".dame_nombre_grupo($ag_group). $result = get_agents_in_group ($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"]."')";
}
$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 { } else {
$string=$string."<td class='".$tdcolor."'>". //Fields is an array with all the groups the user has access to
human_time_comparation($data["last_fired"])."</td>"; $result = get_agents_in_group (array_keys ($fields));
}
$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"]."')";
} }
$result=mysql_query($sql);
$color = 1; $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 = $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."'>" if ($result === false) {
.dame_nombre_alerta($data["id_alerta"])."</td>"; $result = array();
$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 { } else {
$string=$string."<td class='".$tdcolor."'>". $table->head = array(); //Reset table head
human_time_comparation($data["last_fired"])."</td>"; $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
} }
$string=$string."<td class='".$tdcolor."'>".
$data["times_fired"]."</td>";
}
}
} //end while
if ($string != "") { //This result is the array with agents
echo "<td class='f9' style='padding-left: 30px;'>"; foreach ($result as $row) {
echo "<img src='images/pixel_red.png' width=18 height=18> ".__('Alert fired')."</td>"; $id_agente = $row["id_agente"];
echo "<td class='f9' style='padding-left: 30px;'>"; $nombre_agente = strtoupper ($row["nombre"]);
echo "<img src='images/pixel_green.png' width=18 height=18> ".__('Alert not fired'); $result_alerts = get_alerts_in_agent ($id_agente);
echo "</td><td class='f9' valign='bottom' style='padding-left: 10px;'>(*) ".__('Combined alert')."</tr></table>";
echo "<br>"; if ($result_alerts === false)
echo "<table cellpadding='4' cellspacing='4' width='700' class='databox'>"; $result_alerts = array();
echo "<tr>
<th>".__('Agent')."</th> foreach ($result_alerts as $data) {
<th>".__('Status')."</th> $table->data[$idx] = array(); //init array
<th>".__('Type')."</th> $table->data[$idx][0] = '<a href="index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente='.$id_agente.'"><b>'.$nombre_agente.'</b>';
<th>".__('Description')."</th>
<th>".__('Last fired')."</th> if ($data["times_fired"] != 0) {
<th>".__('Times Fired')."</th>"; $table->data[$idx][1] = '<img src="images/pixel_red.png" width="40" height="18" title="'.__('Alert fired').'">';
echo $string; //built table of alerts } else {
echo "</table>"; $table->data[$idx][1] = '<img src="images/pixel_green.png" width="40" height="18" title="'.__('Alert not fired').'">';
} }
else {
echo "</table><br><div class='nf'>". $table->data[$idx][2] = dame_nombre_alerta ($data["id_alerta"]);
__('No agent included in this group has any assigned alert')."</div>"; $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 } // Main alert view
?> ?>