2011-03-04 Miguel de Dios <miguel.dedios@artica.es>

* include/db/postgresql.php, include/db/mysql.php, include/functions_db.php:
	the function "get_system_time" and derivate functions in DB engines.
	
	* include/functions_gis.php, include/functions_servers.php,
	include/help/en/help_timesource.php, include/help/es/help_timesource.php,
	include/help/ja/help_timesource.php, include/functions.php,
	operation/agentes/estado_agente.php, operation/agentes/gis_view.php,
	operation/gis_maps/render_view.php: added the SQL queries PostgreSQL
	compatible, in this case with the function to get unix_timestamp.



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@4058 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
mdtrooper 2011-03-04 12:36:23 +00:00
parent e3cf87c00f
commit d4c0c25414
13 changed files with 215 additions and 50 deletions

View File

@ -1,3 +1,15 @@
2011-03-04 Miguel de Dios <miguel.dedios@artica.es>
* include/db/postgresql.php, include/db/mysql.php, include/functions_db.php:
the function "get_system_time" and derivate functions in DB engines.
* include/functions_gis.php, include/functions_servers.php,
include/help/en/help_timesource.php, include/help/es/help_timesource.php,
include/help/ja/help_timesource.php, include/functions.php,
operation/agentes/estado_agente.php, operation/agentes/gis_view.php,
operation/gis_maps/render_view.php: added the SQL queries PostgreSQL
compatible, in this case with the function to get unix_timestamp.
2011-03-03 Miguel de Dios <miguel.dedios@artica.es>
* include/db/postgresql.php, include/db/mysql.php, include/functions_db.php:
fixed the function "get_db_all_rows_filter" for PostgreSQL engine, added

View File

