2009-01-20 Sancho Lerena <slerena@artica.es>

* Config.pm: Now works without breaking the server :-). Show verbose info
	only when verbosity enabled (>4).
	
	* pandora_server: more issues with verbosity level. Fixed a typo on 
	management of async_proc moduletypes. Freeing a hash reference on keepalive
	solves a memleak.

	* DB.pm: Converting to the same float when comparing two numbers.
	


git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1368 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
slerena 2009-01-20 18:56:30 +00:00
parent 9e6bf36416
commit 8e86c3eded
4 changed files with 104 additions and 56 deletions

View File

@ -1,3 +1,14 @@
2009-01-20 Sancho Lerena <slerena@artica.es>
* Config.pm: Now works without breaking the server :-). Show verbose info
only when verbosity enabled (>4).
* pandora_server: more issues with verbosity level. Fixed a typo on
management of async_proc moduletypes. Freeing a hash reference on keepalive
solves a memleak.
* DB.pm: Converting to the same float when comparing two numbers.
2009-01-20 Evi Vanoost <vanooste@rcbi.rochester.edu>
* lib/PandoraFMS/Config.pm: Commented 2 lines that broke the server

View File

@ -62,7 +62,7 @@ pandora_audit (\%pa_config, "Pandora FMS Data Server Daemon starting", "SYSTEM",
# Daemonize and put in background
if ( $pa_config{"daemon"} eq "1" ){
if ($pa_config{"quiet"} eq "0"){
if ($pa_config{"verbosity"} > 0){
print " [*] Backgrounding Pandora FMS Data Server process.\n\n";
}
&pandora_daemonize ( \%pa_config);
@ -76,7 +76,7 @@ for (my $ax=0; $ax < $pa_config{"dataserver_threads"}; $ax++){
# Launch producer thread
threads->new( \&pandora_data_producer, \%pa_config);
if ($pa_config{"quiet"} == 0){
if ($pa_config{"verbosity"} > 0){
print " [*] All threads loaded and running \n\n";
}
@ -107,7 +107,9 @@ while (1) {
sub pandora_shutdown {
logger (\%pa_config,"Pandora FMS Server '".$pa_config{'servername'}.$pa_config{"servermode"}."' Shutdown by signal ",0);
pandora_updateserver (\%pa_config, $pa_config{'servername'}, 0, 0, $dbh);
print " [*] Shutting down ".$pa_config{'servername'}.$pa_config{"servermode"} ."(received signal)...\n";
if ($pa_config{"verbosity"} > 0){
print " [*] Shutting down ".$pa_config{'servername'}.$pa_config{"servermode"} ."(received signal)...\n";
}
pandora_event (\%pa_config, $pa_config{'servername'}.$pa_config{"servermode"}." going Down", 0,
0, 4, 0, 0, "system", $dbh);
exit;
@ -176,8 +178,9 @@ sub pandora_data_consumer ($$) {
my $thread_id = $_[1];
my $file_name;
my $counter =0;
my $file;
if ($pa_config->{"quiet"} == 0){
if ($pa_config->{"verbosity"} > 0){
print " [*] Starting up Data Consumer Thread # $thread_id \n";
}
@ -208,7 +211,7 @@ sub pandora_data_consumer ($$) {
$active_task_hash{$file_name} = 1;
}
my $file = "$pa_config->{'incomingdir'}/$file_name";
$file = "$pa_config->{'incomingdir'}/$file_name";
# Check file really exists to avoid race conditions
if (! -e "$file") {
@ -217,7 +220,7 @@ sub pandora_data_consumer ($$) {
next LOOP;
}
my $data;
my $data; # Hash to store the XML data file
# Parse the XML file
eval {
@ -254,7 +257,6 @@ sub pandora_data_consumer ($$) {
}
process_datafile ($pa_config, $data, $dbh);
{
lock $queue_lock;
delete($active_task_hash{$file_name});
@ -275,7 +277,19 @@ sub keep_alive_check {
my $pa_config = $_[0];
my $dbh = $_[1];
my $query_idag = " SELECT tagente_modulo.id_agente_modulo, tagente_estado.id_agente, tagente.nombre as agentname, tagente_modulo.nombre as modulename FROM tagente_modulo, tagente_estado, tagente WHERE tagente.id_agente = tagente_estado.id_agente AND tagente.disabled = 0 AND tagente_modulo.id_tipo_modulo = 100 AND tagente_modulo.disabled = 0 AND tagente_estado.datos = 1 AND tagente_estado.estado = 0 AND tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo AND ( tagente_estado.utimestamp + (tagente.intervalo * 2) < UNIX_TIMESTAMP()) ";
my $query_idag = "SELECT tagente_modulo.id_agente_modulo,
tagente_estado.id_agente,
tagente.nombre AS agentname,
tagente_modulo.nombre AS modulename
FROM tagente_modulo, tagente_estado, tagente
WHERE tagente.id_agente = tagente_estado.id_agente
AND tagente.disabled = 0
AND tagente_modulo.id_tipo_modulo = 100
AND tagente_modulo.disabled = 0
AND tagente_estado.datos = 1
AND tagente_estado.estado = 0
AND tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo
AND ( tagente_estado.utimestamp + (tagente.intervalo * 2) < UNIX_TIMESTAMP()) ";
my $s_idag = $dbh->prepare($query_idag);
$s_idag ->execute;
@ -296,7 +310,8 @@ sub keep_alive_check {
$module_name = $data->{'modulename'};
pandora_writestate ($pa_config, $agent_name, "keep_alive", $module_name, 0, 1, $dbh, 1);
}
}
}
undef $data;
$s_idag->finish();
}
@ -429,7 +444,7 @@ sub process_module_data {
elsif (($tipo_modulo eq 'generic_data_string') || ($tipo_modulo eq 'async_string')) {
module_generic_data_string ($pa_config, $module, $timestamp, $agent_name,$tipo_modulo, $dbh);
}
elsif (($tipo_modulo eq 'generic_proc') || ($tipo_modulo eq 'async_data')) {
elsif (($tipo_modulo eq 'generic_proc') || ($tipo_modulo eq 'async_proc')) {
module_generic_proc ($pa_config, $module, $timestamp, $agent_name, $tipo_modulo, $dbh);
}
else {

View File

@ -39,7 +39,7 @@ our @EXPORT = qw(
# version: Defines actual version of Pandora Server for this module only
my $pandora_version = "2.1-dev";
my $pandora_build="PS090116";
my $pandora_build="PS090120";
our $VERSION = $pandora_version." ".$pandora_build;
# Setup hash
@ -54,12 +54,12 @@ my %pa_config;
sub help_screen {
printf "\nSyntax: \n\n pandora_server [ options ] < fullpathname to configuration file > \n\n";
printf "Following options are optional : \n";
printf " -v : Verbose mode activated, write more information in logfile \n";
printf " -d : Debug mode activated, write extensive information in logfile \n";
printf " -D : Daemon mode (runs in background)\n";
printf " -v : Verbose mode activated, give more information in logfile \n";
printf " -d : Debug mode activated, give extensive information in logfile \n";
printf " -D : Daemon mode (runs in backgroup)\n";
printf " -P <file> : Store PID to file.\n";
printf " -q : Quiet startup\n";
printf " -h : This screen. It shows a little help screen \n";
printf " -h : This screen, show a little help screen \n";
printf " \n";
exit;
}
@ -78,11 +78,11 @@ sub pandora_init {
# Load config file from command line
if ($#ARGV == -1 ){
print "I need at least one parameter: Complete path to Pandora FMS Server configuration file. \n";
print "I Need at least one parameter: Complete path to Pandora FMS Server configuration file. \n";
help_screen;
exit;
}
$pa_config->{"verbosity"}=0; # Verbose 0 by default
$pa_config->{"verbosity"}=0; # Verbose 1 by default
$pa_config->{"daemon"}=0; # Daemon 0 by default
$pa_config->{'PID'}=""; # PID file not exist by default
$pa_config->{"quiet"}=0; # Daemon 0 by default
@ -115,7 +115,7 @@ sub pandora_init {
}
}
if ($pa_config->{"pandora_path"} eq ""){
print " [ERROR] I need at least one parameter: Complete path to Pandora FMS configuration file. \n";
print " [ERROR] I Need at least one parameter: Complete path to Pandora FMS configuration file. \n";
print " For example: ./pandora_server /etc/pandora/pandora_server.conf\n\n";
exit;
}
@ -473,60 +473,80 @@ sub pandora_loadconfig {
exit;
}
# Show some config options in startup
#if (($pa_config->{"quiet"} == 0) && ($pa_config->{"verbosity"} > 4)) { #<-- This breaks the server as you don't allow pa_config->{"servermode"} to be set
if ($opmode == 0){
if ($opmode == 0){
if (($pa_config->{"quiet"} == 0) && ($pa_config->{"verbosity"} > 4)) {
print " [*] You are running Pandora FMS Data Server. \n";
$parametro ="Pandora FMS Data Server";
$pa_config->{"servermode"}="_Data";
}
if ($opmode == 1){
}
$parametro ="Pandora FMS Data Server";
$pa_config->{"servermode"}="_Data";
}
if ($opmode == 1){
if (($pa_config->{"quiet"} == 0) && ($pa_config->{"verbosity"} > 4)) {
print " [*] You are running Pandora FMS Network Server. \n";
$parametro ="Pandora FMS Network Server";
$pa_config->{"servermode"}="_Net";
}
if ($opmode == 2){
}
$parametro ="Pandora FMS Network Server";
$pa_config->{"servermode"}="_Net";
}
if ($opmode == 2){
if (($pa_config->{"quiet"} == 0) && ($pa_config->{"verbosity"} > 4)) {
print " [*] You are running Pandora FMS SNMP Console. \n";
$parametro ="Pandora FMS SNMP Console";
$pa_config->{"servermode"}="_SNMP";
}
if ($opmode == 3){
$parametro ="Pandora FMS SNMP Console";
$pa_config->{"servermode"}="_SNMP";
}
if ($opmode == 3){
if (($pa_config->{"quiet"} == 0) && ($pa_config->{"verbosity"} > 4)) {
print " [*] You are running Pandora FMS Recon Server. \n";
$parametro ="Pandora FMS Recon Server";
$pa_config->{"servermode"}="_Recon";
}
if ($opmode == 4){
$parametro ="Pandora FMS Recon Server";
$pa_config->{"servermode"}="_Recon";
}
if ($opmode == 4){
if (($pa_config->{"quiet"} == 0) && ($pa_config->{"verbosity"} > 4)) {
print " [*] You are running Pandora FMS Plugin Server. \n";
$parametro ="Pandora FMS Plugin Server";
$pa_config->{"servermode"}="_Plugin";
}
if ($opmode == 5){
$parametro ="Pandora FMS Plugin Server";
$pa_config->{"servermode"}="_Plugin";
}
if ($opmode == 5){
if (($pa_config->{"quiet"} == 0) && ($pa_config->{"verbosity"} > 4)) {
print " [*] You are running Pandora FMS Prediction Server. \n";
$parametro ="Pandora FMS Prediction Server";
$pa_config->{"servermode"}="_Prediction";
}
if ($opmode == 6){
$parametro ="Pandora FMS Prediction Server";
$pa_config->{"servermode"}="_Prediction";
}
if ($opmode == 6){
if (($pa_config->{"quiet"} == 0) && ($pa_config->{"verbosity"} > 4)) {
print " [*] You are running Pandora FMS WMI Server. \n";
$parametro ="Pandora FMS WMI Server";
$pa_config->{"servermode"}="_WMI";
}
if ($opmode == 7){
}
$parametro ="Pandora FMS WMI Server";
$pa_config->{"servermode"}="_WMI";
}
if ($opmode == 7){
if (($pa_config->{"quiet"} == 0) && ($pa_config->{"verbosity"} > 4)) {
print " [*] You are running Pandora FMS Export Server. \n";
$parametro ="Pandora FMS Export Server";
$pa_config->{"servermode"}="_Export";
}
if ($opmode == 8){
}
$parametro ="Pandora FMS Export Server";
$pa_config->{"servermode"}="_Export";
}
if ($opmode == 8){
if (($pa_config->{"quiet"} == 0) && ($pa_config->{"verbosity"} > 4)) {
print " [*] You are running Pandora FMS Inventory Server. \n";
$parametro ="Pandora FMS Inventory Server";
$pa_config->{"servermode"}="_Inventory";
}
$parametro ="Pandora FMS Inventory Server";
$pa_config->{"servermode"}="_Inventory";
}
if (($pa_config->{"quiet"} == 0) && ($pa_config->{"verbosity"} > 4)) {
if ($pa_config->{"pandora_check"} == 1) {
print " [*] MD5 Security enabled.\n";
}
if ($pa_config->{"pandora_master"} == 1) {
print " [*] This server is running in MASTER mode.\n";
}
#}
logger ($pa_config, "Launching $parametro $pa_config->{'version'} $pa_config->{'build'}", 0);
}
logger ($pa_config, "Launching $pa_config->{'version'} $pa_config->{'build'}", 0);
my $config_options = "Logfile at ".$pa_config->{"logfile"}.", Basepath is ".$pa_config->{"basepath"}.", Checksum is ".$pa_config->{"pandora_check"}.", Master is ".$pa_config->{"pandora_master"}.", SNMP Console is ".$pa_config->{"snmpconsole"}.", Server Threshold at ".$pa_config->{"server_threshold"}." sec, verbosity at ".$pa_config->{"verbosity"}.", Alert Threshold at $pa_config->{'alert_threshold'}, ServerName is '".$pa_config->{'servername'}.$pa_config->{"servermode"}."'";
logger ($pa_config, "Config options: $config_options", 1);
my $dbh;
@ -541,7 +561,7 @@ sub pandora_loadconfig {
print $@;
exit;
}
if (($pa_config->{"quiet"} == 0) && ($pa_config->{"verbosity"} > 4)){
if (($pa_config->{"quiet"} == 0) && ($pa_config->{"verbosity"} > 4)) {
print " [*] Pandora FMS Server [".$pa_config->{'servername'}.$pa_config->{"servermode"}."] is running and operative \n";
}
$pa_config->{'server_id'} = dame_server_id ($pa_config, $pa_config->{'servername'}.$pa_config->{"servermode"}, $dbh);
@ -557,8 +577,7 @@ sub pandora_startlog ($){
open STDERR, ">>$pa_config->{'errorlogfile'}" or die " [ERROR] Pandora FMS can't write to Errorlog. Aborting : \n $! \n";
my $time_now = &UnixDate("today","%Y/%m/%d %H:%M:%S");
print STDERR "$time_now - ".$pa_config->{'servername'}.$pa_config->{"servermode"}." Starting Pandora FMS Server. Error logging activated \n";
# This redirect ANY output to errorlog.
# open STDOUT, ">>$pa_config->{'errorlogfile'}"
}
# End of function declaration
# End of defined Code

View File

@ -1237,6 +1237,9 @@ sub pandora_writedata (%$$$$$$$$$$){
if (is_numeric($data[2])){
$data[2] = sprintf("%.2f", $data[2]);
}
if (is_numeric($datos)){
$datos = sprintf("%.2f", $datos);
}
# Two decimal float. We cannot store more
# to change this, you need to change mysql structure
}
@ -1396,6 +1399,7 @@ sub pandora_planned_downtime (%$) {
}
$query_handle->finish();
# Deactivate a planned downtime: Set agents as disabled for Planned Downtime
$query_sql = "SELECT * FROM tplanned_downtime WHERE executed = 1 AND date_to <= $utimestamp";
@ -1418,7 +1422,6 @@ sub pandora_planned_downtime (%$) {
}
}
$query_handle->finish();
}