diff --git a/pandora_console/extensions/module_groups.php b/pandora_console/extensions/module_groups.php index 60f72ae20d..b73c91a931 100644 --- a/pandora_console/extensions/module_groups.php +++ b/pandora_console/extensions/module_groups.php @@ -153,7 +153,7 @@ function mainModuleGroups() { GROUP BY estado, utimestamp"; break; case "oracle": - $sql = "SELECT COUNT(id_agente) AS count, case when utimestamp = 0 then 5 else estado end estado + $sql = "SELECT COUNT(id_agente) AS count, (case when utimestamp = 0 then 5 else estado end) AS estado FROM tagente_estado WHERE id_agente IN (SELECT id_agente FROM tagente WHERE id_grupo = %d AND (disabled IS NOT NULL AND disabled <> 0)) @@ -161,7 +161,7 @@ function mainModuleGroups() { (SELECT id_agente_modulo FROM tagente_modulo WHERE id_module_group = %d AND (disabled IS NOT NULL AND disabled <> 0) AND (delete_pending IS NOT NULL AND delete_pending <> 0)) - GROUP BY estado"; + GROUP BY (case when utimestamp = 0 then 5 else estado end)"; break; } diff --git a/pandora_console/godmode/agentes/agent_manager.php b/pandora_console/godmode/agentes/agent_manager.php index 5aa6367e81..950e75e970 100644 --- a/pandora_console/godmode/agentes/agent_manager.php +++ b/pandora_console/godmode/agentes/agent_manager.php @@ -33,7 +33,7 @@ if (is_ajax ()) { $filter[] = '(nombre COLLATE utf8_general_ci LIKE "%' . $string . '%" OR direccion LIKE "%'.$string.'%" OR comentarios LIKE "%'.$string.'%")'; break; case "oracle": - $filter[] = '(upper(nombre) LIKE upper("%' . $string . '%") OR upper(direccion) LIKE upper("%'.$string.'%") OR upper(comentarios) LIKE upper("%'.$string.'%"))'; + $filter[] = '(upper(nombre) LIKE upper(\'%'.$string.'%\') OR upper(direccion) LIKE upper(\'%'.$string.'%\') OR upper(comentarios) LIKE upper(\'%'.$string.'%\'))'; break; } $filter[] = 'id_agente != ' . $id_agent; diff --git a/pandora_console/include/class/Tree.class.php b/pandora_console/include/class/Tree.class.php index 0268eba87f..6c198f03dc 100644 --- a/pandora_console/include/class/Tree.class.php +++ b/pandora_console/include/class/Tree.class.php @@ -192,6 +192,8 @@ class Tree { } protected function getAgentCountersSql ($agent_table) { + global $config; + $columns = $this->getAgentCounterColumnsSql($agent_table); switch ($config["dbtype"]) { @@ -203,7 +205,7 @@ class Tree { $columns = "SELECT $columns FROM dual WHERE rownum <= 1"; break; } - + return $columns; } @@ -320,15 +322,13 @@ class Tree { switch ($rootType) { case 'group': // ACL Group + $user_groups_str = "-1"; $group_acl = ""; if (!$this->strictACL) { if (!empty($this->userGroups)) { $user_groups_str = implode(",", array_keys($this->userGroups)); - $group_acl = "AND ta.id_grupo IN ($user_groups_str)"; - } - else { - $group_acl = "AND ta.id_grupo = -1"; } + $group_acl = "AND ta.id_grupo IN ($user_groups_str)"; } else { if (!empty($this->acltags)) { @@ -342,16 +342,10 @@ class Tree { if (!empty($groups)) { if (array_search(0, $groups) === false) { $user_groups_str = implode(",", $groups); - $group_acl = " AND ta.id_grupo IN ($user_groups_str) "; } } - else { - $group_acl = "AND ta.id_grupo = -1"; - } - } - else { - $group_acl = "AND ta.id_grupo = -1"; } + $group_acl = "AND ta.id_grupo IN ($user_groups_str)"; } switch ($type) { @@ -365,63 +359,50 @@ class Tree { $order_fields = 'tg.nombre ASC, tg.id_grupo ASC'; if (! defined('METACONSOLE')) { - // Add the agent counters to the columns - $agent_table = "SELECT COUNT(DISTINCT(ta.id_agente)) - FROM tagente ta - LEFT JOIN tagente_modulo tam - ON tam.disabled = 0 - AND ta.id_agente = tam.id_agente - $module_search_filter - $module_status_join - WHERE ta.disabled = 0 - AND ta.id_grupo = tg.id_grupo - $group_acl - $agent_search_filter - $agent_status_filter"; - $counter_columns = $this->getAgentCounterColumnsSql($agent_table); - if (!empty($counter_columns)) - $columns .= ", $counter_columns"; - - $sql = "SELECT $columns - FROM tgrupo tg - LEFT JOIN tagente ta - LEFT JOIN tagente_modulo tam - ON tam.disabled = 0 - AND ta.id_agente = tam.id_agente - $module_search_filter - $module_status_join - ON ta.disabled = 0 - AND tg.id_grupo = ta.id_grupo - $group_acl - $agent_search_filter - $agent_status_filter - GROUP BY tg.id_grupo - ORDER BY $order_fields"; + // Groups SQL + if ($item_for_count === false) { + $sql = "SELECT $columns + FROM tgrupo tg + WHERE tg.id_grupo IN ($user_groups_str) + ORDER BY $order_fields"; + } + // Counters SQL + else { + $agent_table = "SELECT COUNT(DISTINCT(ta.id_agente)) + FROM tagente ta + LEFT JOIN tagente_modulo tam + ON tam.disabled = 0 + AND ta.id_agente = tam.id_agente + $module_search_filter + $module_status_join + WHERE ta.disabled = 0 + AND ta.id_grupo = $item_for_count + $group_acl + $agent_search_filter + $agent_status_filter"; + $sql = $this->getAgentCountersSql($agent_table); + } } // Metaconsole else { - // Add the agent counters to the columns - $agent_table = "SELECT COUNT(DISTINCT(ta.id_agente)) - FROM tmetaconsole_agent ta - WHERE ta.disabled = 0 - AND ta.id_grupo = tg.id_grupo - $group_acl - $agent_search_filter - $agent_status_filter"; - $counter_columns = $this->getAgentCounterColumnsSql($agent_table); - if (!empty($counter_columns)) - $columns .= ", $counter_columns"; - - $sql = "SELECT $columns - FROM tgrupo tg - LEFT JOIN tagente ta - ON ta.disabled = 0 - AND tg.id_grupo = ta.id_grupo - $group_acl - $agent_search_filter - $agent_status_filter - GROUP BY tg.id_grupo - ORDER BY $order_fields"; + // Groups SQL + if ($item_for_count === false) { + $sql = "SELECT $columns + FROM tgrupo tg + WHERE tg.id_grupo IN ($user_groups_str) + ORDER BY $order_fields"; + } + // Counters SQL + else { + $agent_table = "SELECT COUNT(DISTINCT(ta.id_agente)) + FROM tmetaconsole_agent ta + WHERE ta.disabled = 0 + AND ta.id_grupo = $item_for_count + $group_acl + $agent_search_filter + $agent_status_filter"; + $sql = $this->getAgentCountersSql($agent_table); + } } } else { @@ -444,7 +425,6 @@ class Tree { $group_acl $agent_search_filter $agent_status_filter - GROUP BY ta.id_agente ORDER BY $order_fields"; } else { @@ -461,7 +441,6 @@ class Tree { $group_acl $agent_search_filter $agent_status_filter - GROUP BY ta.id_tagente ORDER BY $order_fields"; } } @@ -1962,6 +1941,13 @@ class Tree { foreach ($items as $key => $item) { if (empty($item['parent'])) { + $counters = $this->getCounters($item['id']); + if (!empty($counters)) { + foreach ($counters as $type => $value) { + $item[$type] = $value; + } + } + unset($items[$key]); $items_tmp = array(); $processed_item = $this->getProcessedItem($item, false, $items, $items_tmp, true); diff --git a/pandora_console/include/functions_networkmap.php b/pandora_console/include/functions_networkmap.php index a1e0f9c2cf..293449e208 100644 --- a/pandora_console/include/functions_networkmap.php +++ b/pandora_console/include/functions_networkmap.php @@ -253,7 +253,7 @@ function networkmap_generate_dot ($pandora_name, $group = 0, break; case "oracle": $filter[] = - '(upper(nombre) LIKE upper("%' . $text_filter . '%"))'; + '(upper(nombre) LIKE upper(\'%' . $text_filter . '%\'))'; break; } } @@ -663,7 +663,7 @@ function networkmap_generate_dot_groups ($pandora_name, $group = 0, break; case "oracle": $filter[] = - '(upper(nombre) LIKE upper("%' . $text_filter . '%"))'; + '(upper(nombre) LIKE upper(\'%' . $text_filter . '%\'))'; break; } } diff --git a/pandora_console/include/functions_tags.php b/pandora_console/include/functions_tags.php index 8f68a283ac..db61e8e8a3 100644 --- a/pandora_console/include/functions_tags.php +++ b/pandora_console/include/functions_tags.php @@ -923,14 +923,29 @@ function tags_get_user_tags($id_user = false, $access = 'AR') { return array(); } - $query = sprintf(" - SELECT count(*) - FROM tusuario_perfil, tperfil - WHERE tperfil.id_perfil = tusuario_perfil.id_perfil - AND tusuario_perfil.id_usuario = '%s' - AND tperfil.%s = 1 - AND tags <> ''", - $id_user, $acl_column); + switch ($config["dbtype"]) { + case "mysql": + case "postgresql": + $query = sprintf(" + SELECT count(*) + FROM tusuario_perfil, tperfil + WHERE tperfil.id_perfil = tusuario_perfil.id_perfil + AND tusuario_perfil.id_usuario = '%s' + AND tperfil.%s = 1 + AND tags <> ''", + $id_user, $acl_column); + break; + case "oracle": + $query = sprintf(" + SELECT count(*) + FROM tusuario_perfil, tperfil + WHERE tperfil.id_perfil = tusuario_perfil.id_perfil + AND tusuario_perfil.id_usuario = '%s' + AND tperfil.%s = 1 + AND dbms_lob.getlength(tags) > 0", + $id_user, $acl_column); + break; + } $profiles_without_tags = db_get_value_sql($query); diff --git a/pandora_console/operation/agentes/status_monitor.php b/pandora_console/operation/agentes/status_monitor.php index d802fd2fd0..006d4d00ae 100644 --- a/pandora_console/operation/agentes/status_monitor.php +++ b/pandora_console/operation/agentes/status_monitor.php @@ -289,7 +289,7 @@ switch ($config["dbtype"]) { $profiles = db_get_all_rows_sql('SELECT id_grupo FROM tusuario_perfil AS t1 INNER JOIN tperfil AS t2 ON t1.id_perfil = t2.id_perfil - WHERE t2.agent_view = 1 AND t1.id_usuario = \'' . $config['id_user'] . '\';'); + WHERE t2.agent_view = 1 AND t1.id_usuario = \'' . $config['id_user'] . '\''); if ($profiles === false) $profiles = array(); @@ -305,14 +305,14 @@ switch ($config["dbtype"]) { //The check of is_admin $flag_is_admin = (bool)db_get_value('is_admin', 'tusuario', 'id_user', $config['id_user']); - $sql = ' SELECT distinct(tagente_modulo.nombre) + $sql = 'SELECT distinct(tagente_modulo.nombre) '. $sql_from . $sql_conditions_acl; break; case "oracle": $profiles = db_get_all_rows_sql('SELECT id_grupo FROM tusuario_perfil t1 INNER JOIN tperfil t2 ON t1.id_perfil = t2.id_perfil - WHERE t2.agent_view = 1 AND t1.id_usuario = \'' . $config['id_user'] . '\';'); + WHERE t2.agent_view = 1 AND t1.id_usuario = \'' . $config['id_user'] . '\''); if ($profiles === false) $profiles = array(); @@ -329,7 +329,7 @@ switch ($config["dbtype"]) { $flag_is_admin = (bool)db_get_value('is_admin', 'tusuario', 'id_user', $config['id_user']); - $sql = ' SELECT DISTINCT dbms_lob.substr(nombre,4000,1) AS nombre' . + $sql = 'SELECT DISTINCT(tagente_modulo.nombre)' . $sql_from . $sql_conditions_acl; break; } @@ -783,7 +783,7 @@ switch ($config["dbtype"]) { $set['limit'] = $limit_sql; $set['offset'] = $offset; $sql = "SELECT - (SELECT wmsys.wm_concat(ttag.name) + (SELECT LISTAGG(ttag.name, ',') WITHIN GROUP (ORDER BY ttag.name) FROM ttag WHERE ttag.id_tag IN ( SELECT ttag_module.id_tag diff --git a/pandora_console/operation/snmpconsole/snmp_statistics.php b/pandora_console/operation/snmpconsole/snmp_statistics.php index 26f4078206..ad7b63bfff 100755 --- a/pandora_console/operation/snmpconsole/snmp_statistics.php +++ b/pandora_console/operation/snmpconsole/snmp_statistics.php @@ -74,17 +74,36 @@ if (!empty($user_groups)) { $last_month_timestamp = date("Y-m-d H:i:s", time() - SECONDS_1MONTH); -$sql_traps_generated = "SELECT %s, COUNT(id_trap) AS num - FROM ttrap - WHERE timestamp >= '%s' - AND (source = '' - OR source NOT IN (SELECT direccion FROM tagente) - OR source IN (SELECT direccion - FROM tagente - WHERE id_grupo IN (%s))) - GROUP BY %s - ORDER BY num DESC, timestamp DESC - LIMIT 25"; +switch ($config["dbtype"]) { + case "mysql": + case "postgresql": + $sql_traps_generated = "SELECT %s, COUNT(id_trap) AS num, MAX(timestamp) AS timestamp + FROM ttrap + WHERE timestamp >= '%s' + AND (source = '' + OR source NOT IN (SELECT direccion FROM tagente) + OR source IN (SELECT direccion + FROM tagente + WHERE id_grupo IN (%s))) + GROUP BY %s + ORDER BY num DESC, timestamp DESC + LIMIT 25"; + break; + case "oracle": + // MAX(timestamp) AS timestamp is needed to do the magic with oracle + $sql_traps_generated = "SELECT %s, COUNT(id_trap) AS num, MAX(timestamp) AS timestamp + FROM ttrap + WHERE timestamp >= '%s' + AND (source = '' + OR source NOT IN (SELECT direccion FROM tagente) + OR source IN (SELECT direccion + FROM tagente + WHERE id_grupo IN (%s))) + GROUP BY %s + ORDER BY num DESC, timestamp DESC"; + $sql_traps_generated = "SELECT * FROM ($sql_traps_generated) WHERE rownum <= 25"; + break; +} $sql_traps_generated_by_source = sprintf($sql_traps_generated, "source", $last_month_timestamp, $user_groups_str, "source"); $sql_traps_generated_by_oid = sprintf($sql_traps_generated, "oid", $last_month_timestamp, $user_groups_str, "oid"); diff --git a/pandora_console/operation/snmpconsole/snmp_view.php b/pandora_console/operation/snmpconsole/snmp_view.php index 1b6a9829a3..aa9211fbe3 100755 --- a/pandora_console/operation/snmpconsole/snmp_view.php +++ b/pandora_console/operation/snmpconsole/snmp_view.php @@ -181,7 +181,6 @@ switch ($config["dbtype"]) { LIMIT %d,%d"; break; case "postgresql": - case "oracle": $sql = "SELECT * FROM ttrap WHERE (source IN ( @@ -191,6 +190,15 @@ switch ($config["dbtype"]) { ORDER BY timestamp DESC LIMIT %d OFFSET %d"; break; + case "oracle": + $sql = "SELECT * + FROM ttrap + WHERE (source IN ( + SELECT direccion FROM tagente + WHERE id_grupo IN ($str_user_groups) + ) OR source='' OR source NOT IN (SELECT direccion FROM tagente)) %s + ORDER BY timestamp DESC"; + break; } $sql_all = "SELECT * FROM ttrap @@ -279,6 +287,7 @@ switch ($config["dbtype"]) { $set = array(); $set['limit'] = $pagination; $set['offset'] = $offset; + $sql = sprintf($sql, $whereSubquery); $sql = oracle_recode_query ($sql, $set); break; } diff --git a/pandora_console/pandoradb.oracle.sql b/pandora_console/pandoradb.oracle.sql index 04e33c9209..2b60a1d3cb 100755 --- a/pandora_console/pandoradb.oracle.sql +++ b/pandora_console/pandoradb.oracle.sql @@ -193,7 +193,7 @@ CREATE TABLE tagente_modulo ( id_tipo_modulo NUMBER(10, 0) DEFAULT 0, descripcion CLOB DEFAULT '', extended_info CLOB DEFAULT '', - nombre CLOB DEFAULT '', + nombre VARCHAR2(4000) DEFAULT '', unit VARCHAR2(100) DEFAULT '', id_policy_module NUMBER(10, 0) DEFAULT 0, max NUMBER(19, 0) DEFAULT 0, @@ -221,7 +221,7 @@ CREATE TABLE tagente_modulo ( max_timeout NUMBER(10, 0) DEFAULT 0, max_retries NUMBER(10, 0) DEFAULT 0, custom_id VARCHAR2(255) DEFAULT '', - history_data NUMBER(5, 0) DEFAULT 1, + history_data NUMBER(5, 0) DEFAULT 1, min_warning BINARY_DOUBLE DEFAULT 0, max_warning BINARY_DOUBLE DEFAULT 0, str_warning CLOB DEFAULT '', @@ -974,8 +974,8 @@ CREATE OR REPLACE TRIGGER ttipo_modulo_inc BEFORE INSERT ON ttipo_modulo REFEREN CREATE TABLE ttrap ( id_trap NUMBER(19, 0) PRIMARY KEY, source VARCHAR2(50) DEFAULT '', - oid CLOB DEFAULT '', - oid_custom CLOB DEFAULT '', + oid VARCHAR2(1024) DEFAULT '', + oid_custom VARCHAR2(1024) DEFAULT '', type NUMBER(10, 0) DEFAULT 0, type_custom VARCHAR2(100) DEFAULT '', value CLOB DEFAULT '', @@ -1042,7 +1042,7 @@ CREATE TABLE tusuario_perfil ( id_grupo NUMBER(10, 0) DEFAULT 0, assigned_by VARCHAR2(100) DEFAULT '', id_policy NUMBER(10, 0) DEFAULT 0, - tags CLOB + tags CLOB DEFAULT '' ); CREATE SEQUENCE tusuario_perfil_s INCREMENT BY 1 START WITH 1; CREATE OR REPLACE TRIGGER tusuario_perfil_inc BEFORE INSERT ON tusuario_perfil REFERENCING NEW AS NEW FOR EACH ROW BEGIN SELECT tusuario_perfil_s.nextval INTO :NEW.id_up FROM dual; END tusuario_perfil_inc;; @@ -1639,9 +1639,11 @@ CREATE TABLE tnetwork_map ( show_groups NUMBER(10, 0) DEFAULT 0, show_modules NUMBER(10, 0) DEFAULT 0, id_agent NUMBER(10, 0) DEFAULT 0, - server_name VARCHAR(100) , + server_name VARCHAR(100), show_modulegroup NUMBER(10, 0) DEFAULT 0, - l2_network NUMBER(1, 0) DEFAULT 0 + l2_network NUMBER(1, 0) DEFAULT 0, + id_tag NUMBER(11, 0) DEFAULT 0, + store_group NUMBER(11, 0) DEFAULT 0 ); CREATE SEQUENCE tnetwork_map_s INCREMENT BY 1 START WITH 1;