2013-08-05 Miguel de Dios <miguel.dedios@artica.es>

* 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
This commit is contained in:
mdtrooper 2013-08-05 14:23:27 +00:00
parent b3e3d18741
commit 55a7a8ffa6
8 changed files with 326 additions and 94 deletions

View File

@ -1,3 +1,13 @@
2013-08-05 Miguel de Dios <miguel.dedios@artica.es>
* 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 <sergio.martin@artica.es>
* include/functions_filemanager.php: added new error message

View File

@ -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") {
$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')." &raquo; ".__('Update alert'),
"images/op_snmp.png", false, "snmp_alert", false);
}
else if ($create_alert || $save_alert) {
ui_print_page_header(__('SNMP Console')." &raquo; ".__('Create 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')." &raquo; ".__('Update alert'),
else {
ui_print_page_header(__('SNMP Console')." &raquo; ".__('Alert overview'),
"images/op_snmp.png", false, "snmp_alert", false);
}
else if (isset ($_GET["submit"])) {
ui_print_page_header (__('SNMP Console')." &raquo; ".__('Update alert'),
"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,
@ -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')." &raquo; ".__('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"];
@ -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 '<form name="agente" method="post" action="index.php?sec=snmpconsole&sec2=godmode/snmpconsole/snmp_alert&submit='.$id_as.'">';
echo '<form name="agente" method="post" action="index.php?sec=snmpconsole&sec2=godmode/snmpconsole/snmp_alert">';
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 '<tr><td class="datos">'.__('Trap type').'</td><td class="datos">';
$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 '</td></tr>';
@ -484,12 +541,108 @@ 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 name="agente" method="post" action="index.php?sec=snmpconsole&sec2=godmode/snmpconsole/snmp_alert">';
$form_filter .= html_print_input_hidden('filter', 1, true);
$form_filter .= html_print_table($table_filter, true);
$form_filter .= '<div style="text-align: right; width: ' . $table_filter->width . '">';
$form_filter .= html_print_submit_button(__('Filter'), 'filter_button', false, 'class="sub filter"', true);
$form_filter .= '</div>';
$form_filter .= '</form>';
echo "<br>";
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 "<div class='nf'>" . __('There are no SNMP alerts') . "</div>";
}
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 ();
$table->head = array ();
@ -517,21 +670,33 @@ else {
$table->head[5] = __('Description');
$table->head[6] = __('Times fired');
$table->head[6] = '<span title="' . __('Times fired') . '">' . __('TF.') . '</span>';
$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] = '<a href="index.php?sec=snmpconsole&sec2=godmode/snmpconsole/snmp_alert&update_alert='.$row["id_as"].'">' . alerts_get_alert_action_name ($row["id_alert"]) . '</a>';
$url = "index.php?" .
"sec=snmpconsole&" .
"sec2=godmode/snmpconsole/snmp_alert&" .
"id_alert_snmp=" . $row["id_as"] ."&" .
"update_alert=1";
$data[1] = '<a href="' . $url . '">' .
alerts_get_alert_action_name ($row["id_alert"]) . '</a>';
$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'))) . '</a>' .
'&nbsp;&nbsp;<a href="index.php?sec=snmpconsole&sec2=godmode/snmpconsole/snmp_alert&delete_alert='.$row["id_as"].'">' .
html_print_image("images/cross.png", true, array("border" => '0', "alt" => __('Delete'))) . '</a>';
$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,13 +730,21 @@ else {
}
if (!empty ($table->data)) {
echo '<form name="agente" method="post" action="index.php?sec=snmpconsole&sec2=godmode/snmpconsole/snmp_alert">';
html_print_table ($table);
ui_pagination ($count, $url_pagination);
echo '<div style="text-align:right; width: ' . $table->width . '; margin-bottom: 30px;">';
html_print_input_hidden('multiple_delete', 1);
html_print_submit_button(__('Delete selected'), 'delete_button', false, 'class="sub delete"');
echo '</div>';
echo '</form>';
}
unset ($table);
echo '<div style="text-align:right; width:98%">';
echo '<form name="agente" method="post" action="index.php?sec=snmpconsole&sec2=godmode/snmpconsole/snmp_alert&update_alert=-1">';
echo '<div style="text-align:right; width:' . $table->width . ';">';
echo '<form name="agente" method="post" action="index.php?sec=snmpconsole&sec2=godmode/snmpconsole/snmp_alert">';
html_print_input_hidden('create_alert', 1);
html_print_submit_button (__('Create'), "add_alert", false, 'class="sub next"');
echo "</form></div>";
@ -578,9 +755,12 @@ else {
echo '<br />';
}
echo '</div>';
unset ($table);
}
?>
<script language="javascript" type="text/javascript">
function time_changed () {
var time = this.value;
if (time == -1) {
@ -593,15 +773,35 @@ function time_changed () {
$(document).ready (function () {
$('#time_threshold').change (time_changed);
$("input[name=all_delete_box]").change (function() {
if ($(this).is(":checked")) {
$("input[name='delete_ids[]']").check();
}
else {
$("input[name='delete_ids[]']").uncheck();
}
});
$("#alert_type").change (function () {
values = Array ();
values.push ({name: "page",
value: "godmode/alerts/alert_commands"});
values.push ({name: "get_alert_command",
value: "1"});
values.push ({name: "id_action",
value: this.value});
jQuery.get (<?php echo "'" . ui_get_full_url("ajax.php", false, false, false) . "'"; ?>,
values.push ({
name: "page",
value: "godmode/alerts/alert_commands"
});
values.push ({
name: "get_alert_command",
value: "1"
});
values.push ({
name: "id_action",
value: this.value
});
jQuery.get (
<?php
echo "'" . ui_get_full_url("ajax.php", false, false, false) . "'";
?>,
values,
function (data, status) {
original_command = js_html_entity_decode (data["command"]);
@ -609,7 +809,10 @@ $(document).ready (function () {
for (i = 1; i <= 10; i++) {
var old_value = '';
// Only keep the value if is provided from hidden (first time)
if ($("[name=field"+i+"_value]").attr('id') == "hidden-field" + i + "_value") {
var id_field = $("[name=field" + i + "_value]").attr('id');
if (id_field == "hidden-field" + i + "_value") {
old_value = $("[name=field" + i + "_value]").val();
}
@ -618,15 +821,24 @@ $(document).ready (function () {
$('#table_macros-field' + i).hide();
}
else {
$('#table_macros-field'+i).replaceWith(data["fields_rows"][i]);
$('#table_macros-field' + i)
.replaceWith(data["fields_rows"][i]);
// The row provided has a predefined class. We delete it
$('#table_macros-field'+i).removeAttr('class');
$('#table_macros-field' + i)
.removeAttr('class');
// Add help hint only in first field
if (i == 1) {
var td_content = $('#table_macros-field'+i).find('td').eq(0);
td_content.html(td_content.html() + $('#help_snmp_alert_hint').html());
var td_content =
$('#table_macros-field' + i)
.find('td').eq(0);
td_content
.html(
td_content.html() +
$('#help_snmp_alert_hint').html()
);
}
$("[name=field" + i + "_value]").val(old_value);

View File

@ -262,6 +262,13 @@ define ('MODULE_PREDICTION_NETFLOW', 4);
/* SNMP CONSTANTS */
define ('SNMP_DIR_MIBS', "attachment/mibs");
define('SNMP_TRAP_TYPE_NONE', -1);
define('SNMP_TRAP_TYPE_COLD_START', 0);
define('SNMP_TRAP_TYPE_WARM_START', 1);
define('SNMP_TRAP_TYPE_LINK_DOWN', 2);
define('SNMP_TRAP_TYPE_LINK_UP', 3);
define('SNMP_TRAP_TYPE_AUTHENTICATION_FAILURE', 4);
define('SNMP_TRAP_TYPE_OTHER', 5);
/* PASSWORD POLICIES */
define('PASSSWORD_POLICIES_OK', 0);

View File

@ -70,7 +70,10 @@ function mysql_db_get_all_rows_sql ($sql, $search_history_db = false, $cache = t
$history = array ();
}
}
$return = mysql_db_process_sql ($sql, 'affected_rows', $dbconnection, $cache);
$return = mysql_db_process_sql ($sql,
'affected_rows', $dbconnection, $cache);
if ($return === false) {
$return = array ();
}

View File

@ -176,15 +176,15 @@ foreach ($result as $event) {
// Colored box
switch($estado) {
case 0:
case EVENT_NEW:
$img_st = "images/star.png";
$title_st = __('New event');
break;
case 1:
case EVENT_VALIDATE:
$img_st = "images/tick.png";
$title_st = __('Event validated');
break;
case 2:
case EVENT_PROCESS:
$img_st = "images/hourglass.png";
$title_st = __('Event in process');
break;