Fixed problems related with the oracle compatibility

This commit is contained in:
Alejandro Gallardo Escobar 2015-04-30 20:11:07 +02:00
parent 64466e4557
commit 1121fbd8b7
9 changed files with 136 additions and 105 deletions

View File

@ -153,7 +153,7 @@ function mainModuleGroups() {
GROUP BY estado, utimestamp"; GROUP BY estado, utimestamp";
break; break;
case "oracle": 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 FROM tagente_estado
WHERE id_agente IN WHERE id_agente IN
(SELECT id_agente FROM tagente WHERE id_grupo = %d AND (disabled IS NOT NULL AND disabled <> 0)) (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 (SELECT id_agente_modulo
FROM tagente_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)) 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; break;
} }

View File

@ -33,7 +33,7 @@ if (is_ajax ()) {
$filter[] = '(nombre COLLATE utf8_general_ci LIKE "%' . $string . '%" OR direccion LIKE "%'.$string.'%" OR comentarios LIKE "%'.$string.'%")'; $filter[] = '(nombre COLLATE utf8_general_ci LIKE "%' . $string . '%" OR direccion LIKE "%'.$string.'%" OR comentarios LIKE "%'.$string.'%")';
break; break;
case "oracle": 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; break;
} }
$filter[] = 'id_agente != ' . $id_agent; $filter[] = 'id_agente != ' . $id_agent;

View File

