From ad4ba4d25183604e089fefcc61b777c57fb11118 Mon Sep 17 00:00:00 2001 From: guruevi Date: Wed, 15 Oct 2008 18:40:34 +0000 Subject: [PATCH] 2008-10-15 Evi Vanoost * include/functions_db.php: Fix where the attachment wouldn't be deleted because of a variable problem * operation/snmpconsole/snmp_alert.php: Rewrite. Fixes bug #2166256. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1158 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_console/ChangeLog | 6 + pandora_console/include/functions_db.php | 4 +- .../operation/snmpconsole/snmp_alert.php | 642 +++++++++--------- 3 files changed, 339 insertions(+), 313 deletions(-) diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 40299573f1..55f699d1d3 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,9 @@ +2008-10-15 Evi Vanoost + + * include/functions_db.php: Fix where the attachment wouldn't be + deleted because of a variable problem + + * operation/snmpconsole/snmp_alert.php: Rewrite. Fixes bug #2166256 2008-10-15 Sancho Lerena diff --git a/pandora_console/include/functions_db.php b/pandora_console/include/functions_db.php index d13c9786dc..7bc4718d62 100644 --- a/pandora_console/include/functions_db.php +++ b/pandora_console/include/functions_db.php @@ -815,10 +815,10 @@ function borrar_incidencia ($id_inc) { // Delete attachments $sql = sprintf ("SELECT `id_attachment`,`filename` FROM `tattachment` WHERE `id_incidencia` = %d", $id_inc); $rows = get_db_all_rows_sql ($sql); - if ($rows){ + if (!empty ($rows)){ foreach ($rows as $row) { // Unlink all attached files for this incident - unlink ($attachment_store."/pand".$row["id_attachment"]."_".$row["filename"]); + unlink ($config["attachment_store"]."/pand".$row["id_attachment"]."_".$row["filename"]); } $sql = sprintf ("DELETE FROM `tattachment` WHERE `id_incidencia` = %d",$id_inc); process_sql ($sql); diff --git a/pandora_console/operation/snmpconsole/snmp_alert.php b/pandora_console/operation/snmpconsole/snmp_alert.php index 2559f2c0bb..929eb65ce9 100644 --- a/pandora_console/operation/snmpconsole/snmp_alert.php +++ b/pandora_console/operation/snmpconsole/snmp_alert.php @@ -27,339 +27,359 @@ if (! give_acl ($config['id_user'], 0, "LW")) { return; } -// Variable init -$view_alert=1; -$alert_add = 0; -$alert_update=0; -$alert_submit=0; - -$id_as = ""; -$id_alert = ""; -$nombre_alerta = ""; -$alert_type = ""; -$agent = ""; -$description = ""; -$oid = ""; -$custom_oid = ""; -$time_threshold = ""; -$al_field1 = ""; -$al_field2 = ""; -$al_field3 = ""; -$last_fired = ""; -$max_alerts = ""; -$min_alerts = ""; -$priority = ""; - // Alert Delete // ============= -if (isset ($_GET["delete_alert"])){ // Delete alert - $alert_delete = $_GET["delete_alert"]; - $sql1='DELETE FROM talert_snmp WHERE id_as = '.$alert_delete; - $result=mysql_query($sql1); - if (!$result) - echo "

".__('There was a problem deleting alert')."

"; - else - echo "

".__('Alert successfully deleted')."

"; -} -// Alert submit (for insert or update) -if (isset ($_GET["submit"])){ - $alert_submit=1; - $create = entrada_limpia($_POST["create"]); - $update = entrada_limpia($_POST["update"]); - $id_as = entrada_limpia($_POST["id_as"]); - $max = entrada_limpia($_POST["max"]); - $min = entrada_limpia($_POST["min"]); - $time = entrada_limpia($_POST["time"]); - $description = entrada_limpia($_POST["description"]); - $oid = entrada_limpia($_POST["oid"]); - $agent = entrada_limpia($_POST["agent"]); - $custom = entrada_limpia($_POST["custom"]); - $alert_id = entrada_limpia($_POST["alert_id"]); - $alert_type = entrada_limpia($_POST["alert_type"]); - $field1 = entrada_limpia($_POST["field1"]); - $field2 = entrada_limpia($_POST["field2"]); - $field3 = entrada_limpia($_POST["field3"]); - $priority = get_parameter ("priority",0); - - if ($create == 1){ - $sql = "INSERT INTO talert_snmp (id_alert,al_field1,al_field2,al_field3,description,alert_type,agent,custom_oid,oid,time_threshold,max_alerts,min_alerts, priority) VALUES ($alert_id,'$field1','$field2','$field3','$description', $alert_type, '$agent', '$custom', '$oid', $time, $max, $min, $priority)"; - $result=mysql_query($sql); - if (!$result) - echo "

