Merge branch 'features/oracle' of https://github.com/pandorafms/pandorafms into features/oracle

This commit is contained in:
Ramon Novoa 2015-04-30 10:59:36 +02:00
commit 665951fe07
6 changed files with 107 additions and 99 deletions

View File

@ -193,7 +193,16 @@ class Tree {
protected function getAgentCountersSql ($agent_table) {
$columns = $this->getAgentCounterColumnsSql($agent_table);
$columns = "SELECT $columns FROM dual LIMIT 1";
switch ($config["dbtype"]) {
case "mysql":
case "postgresql":
$columns = "SELECT $columns FROM dual LIMIT 1";
break;
case "oracle":
$columns = "SELECT $columns FROM dual WHERE rownum <= 1";
break;
}
return $columns;
}
@ -237,7 +246,7 @@ class Tree {
// Agents join
$agents_join = "";
if (!empty($agent_search_filter) || !empty($agent_status_filter)) {
$agents_join = "INNER JOIN tagente AS ta
$agents_join = "INNER JOIN tagente ta
ON ta.disabled = 0
AND tam.id_agente = ta.id_agente
$agent_search_filter
@ -288,13 +297,13 @@ class Tree {
if (!empty($module_search_filter) || !empty($module_status_filter)) {
if (!empty($module_status_filter)) {
$module_status_join = "INNER JOIN tagente_estado AS tae
$module_status_join = "INNER JOIN tagente_estado tae
ON tam.id_agente_modulo IS NOT NULL
AND tam.id_agente_modulo = tae.id_agente_modulo
$module_status_filter";
}
$modules_join = "INNER JOIN tagente_modulo AS tam
$modules_join = "INNER JOIN tagente_modulo tam
ON tam.disabled = 0
AND ta.id_agente = tam.id_agente
$module_search_filter
@ -302,7 +311,7 @@ class Tree {
}
if (empty($module_status_join)) {
$module_status_join = "LEFT JOIN tagente_estado AS tae
$module_status_join = "LEFT JOIN tagente_estado tae
ON tam.id_agente_modulo = tae.id_agente_modulo";
}
@ -358,8 +367,8 @@ class Tree {
if (! defined('METACONSOLE')) {
// Add the agent counters to the columns
$agent_table = "SELECT COUNT(DISTINCT(ta.id_agente))
FROM tagente AS ta
LEFT JOIN tagente_modulo AS tam
FROM tagente ta
LEFT JOIN tagente_modulo tam
ON tam.disabled = 0
AND ta.id_agente = tam.id_agente
$module_search_filter
@ -374,9 +383,9 @@ class Tree {
$columns .= ", $counter_columns";
$sql = "SELECT $columns
FROM tgrupo AS tg
LEFT JOIN tagente AS ta
LEFT JOIN tagente_modulo AS tam
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
@ -393,7 +402,7 @@ class Tree {
else {
// Add the agent counters to the columns
$agent_table = "SELECT COUNT(DISTINCT(ta.id_agente))
FROM tmetaconsole_agent AS ta
FROM tmetaconsole_agent ta
WHERE ta.disabled = 0
AND ta.id_grupo = tg.id_grupo
$group_acl
@ -404,8 +413,8 @@ class Tree {
$columns .= ", $counter_columns";
$sql = "SELECT $columns
FROM tgrupo AS tg
LEFT JOIN tagente AS ta
FROM tgrupo tg
LEFT JOIN tagente ta
ON ta.disabled = 0
AND tg.id_grupo = ta.id_grupo
$group_acl
@ -424,8 +433,8 @@ class Tree {
$order_fields = 'ta.nombre ASC, ta.id_agente ASC';
$sql = "SELECT $columns
FROM tagente AS ta
LEFT JOIN tagente_modulo AS tam
FROM tagente ta
LEFT JOIN tagente_modulo tam
ON tam.disabled = 0
AND ta.id_agente = tam.id_agente
$module_search_filter
@ -446,7 +455,7 @@ class Tree {
$order_fields = 'ta.nombre ASC, ta.id_tagente ASC';
$sql = "SELECT $columns
FROM tmetaconsole_agent AS ta
FROM tmetaconsole_agent ta
WHERE ta.disabled = 0
AND ta.id_grupo = $rootID
$group_acl
@ -464,9 +473,9 @@ class Tree {
$order_fields = 'tam.nombre ASC, tam.id_agente_modulo ASC';
$sql = "SELECT $columns
FROM tagente_modulo AS tam
FROM tagente_modulo tam
$module_status_join
INNER JOIN tagente AS ta
INNER JOIN tagente ta
ON ta.disabled = 0
AND tam.id_agente = ta.id_agente
AND ta.id_grupo = $rootID
@ -540,15 +549,15 @@ class Tree {
// Tags SQL
if ($item_for_count === false) {
$sql = "SELECT $columns
FROM ttag AS tt
INNER JOIN ttag_module AS ttm
FROM ttag tt
INNER JOIN ttag_module ttm
ON tt.id_tag = ttm.id_tag
INNER JOIN tagente_modulo AS tam
INNER JOIN tagente_modulo tam
ON tam.disabled = 0
AND ttm.id_agente_modulo = tam.id_agente_modulo
$module_search_filter
$module_status_join
INNER JOIN tagente AS ta
INNER JOIN tagente ta
ON ta.disabled = 0
AND tam.id_agente = ta.id_agente
$group_acl
@ -561,13 +570,13 @@ class Tree {
// Counters SQL
else {
$agent_table = "SELECT COUNT(DISTINCT(ta.id_agente))
FROM tagente AS ta
INNER JOIN tagente_modulo AS tam
FROM tagente ta
INNER JOIN tagente_modulo tam
ON tam.disabled = 0
AND ta.id_agente = tam.id_agente
$module_search_filter
$module_status_join
INNER JOIN ttag_module AS ttm
INNER JOIN ttag_module ttm
ON tam.id_agente_modulo = ttm.id_agente_modulo
AND ttm.id_tag = $item_for_count
WHERE ta.disabled = 0
@ -585,13 +594,13 @@ class Tree {
$order_fields = 'ta.nombre ASC, ta.id_agente ASC';
$sql = "SELECT $columns
FROM tagente AS ta
INNER JOIN tagente_modulo AS tam
FROM tagente ta
INNER JOIN tagente_modulo tam
ON tam.disabled = 0
AND ta.id_agente = tam.id_agente
$module_search_filter
$module_status_join
INNER JOIN ttag_module AS ttm
INNER JOIN ttag_module ttm
ON tam.id_agente_modulo = ttm.id_agente_modulo
AND ttm.id_tag = $rootID
WHERE ta.disabled = 0
@ -609,12 +618,12 @@ class Tree {
$order_fields = 'tam.nombre ASC, tam.id_agente_modulo ASC';
$sql = "SELECT $columns
FROM tagente_modulo AS tam
INNER JOIN ttag_module AS ttm
FROM tagente_modulo tam
INNER JOIN ttag_module ttm
ON tam.id_agente_modulo = ttm.id_agente_modulo
AND ttm.id_tag = $rootID
$module_status_join
INNER JOIN tagente AS ta
INNER JOIN tagente ta
ON ta.disabled = 0
AND tam.id_agente = ta.id_agente
$group_acl
@ -649,8 +658,8 @@ class Tree {
// OS SQL
if ($item_for_count === false) {
$sql = "SELECT $columns
FROM tconfig_os AS tos
INNER JOIN tagente AS ta
FROM tconfig_os tos
INNER JOIN tagente ta
ON ta.disabled = 0
AND ta.id_os = tos.id_os
$agent_search_filter
@ -663,7 +672,7 @@ class Tree {
// Counters SQL
else {
$agent_table = "SELECT COUNT(DISTINCT(ta.id_agente))
FROM tagente AS ta
FROM tagente ta
$modules_join
WHERE ta.disabled = 0
AND ta.id_os = $item_for_count
@ -681,7 +690,7 @@ class Tree {
$order_fields = 'ta.nombre ASC, ta.id_agente ASC';
$sql = "SELECT $columns
FROM tagente AS ta
FROM tagente ta
$modules_join
WHERE ta.disabled = 0
AND ta.id_os = $rootID
@ -702,9 +711,9 @@ class Tree {
$agent_filter = "AND ta.id_agente = $parent";
$sql = "SELECT $columns
FROM tagente_modulo AS tam
FROM tagente_modulo tam
$module_status_join
INNER JOIN tagente AS ta
INNER JOIN tagente ta
ON ta.disabled = 0
AND tam.id_agente = ta.id_agente
$os_filter
@ -736,17 +745,17 @@ class Tree {
if (empty($rootID) || $rootID == -1) {
$columns = 'tmg.id_mg AS id, tmg.name AS name';
$order_fields = 'tmg.name ASC, tmg.id_mg ASC';
// Module groups SQL
if ($item_for_count === false) {
$sql = "SELECT $columns
FROM tmodule_group AS tmg
INNER JOIN tagente_modulo AS tam
FROM tmodule_group tmg
INNER JOIN tagente_modulo tam
ON tam.disabled = 0
AND tam.id_module_group = tmg.id_mg
$module_search_filter
$module_status_join
INNER JOIN tagente AS ta
INNER JOIN tagente ta
ON ta.disabled = 0
AND tam.id_agente = ta.id_agente
$group_acl
@ -758,8 +767,8 @@ class Tree {
// Counters SQL
else {
$agent_table = "SELECT COUNT(DISTINCT(ta.id_agente))
FROM tagente AS ta
INNER JOIN tagente_modulo AS tam
FROM tagente ta
INNER JOIN tagente_modulo tam
ON tam.disabled = 0
AND ta.id_agente = tam.id_agente
AND tam.id_module_group = $item_for_count
@ -778,10 +787,10 @@ class Tree {
ta.critical_count, ta.unknown_count, ta.notinit_count,
ta.total_count, ta.quiet';
$order_fields = 'ta.nombre ASC, ta.id_agente ASC';
$sql = "SELECT $columns
FROM tagente AS ta
INNER JOIN tagente_modulo AS tam
FROM tagente ta
INNER JOIN tagente_modulo tam
ON tam.disabled = 0
AND ta.id_agente = tam.id_agente
AND tam.id_module_group = $rootID
@ -800,14 +809,14 @@ class Tree {
$columns = 'tam.id_agente_modulo AS id, tam.nombre AS name,
tam.id_tipo_modulo, tam.id_modulo, tae.estado, tae.datos';
$order_fields = 'tam.nombre ASC, tam.id_agente_modulo ASC';
$module_group_filter = "AND tam.id_module_group = $rootID";
$agent_filter = "AND tam.id_agente = $parent";
$sql = "SELECT $columns
FROM tagente_modulo AS tam
FROM tagente_modulo tam
$module_status_join
INNER JOIN tagente AS ta
INNER JOIN tagente ta
ON ta.disabled = 0
AND tam.id_agente = ta.id_agente
$group_acl
@ -832,19 +841,19 @@ class Tree {
else {
$group_acl = "AND ta.id_grupo = -1";
}
switch ($type) {
// Get the agents of a module
case 'module':
if (empty($rootID) || $rootID == -1) {
$columns = 'tam.nombre AS name';
$order_fields = 'tam.nombre ASC';
// Modules SQL
if ($item_for_count === false) {
$sql = "SELECT $columns
FROM tagente_modulo AS tam
INNER JOIN tagente AS ta
FROM tagente_modulo tam
INNER JOIN tagente ta
ON ta.disabled = 0
AND tam.id_agente = ta.id_agente
$group_acl
@ -859,8 +868,8 @@ class Tree {
// Counters SQL
else {
$agent_table = "SELECT COUNT(DISTINCT(ta.id_agente))
FROM tagente AS ta
INNER JOIN tagente_modulo AS tam
FROM tagente ta
INNER JOIN tagente_modulo tam
ON tam.disabled = 0
AND ta.id_agente = tam.id_agente
AND tam.nombre = '$item_for_count'
@ -880,7 +889,7 @@ class Tree {
ta.critical_count, ta.unknown_count, ta.notinit_count,
ta.total_count, ta.quiet';
$order_fields = 'ta.nombre ASC, ta.id_agente ASC';
$symbols = ' !"#$%&\'()*+,./:;<=>?@[\\]^{|}~';
$name = $rootID;
for ($i = 0; $i < strlen($symbols); $i++) {
@ -889,10 +898,10 @@ class Tree {
substr($symbols, $i, 1), $name);
}
$name = io_safe_input($name);
$sql = "SELECT $columns
FROM tagente AS ta
INNER JOIN tagente_modulo AS tam
FROM tagente ta
INNER JOIN tagente_modulo tam
ON tam.disabled = 0
AND ta.id_agente = tam.id_agente
AND tam.nombre = '$name'
@ -912,7 +921,7 @@ class Tree {
$columns = 'tam.id_agente_modulo AS id, tam.nombre AS name,
tam.id_tipo_modulo, tam.id_modulo, tae.estado, tae.datos';
$order_fields = 'tam.nombre ASC, tam.id_agente_modulo ASC';
$symbols = ' !"#$%&\'()*+,./:;<=>?@[\\]^{|}~';
$name = $rootID;
for ($i = 0; $i < strlen($symbols); $i++) {
@ -921,13 +930,13 @@ class Tree {
substr($symbols, $i, 1), $name);
}
$name = io_safe_input($name);
$module_name_filter = "AND tam.nombre = '$name'";
$agent_filter = "AND tam.id_agente = $parent";
// We need the agents table
if (empty($agents_join)) {
$agents_join = "INNER JOIN tagente AS ta
$agents_join = "INNER JOIN tagente ta
ON ta.disabled = 0
AND tam.id_agente = ta.id_agente
$group_acl";
@ -935,11 +944,11 @@ class Tree {
else {
$agents_join .= " $group_acl";
}
$sql = "SELECT $columns
FROM tagente_modulo AS tam
FROM tagente_modulo tam
$module_status_join
INNER JOIN tagente AS ta
INNER JOIN tagente ta
ON ta.disabled = 0
AND tam.id_agente = ta.id_agente
$group_acl
@ -962,7 +971,7 @@ class Tree {
return $sql;
}
// Override this method
protected function getSqlExtended ($item_for_count, $type, $rootType, $parent, $rootID,
$agent_search_filter, $agent_status_filter, $agents_join,
@ -970,7 +979,7 @@ class Tree {
$module_status_join) {
return false;
}
protected function getItems ($item_for_count = false) {
$sql = $this->getSql($item_for_count);
if (empty($sql))

View File

@ -2397,22 +2397,21 @@ function grafico_eventos_grupo ($width = 300, $height = 200, $url = "", $meta =
//is required if both DISTINCT() and COUNT() are in the statement
switch ($config["dbtype"]) {
case "mysql":
case "postgresql":
$sql = sprintf ('SELECT DISTINCT(id_agente) AS id_agente,
COUNT(id_agente) AS count'.$field_extra.'
FROM '.$event_table.'
WHERE 1=1 %s %s
GROUP BY id_agente'.$groupby_extra.'
ORDER BY count DESC LIMIT 8', $url, $tags_condition);
break;
case "postgresql":
case "oracle":
$sql = sprintf ('SELECT DISTINCT(id_agente) AS id_agente,
id_grupo, COUNT(id_agente) AS count'.$field_extra.'
FROM '.$event_table.'
WHERE 1=1 %s %s
WHERE rownum <= 0 %s %s
GROUP BY id_agente, id_grupo'.$groupby_extra.'
ORDER BY count DESC LIMIT 8', $url, $tags_condition);
ORDER BY count DESC', $url, $tags_condition);
break;
}

View File

@ -1265,7 +1265,7 @@ function groups_get_agents_counter ($group, $agent_filter = array(), $module_fil
$module_status_array = array_unique($module_status_array);
$status_str = implode(",", $module_status_array);
$module_status_filter = "INNER JOIN tagente_estado AS tae
$module_status_filter = "INNER JOIN tagente_estado tae
ON tam.id_agente_modulo = tae.id_agente_modulo
AND tae.estado IN ($status_str)";
}
@ -1276,8 +1276,8 @@ function groups_get_agents_counter ($group, $agent_filter = array(), $module_fil
// Realtime
if ($realtime) {
$sql = "SELECT DISTINCT ta.id_agente
FROM tagente AS ta
INNER JOIN tagente_modulo AS tam
FROM tagente ta
INNER JOIN tagente_modulo tam
ON ta.id_agente = tam.id_agente
AND tam.disabled = 0
$module_name_filter
@ -1436,7 +1436,7 @@ function groups_get_agents_counter ($group, $agent_filter = array(), $module_fil
}
$sql = "SELECT COUNT(DISTINCT ta.id_agente)
FROM tagente AS ta
FROM tagente ta
WHERE ta.disabled = 0
$agent_name_filter
$status_filter
@ -1738,11 +1738,11 @@ function groups_get_monitors_counter ($group, $agent_filter = array(), $module_f
if ($realtime) {
$sql = "SELECT COUNT(DISTINCT tam.id_agente_modulo)
FROM tagente_modulo AS tam
INNER JOIN tagente_estado AS tae
FROM tagente_modulo tam
INNER JOIN tagente_estado tae
ON tam.id_agente_modulo = tae.id_agente_modulo
$modules_clause
INNER JOIN tagente AS ta
INNER JOIN tagente ta
ON tam.id_agente = ta.id_agente
AND ta.disabled = 0
$agent_name_filter
@ -1786,7 +1786,7 @@ function groups_get_monitors_counter ($group, $agent_filter = array(), $module_f
$status_columns_str = implode(",", $status_columns_array);
$sql = "SELECT SUM($status_columns_str)
FROM tagente AS ta
FROM tagente ta
WHERE ta.disabled = 0
$agent_name_filter
$agents_clause
@ -2305,7 +2305,7 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu
SELECT *
FROM tgrupo
WHERE id_grupo IN (" . $user_groups_ids . ")
ORDER BY nombre COLLATE utf8_general_ci ASC");
ORDER BY nombre ASC");
break;
}
}

View File

@ -1960,10 +1960,10 @@ function modules_get_relations ($params = array()) {
$sql = "SELECT DISTINCT tmr.id, tmr.module_a, tmr.module_b,
tmr.disable_update
FROM tmodule_relationship AS tmr,
tagente_modulo AS tam,
tagente AS ta,
ttipo_modulo AS ttm
FROM tmodule_relationship tmr,
tagente_modulo tam,
tagente ta,
ttipo_modulo ttm
WHERE ";
$agent_filter = "";

View File

@ -1429,7 +1429,7 @@ function tags_get_agents_counter ($id_tag, $groups_and_tags = array(), $agent_fi
$module_status_array = array_unique($module_status_array);
$status_str = implode(",", $module_status_array);
$module_status_filter = "INNER JOIN tagente_estado AS tae
$module_status_filter = "INNER JOIN tagente_estado tae
ON tam.id_agente_modulo = tae.id_agente_modulo
AND tae.estado IN ($status_str)";
}
@ -1439,13 +1439,13 @@ function tags_get_agents_counter ($id_tag, $groups_and_tags = array(), $agent_fi
$count = 0;
if ($realtime) {
$sql = "SELECT DISTINCT ta.id_agente
FROM tagente AS ta
INNER JOIN tagente_modulo AS tam
FROM tagente ta
INNER JOIN tagente_modulo tam
ON ta.id_agente = tam.id_agente
AND tam.disabled = 0
$module_name_filter
$module_status_filter
INNER JOIN ttag_module AS ttm
INNER JOIN ttag_module ttm
ON ttm.id_tag = $id_tag
AND tam.id_agente_modulo = ttm.id_agente_modulo
WHERE ta.disabled = 0
@ -1602,13 +1602,13 @@ function tags_get_agents_counter ($id_tag, $groups_and_tags = array(), $agent_fi
}
$sql = "SELECT COUNT(DISTINCT ta.id_agente)
FROM tagente AS ta
INNER JOIN tagente_modulo AS tam
FROM tagente ta
INNER JOIN tagente_modulo tam
ON ta.id_agente = tam.id_agente
AND tam.disabled = 0
$module_name_filter
$module_status_filter
INNER JOIN ttag_module AS ttm
INNER JOIN ttag_module ttm
ON ttm.id_tag = $id_tag
AND tam.id_agente_modulo = ttm.id_agente_modulo
WHERE ta.disabled = 0
@ -1892,14 +1892,14 @@ function tags_get_monitors_counter ($id_tag, $groups_and_tags = array(), $agent_
}
$sql = "SELECT COUNT(DISTINCT tam.id_agente_modulo)
FROM tagente_modulo AS tam
INNER JOIN tagente_estado AS tae
FROM tagente_modulo tam
INNER JOIN tagente_estado tae
ON tam.id_agente_modulo = tae.id_agente_modulo
$modules_clause
INNER JOIN ttag_module AS ttm
INNER JOIN ttag_module ttm
ON ttm.id_tag = $id_tag
AND tam.id_agente_modulo = ttm.id_agente_modulo
INNER JOIN tagente AS ta
INNER JOIN tagente ta
ON tam.id_agente = ta.id_agente
AND ta.disabled = 0
$agent_name_filter

View File

@ -307,9 +307,9 @@ if (empty($id_groups)) {
else {
$whereAlertSimple .= ' AND id_agent_module IN (
SELECT tam.id_agente_modulo
FROM tagente_modulo AS tam
FROM tagente_modulo tam
WHERE tam.id_agente IN (SELECT ta.id_agente
FROM tagente AS ta
FROM tagente ta
WHERE ta.id_grupo IN (' . implode(',', $id_groups) . '))) ';
}