diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index f5a7d6bb03..b7d184d8e1 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,21 @@ +2008-11-06 Evi Vanoost + + * operation/snmpconsole/snmp_View.php: Added a span with title over the + time comp since some people want to know what time something went down. + This should maybe be moved into a print_ function + + * operation/agentes/estado_generalagente.php: ACL check and style + changes. Use of new functions + + * include/functions_db.php: dame_numero_datos - added inc and string + can also filter on agent now. Renamed give_agent_address_from_list to + get_agent_addresses. get_agent_addresses now returns an array with ips + Changed give_agent_address to get_agent_address + + * godmode/agentes/manage_config.php, + godmode/agentes/configurar_agente.php: Renamed functions + + 2009-11-05 Esteban Sanchez * include/functions_db.php: Added sql_error_handler() to show SQL diff --git a/pandora_console/godmode/agentes/configurar_agente.php b/pandora_console/godmode/agentes/configurar_agente.php index 8645f753ce..bc57994857 100644 --- a/pandora_console/godmode/agentes/configurar_agente.php +++ b/pandora_console/godmode/agentes/configurar_agente.php @@ -510,7 +510,7 @@ if (isset($_POST["update_agent"])) { // if modified some agent paramenter echo '

'.__('There is already an agent in the database with this name').'

'; } else { //If different IP is specified than previous, add the IP - if ($direccion_agente != give_agent_address ($id_agente)) + if ($direccion_agente != get_agent_address ($id_agente)) agent_add_address ($id_agente, $direccion_agente); //If IP is set for deletion, delete first diff --git a/pandora_console/godmode/agentes/manage_config.php b/pandora_console/godmode/agentes/manage_config.php index 96a00df2ff..f0e0e24e75 100644 --- a/pandora_console/godmode/agentes/manage_config.php +++ b/pandora_console/godmode/agentes/manage_config.php @@ -97,7 +97,7 @@ if (isset($_POST["copy"])) { VALUES (%d,".$module["id_tipo_modulo"].",'".$module["descripcion"]."','".$module["nombre"]."',".$module["max"].",".$module["min"].",".$module["module_interval"].",".$module["tcp_port"].",'".$module["tcp_send"]."','".$module["tcp_rcv"]."', '".$module["snmp_community"]."','".$module["snmp_oid"]."','%s',".$module["id_module_group"].",".$module["flag"].",".$module["id_modulo"].",".$module["disabled"].",".$module["id_export"].", '".$module["plugin_user"]."','".$module["plugin_pass"]."','".$module["plugin_parameter"]."',".$module["id_plugin"].",'".$module["post_process"]."',".$module["prediction_module"].",".$module["max_timeout"].")", - $id_agent_dest,give_agent_address ($id_agent_dest)); + $id_agent_dest,get_agent_address ($id_agent_dest)); $id_new_module = process_sql ($sql, "insert_id"); if (empty ($id_new_module)) { diff --git a/pandora_console/include/functions_db.php b/pandora_console/include/functions_db.php index 50d3a916c1..d9522d0aae 100644 --- a/pandora_console/include/functions_db.php +++ b/pandora_console/include/functions_db.php @@ -774,10 +774,21 @@ function dame_numero_notas ($id_incident) { /** * Get the number of pandora data in the database. * + * @param id_agent Agent id or 0 for all + * * @return */ -function dame_numero_datos () { - return (int) get_db_sql ("SELECT COUNT(*) FROM `tagente_datos`"); +function dame_numero_datos ($id_agent = 0) { + if ($id_agent < 1) { + $query = ''; + } else { + $query = sprintf (" WHERE id_agente_modulo = ANY(SELECT id_agente_modulo FROM tagente_modulo WHERE id_agente = %d)", $id_agent); + } + $datos = 0; + $datos += (int) get_db_sql ("SELECT COUNT(*) FROM tagente_datos".$query); + $datos += (int) get_db_sql ("SELECT COUNT(*) FROM tagente_datos_inc".$query); + $datos += (int) get_db_sql ("SELECT COUNT(*) FROM tagente_datos_string".$query); + return $datos; } /** @@ -1253,11 +1264,11 @@ function agent_delete_address ($id_agent, $ip_address) { $sql = sprintf ("DELETE FROM taddress_agent WHERE id_ag = %d",$id_ag); process_sql ($sql); } - // Need to change main address ? - if (give_agent_address ($id_agent) == $ip_address) { - $new_ip = give_agent_address_from_list ($id_agent); - // Change main address in agent to whis one - $query = sprintf ("UPDATE tagente SET `direccion` = '%s' WHERE id_agente = %d",$new_ip,$id_agent); + // Need to change main address? + if (get_agent_address ($id_agent) == $ip_address) { + $new_ips = get_agent_addresses ($id_agent); + // Change main address in agent to first one in the list + $query = sprintf ("UPDATE tagente SET `direccion` = '%s' WHERE id_agente = %d", $new_ips[0], $id_agent); process_sql ($query); } } @@ -1269,8 +1280,8 @@ function agent_delete_address ($id_agent, $ip_address) { * * @return The address of the given agent */ -function give_agent_address ($id_agent) { - return (string) get_db_value ('direccion', 'tagente', 'id_agente', $id_agent); +function get_agent_address ($id_agent) { + return (string) get_db_value ('direccion', 'tagente', 'id_agente', (int) $id_agent); } /** @@ -1290,17 +1301,29 @@ function get_agent_with_ip ($ip_address) { } /** - * Get IP address of an agent from address list + * Get all IP addresses of an agent * * @param id_agent Agent id * - * @return The IP address of the given agent. + * @return Array with the IP address of the given agent. */ -function give_agent_address_from_list ($id_agent){ - $sql = "SELECT ip FROM taddress_agent, taddress +function get_agent_addresses ($id_agent) { + $sql = sprintf ("SELECT ip FROM taddress_agent, taddress WHERE taddress_agent.id_a = taddress.id_a - AND id_agent = $id_agent"; - return (string) get_db_sql ($sql); + AND id_agent = %d", $id_agent); + + $ips = get_db_all_rows_sql ($sql); + + if ($ips === false) { + $ips = array (); + } + + $ret_arr = array (); + foreach ($ips as $row) { + $ret_arr[] = $row["ip"]; + } + + return $ret_arr; } /** diff --git a/pandora_console/operation/agentes/estado_generalagente.php b/pandora_console/operation/agentes/estado_generalagente.php index 7500db7f55..bdc70d58c5 100644 --- a/pandora_console/operation/agentes/estado_generalagente.php +++ b/pandora_console/operation/agentes/estado_generalagente.php @@ -19,158 +19,117 @@ // Load global vars -require ("include/config.php"); +require_once ("include/config.php"); check_login (); -if (isset($_GET["id_agente"])){ - $id_agente = $_GET["id_agente"]; - // Connect BBDD - $sql1='SELECT * FROM tagente WHERE id_agente = '.$id_agente; - $result=mysql_query($sql1); - if ($row=mysql_fetch_array($result)){ - $intervalo = $row["intervalo"]; // Interval in seconds to receive data - $nombre_agente = $row["nombre"]; - $direccion_agente =$row["direccion"]; - $ultima_act = $row["ultimo_contacto"]; - $ultima_act_remota =$row["ultimo_contacto_remoto"]; - $comentarios = $row["comentarios"]; - $id_grupo = $row["id_grupo"]; - $id_os= $row["id_os"]; - $id_parent= $row["id_parent"]; - $os_version = $row["os_version"]; - $agent_version = $row["agent_version"]; - $disabled= $row["disabled"]; - $network_server = $row["id_network_server"]; - } else { - echo "

".__('There was a problem loading agent')."

"; - echo ""; - echo ""; - exit; - } +$id_agente = get_parameter_get ("id_agente", -1); + +$agent = get_db_row ("tagente", "id_agente", $id_agente); + +if ($agent === false) { + echo '

'.__('There was a problem loading agent').'

'; + return; +} + +if (give_acl ($config["id_user"], $agent["id_grupo"], "AR") == 0) { + audit_db ($config["id_user"], $REMOTE_ADDR, "ACL Violation", + "Trying to access Agent General Information"); + require_once ("general/noaccess.php"); + exit; } echo "

".__('Pandora Agents')." > ".__('Agent general information')."

"; // Blank space below title -echo "
"; +echo '
 
'; -echo ''; -echo "
"; -echo ''; -echo ' - - '; -echo " -
'.__('Agent name').''.strtoupper(salida_limpia($nombre_agente)).' - ".__('Refresh data')." "; -echo ""; -// Data base access graph +//Floating div +echo '
'; +echo ''.__('Agent access rate (24h)').'

'; +echo ''; +echo '
 
'; +echo ''.__('Events generated -by module-').'

'; +echo ''; +echo '
'; + +echo '
'; +echo ''; +//Agent name +echo ''; +echo ''; +echo ''; + +//Addresses +echo ''; +echo ''; -echo ''; +echo ''; -echo ''; -echo ''; - // Parent -echo ''; +echo ''; +echo ''; // Agent Interval -echo ''; +echo ''; +echo ''; // Comments -echo ''; +echo ''; +echo ''; // Group -echo ''; +echo ''; +echo ''; // Agent version -echo ''; +echo ''; +echo ''; // Total packets echo ''; -echo ''; +echo ''; // Last contact -echo ''; + +// Next contact (agent) +$difference = time () - strtotime ($agent["ultimo_contacto"]); +$sql = sprintf ("SELECT MAX(module_interval) FROM tagente_modulo WHERE id_agente = %d", $id_agente); +$max = (int) get_db_sql ($sql); +if ($max > 0) { + //First check if there is a maximum module interval + $progress = round ($difference / (($max * 2) / 100)); +} elseif ($agent["intervalo"] > 0) { + //Then if there is a generic agent interval + $progress = round ($difference / (($agent["intervalo"] * 2) / 100)); +} else { + //Otherwise there is no progress to be reported + $progress = -1; } -// Next contact +echo ''; +echo ''; -$ultima = strtotime($ultima_act); -$ahora = strtotime("now"); -$diferencia = $ahora - $ultima; -// Get higher interval set for the set of modules from this agent -$sql_maxi ="SELECT MAX(module_interval) FROM tagente_modulo WHERE id_agente = ".$id_agente; -$result_maxi=mysql_query($sql_maxi); -if ($row_maxi=mysql_fetch_array($result_maxi)) - if ($row_maxi[0] > 0 ) { - $intervalo = $row_maxi[0]; - } - if ($intervalo > 0){ - $percentil = round($diferencia/(($intervalo*2) / 100)); - } else { - $percentil = -1; - } - echo "
'.__('Agent name').''.strtoupper($agent["nombre"]).' '; +echo '
'.__('IP Address').''; +print_select (get_agent_addresses ($id_agente), "not_used", get_agent_address ($id_agente)); echo '
'.__('IP Address').''; -// Show all address for this agent, show first the main IP (taken from tagente table) -echo ""; - -echo '
'.__('OS').' - '.dame_so_name($id_os); -if ($os_version != "") { - echo ' '.salida_limpia($os_version); -} +//OS +echo '
'.__('OS').' - '.dame_so_name ($agent["id_os"]).' '.$agent["os_version"].'
'.__('Parent').''; -echo ""; -echo dame_nombre_agente($id_parent).'
'.__('Parent').''.dame_nombre_agente ($agent["id_parent"]).'
'.__('Interval').''. human_time_description_raw($intervalo).'
'.__('Interval').''.human_time_description_raw ($agent["intervalo"]).'
'.__('Description').''.$comentarios.'
'.__('Description').''.$agent["comentarios"].'
'.__('Group').''; - -echo ""; -echo '
'.__('Group').''; +echo ' - '. dame_grupo ($agent["id_grupo"]).'
'.__('Agent Version'). ''; -echo ''.salida_limpia($agent_version). '
'.__('Agent Version'). ''.$agent["agent_version"].'
'. __('Total packets'). ''; -$total_paketes= 0; -$sql_3='SELECT COUNT(*) FROM tagente_datos WHERE id_agente = '.$id_agente; -$result_3=mysql_query($sql_3); -$row3=mysql_fetch_array($result_3); -$total_paketes = $row3[0]; -echo $total_paketes; -echo '
'.dame_numero_datos ($id_agente).'
'.__('Last contact')." / ".__('Remote').''; - -if ($ultima_act == "0000-00-00 00:00:00"){ +echo '
'.__('Last contact')." / ".__('Remote').''; +if ($agent["ultimo_contacto"] == "0000-00-00 00:00:00") { echo __('Never'); } else { - echo $ultima_act; + echo $agent["ultimo_contacto"]; } echo " / "; -if ($ultima_act_remota == "0000-00-00 00:00:00"){ +if ($agent["ultimo_contacto_remoto"] == "0000-00-00 00:00:00") { echo __('Never'); } else { - echo $ultima_act_remota; + echo $agent["ultimo_contacto_remoto"]; +} +echo '
'.__('Next agent contact').'
".__('Next agent contact')." - - -
- -
- - -
".__('Agent access rate (24h)')."

- -
- ".__('Events generated -by module-')."

- -
"; -?> +//End of table +echo '
'; +?> \ No newline at end of file diff --git a/pandora_console/operation/snmpconsole/snmp_view.php b/pandora_console/operation/snmpconsole/snmp_view.php index 64f84472b9..6ec0be2bd1 100644 --- a/pandora_console/operation/snmpconsole/snmp_view.php +++ b/pandora_console/operation/snmpconsole/snmp_view.php @@ -326,8 +326,10 @@ foreach ($traps as $trap) { } // Timestamp - $data[6] = human_time_comparation($trap["timestamp"]); - + $data[6] = ''; + $data[6] .= human_time_comparation ($trap["timestamp"]); + $data[6] .= ''; + // Use alert severity if fired if (!empty ($trap["alerted"])) { $data[7] = '';