".__('There was a problem creating alert')."

"; - else - echo "

".__('Alert successfully created')."

"; - } else { - $sql = "UPDATE talert_snmp set priority = $priority, id_alert= $alert_id, al_field1 = '$field1', al_field2 = '$field2', al_field3 = '$field3', description = '$description', alert_type = $alert_type, agent = '$agent', custom_oid = '$custom', oid = '$oid', time_threshold = $time, max_alerts = '$max', min_alerts = '$min' WHERE id_as = $id_as"; - $result=mysql_query($sql); - if (!$result) - echo "

".__('There was a problem updating alert')."

"; - else - echo "

".__('Alert successfully created')."

"; - } - - -} -// Alert update: (first, load data used in form), later use insert/add form -// ============ -if (isset ($_GET["update_alert"])){ - $alert_update = $_GET["update_alert"]; - $sql1='SELECT * FROM talert_snmp WHERE id_as = '.$alert_update; - $result=mysql_query($sql1); - if ($row=mysql_fetch_array($result)){ - $id_as = $row["id_as"]; - $id_alert = $row["id_alert"]; - $nombre_alerta = dame_nombre_alerta($id_alert); - $alert_type = $row["alert_type"]; - $agent = $row["agent"]; - $description = $row["description"]; - $oid = $row["oid"]; - $custom_oid = $row["custom_oid"]; - $time_threshold = $row["time_threshold"]; - $al_field1 = $row["al_field1"]; - $al_field2 = $row["al_field2"]; - $al_field3 = $row["al_field3"]; - $last_fired = $row["last_fired"]; - $max_alerts = $row["max_alerts"]; - $min_alerts = $row["min_alerts"]; - $priority = $row["priority"]; - } -} -if (isset($_POST["add_alert"])){ - $alert_add = 1; -} -echo "

Pandora SNMP > "; -// Add alert form -if (($alert_update != 0) || ($alert_add == 1)) { - - if ($alert_update != 0) { - echo __('Update alert')."

"; +if (isset ($_GET["delete_alert"])) { // Delete alert + $alert_delete = (int) get_parameter_get ("delete_alert", 0); + $sql = sprintf ("DELETE FROM talert_snmp WHERE id_as = %d", $alert_delete); + $result = process_sql ($sql); + if ($result === false) { + echo '

'.__('There was a problem deleting the alert').'

'; } else { - echo __('Create alert').""; + echo '

'.__('Alert successfully deleted').'

'; } - echo '
'; - echo ''; // if known, if add will be undetermined (0). +} + +// Form submitted +// ============= +if (isset ($_GET["submit"])) { + $id_as = (int) get_parameter_get ("submit", -1); + $source_ip = (string) get_parameter_post ("source_ip"); + $alert_type = (int) get_parameter_post ("alert_type"); //Event, e-mail + $alert_trigger = (int) get_parameter_post ("alert_trigger"); //OID, Custom Value + $description = (string) get_parameter_post ("description"); + $oid = (string) get_parameter_post ("oid"); + $custom_value = (string) get_parameter_post ("custom_value"); + $time_threshold = (int) get_parameter_post ("time_threshold", 300); + $time_other = (int) get_parameter_post ("time_other", -1); + $al_field1 = (string) get_parameter_post ("al_field1"); + $al_field2 = (string) get_parameter_post ("al_field2"); + $al_field3 = (string) get_parameter_post ("al_field3"); + $max_alerts = (int) get_parameter_post ("max_alerts", 1); + $min_alerts = (int) get_parameter_post ("min_alerts", 1); + $priority = (int) get_parameter_post ("priority", 0); + + if ($time_threshold == -1) { + $time_threshold = $time_other; + } + + if ($id_as < 1) { + $sql = sprintf ("INSERT INTO talert_snmp + (id_alert, al_field1, al_field2, al_field3, description, alert_type, agent, custom_oid, oid, time_threshold, max_alerts, min_alerts, priority) + VALUES + (%d, '%s', '%s', '%s', '%s', %d, '%s', '%s', '%s', %d, %d, %d, %d)", + $alert_type, $al_field1, $al_field2, $al_field3, $description, $alert_trigger, $source_ip, $custom_value, $oid, $time_threshold, $max_alerts, $min_alerts, $priority); + + //$result = process_sql ($sql); + + if ($result === false) { + echo '

