2014-07-23 Miguel de Dios <miguel.dedios@artica.es>

* include/config_process.php, operation/agentes/status_monitor.php,
	operation/agentes/estado_generalagente.php,
	operation/agentes/estado_agente.php: tiny fixes for the improve the
	support of postgreSQL databases.




git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@10352 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
mdtrooper 2014-07-23 16:59:05 +00:00
parent 807faa6992
commit f0d2ccf98d
5 changed files with 95 additions and 35 deletions

View File

@ -1,3 +1,10 @@
2014-07-23 Miguel de Dios <miguel.dedios@artica.es>
* include/config_process.php, operation/agentes/status_monitor.php,
operation/agentes/estado_generalagente.php,
operation/agentes/estado_agente.php: tiny fixes for the improve the
support of postgreSQL databases.
2014-07-23 Miguel de Dios <miguel.dedios@artica.es> 2014-07-23 Miguel de Dios <miguel.dedios@artica.es>
* include/functions_servers.php, include/functions_reporting.php: * include/functions_servers.php, include/functions_reporting.php:

View File

@ -247,4 +247,24 @@ if (defined('METACONSOLE')) {
// cases (reverse proxy, others ports...). // cases (reverse proxy, others ports...).
//====================================================================== //======================================================================
$config["homeurl"] = ui_get_full_url(false); $config["homeurl"] = ui_get_full_url(false);
//======================================================================
// Get the version of DB manager
//======================================================================
switch ($config["dbtype"]) {
case "mysql":
break;
case "postgresql":
if (!isset($config['dbversion'])) {
$result = db_get_sql("select version();");
$result_chunks = explode(" ", $result);
$config['dbversion'] = $result_chunks[1];
}
break;
case "oracle":
break;
}
//======================================================================
?> ?>

View File

@ -223,18 +223,31 @@ $selectLastContactUp = '';
$selectLastContactDown = ''; $selectLastContactDown = '';
$order = null; $order = null;
$order_collation = "";
switch ($config["dbtype"]) {
case "mysql":
$order_collation = "COLLATE utf8_general_ci";
break;
case "postgresql":
case "oracle":
$order_collation = "";
break;
}
switch ($sortField) { switch ($sortField) {
case 'name': case 'name':
switch ($sort) { switch ($sort) {
case 'up': case 'up':
$selectNameUp = $selected; $selectNameUp = $selected;
$order = array('field' => 'nombre COLLATE utf8_general_ci', $order = array('field' => 'nombre' . $order_collation,
'field2' => 'nombre COLLATE utf8_general_ci', 'order' => 'ASC'); 'field2' => 'nombre' . $order_collation, 'order' => 'ASC');
break; break;
case 'down': case 'down':
$selectNameDown = $selected; $selectNameDown = $selected;
$order = array('field' => 'nombre COLLATE utf8_general_ci', $order = array('field' => 'nombre' . $order_collation,
'field2' => 'nombre COLLATE utf8_general_ci', 'order' => 'DESC'); 'field2' => 'nombre' . $order_collation, 'order' => 'DESC');
break; break;
} }
break; break;
@ -243,12 +256,12 @@ switch ($sortField) {
case 'up': case 'up':
$selectOsUp = $selected; $selectOsUp = $selected;
$order = array('field' => 'id_os', $order = array('field' => 'id_os',
'field2' => 'nombre COLLATE utf8_general_ci', 'order' => 'ASC'); 'field2' => 'nombre' . $order_collation, 'order' => 'ASC');
break; break;
case 'down': case 'down':
$selectOsDown = $selected; $selectOsDown = $selected;
$order = array('field' => 'id_os', $order = array('field' => 'id_os',
'field2' => 'nombre COLLATE utf8_general_ci', 'order' => 'DESC'); 'field2' => 'nombre' . $order_collation, 'order' => 'DESC');
break; break;
} }
break; break;
@ -257,12 +270,12 @@ switch ($sortField) {
case 'up': case 'up':
$selectIntervalUp = $selected; $selectIntervalUp = $selected;
$order = array('field' => 'intervalo', $order = array('field' => 'intervalo',
'field2' => 'nombre COLLATE utf8_general_ci', 'order' => 'ASC'); 'field2' => 'nombre' . $order_collation, 'order' => 'ASC');
break; break;
case 'down': case 'down':
$selectIntervalDown = $selected; $selectIntervalDown = $selected;
$order = array('field' => 'intervalo', $order = array('field' => 'intervalo',
'field2' => 'nombre COLLATE utf8_general_ci', 'order' => 'DESC'); 'field2' => 'nombre' . $order_collation, 'order' => 'DESC');
break; break;
} }
break; break;
@ -271,12 +284,12 @@ switch ($sortField) {
case 'up': case 'up':
$selectGroupUp = $selected; $selectGroupUp = $selected;
$order = array('field' => 'id_grupo', $order = array('field' => 'id_grupo',
'field2' => 'nombre COLLATE utf8_general_ci', 'order' => 'ASC'); 'field2' => 'nombre' . $order_collation, 'order' => 'ASC');
break; break;
case 'down': case 'down':
$selectGroupDown = $selected; $selectGroupDown = $selected;
$order = array('field' => 'id_grupo', $order = array('field' => 'id_grupo',
'field2' => 'nombre COLLATE utf8_general_ci', 'order' => 'DESC'); 'field2' => 'nombre' . $order_collation, 'order' => 'DESC');
break; break;
} }
break; break;
@ -285,12 +298,12 @@ switch ($sortField) {
case 'up': case 'up':
$selectLastContactUp = $selected; $selectLastContactUp = $selected;
$order = array('field' => 'ultimo_contacto', $order = array('field' => 'ultimo_contacto',
'field2' => 'nombre COLLATE utf8_general_ci', 'order' => 'DESC'); 'field2' => 'nombre' . $order_collation, 'order' => 'DESC');
break; break;
case 'down': case 'down':
$selectLastContactDown = $selected; $selectLastContactDown = $selected;
$order = array('field' => 'ultimo_contacto', $order = array('field' => 'ultimo_contacto',
'field2' => 'nombre COLLATE utf8_general_ci', 'order' => 'ASC'); 'field2' => 'nombre' . $order_collation, 'order' => 'ASC');
break; break;
} }
break; break;
@ -305,15 +318,15 @@ switch ($sortField) {
$selectGroupDown = ''; $selectGroupDown = '';
$selectLastContactUp = ''; $selectLastContactUp = '';
$selectLastContactDown = ''; $selectLastContactDown = '';
$order = array('field' => 'nombre COLLATE utf8_general_ci', $order = array('field' => 'nombre' . $order_collation,
'field2' => 'nombre COLLATE utf8_general_ci', 'field2' => 'nombre' . $order_collation,
'order' => 'ASC'); 'order' => 'ASC');
break; break;
} }
$search_sql = ''; $search_sql = '';
if ($search != "") { if ($search != "") {
$search_sql = " AND ( nombre COLLATE utf8_general_ci LIKE '%$search%' OR direccion LIKE '%$search%' OR comentarios LIKE '%$search%') "; $search_sql = " AND ( nombre " . $order_collation . " LIKE '%$search%' OR direccion LIKE '%$search%' OR comentarios LIKE '%$search%') ";
} }
// Show only selected groups // Show only selected groups
@ -340,8 +353,9 @@ $total_agents = agents_get_agents(array (
array ('COUNT(*) as total'), 'AR', false); array ('COUNT(*) as total'), 'AR', false);
$total_agents = isset ($total_agents[0]['total']) ? $total_agents[0]['total'] : 0; $total_agents = isset ($total_agents[0]['total']) ? $total_agents[0]['total'] : 0;
$agents = agents_get_agents(array ( $agents = agents_get_agents(array (
'order' => 'nombre COLLATE utf8_general_ci ASC', 'order' => 'nombre ' . $order_collation . ' ASC',
'id_grupo' => $groups, 'id_grupo' => $groups,
'disabled' => 0, 'disabled' => 0,
'status' => $status, 'status' => $status,
@ -354,7 +368,7 @@ $agents = agents_get_agents(array (
'id_os', 'id_os',
'ultimo_contacto', 'ultimo_contacto',
'intervalo', 'intervalo',
'comentarios description', 'comentarios description',
'quiet', 'quiet',
'normal_count', 'normal_count',
'warning_count', 'warning_count',

View File

@ -255,7 +255,7 @@ if(enterprise_installed()) {
else { else {
$data[1] = __('Enabled'); $data[1] = __('Enabled');
} }
$table_data->data[] = $data; $table_data->data[] = $data;
} }
@ -323,7 +323,7 @@ $last_incident = db_get_row_sql("SELECT * FROM tincidencia
WHERE estado IN (0,1) WHERE estado IN (0,1)
AND id_agent=$id_agente AND id_agent=$id_agente
ORDER BY actualizacion DESC"); ORDER BY actualizacion DESC");
if ($last_incident != false) { if ($last_incident != false) {
$table_incident->id = 'agent_incident_main'; $table_incident->id = 'agent_incident_main';
@ -333,10 +333,10 @@ if ($last_incident != false) {
$table_incident->class = 'databox'; $table_incident->class = 'databox';
$table_incident->style[0] = 'width: 30%;'; $table_incident->style[0] = 'width: 30%;';
$table_incident->style[1] = 'width: 70%;'; $table_incident->style[1] = 'width: 70%;';
$table_incident->head[0] = ' <span>' . '<a href="index.php?sec=incidencias&amp;sec2=operation/incidents/incident_detail&amp;id='.$last_incident["id_incidencia"].'">' .__('Active incident on this agent') .'</a>'. '</span>'; $table_incident->head[0] = ' <span>' . '<a href="index.php?sec=incidencias&amp;sec2=operation/incidents/incident_detail&amp;id='.$last_incident["id_incidencia"].'">' .__('Active incident on this agent') .'</a>'. '</span>';
$table_incident->head_colspan[0] = 2; $table_incident->head_colspan[0] = 2;
$data = array(); $data = array();
$data[0] = '<b>' . __('Author') . '</b>'; $data[0] = '<b>' . __('Author') . '</b>';
$data[1] = $last_incident["id_creator"]; $data[1] = $last_incident["id_creator"];
@ -391,20 +391,20 @@ if (! empty($modules)) {
$table_interface->head_colspan = array(); $table_interface->head_colspan = array();
$table_interface->head_colspan[0] = 4; $table_interface->head_colspan[0] = 4;
$table_interface->data = array(); $table_interface->data = array();
foreach ($modules as $key => $module) { foreach ($modules as $key => $module) {
// Trying to get the interface name from the module name // Trying to get the interface name from the module name
if (preg_match ("/_(.+)$/", (string)$module['nombre'], $matches)) { if (preg_match ("/_(.+)$/", (string)$module['nombre'], $matches)) {
if ($matches[1]) { if ($matches[1]) {
$interface_name = $matches[1]; $interface_name = $matches[1];
$module_id = $module['id_agente_modulo']; $module_id = $module['id_agente_modulo'];
$db_status = modules_get_agentmodule_status($module_id); $db_status = modules_get_agentmodule_status($module_id);
$module_value = modules_get_last_value ($module_id); $module_value = modules_get_last_value ($module_id);
modules_get_status($module_id, $db_status, $module_value, $status, $title); modules_get_status($module_id, $db_status, $module_value, $status, $title);
$status = ui_print_status_image($status, $title, true); $status = ui_print_status_image($status, $title, true);
$ip_target = "--"; $ip_target = "--";
// Trying to get something like an IP from the description // Trying to get something like an IP from the description
if (preg_match ("/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/", (string)$module['descripcion'], $matches) || if (preg_match ("/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/", (string)$module['descripcion'], $matches) ||
@ -421,7 +421,7 @@ if (! empty($modules)) {
$description = $matches[0]; $description = $matches[0];
} }
} }
$data = array(); $data = array();
$data[0] = "<strong>" . $interface_name . "</strong>"; $data[0] = "<strong>" . $interface_name . "</strong>";
$data[1] = $status; $data[1] = $status;
@ -432,7 +432,7 @@ if (! empty($modules)) {
} }
} }
unset($modules); unset($modules);
// This javascript piece of code is used to make expandible the body of the table // This javascript piece of code is used to make expandible the body of the table
?> ?>
<script type="text/javascript"> <script type="text/javascript">

View File

@ -14,8 +14,6 @@
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details. // GNU General Public License for more details.
// Load global vars // Load global vars
global $config; global $config;
@ -45,6 +43,8 @@ else {
ui_meta_print_header(__("Monitor view")); ui_meta_print_header(__("Monitor view"));
} }
$ag_freestring = get_parameter ('ag_freestring'); $ag_freestring = get_parameter ('ag_freestring');
$ag_modulename = (string) get_parameter ('ag_modulename'); $ag_modulename = (string) get_parameter ('ag_modulename');
if (!defined('METACONSOLE')) { if (!defined('METACONSOLE')) {
@ -101,8 +101,12 @@ $sql_conditions_base = " WHERE tagente.id_agente = tagente_modulo.id_agente
$sql_conditions = " AND tagente_modulo.disabled = 0 AND tagente.disabled = 0"; $sql_conditions = " AND tagente_modulo.disabled = 0 AND tagente.disabled = 0";
if (is_numeric($ag_group)) {
$id_ag_group = db_get_value('id_grupo', 'tgrupo', 'nombre', $ag_group); $id_ag_group = 0;
}
else {
$id_ag_group = db_get_value('id_grupo', 'tgrupo', 'nombre', $ag_group);
}
// Agent group selector // Agent group selector
if (!defined('METACONSOLE')) { if (!defined('METACONSOLE')) {
@ -123,6 +127,7 @@ else {
$sql_conditions_group = " AND tagente.id_grupo IN (".$user_groups.")"; $sql_conditions_group = " AND tagente.id_grupo IN (".$user_groups.")";
} }
} }
// Module group // Module group
if (defined('METACONSOLE')) { if (defined('METACONSOLE')) {
if ($modulegroup != '-1') if ($modulegroup != '-1')
@ -310,7 +315,9 @@ if ($flag_is_admin)
if (defined('METACONSOLE')) { if (defined('METACONSOLE')) {
// For each server defined and not disabled: // For each server defined and not disabled:
$servers = db_get_all_rows_sql ("SELECT * FROM tmetaconsole_setup WHERE disabled = 0"); $servers = db_get_all_rows_sql ("SELECT *
FROM tmetaconsole_setup
WHERE disabled = 0");
if ($servers === false) if ($servers === false)
$servers = array(); $servers = array();
@ -727,8 +734,15 @@ switch ($config["dbtype"]) {
LIMIT ".$offset.",".$limit_sql; LIMIT ".$offset.",".$limit_sql;
break; break;
case "postgresql": case "postgresql":
if (strstr($config['dbversion'], "8.4") !== false) {
$string_agg = "array_to_string(array_agg(ttag.name), ',')";
}
else {
$string_agg = "STRING_AGG(ttag.name, ',')";
}
$sql = "SELECT $sql = "SELECT
(SELECT STRING_AGG(ttag.name, ',') (SELECT " . $string_agg . "
FROM ttag FROM ttag
WHERE ttag.id_tag IN ( WHERE ttag.id_tag IN (
SELECT ttag_module.id_tag SELECT ttag_module.id_tag
@ -760,7 +774,10 @@ switch ($config["dbtype"]) {
tagente_modulo.critical_instructions, tagente_modulo.critical_instructions,
tagente_modulo.warning_instructions, tagente_modulo.warning_instructions,
tagente_modulo.unknown_instructions, tagente_modulo.unknown_instructions,
tagente_estado.utimestamp AS utimestamp".$sql_form . $sql_conditions_all." LIMIT " . $limit_sql . " OFFSET " . $offset; tagente_estado.utimestamp AS utimestamp" .
$sql_from .
$sql_conditions_all .
" LIMIT " . $limit_sql . " OFFSET " . $offset;
break; break;
case "oracle": case "oracle":
$set = array(); $set = array();
@ -799,7 +816,9 @@ switch ($config["dbtype"]) {
tagente_modulo.critical_instructions, tagente_modulo.critical_instructions,
tagente_modulo.warning_instructions, tagente_modulo.warning_instructions,
tagente_modulo.unknown_instructions, tagente_modulo.unknown_instructions,
tagente_estado.utimestamp AS utimestamp" . $sql_form . $sql_conditions_all; tagente_estado.utimestamp AS utimestamp" .
$sql_from .
$sql_conditions_all;
$sql = oracle_recode_query ($sql, $set); $sql = oracle_recode_query ($sql, $set);
break; break;
} }