From 42402f6416639eec69bc279c1bbea24c244848ea Mon Sep 17 00:00:00 2001 From: raulmateos Date: Mon, 1 Jan 2007 18:41:27 +0000 Subject: [PATCH] 2007-01-01 Raul Mateos * include/functions_db.php: Add new function to obtain group list. * godmode/alertas/configurar_alerta.php: Clear code. Clear sytle. * operation/agentes/estado_grupo: Clear code. Clear style. Use new list_group2 function. Simplify SQL queries. * operation/events/events.php: Clear code. Clear style. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@345 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_console/ChangeLog | 11 + .../godmode/alertas/configurar_alerta.php | 51 ++- pandora_console/include/functions_db.php | 19 + .../operation/agentes/estado_grupo.php | 418 +++++++++--------- pandora_console/operation/events/events.php | 8 +- 5 files changed, 280 insertions(+), 227 deletions(-) diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 2bd03b7410..02567d3751 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,14 @@ +2007-01-01 Raul Mateos + + * include/functions_db.php: Add new function to obtain group list. + + * godmode/alertas/configurar_alerta.php: Clear code. Clear sytle. + + * operation/agentes/estado_grupo: Clear code. Clear style. Use new + list_group2 function. Simplify SQL queries. + + * operation/events/events.php: Clear code. Clear style. + 2006-12-31 Raul Mateos * include/functions.php, functions_db.php: Move list_group from f*.php diff --git a/pandora_console/godmode/alertas/configurar_alerta.php b/pandora_console/godmode/alertas/configurar_alerta.php index a02f5ce53a..5bcdc28fa0 100644 --- a/pandora_console/godmode/alertas/configurar_alerta.php +++ b/pandora_console/godmode/alertas/configurar_alerta.php @@ -1,11 +1,23 @@ , 2003-2006 -// Raul Mateos , 2005-2006 -// Cargamos variables globales +// Pandora - the Free monitoring system +// ==================================== +// Copyright (c) 2004-2006 Sancho Lerena, slerena@gmail.com +// Copyright (c) 2005-2006 Artica Soluciones Tecnologicas S.L, info@artica.es +// Copyright (c) 2004-2006 Raul Mateos Martin, raulofpandora@gmail.com +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// You should have received a copy of the GNU General Public License +// 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"); if ( (give_acl($id_user, 0, "LM")==1)){ // Var init @@ -32,16 +44,21 @@ if ( (give_acl($id_user, 0, "LM")==1)){ $creacion_alerta = 0; if (isset($_GET["creacion"])){ - // Conecto con la BBDD $creacion_alerta = 1; - - // Codigo de creacion de la alerta } -?> -

-

 

- +echo "

".$lang_label["alert_config"]."

"; +echo "

"; + if (isset($_GET["creacion"])){ + echo $lang_label["create_alert"]; + } + if (isset($_GET["id_alerta"])){ + echo $lang_label["mod_alert"]; + } + echo ' + '.$lang_label["help"].''; +echo "

"; + ?> @@ -77,8 +94,12 @@ _data_
-";} -else {echo "";} ?> +"; +} else { + echo ""; +} ?>
diff --git a/pandora_console/include/functions_db.php b/pandora_console/include/functions_db.php index ad7db61916..c4ee99bf9d 100644 --- a/pandora_console/include/functions_db.php +++ b/pandora_console/include/functions_db.php @@ -595,6 +595,25 @@ function list_group ($id_user){ return ($mis_grupos); } +// ---------------------------------------------------------------------- +// Defines an array +// to put all groups with Agent Read permission +// ---------------------------------------------------------------------- + +function list_group2 ($id_user){ + $mis_grupos[]=""; // Define array mis_grupos to put here all groups with Agent Read permission + $sql='SELECT id_grupo FROM tgrupo'; + $result=mysql_query($sql); + while ($row=mysql_fetch_array($result)){ + if ($row["id_grupo"] != 1){ + if (give_acl($id_user,$row["id_grupo"], "AR") == 1){ + $mis_grupos[]=$row["id_grupo"]; //Put in an array all the groups the user belongs + } + } + } + return ($mis_grupos); +} + // --------------------------------------------------------------- // Return Group iconname given its name // --------------------------------------------------------------- diff --git a/pandora_console/operation/agentes/estado_grupo.php b/pandora_console/operation/agentes/estado_grupo.php index f3df3a3bef..601b55f088 100644 --- a/pandora_console/operation/agentes/estado_grupo.php +++ b/pandora_console/operation/agentes/estado_grupo.php @@ -1,6 +1,6 @@ ".$lang_label["ag_title"].""; - echo "