'.__('There was a problem creating the alert').'

'; + } else { + echo '

'.__('Alert successfully created').'

'; + } + + } else { + $sql = sprintf ("UPDATE talert_snmp SET + priority = %d, id_alert = %d, al_field1 = '%s', al_field2 = '%s', al_field3 = '%s', description = '%s', alert_type = %d, agent = '%s', custom_oid = '%s', + oid = '%s', time_threshold = %d, max_alerts = %d, min_alerts = %d WHERE id_as = %d", + $priority, $alert_type, $al_field1, $al_field2, $al_field3, $description, $alert_trigger, $source_ip, $custom_value, + $oid, $time_threshold, $max_alerts, $min_alerts, $id_as); + + $result = process_sql ($sql); + + if ($result === false) { + echo '

'.__('There was a problem updating the alert').'

'; + } else { + echo '

'.__('Alert successfully updated').'

'; + } + } +} + +// From variable init +// ================== +if (isset ($_GET["update_alert"]) && $_GET["update_alert"]) { + $id_as = (int) get_parameter_get ("update_alert", -1); + $alert = get_db_row ("talert_snmp", "id_as", $id_as); + $id_as = $alert["id_as"]; + $source_ip = $alert["agent"]; + $alert_type = $alert["id_alert"]; + $alert_trigger = $alert["alert_type"]; + $description = $alert["description"]; + $oid = $alert["oid"]; + $custom_value = $alert["custom_oid"]; + $time_threshold = $alert["time_threshold"]; + $al_field1 = $alert["al_field1"]; + $al_field2 = $alert["al_field2"]; + $al_field3 = $alert["al_field3"]; + $max_alerts = $alert["max_alerts"]; + $min_alerts = $alert["min_alerts"]; + $priority = $alert["priority"]; +} elseif (isset ($_GET["update_alert"])) { + // Variable init + $id_as = -1; + $source_ip = ""; + $alert_type = 1; //Event, e-mail + $alert_trigger = 0; //OID, Custom Value + $description = ""; + $oid = ""; + $custom_value = ""; + $time_threshold = 300; + $al_field1 = ""; + $al_field2 = ""; + $al_field3 = ""; + $max_alerts = 1; + $min_alerts = 1; + $priority = 0; +} + +// Alert form +if (isset ($_GET["update_alert"])) { //the update_alert means the form should be displayed. If update_alert > 1 then an existing alert is updated + if ($id_as > 1) { + echo "

Pandora SNMP > ".__('Update alert')."

"; + } else { + echo "

Pandora SNMP > ".__('Create alert')."

