From 267b28ed0adaf5d7da08c13552ec5c363a0286b4 Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Mon, 5 Aug 2013 14:23:27 +0000 Subject: [PATCH] 2013-08-05 Miguel de Dios * include/constants.php, godmode/snmpconsole/snmp_alert.php: added filter in the alert snmp page and pagination. * operation/events/events.build_table.php, godmode/netflow/nf_edit.php, include/functions_ui.php, include/db/mysql.php, include/functions_incidents.php: improved the source code style. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@8630 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_console/ChangeLog | 10 + pandora_console/godmode/netflow/nf_edit.php | 2 +- .../godmode/snmpconsole/snmp_alert.php | 334 ++++++++++++++---- pandora_console/include/constants.php | 7 + pandora_console/include/db/mysql.php | 5 +- .../include/functions_incidents.php | 36 +- pandora_console/include/functions_ui.php | 6 +- .../operation/events/events.build_table.php | 20 +- 8 files changed, 326 insertions(+), 94 deletions(-) diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 1769d55f80..08aab904dd 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,13 @@ +2013-08-05 Miguel de Dios + + * include/constants.php, godmode/snmpconsole/snmp_alert.php: added + filter in the alert snmp page and pagination. + + * operation/events/events.build_table.php, + godmode/netflow/nf_edit.php, include/functions_ui.php, + include/db/mysql.php, include/functions_incidents.php: improved the + source code style. + 2013-08-02 Sergio Martin * include/functions_filemanager.php: added new error message diff --git a/pandora_console/godmode/netflow/nf_edit.php b/pandora_console/godmode/netflow/nf_edit.php index d89b494daf..e8fc076b83 100644 --- a/pandora_console/godmode/netflow/nf_edit.php +++ b/pandora_console/godmode/netflow/nf_edit.php @@ -140,7 +140,7 @@ foreach ($filters as $filter) { array_push ($table->data, $data); } -if(isset($data)) { +if (isset($data)) { echo "
"; html_print_input_hidden('multiple_delete', 1); html_print_table ($table); diff --git a/pandora_console/godmode/snmpconsole/snmp_alert.php b/pandora_console/godmode/snmpconsole/snmp_alert.php index bb7ab03823..1d01bfe42a 100644 --- a/pandora_console/godmode/snmpconsole/snmp_alert.php +++ b/pandora_console/godmode/snmpconsole/snmp_alert.php @@ -23,21 +23,41 @@ if (! check_acl ($config['id_user'], 0, "LW")) { return; } +$trap_types = array( + SNMP_TRAP_TYPE_NONE => __('None'), + SNMP_TRAP_TYPE_COLD_START => __('Cold start (0)'), + SNMP_TRAP_TYPE_WARM_START => __('Warm start (1)'), + SNMP_TRAP_TYPE_LINK_DOWN => __('Link down (2)'), + SNMP_TRAP_TYPE_LINK_UP => __('Link up (3)'), + SNMP_TRAP_TYPE_AUTHENTICATION_FAILURE => __('Authentication failure (4)'), + SNMP_TRAP_TYPE_OTHER => __('Other')); + // Form submitted // ============= -if (isset ($_GET["update_alert"]) && $_GET["update_alert"] == "-1") { - ui_print_page_header (__('SNMP Console')." » ".__('Create alert'), +$update_alert = (bool)get_parameter('update_alert', false); +$create_alert = (bool)get_parameter('create_alert', false); +$save_alert = (bool)get_parameter('save_alert', false); +$modify_alert = (bool)get_parameter('modify_alert', false); +$delete_alert = (bool)get_parameter('delete_alert', false); +$multiple_delete = (bool)get_parameter('multiple_delete', false); + +if ($update_alert || $modify_alert) { + ui_print_page_header(__('SNMP Console')." » ".__('Update alert'), "images/op_snmp.png", false, "snmp_alert", false); } -else if (isset ($_GET["update_alert"]) && $_GET["update_alert"] != "-1") { - ui_print_page_header (__('SNMP Console')." » ".__('Update alert'), +else if ($create_alert || $save_alert) { + ui_print_page_header(__('SNMP Console')." » ".__('Create alert'), "images/op_snmp.png", false, "snmp_alert", false); } -else if (isset ($_GET["submit"])) { - ui_print_page_header (__('SNMP Console')." » ".__('Update alert'), +else { + ui_print_page_header(__('SNMP Console')." » ".__('Alert overview'), "images/op_snmp.png", false, "snmp_alert", false); - $id_as = (int) get_parameter_get ("submit", -1); +} + +if ($save_alert || $modify_alert) { + $id_as = (int) get_parameter("id_alert_snmp", -1); + $source_ip = (string) get_parameter_post ("source_ip"); $alert_type = (int) get_parameter_post ("alert_type"); //Event, e-mail $description = (string) get_parameter_post ("description"); @@ -76,7 +96,7 @@ else if (isset ($_GET["submit"])) { $time_threshold = $time_other; } - if ($id_as < 1) { + if ($save_alert) { $values = array( 'id_alert' => $alert_type, 'al_field1' => $al_field1, @@ -110,8 +130,8 @@ else if (isset ($_GET["submit"])) { 'trap_type' => $trap_type, 'single_value' => $single_value, 'position' => $position); - - $result = db_process_sql_insert('talert_snmp', $values); + + $result = db_process_sql_insert('talert_snmp', $values); if (!$result) { db_pandora_audit("SNMP management", "Fail try to create snmp alert"); @@ -145,7 +165,8 @@ else if (isset ($_GET["submit"])) { $max_alerts, $min_alerts, $custom_oid_data_1, $custom_oid_data_2, $custom_oid_data_3, $custom_oid_data_4, $custom_oid_data_5, $custom_oid_data_6, $custom_oid_data_7, $custom_oid_data_8, - $custom_oid_data_9, $custom_oid_data_10, $trap_type, $single_value, $position, $id_as); + $custom_oid_data_9, $custom_oid_data_10, $trap_type, $single_value, + $position, $id_as); $result = db_process_sql ($sql); @@ -159,14 +180,12 @@ else if (isset ($_GET["submit"])) { } } } -else { - ui_print_page_header (__('SNMP Console')." » ".__('Alert overview'), "images/op_snmp.png", false, "snmp_alert", false); -} // From variable init // ================== -if ((isset ($_GET["update_alert"])) && ($_GET["update_alert"] != -1)) { - $id_as = (int) get_parameter_get ("update_alert", -1); +if ($update_alert) { + $id_as = (int) get_parameter("id_alert_snmp", -1); + $alert = db_get_row ("talert_snmp", "id_as", $id_as); $id_as = $alert["id_as"]; $source_ip = $alert["agent"]; @@ -187,7 +206,7 @@ if ((isset ($_GET["update_alert"])) && ($_GET["update_alert"] != -1)) { $al_field10 = $alert["al_field10"]; $max_alerts = $alert["max_alerts"]; $min_alerts = $alert["min_alerts"]; - $priority = $alert["priority"]; + $priority = $alert["priority"]; $custom_oid_data_1 = $alert["_snmp_f1_"]; $custom_oid_data_2 = $alert["_snmp_f2_"]; $custom_oid_data_3 = $alert["_snmp_f3_"]; @@ -202,7 +221,7 @@ if ((isset ($_GET["update_alert"])) && ($_GET["update_alert"] != -1)) { $single_value = $alert["single_value"]; $position = $alert["position"]; } -elseif (isset ($_GET["update_alert"])) { +elseif ($create_alert) { // Variable init $id_as = -1; $source_ip = ""; @@ -243,10 +262,12 @@ elseif (isset ($_GET["update_alert"])) { // Alert Delete // ============= -if (isset ($_GET["delete_alert"])) { // Delete alert +if ($delete_alert) { // Delete alert $alert_delete = (int) get_parameter_get ("delete_alert", 0); - $result = db_process_sql_delete('talert_snmp', array('id_as' => $alert_delete)); + $result = db_process_sql_delete('talert_snmp', + array('id_as' => $alert_delete)); + if ($result === false) { db_pandora_audit("SNMP management", "Fail try to delete snmp alert #$alert_delete"); ui_print_error_message(__('There was a problem deleting the alert')); @@ -257,10 +278,47 @@ if (isset ($_GET["delete_alert"])) { // Delete alert } } +if ($multiple_delete) { + $delete_ids = get_parameter('delete_ids', array()); + + $total = count($delete_ids); + + $count = 0; + foreach ($delete_ids as $alert_delete) { + $result = db_process_sql_delete('talert_snmp', + array('id_as' => $alert_delete)); + + if ($result !== false) { + db_pandora_audit("SNMP management", "Delete snmp alert #$alert_delete"); + $count++; + } + else { + db_pandora_audit("SNMP management", "Fail try to delete snmp alert #$alert_delete"); + } + } + + if ($count == $total) { + ui_print_success_message(__('Successfully deleted alerts (%s / %s)', $count, $total)); + } + else { + ui_print_error_message(__('Unsuccessfully deleted alerts (%s / %s)', $count, $total)); + } +} + // Alert form -if (isset ($_GET["update_alert"])) { +if ($create_alert || $update_alert) { +//if (isset ($_GET["update_alert"])) { //the update_alert means the form should be displayed. If update_alert > 1 then an existing alert is updated - echo ''; + echo ''; + + html_print_input_hidden('id_alert_snmp', $id_as); + + if ($create_alert) { + html_print_input_hidden('save_alert', 1); + } + if ($update_alert) { + html_print_input_hidden('modify_alert', 1); + } /* SNMP alert filters */ @@ -294,7 +352,6 @@ if (isset ($_GET["update_alert"])) { // Trap type echo ''.__('Trap type').''; - $trap_types = array(-1 => __('None'), 0 => __('Cold start (0)'), 1 => __('Warm start (1)'), 2 => __('Link down (2)'), 3 => __('Link up (3)'), 4 => __('Authentication failure (4)'), 5 => __('Other')); echo html_print_select ($trap_types, 'trap_type', $trap_type, '', '', '', false, false, false); echo ''; @@ -350,31 +407,31 @@ if (isset ($_GET["update_alert"])) { echo ''; html_print_input_text ("custom_oid_data_6", $custom_oid_data_6, '', 60); echo ''; - + // Custom OID/Data #7 echo ''.__('Custom OID/Data #7'); echo ''; html_print_input_text ("custom_oid_data_7", $custom_oid_data_7, '', 60); echo ''; - + // Custom OID/Data #8 echo ''.__('Custom OID/Data #8'); echo ''; html_print_input_text ("custom_oid_data_8", $custom_oid_data_8, '', 60); echo ''; - + // Custom OID/Data #9 echo ''.__('Custom OID/Data #9'); echo ''; html_print_input_text ("custom_oid_data_9", $custom_oid_data_9, '', 60); echo ''; - + // Custom OID/Data #10 echo ''.__('Custom OID/Data #10'); echo ''; html_print_input_text ("custom_oid_data_10", $custom_oid_data_10, '', 60); echo ''; - + //Button //echo ''; @@ -397,9 +454,9 @@ if (isset ($_GET["update_alert"])) { // Hidden div with help hint to fill with javascript html_print_div(array('id' => 'help_snmp_alert_hint', 'content' => ui_print_help_icon ("snmp_alert_field1", true), 'hidden' => true)); - for ($i=1; $i<=10; $i++) { + for ($i = 1; $i <= 10; $i++) { echo ''.html_print_image('images/spinner.gif',true); - echo ''.html_print_image('images/spinner.gif',true); + echo '' . html_print_image('images/spinner.gif',true); html_print_input_hidden('field'.$i.'_value', isset($al['al_field'.$i]) ? $al['al_field'.$i] : ''); echo ''; } @@ -432,7 +489,7 @@ if (isset ($_GET["update_alert"])) { html_print_select ($fields, "time_threshold", $time_threshold, '', '', '0', false, false, false, '" style="margin-right:60px'); echo ''; + echo ' ' . __('seconds') . ''; // Priority echo ''.__('Priority').''; @@ -484,11 +541,107 @@ if (isset ($_GET["update_alert"])) { else { require_once ('include/functions_alerts.php'); + $free_search = (string)get_parameter('free_search', ''); + $trap_type_filter = (int)get_parameter('trap_type_filter', SNMP_TRAP_TYPE_NONE); + $priority_filter = (int)get_parameter('priority_filter', -1); + $filter_param = (bool)get_parameter('filter', false); + $offset = (int) get_parameter ('offset'); + + $table_filter = null; + $table_filter->width = "98%"; + $table_filter->data = array(); + $table_filter->data[0][0] = __('Free search') . ui_print_help_tip( + __('Search by these fields description, OID, Custom Value, SNMP Agent (IP), Single value, each Custom OIDs/Datas.'), true); + $table_filter->data[0][1] = + html_print_input_text('free_search', $free_search, '', 30, 100, true); + $table_filter->data[0][2] = __('Trap type'); + $table_filter->data[0][3] = + html_print_select ($trap_types, 'trap_type_filter', $trap_type_filter, '', '', '', true, false, false); + $table_filter->data[0][4] = __('Priority'); + $table_filter->data[0][5] = + html_print_select (get_priorities(), "priority_filter", $priority_filter, '', __('None'), '-1', true, false, false);; + + $form_filter = ''; + $form_filter .= html_print_input_hidden('filter', 1, true); + $form_filter .= html_print_table($table_filter, true); + $form_filter .= '
'; + $form_filter .= html_print_submit_button(__('Filter'), 'filter_button', false, 'class="sub filter"', true); + $form_filter .= '
'; + $form_filter .= '
'; + + echo "
"; + ui_toggle($form_filter,__('Alert SNMP control filter'), __('Toggle filter(s)')); + + $filter = array(); + $filter['offset'] = (int) get_parameter ('offset'); + $filter['limit'] = (int) $config['block_size']; + if ($filter_param) { + //Move the first page + $offset = 0; + + $url_pagination = "index.php?" . + "sec=snmpconsole&" . + "sec2=godmode/snmpconsole/snmp_alert&" . + "free_seach=" . $free_search . "&" . + "trap_type_filter=" . $trap_type_filter . "&" . + "priority_filter=" . $priority_filter; + } + else { + $url_pagination = "index.php?" . + "sec=snmpconsole&" . + "sec2=godmode/snmpconsole/snmp_alert&" . + "free_seach=" . $free_search . "&" . + "trap_type_filter=" . $trap_type_filter . "&" . + "priority_filter=" . $priority_filter . "&" . + "offset=" . $offset; + } + + $where_sql = ' 1 = 1'; + if ($trap_type_filter != SNMP_TRAP_TYPE_NONE) { + $where_sql .= ' AND `trap_type` = ' . $trap_type_filter; + } + + if ($priority_filter != -1) { + $where_sql .= ' AND `priority` = ' . $priority_filter; + } + + if (!empty($free_search)) { + $where_sql .= " AND (`single_value` = '" . $free_search . "' + OR `_snmp_f10_` = '" . $free_search . "' + OR `_snmp_f9_` = '" . $free_search . "' + OR `_snmp_f8_` = '" . $free_search . "' + OR `_snmp_f7_` = '" . $free_search . "' + OR `_snmp_f6_` = '" . $free_search . "' + OR `_snmp_f5_` = '" . $free_search . "' + OR `_snmp_f4_` = '" . $free_search . "' + OR `_snmp_f3_` = '" . $free_search . "' + OR `_snmp_f2_` = '" . $free_search . "' + OR `_snmp_f1_` = '" . $free_search . "' + OR `oid` = '" . $free_search . "' + OR `custom_oid` = '" . $free_search . "' + OR `agent` = '" . $free_search . "' + OR `description` = '" . $free_search . "')"; + } + + $count = db_get_value_sql('SELECT COUNT(*) + FROM talert_snmp WHERE' . $where_sql); + + + + + $result = array(); + //Overview - $result = db_get_all_rows_in_table ("talert_snmp"); - if ($result === false) { + if ($count == 0) { $result = array (); - echo "
".__('There are no SNMP alerts')."
"; + echo "
" . __('There are no SNMP alerts') . "
"; + } + else { + ui_pagination ($count, $url_pagination); + + $where_sql .= ' LIMIT ' . $config['block_size'] . ' OFFSET ' . $offset; + $result = db_get_all_rows_sql('SELECT * + FROM talert_snmp WHERE' . $where_sql); } $table->data = array (); @@ -517,21 +670,33 @@ else { $table->head[5] = __('Description'); - $table->head[6] = __('Times fired'); + $table->head[6] = '' . __('TF.') . ''; + $table->size[6] = "50px"; $table->align[6] = 'center'; $table->head[7] = __('Last fired'); $table->align[7] = 'center'; $table->head[8] = __('Action'); - $table->size[8] = "50px"; + $table->size[8] = "80px"; $table->align[8] = 'center'; + $table->head[9] = html_print_checkbox ("all_delete_box", "1", false, true); + $table->size[9] = "10px"; + $table->align[9] = 'center'; + foreach ($result as $row) { $data = array (); $data[0] = $row["position"]; - $data[1] = '' . alerts_get_alert_action_name ($row["id_alert"]) . ''; + $url = "index.php?" . + "sec=snmpconsole&" . + "sec2=godmode/snmpconsole/snmp_alert&" . + "id_alert_snmp=" . $row["id_as"] ."&" . + "update_alert=1"; + + $data[1] = '' . + alerts_get_alert_action_name ($row["id_alert"]) . ''; $data[2] = __('SNMP Agent'); $data[2] = $row["agent"]; @@ -554,6 +719,10 @@ else { html_print_image("images/config.png", true, array("border" => '0', "alt" => __('Update'))) . '' . '  ' . html_print_image("images/cross.png", true, array("border" => '0', "alt" => __('Delete'))) . ''; + + $data[9] = html_print_checkbox_extended("delete_ids[]", + $row['id_as'], false, false, false, 'class="chk_delete"', true); + $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); @@ -561,26 +730,37 @@ else { } if (!empty ($table->data)) { + echo '
'; html_print_table ($table); + + ui_pagination ($count, $url_pagination); + + echo '
'; + html_print_input_hidden('multiple_delete', 1); + html_print_submit_button(__('Delete selected'), 'delete_button', false, 'class="sub delete"'); + echo '
'; + echo '
'; } - unset ($table); - - echo '
'; - echo '
'; + echo '
'; + echo ''; + html_print_input_hidden('create_alert', 1); html_print_submit_button (__('Create'), "add_alert", false, 'class="sub next"'); echo "
"; echo '
'; echo '

'.__('Legend').'

'; - foreach (get_priorities () as $num => $name) { - echo ''.$name.''; + foreach (get_priorities() as $num => $name) { + echo '' . $name . ''; echo '
'; } echo '
'; + + unset ($table); } ?>