diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 8bd9e3842e..a37f9feab4 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,16 @@ +2008-10-22 Evi Vanoost + + * operation/snmpconsole/snmp_view.php: Style update and uses new + functions. Also uses (much) less SQL queries now. Fixed some bugs and + if an IP matches an existing agent, it gets checked against ACL + + * operation/snmpconole/snmp_alert.php: Added alert priority colors for + feature request #2166257 + + * godmode/agentes/configurar_agente.php: Added a get_parameter for IP + addresses so creating an agent with predefined IP works. Used in SNMP + view to add agents with unknown IP. To use, pass direccion in request + 2008-10-22 Esteban Sanchez * pandoradb.sql: Style correction. diff --git a/pandora_console/godmode/agentes/configurar_agente.php b/pandora_console/godmode/agentes/configurar_agente.php index 37249ee8c8..8645f753ce 100644 --- a/pandora_console/godmode/agentes/configurar_agente.php +++ b/pandora_console/godmode/agentes/configurar_agente.php @@ -51,7 +51,7 @@ $campo_3 = ""; $maximo = 0; $minimo = 0; $nombre_agente = ""; -$direccion_agente = ""; +$direccion_agente = get_parameter ("direccion", ""); $intervalo = 300; $id_server = ""; $max_alerts = 0; diff --git a/pandora_console/operation/snmpconsole/snmp_alert.php b/pandora_console/operation/snmpconsole/snmp_alert.php index 5cf469cd93..0d63480694 100644 --- a/pandora_console/operation/snmpconsole/snmp_alert.php +++ b/pandora_console/operation/snmpconsole/snmp_alert.php @@ -328,7 +328,27 @@ if (isset ($_GET["update_alert"])) { //the update_alert means the form should be '.__('Delete').'  '.__('Update').''; - array_push ($table->data, $data); + $idx = count ($table->data); //The current index of the table is 1 less than the count of table data so we count before adding to table->data + array_push ($table->data, $data); + switch ($row["priority"]) { + case 0: + $table->rowclass[$idx] = "datos_blue"; + break; + case 1: + $table->rowclass[$idx] = "datos_grey"; + break; + case 2: + $table->rowclass[$idx] = "datos_green"; + break; + case 3: + $table->rowclass[$idx] = "datos_yellow"; + break; + case 4: + $table->rowclass[$idx] = "datos_red"; + break; + default: + $table->rowclass[$idx] = "datos_grey"; + } } if (!empty ($table->data)) { diff --git a/pandora_console/operation/snmpconsole/snmp_view.php b/pandora_console/operation/snmpconsole/snmp_view.php index 2777d469b2..5b81bc0a81 100644 --- a/pandora_console/operation/snmpconsole/snmp_view.php +++ b/pandora_console/operation/snmpconsole/snmp_view.php @@ -18,7 +18,7 @@ // Load global vars -require("include/config.php"); +require_once ("include/config.php"); check_login (); @@ -26,64 +26,31 @@ if (! give_acl ($config['id_user'], 0, "AR")) { audit_db ($config['id_user'], $REMOTE_ADDR, "ACL Violation", "Trying to access SNMP Console"); require ("general/noaccess.php"); - return; + exit; } -?> - - - -".__('Event successfully deleted')."";} +// Delete SNMP Trap entry Event (only incident management access). +if (isset ($_GET["delete"])){ + $id_trap = (int) get_parameter_get ("delete", 0); + if ($id_trap > 0 && give_acl ($config['id_user'], 0, "IM")) { + $sql = sprintf ("DELETE FROM ttrap WHERE id_trap = %d", $id_trap); + $result = process_sql ($sql); + print_error_message ($result, __('Event successfully deleted'), __('Error removing event')); } else { audit_db ($config['id_user'], $REMOTE_ADDR, "ACL Violation", - "Trying to delete event ID".$id_trap); + "Trying to delete SNMP event ID #".$id_trap); } } // Check Event (only incident write access). -if (isset($_GET["check"])){ - $id_trap = $_GET["check"]; - if (give_acl ($config['id_user'], 0, "IW")) { - $sql2="UPDATE ttrap set status=1, id_usuario = '".$config['id_user']."' WHERE id_trap = ".$id_trap; - $result2=mysql_query($sql2); - if ($result2) { echo "

".__('Event successfully validated')."