"; + } + echo ''; echo ''; - // Alert - echo ''; - // Description - echo ''; - echo ''; + + // Alert trigger (OID, custom_value) + echo ''; + + // Description + echo ''; + // OID - echo ''; - echo ''; // OID Custom - echo ''; - echo ''; // SNMP Agent - echo ''; - echo ''; + // Alert fields - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; + + echo ''; + + echo ''; // Max / Min alerts - echo ' - '; - echo ''; - echo ' - '; - echo ''; + echo ''; // Time Threshold - echo ' - '; - echo ''; + // Priority - echo '
'.__('Alert').'"; - // Alert type - echo '
'.__('Alert type'); - echo '
'.__('Alert type').''; + + $fields = array (); + $result = get_db_all_rows_in_table ("talerta", "nombre"); + if ($result === false) { + $result = array (); } - echo '
'.__('Description').''; + foreach ($result as $row) { + $fields[$row["id_alerta"]] = $row["nombre"]; + } + + print_select ($fields, "alert_type", $alert_type, '', '', '0', false, false, false); + echo '
'.__('Alert trigger').''; + + $fields = array (); + $fields[0] = "OID"; + $fields[1] = "Custom Value/OID"; + $fields[2] = "SNMP Agent"; + + print_select ($fields, "alert_trigger", $alert_trigger); + echo '
'.__('Description').''; + print_input_text ("description", $description, '', 60); + echo '
'.__('OID').''; + echo '
'.__('OID').''; + print_input_text ("oid", $oid, '', 30); + echo '
'.__('Custom value')."/".__("Value").''; + echo '
'.__('SNMP Agent').' IP'; - + echo '
'.__('Field #1 (Alias, name)').'
'.__('Field #2 (Single Line)').'
'.__('Field #3 (Full Text)'); - echo ''; + echo '
'.__('Field #1 (Alias, name)').''; + print_input_text ("al_field1", $al_field1, '', 30); + echo '
'.__('Field #2 (Single Line)').''; + print_input_text ("al_field2", $al_field2, '', 30); + echo '
'.__('Field #3 (Full Text)').''; + print_textarea ("al_field3", $al_field3, 4, $al_field3, 'style="width:400px"'); + echo '
'.__('Min. number of alerts').'
'.__('Max. number of alerts').'
'.__('Min. number of alerts').''; + print_input_text ("min_alerts", $min_alerts, '', 3); + + echo '
'.__('Max. number of alerts').''; + print_input_text ("max_alerts", $max_alerts, '', 3); + echo '
'.__('Time threshold').''; - echo ''; - + echo '
'.__('Time threshold').''; + + $fields = array (); + $fields[$time_threshold] = human_time_description ($time_threshold); + $fields[300] = human_time_description (300); + $fields[600] = human_time_description (600); + $fields[900] = human_time_description (900); + $fields[1800] = human_time_description (1800); + $fields[3600] = human_time_description (3600); + $fields[7200] = human_time_description (7200); + $fields[18000] = human_time_description (18000); + $fields[43200] = human_time_description (43200); + $fields[86400] = human_time_description (86400); + $fields[604800] = human_time_description (604800); + $fields[-1] = __('Other value'); + + print_select ($fields, "time_threshold", $time_threshold, '', '', '0', false, false, false, '" style="margin-right:60px'); + echo '
'.__('Priority'); - echo ''; - echo print_select (get_priorities (), "alert_priority", $priority, '', '', ''); - - echo '
'; - echo ' - '; + + //Button + echo '
'; - // Update or Add button - if ($alert_update != 0) { - echo ''; - echo ""; - echo ""; + echo '
'.__('Priority').''; + echo print_select (get_priorities (), "priority", $priority, '', '', '0', false, false, false); + echo '
'; + if ($id_as > 0) { + print_submit_button (__('Update'), "submit", false, 'class="sub upd"', false); } else { - echo ''; - echo ""; - echo ""; + print_submit_button (__('Create'), "submit", false, 'class="sub next"', false); } - // Endtable + + // End table echo "
"; - $view_alert =0; // Do not show alert list -} - -if ($view_alert == 1) { // View alerts defined on SNMP traps - - $sql1='SELECT * FROM talert_snmp'; - $result=mysql_query($sql1); - - echo __('SNMP alerts').""; - if (mysql_num_rows($result)){ - - echo ''; - echo '"; - echo '"; - echo '"; - echo '"; - echo '"; - echo '"; - echo '"; - echo '"; - echo '"; - $color=1; - while ($row=mysql_fetch_array($result)){ - if ($color == 1){ - $tdcolor = "datos"; - $color = 0; - } - else { - $tdcolor = "datos2"; - $color = 1; - } - $id_as = $row["id_as"]; - $id_alert = $row["id_alert"]; - $nombre_alerta = dame_nombre_alerta($id_alert); - $alert_type = $row["alert_type"]; - $agent = $row["agent"]; - $description = $row["description"]; - $oid = $row["oid"]; - $custom_oid = $row["custom_oid"]; - $time_threshold = $row["time_threshold"]; - $al_field1 = $row["al_field1"]; - $al_field2 = $row["al_field2"]; - $al_field3 = $row["al_field3"]; - $last_fired = $row["last_fired"]; - $times_fired = $row["times_fired"]; - $max_alerts = $row["max_alerts"]; - $min_alerts = $row["min_alerts"]; - - echo ""; - } - echo "
'.__('Alert')."'.__('Alert type')."'.__('SNMP Agent')."'.__('OID')."'.__('Custom value')."'.__('Description')."'.__('Times Fired')."'.__('Last fired')."'.__('Action')."
"; - echo $nombre_alerta; - echo ""; - if ($alert_type == 0) { - $tipo_alerta = __('OID'); - } elseif ($alert_type == 1) { - $tipo_alerta = __('Custom value'); - } elseif ($alert_type == 2) { - $tipo_alerta = __('SNMP Agent'); - } else { - $tipo_alerta = "N/A"; - } - echo $tipo_alerta; - echo ""; - if ($alert_type == 2) { - echo $agent; - } else { - echo "N/A"; - } - - echo ""; - if ($alert_type == 0) { - echo $oid; - } else { - echo "N/A"; - } - - echo ""; - if ($alert_type == 1) { - echo $custom_oid; - } else { - echo "N/A"; - } - - echo ""; - echo $description; - - echo ""; - echo $times_fired; - echo ""; - if ($last_fired != "0000-00-00 00:00:00") - echo $last_fired; - else - echo __('Never'); - echo ""; - echo " - ".__(   "; - echo " - ".__(
"; - echo ""; - echo "
"; - echo ''; - echo ''; - echo ""; - echo "
"; - } else { +} else { + echo "

Pandora SNMP > ".__('Alert Overview')."

"; + //Overview + $result = get_db_all_rows_in_table ("talert_snmp"); + if ($result === false) { + $result = array (); echo "
".__('There are no SNMP alerts')."
"; - echo "
"; - echo '
'; - echo ''; - echo "
"; - } // End of view snmp alert + } + + $table->data = array (); + $table->head = array (); + $table->size = array (); + $table->cellpadding = 4; + $table->cellspacing = 4; + $table->width = 750; + $table->class= "databox"; + $table->align = array (); + + $table->head[0] = __('Alert type'); + + $table->head[1] = __('Alert trigger'); + $table->align[1] = 'center'; + + $table->head[2] = __('SNMP Agent'); + $table->size[2] = 75; + $table->align[2] = 'center'; + + $table->head[3] = __('OID'); + $table->align[3] = 'center'; + + $table->head[4] = __('Custom Value/OID'); + $table->align[4] = 'center'; + + $table->head[5] = __('Description'); + + $table->head[6] = __('Times fired'); + $table->align[6] = 'center'; + + $table->head[7] = __('Last fired'); + $table->align[7] = 'center'; + + $table->head[8] = __('Action'); + $table->size[8] = 50; + $table->align[8] = 'right'; + + foreach ($result as $row) { + $data = array (); + $data[0] = dame_nombre_alerta ($row["id_alert"]); + $data[1] = __('N/A'); + $data[2] = __('N/A'); + $data[3] = __('N/A'); + $data[4] = __('N/A'); + + switch ($row["alert_type"]) { + case 0: + $data[1] = __('OID'); + $data[3] = $row["oid"]; + break; + case 1: + $data[1] = __('Custom Value/OID'); + $data[4] = $row["custom_oid"]; + break; + case 2: + $data[1] = __('SNMP Agent'); + $data[2] = $row["agent"]; + break; + } + + $data[5] = $row["description"]; + $data[6] = $row["times_fired"]; + + if ($row["last_fired"] != "0000-00-00 00:00:00") { + $data[7] = $row["last_fired"]; + } else { + $data[7] = __('Never'); + } + + $data[8] = ' + '.__('Delete').'  + + '.__('Update').''; + array_push ($table->data, $data); + } + + if (!empty ($table->data)) { + print_table ($table); + } + + unset ($table); + + echo '
'; + echo '
'; + print_submit_button (__('Create'), "add_alert", false, 'class="sub next"'); + echo "
"; + } ?> - - + + +