2012-10-16 Ramon Novoa <rnovoa@artica.es>

* include/db/postgresql.php, include/db/mysql.php,
	  include/db/oracle.php, include/functions_db.php,
	  operation/agentes/datos_agente.php: Merged from 4.0 branch. Fixed
	  history database connection when the main database and the history
	  database are on the same host. Allow switching between the main
	  database and the history database to retrieve module data.



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@7078 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
ramonn 2012-10-16 11:49:13 +00:00
parent 4e6ebfa912
commit 3679d7db92
6 changed files with 42 additions and 16 deletions

View File

@ -1,3 +1,12 @@
2012-10-16 Ramon Novoa <rnovoa@artica.es>
* include/db/postgresql.php, include/db/mysql.php,
include/db/oracle.php, include/functions_db.php,
operation/agentes/datos_agente.php: Merged from 4.0 branch. Fixed
history database connection when the main database and the history
database are on the same host. Allow switching between the main
database and the history database to retrieve module data.
2012-10-15 Dario Roriguez <dario.rodriguez@artica.es>
* extensions/agents_alerts.php: Modified to show

View File

@ -30,7 +30,7 @@ function mysql_connect_db($host = null, $db = null, $user = null, $pass = null,
// Non-persistent connection: This will help to avoid mysql errors like "has gone away" or locking problems
// If you want persistent connections change it to mysql_pconnect().
$connect_id = mysql_connect($host . ":" . $port, $user, $pass);
$connect_id = mysql_connect($host . ":" . $port, $user, $pass, true);
if (! $connect_id) {
return false;
}

View File

@ -30,7 +30,7 @@ function oracle_connect_db($host = null, $db = null, $user = null, $pass = null,
// Non-persistent connection: This will help to avoid mysql errors like "has gone away" or locking problems
// If you want persistent connections change it to oci_pconnect().
$connect_id = oci_connect($user, $pass, '//' . $host . ':' . $port . '/' . $db);
$connect_id = oci_new_connect($user, $pass, '//' . $host . ':' . $port . '/' . $db);
if (! $connect_id) {
return false;
}

View File

@ -32,7 +32,7 @@ function postgresql_connect_db($host = null, $db = null, $user = null, $pass = n
" port=" . $port .
" dbname='" . $db . "'" .
" user='" . $user . "'" .
" password='" . $pass . "'");
" password='" . $pass . "'", PGSQL_CONNECT_FORCE_NEW);
if (! $connect_id) {
return false;

View File

@ -278,18 +278,18 @@ function db_get_value_filter ($field, $table, $filter, $where_join = 'AND') {
* @return the first value of the first row of a table result from query.
*
*/
function db_get_value_sql($sql) {
function db_get_value_sql($sql, $dbconnection = false) {
global $config;
switch ($config["dbtype"]) {
case "mysql":
return mysql_db_get_value_sql($sql);
return mysql_db_get_value_sql($sql, $dbconnection);
break;
case "postgresql":
return postgresql_db_get_value_sql($sql);
return postgresql_db_get_value_sql($sql, $dbconnection);
break;
case "oracle":
return oracle_db_get_value_sql($sql);
return oracle_db_get_value_sql($sql, $dbconnection);
break;
}
}
@ -420,18 +420,18 @@ function db_get_sql ($sql, $field = 0, $search_history_db = false) {
* @return mixed A matrix with all the values returned from the SQL statement or
* false in case of empty result
*/
function db_get_all_rows_sql($sql, $search_history_db = false, $cache = true) {
function db_get_all_rows_sql($sql, $search_history_db = false, $cache = true, $dbconnection = false) {
global $config;
switch ($config["dbtype"]) {
case "mysql":
return mysql_db_get_all_rows_sql($sql, $search_history_db, $cache);
return mysql_db_get_all_rows_sql($sql, $search_history_db, $cache, $dbconnection);
break;
case "postgresql":
return postgresql_db_get_all_rows_sql($sql, $search_history_db, $cache);
return postgresql_db_get_all_rows_sql($sql, $search_history_db, $cache, $dbconnection);
break;
case "oracle":
return oracle_db_get_all_rows_sql($sql, $search_history_db, $cache);
return oracle_db_get_all_rows_sql($sql, $search_history_db, $cache, $dbconnection);
break;
}
}

View File

@ -28,6 +28,17 @@ $group = agents_get_agentmodule_group ($module_id);
$agentId = get_parameter("id_agente");
$freestring = get_parameter ("freestring");
// Select active connection
$connection = get_parameter ("connection", 'main');
if ($connection == 'history' && $config['history_db_enabled'] == 1) {
if (! isset ($config['history_db_connection']) || $config['history_db_connection'] === false) {
$config['history_db_connection'] = db_connect($config['history_db_host'], $config['history_db_name'], $config['history_db_user'], $config['history_db_pass'], $config['history_db_port'], false);
}
$connection_handler = $config['history_db_connection'];
} else {
$connection_handler = $config['dbconnection'];
}
$selection_mode = get_parameter('selection_mode', 'fromnow');
$date_from = (string) get_parameter ('date_from', date ('Y-m-j'));
$time_from = (string) get_parameter ('time_from', date ('h:iA'));
@ -125,7 +136,7 @@ $sql_body = io_safe_output($sql_body);
$sql = "SELECT * " . $sql_body;
$sql_count = "SELECT count(*) " . $sql_body;
$count = db_get_table_count($sql_count, true);
$count = db_get_value_sql ($sql_count, $connection_handler);
switch ($config["dbtype"]) {
case "mysql":
@ -142,7 +153,7 @@ switch ($config["dbtype"]) {
break;
}
$result = db_get_all_rows_sql ($sql, true);
$result = db_get_all_rows_sql ($sql, false, true, $connection_handler);
if ($result === false) {
$result = array ();
}
@ -155,7 +166,15 @@ if (($config['dbtype'] == 'oracle') && ($result !== false)) {
$header_title = __('Received data from')." ".modules_get_agentmodule_agent_name ($module_id)." / ".modules_get_agentmodule_name ($module_id);
echo "<h4>".$header_title. "</h4>";
echo "<form method='post' action='index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente=" . $agentId . "&tab=data_view&id=" . $module_id . "'>";
echo "<h4>".$header_title;
if ($config['history_db_enabled'] == 1) {
echo "&nbsp;";
html_print_select (array ('main' => __('Main database'), 'history' => __('History database')), "connection", $connection);
ui_print_help_tip (__('Switch between the main database and the history database to retrieve module data'));
}
echo "</h4>";
$formtable->width = '98%';
$formtable->class = "databox";
@ -165,8 +184,6 @@ $formtable->size[0] = '40%';
$formtable->size[1] = '20%';
$formtable->size[2] = '30%';
echo "<form method='post' action='index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente=" . $agentId . "&tab=data_view&id=" . $module_id . "'>";
$formtable->data[0][0] = html_print_radio_button_extended ("selection_mode", 'fromnow', '', $selection_mode, false, '', 'style="margin-right: 15px;"', true) . __("Choose a time from now");
$formtable->data[0][1] = html_print_extended_select_for_time ('period', $period, '', '', '0', 10, true);