";} - +if (isset ($_GET["check"])) { + $id_trap = (int) get_parameter_get ("check", 0); + if ($id_trap > 1 && give_acl ($config['id_user'], 0, "IW")) { + $sql = sprintf ("UPDATE ttrap SET status = 1, id_usuario = '%s' WHERE id_trap = %d", $config["id_user"], $id_trap); + $result = process_sql ($sql); + print_error_message ($result, __('Event successfully updated'), __('Error updating event')); } else { audit_db ($config['id_user'], $REMOTE_ADDR, "ACL Violation", "Trying to checkout SNMP Trap ID".$id_trap); @@ -91,15 +58,12 @@ if (isset($_GET["check"])){ } // Mass-process DELETE -if (isset($_POST["deletebt"])){ - $count=0; - if (give_acl ($config['id_user'], 0, "IW")) { - while ($count <= $config["block_size"]) { - if (isset($_POST["snmptrapid".$count])){ - $trap_id = $_POST["snmptrapid".$count]; - mysql_query("DELETE FROM ttrap WHERE id_trap =".$trap_id); - } - $count++; +if (isset ($_POST["deletebt"])) { + $trap_ids = get_parameter_post ("snmptrapid", array ()); + if (is_array ($trap_ids) && give_acl ($config['id_user'], 0, "IW")) { + foreach ($trap_ids as $id_trap) { + $sql = sprintf ("DELETE FROM ttrap WHERE id_trap = %d", $id_trap); + process_sql ($sql); } } else { audit_db ($config['id_user'], $REMOTE_ADDR, "ACL Violation", @@ -108,174 +72,183 @@ if (isset($_POST["deletebt"])){ } // Mass-process UPDATE -if (isset($_POST["updatebt"])){ - $count=0; - if (give_acl ($config['id_user'], 0, "IW")) { - while ($count <= $config["block_size"]){ - if (isset($_POST["snmptrapid".$count])){ - $id_trap = $_POST["snmptrapid".$count]; - $sql2="UPDATE ttrap SET status=1, id_usuario = '".$config['id_user']."' WHERE status = 0 and id_trap = ".$id_trap; - $result2=mysql_query($sql2); - } - $count++; - } +if (isset ($_POST["updatebt"])) { + $trap_ids = get_parameter_post ("snmptrapid", array ()); + if (is_array ($trap_ids) && give_acl ($config['id_user'], 0, "IW")) { + foreach ($trap_ids as $id_trap) { + $sql = sprintf ("UPDATE ttrap SET status = 1, id_usuario = '%s' WHERE id_trap = %d", $config["id_user"], $id_trap); + process_sql ($sql); + } } else { audit_db ($config['id_user'], $REMOTE_ADDR, "ACL Violation", - "Trying to mass-validate SNMP Trap ID"); + "Trying to mass-delete SNMP Trap ID"); } } -echo "

Pandora SNMP > "; -echo __('SNMP console')."

"; -$offset = get_parameter ('offset'); +echo "

Pandora SNMP > ".__('SNMP console')."

