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 5f1f44fb9a
commit 591a984a66
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>
* include/functions_servers.php, include/functions_reporting.php:

View File

@ -247,4 +247,24 @@ if (defined('METACONSOLE')) {
// cases (reverse proxy, others ports...).
//======================================================================
$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 = '';
$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) {
case 'name':
switch ($sort) {
case 'up':
$selectNameUp = $selected;
$order = array('field' => 'nombre COLLATE utf8_general_ci',
'field2' => 'nombre COLLATE utf8_general_ci', 'order' => 'ASC');
$order = array('field' => 'nombre' . $order_collation,
'field2' => 'nombre' . $order_collation, 'order' => 'ASC');
break;
case 'down':
$selectNameDown = $selected;
$order = array('field' => 'nombre COLLATE utf8_general_ci',
'field2' => 'nombre COLLATE utf8_general_ci', 'order' => 'DESC');
$order = array('field' => 'nombre' . $order_collation,
'field2' => 'nombre' . $order_collation, 'order' => 'DESC');
break;
}
break;
@ -243,12 +256,12 @@ switch ($sortField) {
case 'up':
$selectOsUp = $selected;
$order = array('field' => 'id_os',
'field2' => 'nombre COLLATE utf8_general_ci', 'order' => 'ASC');
'field2' => 'nombre' . $order_collation, 'order' => 'ASC');
break;
case 'down':
$selectOsDown = $selected;
$order = array('field' => 'id_os',
'field2' => 'nombre COLLATE utf8_general_ci', 'order' => 'DESC');
'field2' => 'nombre' . $order_collation, 'order' => 'DESC');
break;
}
break;
@ -257,12 +270,12 @@ switch ($sortField) {
case 'up':
$selectIntervalUp = $selected;
$order = array('field' => 'intervalo',
'field2' => 'nombre COLLATE utf8_general_ci', 'order' => 'ASC');
'field2' => 'nombre' . $order_collation, 'order' => 'ASC');
break;
case 'down':
$selectIntervalDown = $selected;
$order = array('field' => 'intervalo',
'field2' => 'nombre COLLATE utf8_general_ci', 'order' => 'DESC');
'field2' => 'nombre' . $order_collation, 'order' => 'DESC');
break;
}
break;
@ -271,12 +284,12 @@ switch ($sortField) {
case 'up':
$selectGroupUp = $selected;
$order = array('field' => 'id_grupo',
'field2' => 'nombre COLLATE utf8_general_ci', 'order' => 'ASC');
'field2' => 'nombre' . $order_collation, 'order' => 'ASC');
break;
case 'down':
$selectGroupDown = $selected;
$order = array('field' => 'id_grupo',
'field2' => 'nombre COLLATE utf8_general_ci', 'order' => 'DESC');
'field2' => 'nombre' . $order_collation, 'order' => 'DESC');
break;
}
break;
@ -285,12 +298,12 @@ switch ($sortField) {
case 'up':
$selectLastContactUp = $selected;
$order = array('field' => 'ultimo_contacto',
'field2' => 'nombre COLLATE utf8_general_ci', 'order' => 'DESC');
'field2' => 'nombre' . $order_collation, 'order' => 'DESC');
break;
case 'down':
$selectLastContactDown = $selected;
$order = array('field' => 'ultimo_contacto',
'field2' => 'nombre COLLATE utf8_general_ci', 'order' => 'ASC');
'field2' => 'nombre' . $order_collation, 'order' => 'ASC');
break;
}
break;
@ -305,15 +318,15 @@ switch ($sortField) {
$selectGroupDown = '';
$selectLastContactUp = '';
$selectLastContactDown = '';
$order = array('field' => 'nombre COLLATE utf8_general_ci',
'field2' => 'nombre COLLATE utf8_general_ci',
$order = array('field' => 'nombre' . $order_collation,
'field2' => 'nombre' . $order_collation,
'order' => 'ASC');
break;
}
$search_sql = '';
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
@ -340,8 +353,9 @@ $total_agents = agents_get_agents(array (
array ('COUNT(*) as total'), 'AR', false);
$total_agents = isset ($total_agents[0]['total']) ? $total_agents[0]['total'] : 0;
$agents = agents_get_agents(array (
'order' => 'nombre COLLATE utf8_general_ci ASC',
'order' => 'nombre ' . $order_collation . ' ASC',
'id_grupo' => $groups,
'disabled' => 0,
'status' => $status,
@ -354,7 +368,7 @@ $agents = agents_get_agents(array (
'id_os',
'ultimo_contacto',
'intervalo',
'comentarios description',
'comentarios description',
'quiet',
'normal_count',
'warning_count',

View File

@ -255,7 +255,7 @@ if(enterprise_installed()) {
else {
$data[1] = __('Enabled');
}
$table_data->data[] = $data;
}
@ -323,7 +323,7 @@ $last_incident = db_get_row_sql("SELECT * FROM tincidencia
WHERE estado IN (0,1)
AND id_agent=$id_agente
ORDER BY actualizacion DESC");
if ($last_incident != false) {
$table_incident->id = 'agent_incident_main';
@ -333,10 +333,10 @@ if ($last_incident != false) {
$table_incident->class = 'databox';
$table_incident->style[0] = 'width: 30%;';
$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_colspan[0] = 2;
$data = array();
$data[0] = '<b>' . __('Author') . '</b>';
$data[1] = $last_incident["id_creator"];
@ -391,20 +391,20 @@ if (! empty($modules)) {
$table_interface->head_colspan = array();
$table_interface->head_colspan[0] = 4;
$table_interface->data = array();
foreach ($modules as $key => $module) {
// Trying to get the interface name from the module name
if (preg_match ("/_(.+)$/", (string)$module['nombre'], $matches)) {
if ($matches[1]) {
$interface_name = $matches[1];
$module_id = $module['id_agente_modulo'];
$db_status = modules_get_agentmodule_status($module_id);
$module_value = modules_get_last_value ($module_id);
modules_get_status($module_id, $db_status, $module_value, $status, $title);
$status = ui_print_status_image($status, $title, true);
$ip_target = "--";
// 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) ||
@ -421,7 +421,7 @@ if (! empty($modules)) {
$description = $matches[0];
}
}
$data = array();
$data[0] = "<strong>" . $interface_name . "</strong>";
$data[1] = $status;
@ -432,7 +432,7 @@ if (! empty($modules)) {
}
}
unset($modules);
// This javascript piece of code is used to make expandible the body of the table
?>
<script type="text/javascript">

View File

@ -14,8 +14,6 @@
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// Load global vars
global $config;
@ -45,6 +43,8 @@ else {
ui_meta_print_header(__("Monitor view"));
}
$ag_freestring = get_parameter ('ag_freestring');
$ag_modulename = (string) get_parameter ('ag_modulename');
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";
$id_ag_group = db_get_value('id_grupo', 'tgrupo', 'nombre', $ag_group);
if (is_numeric($ag_group)) {
$id_ag_group = 0;
}
else {
$id_ag_group = db_get_value('id_grupo', 'tgrupo', 'nombre', $ag_group);
}
// Agent group selector
if (!defined('METACONSOLE')) {
@ -123,6 +127,7 @@ else {
$sql_conditions_group = " AND tagente.id_grupo IN (".$user_groups.")";
}
}
// Module group
if (defined('METACONSOLE')) {
if ($modulegroup != '-1')
@ -310,7 +315,9 @@ if ($flag_is_admin)
if (defined('METACONSOLE')) {
// 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)
$servers = array();
@ -727,8 +734,15 @@ switch ($config["dbtype"]) {
LIMIT ".$offset.",".$limit_sql;
break;
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
(SELECT STRING_AGG(ttag.name, ',')
(SELECT " . $string_agg . "
FROM ttag
WHERE ttag.id_tag IN (
SELECT ttag_module.id_tag
@ -760,7 +774,10 @@ switch ($config["dbtype"]) {
tagente_modulo.critical_instructions,
tagente_modulo.warning_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;
case "oracle":
$set = array();
@ -799,7 +816,9 @@ switch ($config["dbtype"]) {
tagente_modulo.critical_instructions,
tagente_modulo.warning_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);
break;
}