@ -192,6 +192,8 @@ class Tree {
} }
protected function getAgentCountersSql ($agent_table) { protected function getAgentCountersSql ($agent_table) {
global $config;
$columns = $this->getAgentCounterColumnsSql($agent_table); $columns = $this->getAgentCounterColumnsSql($agent_table);
switch ($config["dbtype"]) { switch ($config["dbtype"]) {
@ -320,16 +322,14 @@ class Tree {
switch ($rootType) { switch ($rootType) {
case 'group': case 'group':
// ACL Group // ACL Group
$user_groups_str = "-1";
$group_acl = ""; $group_acl = "";
if (!$this->strictACL) { if (!$this->strictACL) {
if (!empty($this->userGroups)) { if (!empty($this->userGroups)) {
$user_groups_str = implode(",", array_keys($this->userGroups)); $user_groups_str = implode(",", array_keys($this->userGroups));
}
$group_acl = "AND ta.id_grupo IN ($user_groups_str)"; $group_acl = "AND ta.id_grupo IN ($user_groups_str)";
} }
else {
$group_acl = "AND ta.id_grupo = -1";
}
}
else { else {
if (!empty($this->acltags)) { if (!empty($this->acltags)) {
$groups = array(); $groups = array();
@ -342,16 +342,10 @@ class Tree {
if (!empty($groups)) { if (!empty($groups)) {
if (array_search(0, $groups) === false) { if (array_search(0, $groups) === false) {
$user_groups_str = implode(",", $groups); $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) { switch ($type) {
@ -365,7 +359,15 @@ class Tree {
$order_fields = 'tg.nombre ASC, tg.id_grupo ASC'; $order_fields = 'tg.nombre ASC, tg.id_grupo ASC';
if (! defined('METACONSOLE')) { if (! defined('METACONSOLE')) {
// Add the agent counters to the columns // 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)) $agent_table = "SELECT COUNT(DISTINCT(ta.id_agente))
FROM tagente ta FROM tagente ta
LEFT JOIN tagente_modulo tam LEFT JOIN tagente_modulo tam
@ -374,54 +376,33 @@ class Tree {
$module_search_filter $module_search_filter
$module_status_join $module_status_join
WHERE ta.disabled = 0 WHERE ta.disabled = 0
AND ta.id_grupo = tg.id_grupo AND ta.id_grupo = $item_for_count
$group_acl $group_acl
$agent_search_filter $agent_search_filter
$agent_status_filter"; $agent_status_filter";
$counter_columns = $this->getAgentCounterColumnsSql($agent_table); $sql = $this->getAgentCountersSql($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";
} }
// Metaconsole // Metaconsole
else { else {
// Add the agent counters to the columns // 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)) $agent_table = "SELECT COUNT(DISTINCT(ta.id_agente))
FROM tmetaconsole_agent ta FROM tmetaconsole_agent ta
WHERE ta.disabled = 0 WHERE ta.disabled = 0
AND ta.id_grupo = tg.id_grupo AND ta.id_grupo = $item_for_count
$group_acl $group_acl
$agent_search_filter $agent_search_filter
$agent_status_filter"; $agent_status_filter";
$counter_columns = $this->getAgentCounterColumnsSql($agent_table); $sql = $this->getAgentCountersSql($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";
} }
} }
else { else {
@ -444,7 +425,6 @@ class Tree {
$group_acl $group_acl
$agent_search_filter $agent_search_filter
$agent_status_filter $agent_status_filter
GROUP BY ta.id_agente
ORDER BY $order_fields"; ORDER BY $order_fields";
} }
else { else {
@ -461,7 +441,6 @@ class Tree {
$group_acl $group_acl
$agent_search_filter $agent_search_filter
$agent_status_filter $agent_status_filter
GROUP BY ta.id_tagente
ORDER BY $order_fields"; ORDER BY $order_fields";
} }
} }
@ -1962,6 +1941,13 @@ class Tree {
foreach ($items as $key => $item) { foreach ($items as $key => $item) {
if (empty($item['parent'])) { if (empty($item['parent'])) {
$counters = $this->getCounters($item['id']);
if (!empty($counters)) {
foreach ($counters as $type => $value) {
$item[$type] = $value;
}
}
unset($items[$key]); unset($items[$key]);
$items_tmp = array(); $items_tmp = array();
$processed_item = $this->getProcessedItem($item, false, $items, $items_tmp, true); $processed_item = $this->getProcessedItem($item, false, $items, $items_tmp, true);

View File

@ -253,7 +253,7 @@ function networkmap_generate_dot ($pandora_name, $group = 0,
break; break;
case "oracle": case "oracle":
$filter[] = $filter[] =
'(upper(nombre) LIKE upper("%' . $text_filter . '%"))'; '(upper(nombre) LIKE upper(\'%' . $text_filter . '%\'))';
break; break;
} }
} }
@ -663,7 +663,7 @@ function networkmap_generate_dot_groups ($pandora_name, $group = 0,
break; break;
case "oracle": case "oracle":
$filter[] = $filter[] =
'(upper(nombre) LIKE upper("%' . $text_filter . '%"))'; '(upper(nombre) LIKE upper(\'%' . $text_filter . '%\'))';
break; break;
} }
} }

View File

@ -923,6 +923,9 @@ function tags_get_user_tags($id_user = false, $access = 'AR') {
return array(); return array();
} }
switch ($config["dbtype"]) {
case "mysql":
case "postgresql":
$query = sprintf(" $query = sprintf("
SELECT count(*) SELECT count(*)
FROM tusuario_perfil, tperfil FROM tusuario_perfil, tperfil
@ -931,6 +934,18 @@ function tags_get_user_tags($id_user = false, $access = 'AR') {
AND tperfil.%s = 1 AND tperfil.%s = 1
AND tags <> ''", AND tags <> ''",
$id_user, $acl_column); $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); $profiles_without_tags = db_get_value_sql($query);

View File

@ -289,7 +289,7 @@ switch ($config["dbtype"]) {
$profiles = db_get_all_rows_sql('SELECT id_grupo $profiles = db_get_all_rows_sql('SELECT id_grupo
FROM tusuario_perfil AS t1 FROM tusuario_perfil AS t1
INNER JOIN tperfil AS t2 ON t1.id_perfil = t2.id_perfil 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) if ($profiles === false)
$profiles = array(); $profiles = array();
@ -305,14 +305,14 @@ switch ($config["dbtype"]) {
//The check of is_admin //The check of is_admin
$flag_is_admin = (bool)db_get_value('is_admin', 'tusuario', 'id_user', $config['id_user']); $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; '. $sql_from . $sql_conditions_acl;
break; break;
case "oracle": case "oracle":
$profiles = db_get_all_rows_sql('SELECT id_grupo $profiles = db_get_all_rows_sql('SELECT id_grupo
FROM tusuario_perfil t1 FROM tusuario_perfil t1
INNER JOIN tperfil t2 ON t1.id_perfil = t2.id_perfil 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) if ($profiles === false)
$profiles = array(); $profiles = array();
@ -329,7 +329,7 @@ switch ($config["dbtype"]) {
$flag_is_admin = (bool)db_get_value('is_admin', 'tusuario', $flag_is_admin = (bool)db_get_value('is_admin', 'tusuario',
'id_user', $config['id_user']); '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; $sql_from . $sql_conditions_acl;
break; break;
} }
@ -783,7 +783,7 @@ switch ($config["dbtype"]) {
$set['limit'] = $limit_sql; $set['limit'] = $limit_sql;
$set['offset'] = $offset; $set['offset'] = $offset;
$sql = "SELECT $sql = "SELECT
(SELECT wmsys.wm_concat(ttag.name) (SELECT LISTAGG(ttag.name, ',') WITHIN GROUP (ORDER BY ttag.name)
FROM ttag FROM ttag
WHERE ttag.id_tag IN ( WHERE ttag.id_tag IN (
SELECT ttag_module.id_tag SELECT ttag_module.id_tag

View File

@ -74,7 +74,10 @@ if (!empty($user_groups)) {
$last_month_timestamp = date("Y-m-d H:i:s", time() - SECONDS_1MONTH); $last_month_timestamp = date("Y-m-d H:i:s", time() - SECONDS_1MONTH);
$sql_traps_generated = "SELECT %s, COUNT(id_trap) AS num switch ($config["dbtype"]) {
case "mysql":
case "postgresql":
$sql_traps_generated = "SELECT %s, COUNT(id_trap) AS num, MAX(timestamp) AS timestamp
FROM ttrap FROM ttrap
WHERE timestamp >= '%s' WHERE timestamp >= '%s'
AND (source = '' AND (source = ''
@ -85,6 +88,22 @@ $sql_traps_generated = "SELECT %s, COUNT(id_trap) AS num
GROUP BY %s GROUP BY %s
ORDER BY num DESC, timestamp DESC ORDER BY num DESC, timestamp DESC
LIMIT 25"; 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_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"); $sql_traps_generated_by_oid = sprintf($sql_traps_generated, "oid", $last_month_timestamp, $user_groups_str, "oid");

View File

@ -181,7 +181,6 @@ switch ($config["dbtype"]) {
LIMIT %d,%d"; LIMIT %d,%d";
break; break;
case "postgresql": case "postgresql":
case "oracle":
$sql = "SELECT * $sql = "SELECT *
FROM ttrap FROM ttrap
WHERE (source IN ( WHERE (source IN (
@ -191,6 +190,15 @@ switch ($config["dbtype"]) {
ORDER BY timestamp DESC ORDER BY timestamp DESC
LIMIT %d OFFSET %d"; LIMIT %d OFFSET %d";
break; 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 * $sql_all = "SELECT *
FROM ttrap FROM ttrap
@ -279,6 +287,7 @@ switch ($config["dbtype"]) {
$set = array(); $set = array();
$set['limit'] = $pagination; $set['limit'] = $pagination;
$set['offset'] = $offset; $set['offset'] = $offset;
$sql = sprintf($sql, $whereSubquery);
$sql = oracle_recode_query ($sql, $set); $sql = oracle_recode_query ($sql, $set);
break; break;
} }

View File

@ -193,7 +193,7 @@ CREATE TABLE tagente_modulo (
id_tipo_modulo NUMBER(10, 0) DEFAULT 0, id_tipo_modulo NUMBER(10, 0) DEFAULT 0,
descripcion CLOB DEFAULT '', descripcion CLOB DEFAULT '',
extended_info CLOB DEFAULT '', extended_info CLOB DEFAULT '',
nombre CLOB DEFAULT '', nombre VARCHAR2(4000) DEFAULT '',
unit VARCHAR2(100) DEFAULT '', unit VARCHAR2(100) DEFAULT '',
id_policy_module NUMBER(10, 0) DEFAULT 0, id_policy_module NUMBER(10, 0) DEFAULT 0,
max NUMBER(19, 0) DEFAULT 0, max NUMBER(19, 0) DEFAULT 0,
@ -974,8 +974,8 @@ CREATE OR REPLACE TRIGGER ttipo_modulo_inc BEFORE INSERT ON ttipo_modulo REFEREN
CREATE TABLE ttrap ( CREATE TABLE ttrap (
id_trap NUMBER(19, 0) PRIMARY KEY, id_trap NUMBER(19, 0) PRIMARY KEY,
source VARCHAR2(50) DEFAULT '', source VARCHAR2(50) DEFAULT '',
oid CLOB DEFAULT '', oid VARCHAR2(1024) DEFAULT '',
oid_custom CLOB DEFAULT '', oid_custom VARCHAR2(1024) DEFAULT '',
type NUMBER(10, 0) DEFAULT 0, type NUMBER(10, 0) DEFAULT 0,
type_custom VARCHAR2(100) DEFAULT '', type_custom VARCHAR2(100) DEFAULT '',
value CLOB DEFAULT '', value CLOB DEFAULT '',
@ -1042,7 +1042,7 @@ CREATE TABLE tusuario_perfil (
id_grupo NUMBER(10, 0) DEFAULT 0, id_grupo NUMBER(10, 0) DEFAULT 0,
assigned_by VARCHAR2(100) DEFAULT '', assigned_by VARCHAR2(100) DEFAULT '',
id_policy NUMBER(10, 0) DEFAULT 0, id_policy NUMBER(10, 0) DEFAULT 0,
tags CLOB tags CLOB DEFAULT ''
); );
CREATE SEQUENCE tusuario_perfil_s INCREMENT BY 1 START WITH 1; 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;; 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_groups NUMBER(10, 0) DEFAULT 0,
show_modules NUMBER(10, 0) DEFAULT 0, show_modules NUMBER(10, 0) DEFAULT 0,
id_agent 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, 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; CREATE SEQUENCE tnetwork_map_s INCREMENT BY 1 START WITH 1;