From 444148c60a831e8a3fe82d534723a4d67ec3a00a Mon Sep 17 00:00:00 2001
From: mdtrooper
Date: Fri, 4 Mar 2011 12:36:23 +0000
Subject: [PATCH] 2011-03-04 Miguel de Dios
* 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
---
pandora_console/ChangeLog | 12 +++
pandora_console/include/db/mysql.php | 25 +++++
pandora_console/include/db/postgresql.php | 25 +++++
pandora_console/include/functions.php | 21 ++--
pandora_console/include/functions_db.php | 4 +-
pandora_console/include/functions_gis.php | 10 +-
pandora_console/include/functions_servers.php | 96 +++++++++++++------
.../include/help/en/help_timesource.php | 15 ++-
.../include/help/es/help_timesource.php | 15 ++-
.../include/help/ja/help_timesource.php | 15 ++-
.../operation/agentes/estado_agente.php | 7 ++
.../operation/agentes/gis_view.php | 9 +-
.../operation/gis_maps/render_view.php | 11 ++-
13 files changed, 215 insertions(+), 50 deletions(-)
diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog
index 7a6d453ece..b13f5f80cb 100644
--- a/pandora_console/ChangeLog
+++ b/pandora_console/ChangeLog
@@ -1,3 +1,15 @@
+2011-03-04 Miguel de Dios
+
+ * 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
* include/db/postgresql.php, include/db/mysql.php, include/functions_db.php:
fixed the function "get_db_all_rows_filter" for PostgreSQL engine, added
diff --git a/pandora_console/include/db/mysql.php b/pandora_console/include/db/mysql.php
index da5ec44ab5..cf5340eb8a 100644
--- a/pandora_console/include/db/mysql.php
+++ b/pandora_console/include/db/mysql.php
@@ -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 ();
+ }
+}
?>
\ No newline at end of file
diff --git a/pandora_console/include/db/postgresql.php b/pandora_console/include/db/postgresql.php
index a84daec18e..d9b68a36bb 100644
--- a/pandora_console/include/db/postgresql.php
+++ b/pandora_console/include/db/postgresql.php
@@ -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 ();
+ }
+}
?>
\ No newline at end of file
diff --git a/pandora_console/include/functions.php b/pandora_console/include/functions.php
index bd614f4a37..4011519e84 100644
--- a/pandora_console/include/functions.php
+++ b/pandora_console/include/functions.php
@@ -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;
}
}
diff --git a/pandora_console/include/functions_db.php b/pandora_console/include/functions_db.php
index 537478b32d..d4227e716f 100644
--- a/pandora_console/include/functions_db.php
+++ b/pandora_console/include/functions_db.php
@@ -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;
}
}
diff --git a/pandora_console/include/functions_gis.php b/pandora_console/include/functions_gis.php
index cbbebfe5c5..eb706b7be0 100644
--- a/pandora_console/include/functions_gis.php
+++ b/pandora_console/include/functions_gis.php
@@ -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 *
diff --git a/pandora_console/include/functions_servers.php b/pandora_console/include/functions_servers.php
index f56db4ae56..20f794b366 100644
--- a/pandora_console/include/functions_servers.php
+++ b/pandora_console/include/functions_servers.php
@@ -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"] = ''.$server["name"].'';
@@ -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
diff --git a/pandora_console/include/help/en/help_timesource.php b/pandora_console/include/help/en/help_timesource.php
index 1996e19ec3..c23c9248e7 100644
--- a/pandora_console/include/help/en/help_timesource.php
+++ b/pandora_console/include/help/en/help_timesource.php
@@ -34,7 +34,20 @@ $option = array ("prominent" => "timestamp");
?>
Current System time:
-Current Database time:
+Current Database time:
+
Your browser time:
\ No newline at end of file
diff --git a/pandora_console/include/help/es/help_timesource.php b/pandora_console/include/help/es/help_timesource.php
index ed6c3fe9ad..0b278b614b 100644
--- a/pandora_console/include/help/es/help_timesource.php
+++ b/pandora_console/include/help/es/help_timesource.php
@@ -34,7 +34,20 @@ $option = array ("prominent" => "timestamp");
?>
Hora actual del sistema:
-Hora actual de la base de datos:
+Hora actual de la base de datos:
+
Hora de su navegador:
\ No newline at end of file
diff --git a/pandora_console/include/help/ja/help_timesource.php b/pandora_console/include/help/ja/help_timesource.php
index 655bd45018..d494c5dcb0 100644
--- a/pandora_console/include/help/ja/help_timesource.php
+++ b/pandora_console/include/help/ja/help_timesource.php
@@ -29,7 +29,20 @@ $option = array ("prominent" => "timestamp");
?>
現在のシステムの時刻:
-現在のデータベースの時刻:
+現在のデータベースの時刻:
+
あなたのブラウザの時刻:
diff --git a/pandora_console/operation/agentes/estado_agente.php b/pandora_console/operation/agentes/estado_agente.php
index a996f97b96..f9552d3dff 100644
--- a/pandora_console/operation/agentes/estado_agente.php
+++ b/pandora_console/operation/agentes/estado_agente.php
@@ -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", ""));
diff --git a/pandora_console/operation/agentes/gis_view.php b/pandora_console/operation/agentes/gis_view.php
index 57e2bf2f80..8e3387a023 100644
--- a/pandora_console/operation/agentes/gis_view.php
+++ b/pandora_console/operation/agentes/gis_view.php
@@ -49,7 +49,14 @@ if (!getAgentMap($agentId, "500px", "98%", true, true, $period)) {
echo "
" . __("There is no default map.") . "
";
}
-$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();
diff --git a/pandora_console/operation/gis_maps/render_view.php b/pandora_console/operation/gis_maps/render_view.php
index fd7c4e3304..60250e9f65 100644
--- a/pandora_console/operation/gis_maps/render_view.php
+++ b/pandora_console/operation/gis_maps/render_view.php
@@ -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);