".$lang_label["group_view"]." ".$lang_label["help"]."

"; - $iduser_temp = $_SESSION['id_usuario']; + echo "

".$lang_label["group_view"]." + + ".$lang_label["help"]." +

"; - $sql1 = 'SELECT * FROM tgrupo'; - $result2 = mysql_query ($sql1); - if (mysql_num_rows ($result2)) { - while ($row = mysql_fetch_array ($result2)) { - if ($row["id_grupo"] != 1 && - give_acl($iduser_temp,$row["id_grupo"], "AR") == 1) { - $mis_grupos[]=$row["id_grupo"]; //All my groups in an array + $mis_grupos=list_group2 ($id_user); + + // Update network modules for this group + // Check for Network FLAG change request + if (isset ($_GET["update_netgroup"])) { + if (give_acl ($id_user, $_GET["update_netgroup"], "AW") == 1) { + $sql = "SELECT * FROM tagente WHERE id_grupo = ". + $_GET["update_netgroup"]; + $result = mysql_query ($sql); + while ($row = mysql_fetch_array ($result)) { + $id_agente = $row["id_agente"]; + $query2 ="UPDATE tagente_modulo SET flag=1 + WHERE id_agente = ".$id_agente; + $res = mysql_query ($query2); } - } + } + } - // Update network modules for this group - // Check for Network FLAG change request - if (isset ($_GET["update_netgroup"])) { - if (give_acl ($id_user, $_GET["update_netgroup"], "AW") == 1) { - $sql = "SELECT * FROM tagente WHERE id_grupo = ". - $_GET["update_netgroup"]; - $result = mysql_query ($sql); - while ($row = mysql_fetch_array ($result)) { - $id_agente = $row["id_agente"]; - $query2 ="UPDATE tagente_modulo SET flag=1 - WHERE id_agente = ".$id_agente; - $res = mysql_query ($query2); - } - } - } - - $contador_grupo = 0; - $contador_agente = 0; - $array_index = 0; - - // Recorro cada grupo para ver el estado de todos los modulos - foreach ($mis_grupos as $migrupo) { - if ($migrupo != "") { - $grupo[$array_index]["agent"] = 0; - $grupo[$array_index]["ok"] = 0; - $grupo[$array_index]["down"] = 0; - $grupo[$array_index]["bad"] = 0; - $grupo[$array_index]["alerts"] = 0; - $grupo[$array_index]["data"] = 0; - $grupo[$array_index]["icon"] = dame_grupo_icono ($migrupo); - $grupo[$array_index]["id_grupo"] = $migrupo; - $existen_agentes =0; - - $sql1 = "SELECT * FROM tagente WHERE disabled=0 - AND id_grupo =".$migrupo; - if ($result1 = mysql_query ($sql1)) { - while ($row1 = mysql_fetch_array ($result1)) { - $existen_agentes = 1; - $intervalo = $row1["intervalo"]; - $id_agente = $row1["id_agente"]; - - // Check for recent alerts - if (check_alert_fired($id_agente) == 1) { - $grupo[$array_index]["alerts"]++; + $contador_grupo = 0; + $contador_agente = 0; + $array_index = 0; + + // Recorro cada grupo para ver el estado de todos los modulos + foreach ($mis_grupos as $migrupo) { + if ($migrupo != "") { + $grupo[$array_index]["agent"] = 0; + $grupo[$array_index]["ok"] = 0; + $grupo[$array_index]["down"] = 0; + $grupo[$array_index]["bad"] = 0; + $grupo[$array_index]["alerts"] = 0; + $grupo[$array_index]["data"] = 0; + $grupo[$array_index]["icon"] = dame_grupo_icono ($migrupo); + $grupo[$array_index]["id_grupo"] = $migrupo; + $existen_agentes =0; + + $sql1 = "SELECT intervalo, id_agente + FROM tagente WHERE disabled=0 + AND id_grupo =".$migrupo; + if ($result1 = mysql_query ($sql1)) { + while ($row1 = mysql_fetch_array ($result1)) { + $existen_agentes = 1; + $intervalo = $row1["intervalo"]; + $id_agente = $row1["id_agente"]; + + // Check for recent alerts + if (check_alert_fired($id_agente) == 1) { + $grupo[$array_index]["alerts"]++; + } + + $grupo[$array_index]["agent"]++; + $grupo[$array_index]["group"] = dame_nombre_grupo ($migrupo); + // Estado grupo, agent + $contador_agente++; + $sql3 = "SELECT estado, timestamp, id_agente_modulo, + datos FROM tagente_estado + WHERE id_agente = ".$row1["id_agente"]; + $result3 = mysql_query ($sql3); + while ($row3 = mysql_fetch_array ($result3)) { + $estado = $row3["estado"]; + // Get module interval + $ahora = date ("Y/m/d H:i:s"); + $sql4 = "SELECT module_interval + FROM tagente_modulo + WHERE id_agente_modulo = ".$row3["id_agente_modulo"]; + $result4 = mysql_query ($sql4); + if ($row4 = mysql_fetch_array ($result4)) { + $module_interval = $row4["module_interval"]; + if ($module_interval > 0) { + $intervalo_comp = $module_interval; + } else { + $intervalo_comp = $intervalo; + } } - $grupo[$array_index]["agent"]++; - $grupo[$array_index]["group"] = dame_nombre_grupo ($migrupo); - // Estado grupo, agent - $contador_agente++; - $sql3 = "SELECT * FROM tagente_estado WHERE id_agente = ".$row1["id_agente"]; - $result3 = mysql_query ($sql3); - while ($row3 = mysql_fetch_array ($result3)) { - $estado = $row3["estado"]; - // Get module interval - $ahora = date ("Y/m/d H:i:s"); - $sql4 = "SELECT * FROM tagente_modulo WHERE id_agente_modulo = ".$row3["id_agente_modulo"]; - $result4 = mysql_query ($sql4); - if ($row4 = mysql_fetch_array ($result4)) { - $module_interval = $row4["module_interval"]; - if ($module_interval > 0) { - $intervalo_comp = $module_interval; + $ultimo_contacto_modulo = $row3["timestamp"]; + + // Defines if module is down (interval x 2 > time last contact) + if ($ultimo_contacto_modulo != "0000-00-00 00:00:00") { + $seconds = strtotime ($ahora) - + strtotime ($ultimo_contacto_modulo); + if ($seconds >= ($intervalo_comp * 2)) { + $grupo[$array_index]["down"]++; + } elseif ($estado != 100) { + if ($row3["datos"] != 0) { + $grupo[$array_index]["ok"]++; } else { - $intervalo_comp = $intervalo; + $grupo[$array_index]["bad"]++; } - } - - $ultimo_contacto_modulo = $row3["timestamp"]; - - // Defines if module is down (interval x 2 > time last contact) - if ($ultimo_contacto_modulo != "0000-00-00 00:00:00") { - $seconds = strtotime ($ahora) - strtotime ($ultimo_contacto_modulo); - if ($seconds >= ($intervalo_comp * 2)) { - $grupo[$array_index]["down"]++; - } elseif ($estado != 100) { - if ($row3["datos"] != 0) { - $grupo[$array_index]["ok"]++; - } else { - $grupo[$array_index]["bad"]++; - } - } elseif ($estado == 100) // For data module, not monitors - $grupo[$array_index]["data"]++; // Data module - } + } elseif ($estado == 100) // For data module, not monitors + $grupo[$array_index]["data"]++; // Data module } } } - - if ($existen_agentes == 1){ - $array_index++; - } - } - } - - if ($contador_agente != 0) { - $ancho = ceil(sqrt($array_index+1)); - $real_count =0; - echo ""; - for ($table=0; $table < $ancho; $table++) { - echo ""; - for ($table_row=0; $table_row < $ancho; $table_row++) { - if ($real_count < $array_index) { - - $group_name = $grupo[$real_count]["group"]; - $icono_grupo = $grupo[$real_count]["icon"]; - $icono_type = ""; - - if ($grupo[$real_count]["down"] > 0) { - $icono_type = " - "; - } - if ($grupo[$real_count]["bad"] > 0) { - $icono_type = $icono_type." - "; - } - if ($grupo[$real_count]["ok"] > 0) { - $icono_type = $icono_type." - "; - } - if ($grupo[$real_count]["data"] > 0) { - $icono_type = $icono_type." - "; - } - // Show yellow light if there are recent alerts fired for this group - if ($grupo[$real_count]["alerts"] > 0 ){ - $icono_type=$icono_type." - "; - } - - // TOOLTIP. - $celda = ""; } - echo "
- - - - - - -
". - $lang_label["agents"].":
". - $grupo[$real_count]["agent"]."
- - - - - - - - - - - - - - - - - - - - -
". - ucfirst($lang_label["monitors"]).":
- - ".$lang_label["ok"].": - ".$grupo[$real_count]["ok"]." -
- - ".$lang_label["down"].": ". - $grupo[$real_count]["down"]."
- - ".$lang_label["fail"].": ". - $grupo[$real_count]["bad"]."
- - ".$lang_label["alerts"].": ". - $grupo[$real_count]["alerts"]."
-
"; - // Render network exec module button, only when this group is writtable by user - if (give_acl ($id_user, $grupo[$real_count]["id_grupo"], "AW") == 1) { - $celda .= " - "; - } - $celda .= "

