From 8110a458a93f184dcc2c7385ad8408264b51c186 Mon Sep 17 00:00:00 2001
From: slerena <slerena@gmail.com>
Date: Wed, 18 Jul 2007 18:01:06 +0000
Subject: [PATCH] 2007-07-18  Sancho Lerena  <slerena@artica.es>

        * include/functions_reporting.php: With last change in server, we
        have control of not initilizated modules (those who never got
        data/contact), we need to take care of them here.

        * pandoradb.sql: last_execution_try field is added to
        tagente_estado to be able to keep last execution try from network
        server, later method was incompatible with automatic compatation
        of data and with data server.

        * operation/agentes/estado_grupo.php: Unknown data not includes
        non initialized data. It's possible that need to make changes of
        this kind in other files because the nature of the problem
        detected.

        * operation/agentes/tactical.php: BugFix: LAG is now correct and
        makes reference to the oldest module that has been processed. Also
        are shown non initialized data.


        * operation/servers/view_server.php: BugFix: LAG is now correct
        (see above).



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@567 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
---
 pandora_console/ChangeLog                     | 24 ++++++++++
 .../include/functions_reporting.php           | 45 ++++++++++++-------
 pandora_console/index.php                     |  4 +-
 .../operation/agentes/estado_grupo.php        |  2 +-
 .../operation/agentes/tactical.php            | 23 ++++++++--
 .../operation/servers/view_server.php         |  2 +-
 pandora_console/pandoradb.sql                 |  2 +-
 7 files changed, 77 insertions(+), 25 deletions(-)

diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog
index a63abd66b3..5f48b93372 100644
--- a/pandora_console/ChangeLog
+++ b/pandora_console/ChangeLog
@@ -1,3 +1,27 @@
+2007-07-18  Sancho Lerena  <slerena@artica.es>
+
+        * include/functions_reporting.php: With last change in server, we
+        have control of not initilizated modules (those who never got
+        data/contact), we need to take care of them here.
+
+        * pandoradb.sql: last_execution_try field is added to
+        tagente_estado to be able to keep last execution try from network
+        server, later method was incompatible with automatic compatation
+        of data and with data server.
+
+        * operation/agentes/estado_grupo.php: Unknown data not includes
+        non initialized data. It's possible that need to make changes of
+        this kind in other files because the nature of the problem
+        detected.
+
+        * operation/agentes/tactical.php: BugFix: LAG is now correct and
+        makes reference to the oldest module that has been processed. Also
+        are shown non initialized data.
+
+
+        * operation/servers/view_server.php: BugFix: LAG is now correct
+        (see above).
+
 2007-07-16  Sancho Lerena <slerena@gmail.com>
 
 	* include/functions_db.php: Bugfix; list_group and list_group2 funtions
diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php
index 2ae9adb7f5..4fb00da278 100644
--- a/pandora_console/include/functions_reporting.php
+++ b/pandora_console/include/functions_reporting.php
@@ -56,9 +56,11 @@ function general_stats ( $id_user, $id_group = 0) {
 	$monitor_bad = 0;
 	$monitor_unknown =0;
 	$monitor_alert = 0;
+	$monitor_not_init=0;
 	$total_agents = 0;
 	$data_checks = 0;
 	$data_unknown =0;
+	$data_not_init = 0;
 	$data_alert = 0;
 	$data_alert_total = 0;
 	$monitor_alert_total = 0;
@@ -78,19 +80,22 @@ function general_stats ( $id_user, $id_group = 0) {
 				$existen_agentes = 1;
 
 			// SQL Join to get monitor status for agents belong this group
-			$sql1 = "SELECT tagente.id_agente, tagente_estado.estado, tagente_estado.datos, tagente_estado.current_interval, tagente_estado.utimestamp, tagente_estado.id_agente_modulo FROM tagente, tagente_estado WHERE tagente.disabled = 0 AND tagente.id_grupo = $migrupo AND tagente.id_agente = tagente_estado.id_agente";
+			$sql1 = "SELECT tagente.id_agente, tagente_estado.estado, tagente_estado.datos, tagente_estado.current_interval, tagente_estado.utimestamp, tagente_estado.id_agente_modulo FROM tagente, tagente_estado WHERE tagente.disabled = 0 AND tagente.id_grupo = $migrupo AND tagente.id_agente = tagente_estado.id_agente ";
 			if ($result1 = mysql_query ($sql1)){
 				while ($row1 = mysql_fetch_array ($result1)) {
 					$id_agente = $row1[0];
 					$estado = $row1[1];
 					$datos = $row1[2];
 					$module_interval = $row1[3];
-					$seconds = $ahora_sec - $row1[4];
+					$utimestamp = $row1[4];
+					$seconds = $ahora_sec - $utimestamp;
 					$id_agente_modulo = $row1[5];
 					if ($estado != 100){
 						// Monitor check
 						$monitor_checks++;
-						if ($seconds >= ($module_interval*2))
+						if ($utimestamp == 0)
+                                                        $monitor_not_init++;
+						elseif ($seconds >= ($module_interval*2))
 							$monitor_unknown++;
 						elseif ($datos != 0) {
 							$monitor_ok++;
@@ -98,26 +103,32 @@ function general_stats ( $id_user, $id_group = 0) {
 							$monitor_bad++;
 						}
 						// Alert
-						$sql2 = "SELECT times_fired FROM talerta_agente_modulo WHERE id_agente_modulo = $id_agente_modulo";
-						if ($result2 = mysql_query ($sql2)){
-							if ($row2 = mysql_fetch_array ($result2)){
-								$monitor_alert_total++;
-								if ($row2[0] > 0)
-									$monitor_alert++;
+						if ($utimestamp != 0){
+							$sql2 = "SELECT times_fired FROM talerta_agente_modulo WHERE id_agente_modulo = $id_agente_modulo";
+							if ($result2 = mysql_query ($sql2)){
+								if ($row2 = mysql_fetch_array ($result2)){
+									$monitor_alert_total++;
+									if ($row2[0] > 0)
+										$monitor_alert++;
+								}
 							}
 						}
 					} else {
 						// Data check
-						if ($seconds >= ($module_interval*2))
+						if ($utimestamp == 0)
+							$data_not_init++;
+						elseif ($seconds >= ($module_interval*2))
 							$data_unknown++;
 						$data_checks++;
 						// Alert
-						$sql2 = "SELECT times_fired FROM talerta_agente_modulo WHERE id_agente_modulo = $id_agente_modulo";
-						if ($result2 = mysql_query ($sql2)){
-							if ($row2 = mysql_fetch_array ($result2)) {
-								$data_alert_total++;
-								if ($row2[0] > 0)
-									$data_alert++;
+						if ($utimestamp != 0){
+							$sql2 = "SELECT times_fired FROM talerta_agente_modulo WHERE id_agente_modulo = $id_agente_modulo";
+							if ($result2 = mysql_query ($sql2)){
+								if ($row2 = mysql_fetch_array ($result2)) {
+									$data_alert_total++;
+									if ($row2[0] > 0)
+										$data_alert++;
+								}
 							}
 						}
 					}
@@ -137,6 +148,8 @@ function general_stats ( $id_user, $id_group = 0) {
 	$data[8] = $data_alert;
 	$data[9] = $data_alert_total;
 	$data[10] = $monitor_alert_total;
+	$data[11] = $data_not_init;
+	$data[12] = $monitor_not_init;
 	return $data;
 }
 
diff --git a/pandora_console/index.php b/pandora_console/index.php
index cd121de794..61f2dc24e0 100644
--- a/pandora_console/index.php
+++ b/pandora_console/index.php
@@ -25,8 +25,8 @@
 // Pandora FMS 1.x uses Pear Image::Graph code
 
 //Pandora Version, if not defined here it would take from config.php
-$build_version="PC070627";
-$pandora_version="v1.3 Beta 2";
+$build_version="PC070718";
+$pandora_version="v1.3-dev";
 global $build_version;
 global $pandora_version;
 
diff --git a/pandora_console/operation/agentes/estado_grupo.php b/pandora_console/operation/agentes/estado_grupo.php
index a0edbcac85..a41878615f 100644
--- a/pandora_console/operation/agentes/estado_grupo.php
+++ b/pandora_console/operation/agentes/estado_grupo.php
@@ -85,7 +85,7 @@
 				$existen_agentes = 1;
 
 			// SQL Join to get monitor status for agents belong this group
-			$sql1 = "SELECT tagente.id_agente, tagente_estado.estado, tagente_estado.datos, tagente_estado.current_interval, tagente_estado.utimestamp, tagente_estado.id_agente_modulo FROM tagente, tagente_estado WHERE tagente.disabled = 0 AND tagente.id_grupo = $migrupo AND tagente.id_agente = tagente_estado.id_agente AND tagente_estado.estado != 100";
+			$sql1 = "SELECT tagente.id_agente, tagente_estado.estado, tagente_estado.datos, tagente_estado.current_interval, tagente_estado.utimestamp, tagente_estado.id_agente_modulo FROM tagente, tagente_estado WHERE tagente.disabled = 0 AND tagente.id_grupo = $migrupo AND tagente.id_agente = tagente_estado.id_agente AND tagente_estado.estado != 100 AND tagente_estado.utimestamp != 0";
 			if ($result1 = mysql_query ($sql1)){
 				while ($row1 = mysql_fetch_array ($result1)) {
 					$id_agente = $row1[0];
diff --git a/pandora_console/operation/agentes/tactical.php b/pandora_console/operation/agentes/tactical.php
index 1e29b07787..9b1bfeb00b 100644
--- a/pandora_console/operation/agentes/tactical.php
+++ b/pandora_console/operation/agentes/tactical.php
@@ -47,7 +47,8 @@
 	$data_alert = $data[8];
 	$data_alert_total = $data[9];
 	$monitor_alert_total = $data[10];
-	
+	$data_not_init = $data[11];
+	$monitor_not_init = $data[12];	
 	$total_checks = $data_checks + $monitor_checks;
 
 	// Monitor checks
@@ -72,6 +73,14 @@
 		echo $monitor_unknown;
 	else
 		echo "-";
+
+	echo "</td></tr><tr><td class=datos><b>"."Monitor Not Init"."</b></td>";
+        echo "<td class=datos style='font: bold 2em Arial, Sans-serif; color: #888;'>";
+        if ($monitor_unknown > 0)
+                echo $monitor_not_init;
+        else
+                echo "-";
+
 	echo "<tr><td class=datos2><b>"."Alerts Fired"."</b></td>";
 	echo "<td class=datos2 style='font: bold 2em Arial, Sans-serif; color: #ff0000;'>";
 	if ($monitor_alert > 0)
@@ -94,12 +103,18 @@
 		echo $data_unknown;
 	else
 		echo "-";
-	echo "<tr><td class=datos2><b>"."Alerts Fired"."</b></td>";
+	echo "<tr><td class=datos2><b>"."Data not init"."</b></td>";
 	echo "<td class=datos2 style='font: bold 2em Arial, Sans-serif; color: #f00;'>";
 	if ($data_alert > 0)
-		echo $data_alert;
+		echo $data_not_init;
 	else
 		echo "-";
+	echo "<tr><td class=datos2><b>"."Alerts Fired"."</b></td>";
+        echo "<td class=datos2 style='font: bold 2em Arial, Sans-serif; color: #f00;'>";
+        if ($data_alert > 0)
+                echo $data_alert;
+        else
+                echo "-";
 	echo "<tr><td class=datos><b>"."Alerts Total";
 	echo "<td class=datos style='font: bold 2em Arial, Sans-serif; color: #000;'>".$data_alert_total;
 	echo "</table>";
@@ -264,7 +279,7 @@
 	                        // and calculate difference in seconds
 	                        // Get total modules defined for this server
 	                        if (($network_server == 1) OR ($data_server == 1)){
-	                                $sql1 = "SELECT MIN(utimestamp),current_interval FROM tagente_estado WHERE utimestamp > 0 AND running_by=$id_server GROUP BY current_interval ORDER BY 1";
+	                                $sql1 = "SELECT MIN(last_execution_try), current_interval FROM tagente_estado WHERE last_execution_try > 0 AND running_by=$id_server GROUP BY current_interval ORDER BY 1";
 	                                $nowtime = time();
 	                                $maxlag=0;
 	                                if ($result1=mysql_query($sql1))
diff --git a/pandora_console/operation/servers/view_server.php b/pandora_console/operation/servers/view_server.php
index 1336db423e..5340027200 100644
--- a/pandora_console/operation/servers/view_server.php
+++ b/pandora_console/operation/servers/view_server.php
@@ -170,7 +170,7 @@ if (comprueba_login() == 0) {
 			// and calculate difference in seconds 
 			// Get total modules defined for this server
 			if (($network_server == 1) OR ($data_server == 1)){
-				$sql1 = "SELECT MIN(utimestamp),current_interval FROM tagente_estado WHERE utimestamp > 0 AND running_by=$id_server GROUP BY current_interval ORDER BY 1";
+				$sql1 = "SELECT MIN(last_execution_try),current_interval FROM tagente_estado WHERE last_execution_try > 0 AND running_by=$id_server GROUP BY current_interval ORDER BY 1";
 				$nowtime = time();
 				$maxlag=0;
 				if ($result1=mysql_query($sql1))
diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql
index 60f4063010..0f64e68f07 100644
--- a/pandora_console/pandoradb.sql
+++ b/pandora_console/pandoradb.sql
@@ -95,6 +95,7 @@ CREATE TABLE `tagente_estado` (
   `utimestamp` bigint(20) NOT NULL default '0',
   `current_interval` int(10) unsigned NOT NULL default '0',
   `running_by` int(10) unsigned NULL default 0,
+  `last_execution_try` bigint(20) NOT NULL default '0',
   PRIMARY KEY  (`id_agente_estado`),
   KEY `status_index_1` (`id_agente_modulo`),
   KEY `status_index_2` (`id_agente_modulo`,`estado`)
@@ -572,4 +573,3 @@ CREATE TABLE `tlayout_data` (
   `no_link_color` tinyint(1) UNSIGNED NOT NULL default 0,
   PRIMARY KEY(`id`)
 ) ENGINE = InnoDB;
-