From 449e38dc44c8d9c6866a4810cca1f92a0260a824 Mon Sep 17 00:00:00 2001
From: slerena <slerena@gmail.com>
Date: Thu, 3 May 2007 02:15:42 +0000
Subject: [PATCH] 2007-05-03  Sancho Lerena  <slerena@artica.es>

        * bin/pandora_network.pl: Fix problem with ICMP timeouts.

        * util/pandora_dbstress.pl: Update for new needsupdate fix in some
        DB code. Needs to be improved for specific module/agent selection.




git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@449 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
---
 pandora_server/ChangeLog                |  8 ++++++++
 pandora_server/bin/pandora_network.pl   | 12 +++++------
 pandora_server/conf/pandora_server.conf | 12 +++++------
 pandora_server/util/pandora_dbstress.pl | 27 +++++++++++++------------
 4 files changed, 34 insertions(+), 25 deletions(-)

diff --git a/pandora_server/ChangeLog b/pandora_server/ChangeLog
index 29bd97b173..70c7f598ed 100644
--- a/pandora_server/ChangeLog
+++ b/pandora_server/ChangeLog
@@ -1,3 +1,11 @@
+2007-05-03  Sancho Lerena  <slerena@artica.es>
+
+	* bin/pandora_network.pl: Fix problem with ICMP timeouts.
+	
+	* util/pandora_dbstress.pl: Update for new needsupdate fix in some
+	DB code. Needs to be improved for specific module/agent selection.
+	
+
 2007-04-24  Sancho Lerena  <slerena@artica.es>
 
 	* pandora_db.pm: Added sanity checks to avoid problems when some
diff --git a/pandora_server/bin/pandora_network.pl b/pandora_server/bin/pandora_network.pl
index f7182bd840..069541cd9a 100755
--- a/pandora_server/bin/pandora_network.pl
+++ b/pandora_server/bin/pandora_network.pl
@@ -25,7 +25,7 @@ use Time::Local;            # DateTime basic manipulation
 use Net::Ping;				# For ICMP latency
 use Time::HiRes;			# For high precission timedate functions (Net::Ping)
 use IO::Socket;				# For TCP/UDP access
-use SNMP;				# For SNMP access (libnet-snmp-perl package!
+use SNMP;				# For SNMP access (libsnmp-perl PACKAGE!)
 use threads;
 
 # Pandora Modules
