diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index cb3eac40f3..968e38a153 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,15 @@ +2014-03-18 Vanessa Gil + + * pandoradb.oracle.sql + pandoradb.postgreSQL.sql + pandoradb.sql + extras/pandoradb_migrate_5.0_to_5.1.mysql.sql + extras/pandoradb_migrate_5.0_to_5.1.oracle.sql + extras/pandoradb_migrate_5.0_to_5.1.postgreSQL.sql + godmode/snmpconsole/snmp_alert.php + godmode/snmpconsole/snmp_view.php: Improved ACLs in + SNMP Traps. + 2014-03-18 Miguel de Dios * godmode/agentes/configurar_agente.php, diff --git a/pandora_console/extras/pandoradb_migrate_5.0.x_to_5.1.mysql.sql b/pandora_console/extras/pandoradb_migrate_5.0.x_to_5.1.mysql.sql index 6332a7c4e5..6782f554dc 100644 --- a/pandora_console/extras/pandoradb_migrate_5.0.x_to_5.1.mysql.sql +++ b/pandora_console/extras/pandoradb_migrate_5.0.x_to_5.1.mysql.sql @@ -57,3 +57,8 @@ CREATE TABLE IF NOT EXISTS `tmodule_relationship` ( FOREIGN KEY (`module_b`) REFERENCES tagente_modulo(`id_agente_modulo`) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +-- --------------------------------------------------------------------- +-- Table `talert_snmp` +-- --------------------------------------------------------------------- +ALTER TABLE `talert_snmp` ADD COLUMN `id_group` int(10) unsigned NOT NULL default '0'; diff --git a/pandora_console/extras/pandoradb_migrate_5.0.x_to_5.1.oracle.sql b/pandora_console/extras/pandoradb_migrate_5.0.x_to_5.1.oracle.sql index 6c7829b775..8faeb2b47b 100644 --- a/pandora_console/extras/pandoradb_migrate_5.0.x_to_5.1.oracle.sql +++ b/pandora_console/extras/pandoradb_migrate_5.0.x_to_5.1.oracle.sql @@ -47,3 +47,8 @@ CREATE TABLE IF NOT EXISTS tmodule_relationship ( CREATE SEQUENCE tmodule_relationship_s INCREMENT BY 1 START WITH 1; CREATE OR REPLACE TRIGGER tmodule_relationship_inc BEFORE INSERT ON tmodule_relationship REFERENCING NEW AS NEW FOR EACH ROW BEGIN SELECT tmodule_relationship_s.nextval INTO :NEW.ID FROM dual; END;; + +-- --------------------------------------------------------------------- +-- Table `talert_snmp` +-- --------------------------------------------------------------------- +ALTER TABLE talert_snmp ADD (id_group NUMBER(10, 0) default 0 NOT NULL); diff --git a/pandora_console/extras/pandoradb_migrate_5.0.x_to_5.1.postgreSQL.sql b/pandora_console/extras/pandoradb_migrate_5.0.x_to_5.1.postgreSQL.sql index f2f286e9b5..b279b74d42 100644 --- a/pandora_console/extras/pandoradb_migrate_5.0.x_to_5.1.postgreSQL.sql +++ b/pandora_console/extras/pandoradb_migrate_5.0.x_to_5.1.postgreSQL.sql @@ -44,3 +44,8 @@ CREATE TABLE "tmodule_relationship" ( ON DELETE CASCADE, "disable_update" SMALLINT NOT NULL default 0 ); + +-- --------------------------------------------------------------------- +-- Table "talert_snmp" +-- --------------------------------------------------------------------- +ALTER TABLE "talert_snmp" ADD COLUMN "id_group" INTEGER NOT NULL default 0; diff --git a/pandora_console/godmode/snmpconsole/snmp_alert.php b/pandora_console/godmode/snmpconsole/snmp_alert.php index d6e6b4aabc..3568cacc32 100644 --- a/pandora_console/godmode/snmpconsole/snmp_alert.php +++ b/pandora_console/godmode/snmpconsole/snmp_alert.php @@ -91,6 +91,7 @@ if ($save_alert || $modify_alert) { $trap_type = (int) get_parameter ("trap_type", -1); $single_value = (string) get_parameter ("single_value"); $position = (int) get_parameter ("position"); + $group = (int) get_parameter ("group"); if ($time_threshold == -1) { $time_threshold = $time_other; @@ -129,7 +130,8 @@ if ($save_alert || $modify_alert) { '_snmp_f10_' => $custom_oid_data_10, 'trap_type' => $trap_type, 'single_value' => $single_value, - 'position' => $position); + 'position' => $position, + 'id_group' => $group); $result = db_process_sql_insert('talert_snmp', $values); @@ -156,7 +158,7 @@ if ($save_alert || $modify_alert) { _snmp_f4_ = '%s', _snmp_f5_ = '%s', _snmp_f6_ = '%s', _snmp_f7_ = '%s', _snmp_f8_ = '%s', _snmp_f9_ = '%s', _snmp_f10_ = '%s', trap_type = %d, single_value = '%s', - position = '%s' + position = '%s', id_group ='%s' WHERE id_as = %d", $priority, $alert_type, $al_field1, $al_field2, $al_field3, $al_field4, $al_field5, $al_field6, $al_field7, $al_field8, @@ -166,8 +168,8 @@ if ($save_alert || $modify_alert) { $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); - + $position, $group, $id_as); + $result = db_process_sql ($sql); if (!$result) { @@ -220,6 +222,7 @@ if ($update_alert) { $trap_type = $alert["trap_type"]; $single_value = $alert["single_value"]; $position = $alert["position"]; + $group = $alert["id_group"]; } elseif ($create_alert) { // Variable init @@ -256,6 +259,7 @@ elseif ($create_alert) { $trap_type = -1; $single_value = ''; $position = 0; + $group = 0; } // Header @@ -305,6 +309,18 @@ if ($multiple_delete) { } } +$user_groups = users_get_groups($config['id_user'],"AR", true); +$str_user_groups = ''; +$i = 0; +foreach ($user_groups as $id=>$name) { + if ($i == 0) { + $str_user_groups .= $id; + } else { + $str_user_groups .= ','.$id; + } + $i++; +} + // Alert form if ($create_alert || $update_alert) { //if (isset ($_GET["update_alert"])) { @@ -352,6 +368,11 @@ if ($create_alert || $update_alert) { html_print_input_text ("source_ip", $source_ip, '', 20); echo ''; + // Group + echo ''.__('Group').''; + html_print_select ($user_groups, "group", $group); + echo ''; + // Trap type echo ''.__('Trap type').''; echo html_print_select ($trap_types, 'trap_type', $trap_type, '', '', '', false, false, false); @@ -610,8 +631,8 @@ else { "priority_filter=" . $priority_filter . "&" . "offset=" . $offset; } - - $where_sql = ' 1 = 1'; + + //$where_sql = ' 1 = 1'; if ($trap_type_filter != SNMP_TRAP_TYPE_NONE) { $where_sql .= ' AND `trap_type` = ' . $trap_type_filter; } @@ -638,10 +659,9 @@ else { OR `description` LIKE '%" . $free_search . "%')"; } - $count = db_get_value_sql('SELECT COUNT(*) - FROM talert_snmp WHERE' . $where_sql); - - + $count = db_get_value_sql("SELECT COUNT(*) + FROM talert_snmp WHERE id_group IN ($str_user_groups) " . $where_sql); + $result = array(); //Overview @@ -653,8 +673,9 @@ 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); + $result = db_get_all_rows_sql("SELECT * + FROM talert_snmp + WHERE id_group IN ($str_user_groups) " . $where_sql); } $table = new stdClass(); diff --git a/pandora_console/operation/snmpconsole/snmp_view.php b/pandora_console/operation/snmpconsole/snmp_view.php index e9bc4db328..c5191ca5ea 100644 --- a/pandora_console/operation/snmpconsole/snmp_view.php +++ b/pandora_console/operation/snmpconsole/snmp_view.php @@ -43,6 +43,18 @@ $offset = (int) get_parameter ('offset',0); $trap_type = (int) get_parameter ('trap_type', -1); $group_by = (int) get_parameter('group_by', 0); +$user_groups = users_get_groups ($config['id_user'],"AR", false); +$str_user_groups = ''; +$i = 0; +foreach ($user_groups as $id=>$name) { + if ($i == 0) { + $str_user_groups .= $id; + } else { + $str_user_groups .= ','.$id; + } + $i++; +} + $url = "index.php?sec=estado&sec2=operation/snmpconsole/snmp_view&filter_agent=".$filter_agent."&filter_oid=".$filter_oid."&filter_severity=".$filter_severity."&filter_fired=".$filter_fired."&search_string=".$search_string."&free_search_string=".$free_search_string."&pagination=".$pagination."&offset=".$offset . "&trap_type=" . $trap_type ."&group_by=" .$group_by; @@ -128,6 +140,11 @@ switch ($config["dbtype"]) { $sql = sprintf (" SELECT * FROM ttrap + WHERE `source` IN ( + SELECT direccion FROM tagente + WHERE id_grupo IN ($str_user_groups) + ) + OR `source`='' ORDER BY timestamp DESC LIMIT %d,%d",$offset,$pagination); break; @@ -135,8 +152,13 @@ switch ($config["dbtype"]) { $sql = sprintf (" SELECT * FROM ttrap + WHERE `source` IN ( + SELECT direccion FROM tagente + WHERE id_grupo IN ($str_user_groups) + ) + OR `source`='' ORDER BY timestamp DESC - LIMIT %d OFFSET %d", $pagination, $offset); + LIMIT %d OFFSET %d",$pagination, $offset); break; case "oracle": $set = array(); @@ -145,13 +167,24 @@ switch ($config["dbtype"]) { $sql = sprintf (" SELECT * FROM ttrap + WHERE `source` IN ( + SELECT direccion FROM tagente + WHERE id_grupo IN ($str_user_groups) + ) + OR `source`='' ORDER BY timestamp DESC"); $sql = oracle_recode_query ($sql, $set); break; } + $traps = db_get_all_rows_sql ($sql); // All traps -$all_traps = db_get_all_rows_sql ("SELECT DISTINCT source FROM ttrap"); +$all_traps = db_get_all_rows_sql ("SELECT DISTINCT source FROM ttrap + WHERE `source` IN ( + SELECT direccion FROM tagente + WHERE id_grupo IN ($str_user_groups) + ) + OR `source`=''"); if (($config['dbtype'] == 'oracle') && ($traps !== false)) { for ($i=0; $i < count($traps); $i++) { @@ -188,27 +221,41 @@ foreach ($all_traps as $trap) { //Make query to extract traps of DB. switch ($config["dbtype"]) { case "mysql": - $sql = " - SELECT * - FROM ttrap %s + $sql = "SELECT * + FROM ttrap + WHERE `source` IN ( + SELECT direccion FROM tagente + WHERE id_grupo IN ($str_user_groups) + ) + OR `source`='' %s ORDER BY timestamp DESC LIMIT %d,%d"; break; case "postgresql": - $sql = " - SELECT * - FROM ttrap %s + $sql = "SELECT * + FROM ttrap + WHERE source IN ( + SELECT direccion FROM tagente + WHERE id_grupo IN ($str_user_groups) + ) + OR source='' %s ORDER BY timestamp DESC LIMIT %d OFFSET %d"; break; case "oracle": - $sql = " - SELECT * - FROM ttrap %s - ORDER BY timestamp DESC"; + $sql = "SELECT * + FROM ttrap + WHERE source IN ( + SELECT direccion FROM tagente + WHERE id_grupo IN ($str_user_groups) + ) + OR source='' %s + ORDER BY timestamp DESC + LIMIT %d OFFSET %d"; break; } -$whereSubquery = 'WHERE 1=1'; +//$whereSubquery = 'WHERE 1=1'; +$whereSubquery = ''; if ($filter_agent != '') { switch ($config["dbtype"]) { @@ -479,6 +526,7 @@ $table->style[7] = "background: #F3F3F3; color: #111 !important;"; // Skip offset records $idx = 0; if ($traps !== false) { + foreach ($traps as $trap) { $data = array (); if (empty($trap["description"])){ @@ -513,7 +561,7 @@ if ($traps !== false) { $data[1] = ''; $data[1] .= ''.$agent["nombre"].''; } - + //OID $table->cellclass[$idx][2] = get_priority_class ($severity); $data[2] = '' . (empty($trap["oid"]) ? __('N/A') : $trap["oid"]) .''; @@ -558,15 +606,24 @@ if ($traps !== false) { if (empty ($trap["status"]) && check_acl ($config["id_user"], 0, "IW")) { $data[7] .= '' . html_print_image("images/ok.png", true, array("border" => '0', "title" => __('Validate'))) . ' '; } - if (check_acl ($config["id_user"], 0, "IM")) { - $data[7] .= '' . html_print_image("images/cross.png", true, array("border" => "0", "title" => __('Delete'))) . ' '; + if ($trap['source'] == '') { + $is_admin = db_get_value('is_admin', 'tusuario', 'id_user',$config['id_user']); + if ($is_admin) { + $data[7] .= '' . html_print_image("images/cross.png", true, array("border" => "0", "title" => __('Delete'))) . ' '; + } + } else { + $agent_trap_group = db_get_value('id_grupo', 'tagente', 'nombre', $trap['source']); + if ((check_acl ($config["id_user"], $agent_trap_group, "AW"))) { + $data[7] .= '' . html_print_image("images/cross.png", true, array("border" => "0", "title" => __('Delete'))) . ' '; + } } + $data[7] .= '' . html_print_image("images/eye.png", true, array("alt" => __('Show more'), "title" => __('Show more'))) .''; $data[7] .= enterprise_hook ('editor_link', array ($trap)); $data[8] = html_print_checkbox_extended ("snmptrapid[]", $trap["id_trap"], false, false, '', 'class="chk"', true); - + array_push ($table->data, $data); //Hiden file for description @@ -623,23 +680,26 @@ if ($traps !== false) { } $string .= '' . '' . __('Type:') . '' . $desc_trap_type . ''; } - + if ($group_by) { - $sql = "SELECT * FROM ttrap $where_without_group + $sql = "SELECT * FROM ttrap WHERE 1=1 + $where_without_group AND oid='".$trap['oid']."' - AND `source`='".$trap['source']."'"; + AND source='".$trap['source']."'"; $group_traps = db_get_all_rows_sql($sql); $count_group_traps = count($group_traps); - $sql = "SELECT `timestamp` FROM ttrap $where_without_group + $sql = "SELECT timestamp FROM ttrap WHERE 1=1 + $where_without_group AND oid='".$trap['oid']."' - AND `source`='".$trap['source']."' + AND source='".$trap['source']."' ORDER BY `timestamp` DESC"; $last_trap = db_get_value_sql($sql); - $sql = "SELECT `timestamp` FROM ttrap $where_without_group + $sql = "SELECT timestamp FROM ttrap WHERE 1=1 + $where_without_group AND oid='".$trap['oid']."' - AND `source`='".$trap['source']."' + AND source='".$trap['source']."' ORDER BY `timestamp` ASC"; $first_trap = db_get_value_sql($sql); @@ -655,6 +715,7 @@ if ($traps !== false) { ' . '' . __('Last trap:') . ' ' . $last_trap . ' '; + } $string .= ''; diff --git a/pandora_console/pandoradb.oracle.sql b/pandora_console/pandoradb.oracle.sql index 26e259af0e..31872db22f 100644 --- a/pandora_console/pandoradb.oracle.sql +++ b/pandora_console/pandoradb.oracle.sql @@ -306,7 +306,8 @@ CREATE TABLE talert_snmp ( _snmp_f10_ CLOB default '', trap_type NUMBER(10, 0) DEFAULT -1 NOT NULL, single_value VARCHAR2(255) DEFAULT '', - "position" NUMBER(10, 0) default 0 NOT NULL + "position" NUMBER(10, 0) default 0 NOT NULL, + id_group NUMBER(10, 0) default 0 NOT NULL ); CREATE SEQUENCE talert_snmp_s INCREMENT BY 1 START WITH 1; diff --git a/pandora_console/pandoradb.postgreSQL.sql b/pandora_console/pandoradb.postgreSQL.sql index dac6f866b8..0966cca543 100644 --- a/pandora_console/pandoradb.postgreSQL.sql +++ b/pandora_console/pandoradb.postgreSQL.sql @@ -289,7 +289,8 @@ CREATE TABLE "talert_snmp" ( "_snmp_f10_" text DEFAULT '', "trap_type" INTEGER NOT NULL DEFAULT '-1', "single_value" varchar(255) DEFAULT '', - "position" INTEGER NOT NULL default 0 + "position" INTEGER NOT NULL default 0, + "id_group" INTEGER NOT NULL default 0 ); CREATE TABLE "talert_commands" ( diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index bd0a748d1d..bc8bdb5aec 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -296,6 +296,7 @@ CREATE TABLE IF NOT EXISTS `talert_snmp` ( `trap_type` int(11) NOT NULL default '-1', `single_value` varchar(255) default '', `position` int(10) unsigned NOT NULL default '0', + `id_group` int(10) unsigned NOT NULL default '0', PRIMARY KEY (`id_as`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;