@ -959,4 +959,29 @@ function mysql_safe_sql_string($string) {
function mysql_get_db_last_error() {
return mysql_error();
}
/**
* This function gets the time from either system or sql based on preference and returns it
*
* @return int Unix timestamp
*/
function mysql_get_system_time() {
global $config;
static $time = 0;
if ($time != 0)
return $time;
if ($config["timesource"] = "sql") {
$time = get_db_sql ("SELECT UNIX_TIMESTAMP();");
if (empty ($time)) {
return time ();
}
return $time;
}
else {
return time ();
}
}
?>

View File

@ -976,4 +976,29 @@ function postgresql_safe_sql_string($string) {
function postgresql_get_db_last_error() {
return pg_last_error();
}
/**
* This function gets the time from either system or sql based on preference and returns it
*
* @return int Unix timestamp
*/
function postgresql_get_system_time() {
global $config;
static $time = 0;
if ($time != 0)
return $time;
if ($config["timesource"] = "sql") {
$time = get_db_sql ("SELECT ceil(date_part('epoch', CURRENT_TIMESTAMP));");
if (empty ($time)) {
return time ();
}
return $time;
}
else {
return time ();
}
}
?>

View File

@ -314,19 +314,14 @@ function human_time_comparation ($timestamp, $units = 'large') {
*/
function get_system_time () {
global $config;
static $time = 0;
if ($time != 0)
return $time;
if ($config["timesource"] = "sql") {
$time = get_db_sql ("SELECT UNIX_TIMESTAMP()");
if (empty ($time)) {
return time ();
}
return $time;
} else {
return time ();
switch ($config["dbtype"]) {
case "mysql":
require_once ($config['homedir'] . '/include/db/mysql.php');
break;
case "postgresql":
require_once ($config['homedir'] . '/include/db/postgresql.php');
break;
}
}

View File

@ -26,10 +26,10 @@ function select_db_engine() {
switch ($config["dbtype"]) {
case "mysql":
require_once ($config['homedir'] . '/include/db/mysql.php');
return mysql_get_system_time();
break;
case "postgresql":
require_once ($config['homedir'] . '/include/db/postgresql.php');
return postgresql_get_system_time();
break;
}
}

View File

@ -502,12 +502,20 @@ function get_agent_icon_map($idAgent, $state = false, $status = null) {
* @return None
*/
function addPath($layerName, $idAgent, $lastPosition = null, $history_time = null) {
global $config;
if ($history_time === null) {
$where = '1 = 1';
}
else {
$where = 'start_timestamp >= FROM_UNIXTIME(UNIX_TIMESTAMP() - ' . $history_time . ')';
switch ($config["dbtype"]) {
case "mysql":
$where = 'start_timestamp >= FROM_UNIXTIME(UNIX_TIMESTAMP() - ' . $history_time . ')';
break;
case "postgresql":
$where = 'start_timestamp >= to_timestamp(ceil(date_part("epoch", CURRENT_TIMESTAMP)) - ' . $history_time . ')';
break;
}
}
$listPoints = get_db_all_rows_sql('SELECT *

View File

@ -112,14 +112,15 @@ function get_server_performance () {
* @return mixed False in case the server doesn't exist or an array with info.
*/
function get_server_info ($id_server = -1) {
global $config;
if (is_array ($id_server)) {
$select_id = " WHERE id_server IN (".implode (",", $id_server).")";
} elseif ($id_server > 0) {
}
elseif ($id_server > 0) {
$select_id = " WHERE id_server IN (".(int) $id_server.")";
} else {
}
else {
$select_id = "";
}
@ -202,7 +203,8 @@ function get_server_info ($id_server = -1) {
$server["modules"] = get_db_sql ("SELECT my_modules FROM tserver WHERE id_server = ".$server["id_server"]);
$server["modules_total"] = get_db_sql ("SELECT total_modules_running FROM tserver WHERE id_server = ".$server["id_server"]);
} else {
}
else {
// ---------------------------------------------------------------
// Take data in realtime
@ -224,27 +226,56 @@ function get_server_info ($id_server = -1) {
$server["modules_total"] = get_db_sql ("SELECT count(tagente_estado.id_agente_modulo) FROM tserver, tagente_estado, tagente_modulo, tagente WHERE tagente.disabled=0 AND tagente_modulo.id_agente = tagente.id_agente AND tagente_modulo.disabled = 0 AND tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo AND tagente_estado.running_by = tserver.id_server AND tserver.server_type = ".$server["server_type"]);
// Remote servers LAG Calculation (server_type != 0)
if ($server["server_type"] != 0){
$result = get_db_row_sql ("SELECT COUNT(tagente_modulo.id_agente_modulo) AS module_lag, AVG(UNIX_TIMESTAMP() - utimestamp - current_interval) AS lag FROM tagente_estado, tagente_modulo
WHERE utimestamp > 0
AND tagente_modulo.disabled = 0
AND tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo
AND current_interval > 0
AND running_by = ".$server["id_server"]."
AND (UNIX_TIMESTAMP() - utimestamp) < ( current_interval * 10)
AND (UNIX_TIMESTAMP() - utimestamp) > current_interval");
} else {
// Local/Dataserver server LAG calculation:
$result = get_db_row_sql ("SELECT COUNT(tagente_modulo.id_agente_modulo) AS module_lag, AVG(UNIX_TIMESTAMP() - utimestamp - current_interval) AS lag FROM tagente_estado, tagente_modulo
WHERE utimestamp > 0
AND tagente_modulo.disabled = 0
AND tagente_modulo.id_tipo_modulo < 5
AND tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo
AND current_interval > 0
AND (UNIX_TIMESTAMP() - utimestamp) < ( current_interval * 10)
AND running_by = ".$server["id_server"]."
AND (UNIX_TIMESTAMP() - utimestamp) > (current_interval * 1.1)");
if ($server["server_type"] != 0) {
switch ($config["dbtype"]) {
case "mysql":
$result = get_db_row_sql ("SELECT COUNT(tagente_modulo.id_agente_modulo) AS module_lag, AVG(UNIX_TIMESTAMP() - utimestamp - current_interval) AS lag FROM tagente_estado, tagente_modulo
WHERE utimestamp > 0
AND tagente_modulo.disabled = 0
AND tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo
AND current_interval > 0
AND running_by = ".$server["id_server"]."
AND (UNIX_TIMESTAMP() - utimestamp) < ( current_interval * 10)
AND (UNIX_TIMESTAMP() - utimestamp) > current_interval");
break;
case "postgresql":
$result = get_db_row_sql ("SELECT COUNT(tagente_modulo.id_agente_modulo) AS module_lag, AVG(ceil(date_part('epoch', CURRENT_TIMESTAMP)) - utimestamp - current_interval) AS lag FROM tagente_estado, tagente_modulo
WHERE utimestamp > 0
AND tagente_modulo.disabled = 0
AND tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo
AND current_interval > 0
AND running_by = ".$server["id_server"]."
AND (ceil(date_part('epoch', CURRENT_TIMESTAMP)) - utimestamp) < ( current_interval * 10)
AND (ceil(date_part('epoch', CURRENT_TIMESTAMP)) - utimestamp) > current_interval");
break;
}
}
else {
// Local/Dataserver server LAG calculation:
switch ($config["dbtype"]) {
case "mysql":
$result = get_db_row_sql ("SELECT COUNT(tagente_modulo.id_agente_modulo) AS module_lag, AVG(UNIX_TIMESTAMP() - utimestamp - current_interval) AS lag FROM tagente_estado, tagente_modulo
WHERE utimestamp > 0
AND tagente_modulo.disabled = 0
AND tagente_modulo.id_tipo_modulo < 5
AND tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo
AND current_interval > 0
AND (UNIX_TIMESTAMP() - utimestamp) < ( current_interval * 10)
AND running_by = ".$server["id_server"]."
AND (UNIX_TIMESTAMP() - utimestamp) > (current_interval * 1.1)");
break;
case "postgresql":
$result = get_db_row_sql ("SELECT COUNT(tagente_modulo.id_agente_modulo) AS module_lag, AVG(ceil(date_part('epoch', CURRENT_TIMESTAMP)) - utimestamp - current_interval) AS lag FROM tagente_estado, tagente_modulo
WHERE utimestamp > 0
AND tagente_modulo.disabled = 0
AND tagente_modulo.id_tipo_modulo < 5
AND tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo
AND current_interval > 0
AND (ceil(date_part('epoch', CURRENT_TIMESTAMP)) - utimestamp) < ( current_interval * 10)
AND running_by = ".$server["id_server"]."
AND (ceil(date_part('epoch', CURRENT_TIMESTAMP)) - utimestamp) > (current_interval * 1.1)");
break;
}
}
// Lag over current_interval * 2 is not lag, it's a timed out module
@ -261,7 +292,8 @@ function get_server_info ($id_server = -1) {
// Recon server only
// ---------------------------------------------------------------
} elseif ($server["server_type"] == 3) {
}
elseif ($server["server_type"] == 3) {
$server["name"] = '<a href="index.php?sec=estado_server&amp;sec2=operation/servers/view_server_detail&amp;server_id='.$server["id_server"].'">'.$server["name"].'</a>';
@ -274,10 +306,18 @@ function get_server_info ($id_server = -1) {
//Lag (take average active time of all active tasks)
$server["module_lag"] = 0;
$server["lag"] = get_db_sql ("SELECT UNIX_TIMESTAMP() - utimestamp from trecon_task WHERE UNIX_TIMESTAMP() > (utimestamp + interval_sweep) AND id_recon_server = ".$server["id_server"]);
switch ($config["dbtype"]) {
case "mysql":
$server["lag"] = get_db_sql ("SELECT UNIX_TIMESTAMP() - utimestamp from trecon_task WHERE UNIX_TIMESTAMP() > (utimestamp + interval_sweep) AND id_recon_server = ".$server["id_server"]);
$server["module_lag"] = get_db_sql ("SELECT COUNT(id_rt) FROM trecon_task WHERE UNIX_TIMESTAMP() > (utimestamp + interval_sweep) AND id_recon_server = ".$server["id_server"]);
$server["module_lag"] = get_db_sql ("SELECT COUNT(id_rt) FROM trecon_task WHERE UNIX_TIMESTAMP() > (utimestamp + interval_sweep) AND id_recon_server = ".$server["id_server"]);
break;
case "postgresql":
$server["lag"] = get_db_sql ("SELECT ceil(date_part('epoch', CURRENT_TIMESTAMP)) - utimestamp from trecon_task WHERE ceil(date_part('epoch', CURRENT_TIMESTAMP)) > (utimestamp + interval_sweep) AND id_recon_server = ".$server["id_server"]);
$server["module_lag"] = get_db_sql ("SELECT COUNT(id_rt) FROM trecon_task WHERE ceil(date_part('epoch', CURRENT_TIMESTAMP)) > (utimestamp + interval_sweep) AND id_recon_server = ".$server["id_server"]);
break;
}
} // recon
} // Take data for realtime mode

View File

@ -34,7 +34,20 @@ $option = array ("prominent" => "timestamp");
?>
<b>Current System time:</b> <?php print_timestamp (time (), false, $option); ?>
<br />
<b>Current Database time:</b> <?php print_timestamp (get_db_sql ("SELECT UNIX_TIMESTAMP()"), false, $option); ?>
<b>Current Database time:</b>
<?php
global $config;
switch ($config["dbtype"]) {
case "mysql":
$timestamp = get_db_value_sql("SELECT UNIX_TIMESTAMP();");
break;
case "postgresql":
$timestamp = get_db_value_sql("SELECT ceil(date_part('epoch', CURRENT_TIMESTAMP));");
break;
}
print_timestamp ($timestamp, false, $option);
?>
<br />
<b>Your browser time:</b> <script type="text/javascript">document.write (date);</script>
</p>

View File

@ -34,7 +34,20 @@ $option = array ("prominent" => "timestamp");
?>
<b>Hora actual del sistema:</b> <?php print_timestamp (time (), false, $option); ?>
<br />
<b>Hora actual de la base de datos:</b> <?php print_timestamp (get_db_sql ("SELECT UNIX_TIMESTAMP()"), false, $option); ?>
<b>Hora actual de la base de datos:</b>
<?php
global $config;
switch ($config["dbtype"]) {
case "mysql":
$timestamp = get_db_value_sql("SELECT UNIX_TIMESTAMP();");
break;
case "postgresql":
$timestamp = get_db_value_sql("SELECT ceil(date_part('epoch', CURRENT_TIMESTAMP));");
break;
}
print_timestamp ($timestamp, false, $option);
?>
<br />
<b>Hora de su navegador:</b> <script type="text/javascript">document.write (date);</script>
</p>

View File

@ -29,7 +29,20 @@ $option = array ("prominent" => "timestamp");
?>
<b>現在のシステムの時刻:</b> <?php print_timestamp (time (), false, $option); ?>
<br />
<b>現在のデータベースの時刻:</b> <?php print_timestamp (get_db_sql ("SELECT UNIX_TIMESTAMP()"), false, $option); ?>
<b>現在のデータベースの時刻:</b>
<?php
global $config;
switch ($config["dbtype"]) {
case "mysql":
$timestamp = get_db_value_sql("SELECT UNIX_TIMESTAMP();");
break;
case "postgresql":
$timestamp = get_db_value_sql("SELECT ceil(date_part('epoch', CURRENT_TIMESTAMP));");
break;
}
print_timestamp ($timestamp, false, $option);
?>
<br />
<b>あなたのブラウザの時刻:</b> <script type="text/javascript">document.write (date);</script>
</p>

View File

@ -76,6 +76,13 @@ if (is_ajax ()) {
return;
}
$first = true;
while ($row = get_db_all_row_by_steps_sql($first, $result, "SELECT * FROM tgrupo")){
$first = false;
debugPrint($row);
}
// Take some parameters (GET)
$group_id = (int) get_parameter ("group_id", 0);
$search = safe_output(get_parameter ("search", ""));

View File

@ -49,7 +49,14 @@ if (!getAgentMap($agentId, "500px", "98%", true, true, $period)) {
echo "<br /><div class='nf'>" . __("There is no default map.") . "</div>";
}
$timestampLastOperation = get_db_value_sql("SELECT UNIX_TIMESTAMP()");
switch ($config["dbtype"]) {
case "mysql":
$timestampLastOperation = get_db_value_sql("SELECT UNIX_TIMESTAMP();");
break;
case "postgresql":
$timestampLastOperation = get_db_value_sql("SELECT ceil(date_part('epoch', CURRENT_TIMESTAMP));");
break;
}
activateAjaxRefresh(null, $timestampLastOperation);
activateSelectControl();

View File

@ -171,8 +171,15 @@ if ($layers != false) {
}
}
addParentLines();
$timestampLastOperation = get_db_value_sql("SELECT UNIX_TIMESTAMP()");
switch ($config["dbtype"]) {
case "mysql":
$timestampLastOperation = get_db_value_sql("SELECT UNIX_TIMESTAMP();");
break;
case "postgresql":
$timestampLastOperation = get_db_value_sql("SELECT ceil(date_part('epoch', CURRENT_TIMESTAMP));");
break;
}
activateSelectControl();
activateAjaxRefresh($layers, $timestampLastOperation);