". - $icono_type."

- ".$group_name.""; - echo $celda; - } - $real_count++; - } - echo "
"; - } else { - echo "
".$lang_label["no_agent_def"]."
"; + if ($existen_agentes == 1){ + $array_index++; + } } + } + + if ($contador_agente != 0) { + $ancho = ceil(sqrt($array_index+1)); + $real_count =0; + echo ""; + for ($table=0; $table < $ancho; $table++) { + echo ""; + for ($table_row=0; $table_row < $ancho; $table_row++) { + if ($real_count < $array_index) { + + $group_name = $grupo[$real_count]["group"]; + $icono_grupo = $grupo[$real_count]["icon"]; + $icono_type = ""; + + if ($grupo[$real_count]["down"] > 0) { + $icono_type = " + "; + } + if ($grupo[$real_count]["bad"] > 0) { + $icono_type = $icono_type." + "; + } + if ($grupo[$real_count]["ok"] > 0) { + $icono_type = $icono_type." + "; + } + if ($grupo[$real_count]["data"] > 0) { + $icono_type = $icono_type." + "; + } + // Show yellow light if there are recent alerts fired for this group + if ($grupo[$real_count]["alerts"] > 0 ){ + $icono_type=$icono_type." + "; + } + + // TOOLTIP. + $celda = ""; + } + + echo "
+ + + + + + +
". + $lang_label["agents"].":
". + $grupo[$real_count]["agent"]."
+ + + + + + + + + + + + + + + + + + + + +
". + ucfirst($lang_label["monitors"]).":
+ + ".$lang_label["ok"].": + ".$grupo[$real_count]["ok"]." +
+ + ".$lang_label["down"].": ". + $grupo[$real_count]["down"]."
+ + ".$lang_label["fail"].": ". + $grupo[$real_count]["bad"]."
+ + ".$lang_label["alerts"].": ". + $grupo[$real_count]["alerts"]."
+
"; + // Render network exec module button, only when this group is writtable by user + if (give_acl ($id_user, $grupo[$real_count]["id_grupo"], "AW") == 1) { + $celda .= "  + "; + } + $celda .= "