@@ -324,7 +324,7 @@ sub pandora_ping_icmp {
 	my $l_timeout = $_[1];
 
 	$p = Net::Ping->new("icmp",$l_timeout);
-	if ($p->ping($dest)) {
+	if ($p->ping($dest) == 1) {
 		$p->close();  
 		return 1;
 	} else {
@@ -510,7 +510,7 @@ sub exec_network_module {
 			$module_result = 0; # Successful
 			$module_data = 1;
 		} else {
-			$module_result = 1; # Error, cannot connect
+			$module_result = 0; # If cannot connect, its down.
 			$module_data = 0;
 		}
 	} elsif ($id_tipo_modulo == 7){ # ICMP (data for latency in ms)
@@ -576,9 +576,9 @@ sub exec_network_module {
 		my %part;
 		$part{'name'}[0]=$nombre;
 		$part{'description'}[0]="";
-		$part{'data'}[0]=$module_data;
-		$part{'max'}[0]=$max;
-		$part{'min'}[0]=$min;
+		$part{'data'}[0] = $module_data;
+		$part{'max'}[0] = $max;
+		$part{'min'}[0] = $min;
 		my $timestamp = &UnixDate("today","%Y-%m-%d %H:%M:%S");
 		my $tipo_modulo = dame_nombretipomodulo_idagentemodulo ($pa_config, $id_tipo_modulo, $dbh);
 		if (($tipo_modulo eq 'remote_snmp') || ($tipo_modulo eq 'remote_icmp') || ($tipo_modulo eq 'remote_tcp') || ($tipo_modulo eq 'remote_udp'))  {
diff --git a/pandora_server/conf/pandora_server.conf b/pandora_server/conf/pandora_server.conf
index 7f893160e0..89cf759dbe 100755
--- a/pandora_server/conf/pandora_server.conf
+++ b/pandora_server/conf/pandora_server.conf
@@ -6,7 +6,7 @@
 # if not given, it takes localhost. It's preferable to setup one
 # because machine name could change by some reason.
 
-servername localhost
+#servername 
 
 # incomingdir:  Defines directory where incoming data packets are stored
 # You could set directory relative to base path or absolute, starting with /
@@ -25,7 +25,7 @@ errorlog_file /var/log/pandora_server.error
 
 # dbuser:  Database user name (pandora by default)
 
-dbuser pandora
+dbuser root
 
 # daemon: Runs in daemon mode (background) if 1, if 0 runs in foreground 
 # this could be setup on command line with -D option
@@ -34,7 +34,7 @@ dbuser pandora
 
 # dbpass: Database password
 
-dbpass pandora
+dbpass none
 
 # dbhost: Database hostname or IP address
 
@@ -43,7 +43,7 @@ dbhost localhost
 # verbosity: level of detail on errors/messages (0 default, 1 verbose, 2 debug.... 10 noisy)
 # -v in command line (verbose) or -d (debug)
 
-verbosity 4
+verbosity 10
 
 # Alert threshold
 
@@ -80,9 +80,9 @@ network_timeout 5
 
 # Server keepalive (in seconds)
 
-server_keepalive 90
+server_keepalive 30
 
 # Server Threshold: defines number of seconds of main loop (in sec)
 
-server_threshold 5
+server_threshold 10
 
diff --git a/pandora_server/util/pandora_dbstress.pl b/pandora_server/util/pandora_dbstress.pl
index 2ad494ff70..39c667865a 100755
--- a/pandora_server/util/pandora_dbstress.pl
+++ b/pandora_server/util/pandora_dbstress.pl
@@ -18,9 +18,10 @@
 #Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 ################################################################################
 
+# Configure here target (AGENT_ID for Stress)
+my $target_agent_id = 1; # -1 for all modules of that agent
 my $target_interval = 300;
-my $target_days = 30 ;
-my $target_agent = 640; # if -1, uses ALL agents
+my $target_days = 45;
 
 ################################################################################
 ################################################################################
@@ -40,7 +41,7 @@ use pandora_db;
 ################################################################################
 ################################################################################
 
-my $version = "1.3-dev 070312";
+my $version = "1.3-dev 070216";
 
 # FLUSH in each IO (only for debug, very slooow)
 # ENABLED in DEBUGMODE
@@ -58,9 +59,11 @@ pandora_loadconfig (\%pa_config,0); #Start like a data server
 # open database, only ONCE. We pass reference to DBI handler ($dbh) to all subprocess
 my $dbh = DBI->connect("DBI:mysql:pandora:$pa_config{'dbhost'}:3306",$pa_config{'dbuser'}, $pa_config{'dbpass'},	{ RaiseError => 1, AutoCommit => 1 });
 
+print " [*] Working for agent ID $target_agent_id \n";
 print " [*] Generating data of $target_days days ago \n";
 print " [*] Interval for this workload is $target_interval \n";
 
+# For each module of $target_agent_id
 my $query_idag;
 
 if ($target_agent ne -1){
@@ -72,12 +75,10 @@ if ($target_agent ne -1){
 my $s_idag = $dbh->prepare($query_idag);
 $s_idag ->execute;
 my @data;
-# Read all alerts and apply to this incoming trap 
 if ($s_idag->rows != 0) {
 	while (@data = $s_idag->fetchrow_array()) {
-print " [*] Working for agent ID ".$data[1]." \n";
 		# Fill this module with data !
-		process_module (\%pa_config, $data[0], $target_interval, $data[4], $target_days, $data[2], $data[1], $dbh);
+		process_module (\%pa_config, $data[0], $target_interval, $data[4], $target_days, $data[2], $target_agent_id, $dbh);
 	}
 }
 $s_idag->finish();
@@ -115,7 +116,7 @@ sub process_module(){
 	my $fecha_actual = &UnixDate("today","%Y-%m-%d %H:%M:%S");      
 	my $m_timestamp = DateCalc($fecha_actual,"- $target_days days",\$err);
 	my $mysql_date;
-
+	my $bUpdateDatos;
 	# Calculate how many iterations need to fill data range
 	# $target_days*min*sec / $target_interval 
 
@@ -145,8 +146,8 @@ sub process_module(){
 			}
 			pandora_lastagentcontact($pa_config, $mysql_date, $agent_name, "none","1.2", $target_interval, $dbh);
 			# print LOG $mysql_date, $target_name, $valor, "\n";
-			pandora_writedata($pa_config,$mysql_date,$agent_name,$target_type,$target_name,$valor,0,0,"",$dbh);			
-			pandora_writestate ($pa_config,$agent_name,$target_type,$target_name,$valor,100,$dbh);
+			pandora_writedata($pa_config,$mysql_date,$agent_name,$target_type,$target_name,$valor,0,0,"",$dbh,\$bUpdateDatos);			
+			pandora_writestate ($pa_config,$agent_name,$target_type,$target_name,$valor,100,$dbh,$bUpdateDatos);
 			}
 	}
 
@@ -164,8 +165,8 @@ sub process_module(){
 			}
 			pandora_lastagentcontact($pa_config, $mysql_date, $agent_name, "none","1.2", $target_interval, $dbh);
 			#print LOG $mysql_date, $target_name, $valor, "\n";
-			pandora_writedata($pa_config,$mysql_date,$agent_name,$target_type,$target_name,$valor,0,0,"",$dbh);			
-			pandora_writestate ($pa_config,$agent_name,$target_type,$target_name,$valor,100,$dbh);
+			pandora_writedata($pa_config,$mysql_date,$agent_name,$target_type,$target_name,$valor,0,0,"",$dbh,\$bUpdateDatos);			
+			pandora_writestate ($pa_config,$agent_name,$target_type,$target_name,$valor,100,$dbh,$bUpdateDatos);
 		}
 
 	}
@@ -186,8 +187,8 @@ sub process_module(){
 			}
 			pandora_lastagentcontact($pa_config, $mysql_date, $agent_name, "none","1.2", $target_interval, $dbh);
 			#print LOG $mysql_date, $target_name, $valor, "\n";
-			pandora_writedata($pa_config,$mysql_date,$agent_name,$target_type,$target_name,$valor,0,0,"",$dbh);
-			pandora_writestate ($pa_config,$agent_name,$target_type,$target_name,$valor,$valor,$dbh);
+			pandora_writedata($pa_config,$mysql_date,$agent_name,$target_type,$target_name,$valor,0,0,"",$dbh,\$bUpdateDatos);
+			pandora_writestate ($pa_config,$agent_name,$target_type,$target_name,$valor,$valor,$dbh,$bUpdateDatos);
 		}
 
 	}