"; -$sql2="SELECT * FROM ttrap ORDER BY timestamp DESC"; -$result2=mysql_query($sql2); +$offset = (int) get_parameter ('offset',0); -if (mysql_num_rows ($result2) == 0) { - echo "
".__('There are no SNMP traps in database')."
"; + +$sql = sprintf ("SELECT * FROM ttrap ORDER BY timestamp DESC LIMIT %d,%d",$offset,$config['block_size']); +$traps = get_db_all_rows_sql ($sql); + +if (empty ($traps)) { + echo '
'.__('There are no SNMP traps in database').'
'; return; } -echo ""; -echo ""; -echo ""; -echo "
"; -echo " - ".__('Validated event'); -echo "
"; -echo " - ".__('Not validated event'); -//echo "
"; -//echo " - ".__('Alert'); -echo "
"; -echo " - ".__('Validate event'); -echo "
"; -echo " - ".__('Delete event'); -echo "
"; -echo "
"; +echo ''; +echo ''; +echo ''; +echo '
'.__('Status').''.__('Alert').''.__('Action').'
'; +echo ' - '.__('Validated event'); +echo '
'; +echo ' - '.__('Not validated event'); +echo '
'; +echo ' - '.__('Alert fired'); +echo ''; +echo ' - '.__('Validate event'); +echo '
'; +echo ' - '.__('Delete event'); +echo '
'; +echo '
'; -// Prepare index for pagination -$trap_list[]=""; +// Prepare index for paginationi +$trapcount = get_db_sql ("SELECT COUNT(*) FROM ttrap"); +pagination ($trapcount, "index.php?sec=snmpconsole&sec2=operation/snmpconsole/snmp_view", $offset); -while ($row2=mysql_fetch_array($result2)){ // Jump offset records - $trap_list[]=$row2["id_trap"]; -} +echo "
"; +echo '
'; -$total_traps = count ($trap_list); -pagination ($total_traps, "index.php?sec=snmpconsole&sec2=operation/snmpconsole/snmp_view", $offset); +$table->cellpadding = 4; +$table->cellspacing = 4; +$table->width = 735; +$table->class = "databox"; +$table->head = array (); +$table->size = array (); +$table->data = array (); -echo "
"; -echo ""; -echo ""; -echo ""; -echo ""; -echo ""; -echo ""; -echo ""; -echo ""; -echo ""; -echo ""; -echo ""; -echo "'; -echo ""; +$table->head[0] = __('Status'); +$table->head[1] = __('SNMP Agent'); +$table->head[2] = __('OID'); +$table->head[3] = __('Value'); +$table->head[4] = __('Custom'); +$table->head[5] = __('User ID'); + +$table->head[6] = __('Timestamp'); +$table->size[6] = 130; + +$table->head[7] = __('Alert'); +$table->head[8] = __('Action'); + +$table->head[9] = print_checkbox_extended ("allbox", 1, false, false, "javascript:CheckAll();", 'class="chk" title="'.__('All').'"', true); -$id_trap = 0; -$color = 0; -if ($offset != 0) - $offset_limit = $offset + 1; -else - $offset_limit = $offset; // Skip offset records -for ($a=$offset_limit;$a < ($config["block_size"] + $offset + 1);$a++){ - if (isset($trap_list[$a])){ - $id_trap = $trap_list[$a]; - $sql="SELECT * FROM ttrap WHERE id_trap = $id_trap"; - if ($result=mysql_query($sql)){ - $trap=mysql_fetch_array($result); - if ($color == 1){ - $tdcolor = "datos"; - $color = 0; - } - else { - $tdcolor = "datos2"; - $color = 1; - } - $offset_counter++; - echo ""; - echo ""; - - - // Agent ID - $agent = get_db_row ('tagente', 'direccion', $trap['source']); - if ($agent) { - echo ""; - } else { - echo ""; - } +foreach ($traps as $trap) { + $data = array (); - // OID - echo ""; - - // CUSTOM - $custom = substr ($trap["value_custom"], 0, 15); - if (strlen ($trap["value_custom"]) > 15) - $custom .= "..."; - echo ""; - - // User - echo ""; - - // Timestamp - echo ""; - - // Alerted ? - echo ""; - - // Delete and ACK - echo ""; - - echo ""; - } + //Status + if ($trap["status"] == 0) { + $data[0] = ''; + } else { + $data[0] = ''; } -} -echo "
".__('Status')."".__('SNMP Agent')."".__('OID')."".__('Value')."".__('Custom')."".__('User ID')."".__('Timestamp')."".__('Alert')."".__('Action').""; -echo ""; -echo ' -
"; - if ($trap["status"] == 0){ - echo ""; - } - else { - echo ""; - } - echo " - - ".$agent['nombre']."".$trap["source"]."".$trap["oid"]; - - - // Value - $value = substr ($trap["value"], 0, 15); - if (strlen ($trap["value"]) > 15) - $value .= "..."; - echo "".$value."".$custom.""; - if ($trap["status"]) - echo " ".dame_nombre_real($trap["id_usuario"])."".substr($trap["id_usuario"],0,8).""; - echo "".$trap["timestamp"].""; - if ($trap["alerted"]) - echo ""; - echo ""; - if ($trap["status"] == 0 && give_acl ($config['id_user'],"0","IW")) - echo ""; - if (give_acl ($config['id_user'], "0", "IM")) - echo ""; - echo ""; - echo ""; - echo "
"; -$offset_counter = 0; -echo "
"; -echo " "; -if (give_acl ($config['id_user'], 0, "IM")) { - echo ""; + // Agent matching + $agent = get_db_row ('tagente', 'direccion', $trap['source']); + if ($agent !== false && ! give_acl ($config["id_user"], $agent["id_grupo"], "AR")) { + //Agent found, no rights + continue; + } elseif ($agent === false) { + //Agent not found + $data[1] = $trap["source"]; + if (give_acl ($config["id_user"], 0, "AW")) { + //We have rights to create agents + $data[1] = ''.$data[1].''; + } + } else { + //Agent found + $data[1] = ''; + $data[1] .= ''.$agent["nombre"].''; + } + + //OID + $data[2] = $trap["oid"]; + if (empty ($data[2])) + $data[2] = __('N/A'); + + //Value + $data[3] = substr ($trap["value"], 0, 15); + + if (empty ($data[3])) { + $data[3] = __('N/A'); + } elseif (strlen ($trap["value"]) > 15) { + $data[3] = ''.$data[3].'...'; + } + + //Custom + $data[4] = $trap["value_custom"]; + + if (empty ($data[4])) { + $data[4] = __('N/A'); + } elseif (strlen ($trap["value_custom"]) > 15) { + $data[4] = ''.$data[4].'...'; + } + + //User + if (!empty ($trap["status"])) { + $data[5] = ''.substr ($trap["id_usuario"], 0, 8).''; + $data[5] .= ' '.dame_nombre_real($trap["id_usuario"]).''; + } else { + $data[5] = '--'; + } + + // Timestamp + $data[6] = $trap["timestamp"]; + + //Alert fired + if (!empty ($trap["alerted"])) { + $data[7] = ''; + } else { + $data[7] = '--'; + } + + //Actions + $data[8] = ""; + if (empty ($trap["status"]) && give_acl ($config["id_user"], 0, "IW")) { + $data[8] .= ''; + } + if (give_acl ($config["id_user"], 0, "IW")) { + $data[8] .= ''; + } + + $data[9] = print_checkbox_extended ("snmptrapid[]", $trap["id_trap"], false, false, '', 'class="chk"', true); + + array_push ($table->data, $data); } -echo "
"; + +print_table ($table); +unset ($table); + +echo '
'; +print_submit_button (__('Validate'), "updatebt", false, 'class="sub ok"'); + +if (give_acl ($config['id_user'], 0, "IM")) { + print_submit_button (__('Delete'), "deletebt", false, 'class="sub delete" onClick="javascript:confirm(\''.__('Are you sure').'\')"'); +} +echo "
"; + + ?> +