". + $icono_type."

+ ".$group_name.""; + echo $celda; + } + $real_count++; + } + echo "
"; } else { - echo "
".$lang_label["no_agent"]."
"; + echo "
".$lang_label["no_agent_def"]."
"; } } else { - audit_db ($id_user, $REMOTE_ADDR, "ACL Violation", - "Trying to access Agent view (Grouped)"); - require ("general/noaccess.php"); + echo "
".$lang_label["no_agent"]."
"; } +} else { + audit_db ($id_user, $REMOTE_ADDR, "ACL Violation", + "Trying to access Agent view (Grouped)"); + require ("general/noaccess.php"); } + ?> diff --git a/pandora_console/operation/events/events.php b/pandora_console/operation/events/events.php index 537ecce17d..e3ce882002 100644 --- a/pandora_console/operation/events/events.php +++ b/pandora_console/operation/events/events.php @@ -64,9 +64,12 @@ if (comprueba_login() == 0) { if (give_acl($id_user, $id_group, "IM") ==1){ $sql2="DELETE FROM tevento WHERE id_evento =".$id_evento; $result2=mysql_query($sql2); - if ($result) {echo "

".$lang_label["delete_event_ok"]."

";} + if ($result) { + echo "

".$lang_label["delete_event_ok"]."

"; + } } else { - audit_db($id_user,$REMOTE_ADDR, "ACL Violation","Trying to delete event ID".$id_evento); + audit_db($id_user,$REMOTE_ADDR, "ACL Violation", + "Trying to delete event ID".$id_evento); } } @@ -121,7 +124,6 @@ if (comprueba_login() == 0) { } } - echo "

".$lang_label["events"]."

"; echo "

".$lang_label["event_main_view"]." ".$lang_label["help"]."

"; echo "";