From 498a45ad7923d37368a2050219306c3c57b2d886 Mon Sep 17 00:00:00 2001 From: slerena Date: Sat, 1 Jul 2006 01:54:36 +0000 Subject: [PATCH] * Updated functions pandora_serverkeepaliver and pandora_updateserver to work on instances of server instead of single name. Now instances for servers will be called "xxx_Net" for Network, "xxx_Data" for Data Server, and "xxx_SNMP" for SNMP Server. This way, a individual keepalive will be used for each instance. * Added the keywork "server_keepalive" for server configuration: Time to check another server is down. Would be nice if all servers in a setup has the same value (reflect this in doc. please!). * Fixed a stupid issue in numeric data (commas and dots for use real numeric values).... I wish this fix an old bug identified in SourceForge. * Something more I cannot remeber now, it's 3:44am of Saturdar 1th July... Beta2 need to be finished NOW!. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@69 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_server/bin/pandora_config.pm | 17 +++--- pandora_server/bin/pandora_db.pm | 73 ++++++++++++----------- pandora_server/bin/pandora_network.pl | 13 ++-- pandora_server/bin/pandora_server.pl | 4 +- pandora_server/bin/pandora_snmpconsole.pl | 4 +- pandora_server/conf/pandora_server.conf | 3 + 6 files changed, 63 insertions(+), 51 deletions(-) diff --git a/pandora_server/bin/pandora_config.pm b/pandora_server/bin/pandora_config.pm index 0b2456a820..c413a4cee8 100755 --- a/pandora_server/bin/pandora_config.pm +++ b/pandora_server/bin/pandora_config.pm @@ -3,7 +3,7 @@ package pandora_config; # Pandora Config package ################################################################################## # Copyright (c) 2004-2006 Sancho Lerena, slerena@gmail.com -# Copyright (c) 2005-2006 Artica Soluciones Tecnológicas S.L +# Copyright (c) 2005-2006 Artica Soluciones Tecnol�icas S.L # #This program is free software; you can redistribute it and/or #modify it under the terms of the GNU General Public License @@ -136,8 +136,8 @@ sub pandora_loadconfig { $pa_config->{"networkserver"}=0; $pa_config->{"dataserver"}=0; $pa_config->{"network_threads"}=10; # Fixed default - $pa_config->{"keepalive"}=200; # 200 Seconds initially for server keepalive - + $pa_config->{"keepalive"}=60; # 200 Seconds initially for server keepalive + $pa_config->{"keepalive_orig"}=$pa_config->{"keepalive"}; # Check for UID0 if ($> == 0){ printf " [W] It is not a good idea running Pandora Server as root user, please DON'T DO IT!\n"; @@ -190,8 +190,13 @@ sub pandora_loadconfig { elsif ($parametro =~ m/^server_threshold\s([0-9]*)/i) { $pa_config->{"server_threshold"} = $1; } elsif ($parametro =~ m/^alert_threshold\s([0-9]*)/i) { $pa_config->{"alert_threshold"} = $1; } elsif ($parametro =~ m/^network_timeout\s([0-9]*)/i) { $pa_config->{'networktimeout'}= $1; } + elsif ($parametro =~ m/^server_keepalive\s([0-9]*)/i) { $pa_config->{"keepalive"} = $1; $pa_config->{"keepalive_orig"} = $1; } } - + if ( $pa_config->{"verbosity"} > 0){ + print " [*] Server keepalive ".$pa_config->{"keepalive"}."\n"; + print " [*] Server threshold ".$pa_config->{"server_threshold"}."\n"; + } + # Check for valid token token values if (( $pa_config->{"dbuser"} eq "" ) || ( $pa_config->{"basepath"} eq "" ) || ( $pa_config->{"incomingdir"} eq "" ) || ( $pa_config->{"logfile"} eq "" ) || ( $pa_config->{"dbhost"} eq "") || ( $pa_config->{"pandora_master"} eq "") || ( $pa_config->{"dbpass"} eq "" ) ) { print "[ERROR] Bad Config values. Be sure that $archivo_cfg is a valid setup file. \n\n"; @@ -231,15 +236,13 @@ sub pandora_loadconfig { if ($pa_config->{"daemon"} == 1) { print " [*] This server is running in DAEMON mode.\n"; } - # Abrimos el directorio de datos y leemos cada fichero logger ($pa_config, "Launching $parametro $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'}"; logger ($pa_config, "Config options: $config_options"); - # Check valid Database variables and update server status eval { my $dbh = DBI->connect("DBI:mysql:pandora:$pa_config->{'dbhost'}:3306", $pa_config->{'dbuser'}, $pa_config->{'dbpass'}, { RaiseError => 1, AutoCommit => 1 }); - pandora_updateserver ($pa_config, $pa_config->{'servername'},1, $dbh); # Alive status + pandora_updateserver ($pa_config, $pa_config->{'servername'},1, $opmode, $dbh); # Alive status }; if ($@) { diff --git a/pandora_server/bin/pandora_db.pm b/pandora_server/bin/pandora_db.pm index e14206e438..9f9a218258 100644 --- a/pandora_server/bin/pandora_db.pm +++ b/pandora_server/bin/pandora_db.pm @@ -3,7 +3,7 @@ package pandora_db; # Pandora Database Package ################################################################################## # Copyright (c) 2004-2006 Sancho Lerena, slerena@gmail.com -# Copyright (c) 2005-2006 Artica Soluciones Tecnológicas S.L +# Copyright (c) 2005-2006 Artica Soluciones Tecnol�icas S.L # #This program is free software; you can redistribute it and/or #modify it under the terms of the GNU General Public License @@ -537,6 +537,7 @@ sub module_generic_data (%$$$$$) { if (ref($m_data) ne "HASH"){ if ($m_data =~ /[0-9]*/){ + $m_data =~ s/\,/\./g; # replace "," by "." $m_data = sprintf("%.2f", $m_data); # Two decimal float. We cannot store more } else { $m_data =0; @@ -584,8 +585,9 @@ sub module_generic_data_inc (%$$$$$) { my $a_min = $datos->{min}->[0]; if (ref($m_data) ne "HASH"){ + $m_data =~ s/\,/\./g; # replace "," by "." $m_data = sprintf("%.2f", $m_data); # Two decimal float. We cannot store more - # to change this, you need to change mysql structure + # to change this, you need to change mysql structure $m_data =~ s/\,/\./g; # replace "," by "." if (ref($a_max) eq "HASH") { @@ -845,43 +847,31 @@ fin_DB_insert_datos: ################################################################################## sub pandora_serverkeepaliver (%$) { my $pa_config= $_[0]; - my $dbh = $_[1]; + my $opmode = $_[1]; # 0 dataserver, 1 network server, 2 snmp console + my $dbh = $_[2]; + my $pandorasuffix; + my @data; if ($pa_config->{"keepalive"} <= 0){ my $timestamp = &UnixDate("today","%Y-%m-%d %H:%M:%S"); - my $temp = 300; # Update each 2,5 minutes, down if 5minutes unknown + my $temp = $pa_config->{"keepalive_orig"} * 2; # Down if keepalive x 2 seconds unknown my $fecha_limite = DateCalc($timestamp,"- $temp seconds",\$err); - $fecha_limite = &UnixDate($fecha_limite,"%Y-%m-%d %H:%M:%S"); - + $fecha_limite = &UnixDate($fecha_limite,"%Y-%m-%d %H:%M:%S"); # Look updated servers and take down non updated servers my $query_idag = "select * from tserver where keepalive < '$fecha_limite'"; my $s_idag = $dbh->prepare($query_idag); $s_idag ->execute; - my @data; - # If exists a defined alert for this module then continue if ($s_idag->rows != 0) { - @data = $s_idag->fetchrow_array(); - # Update server data - my $sql_update = "update tserver set status = 0 where id_server = $data[0]"; - $dbh->do($sql_update); + while (@data = $s_idag->fetchrow_array()){ + # Update server data + my $sql_update = "update tserver set status = 0 where id_server = $data[0]"; + $dbh->do($sql_update); + } } $s_idag->finish(); - - # Update my server - my $id_server = dame_server_id($pa_config, $pa_config->{'servername'}, $dbh); - if ($id_server == -1){ - # Must create a server entry - my $sql_server = "insert into tserver (name,description) values ('$servername','Autocreated at startup')"; - $dbh->do($sql_server); - $id_server = dame_server_id($pa_config, $pa_config->{'servername'}, $dbh); - } - - # Update server data - my $sql_update = "update tserver set status = 1, keepalive = '$timestamp', snmp_server = $pa_config->{snmpconsole}, network_server = $pa_config->{'networkserver'}, data_server = $pa_config->{'dataserver'}, master = $pa_config->{'pandora_master'}, checksum = $pa_config->{'pandora_check'} where id_server = $id_server"; - $dbh->do($sql_update); - - $pa_config->{"keepalive"}=200; + pandora_updateserver ($pa_config,$pa_config->{'servername'},1,$opmode, $dbh); + $pa_config->{"keepalive"}=$pa_config->{"keepalive_orig"}; } $pa_config->{"keepalive"}=$pa_config->{"keepalive"}-$pa_config->{"server_threshold"}; } @@ -895,19 +885,34 @@ sub pandora_updateserver (%$$$) { my $pa_config= $_[0]; my $servername = $_[1]; my $status = $_[2]; - my $dbh = $_[3]; - - my $id_server = dame_server_id($pa_config, $pa_config->{'servername'}, $dbh); + my $opmode = $_[3]; # 0 dataserver, 1 network server, 2 snmp console + my $dbh = $_[4]; + my $sql_update; + + my $pandorasuffix; + if ($opmode == 0){ + $pandorasuffix = "_Data"; + } elsif ($opmode == 1){ + $pandorasuffix = "_Net"; + } else { + $pandorasuffix = "_SNMP"; + } + my $id_server = dame_server_id($pa_config, $servername.$pandorasuffix, $dbh); if ($id_server == -1){ # Must create a server entry - my $sql_server = "insert into tserver (name,description) values ('$servername','Autocreated at startup')"; + my $sql_server = "insert into tserver (name,description) values ('$servername".$pandorasuffix."','Autocreated at startup')"; $dbh->do($sql_server); - $id_server = dame_server_id($pa_config, $pa_config->{'servername'}, $dbh); + $id_server = dame_server_id($pa_config, $pa_config->{'servername'}.$pandorasuffix, $dbh); } - # Update server data my $timestamp = &UnixDate("today","%Y-%m-%d %H:%M:%S"); - my $sql_update = "update tserver set status = 1, laststart = '$timestamp', keepalive = '$timestamp', snmp_server = $pa_config->{snmpconsole}, network_server = $pa_config->{'networkserver'}, data_server = $pa_config->{'dataserver'}, master = $pa_config->{'pandora_master'}, checksum = $pa_config->{'pandora_check'} where id_server = $id_server"; + if ($opmode == 0){ + $sql_update = "update tserver set status = 1, laststart = '$timestamp', keepalive = '$timestamp', snmp_server = 0, network_server = 0, data_server = 1, master = $pa_config->{'pandora_master'}, checksum = $pa_config->{'pandora_check'} where id_server = $id_server"; + } elsif ($opmode == 1){ + $sql_update = "update tserver set status = 1, laststart = '$timestamp', keepalive = '$timestamp', snmp_server = 0, network_server = 1, data_server = 0, master = $pa_config->{'pandora_master'}, checksum = 0 where id_server = $id_server"; + } else { + $sql_update = "update tserver set status = 1, laststart = '$timestamp', keepalive = '$timestamp', snmp_server = 1, network_server = 0, data_server = 0, master = $pa_config->{'pandora_master'}, checksum = 0 where id_server = $id_server"; + } $dbh->do($sql_update); } diff --git a/pandora_server/bin/pandora_network.pl b/pandora_server/bin/pandora_network.pl index e6ae8ecff5..0d2ebea5da 100755 --- a/pandora_server/bin/pandora_network.pl +++ b/pandora_server/bin/pandora_network.pl @@ -103,7 +103,7 @@ sub pandora_network_subsystem { my $query_sql; my $query_sql2; my $query_sql3; my $exec_sql; my $exec_sql2; my $exec_sql3; my $buffer; - + my $opmode = 1; # network server code for pandora_updateserver function while ( 1 ) { logger ($pa_config,"Loop in Network Module Subsystem",10); # For each element @@ -115,14 +115,15 @@ sub pandora_network_subsystem { # siguiente elemento # Calculate ID Agent from a select where module_type (id_tipo_modulo) > 4 (network modules) # Check for MASTER SERVERS only: check another agents if their servers are gone - $server_id = dame_server_id($pa_config, $pa_config->{'servername'}, $dbh); + + $server_id = dame_server_id($pa_config, $pa_config->{'servername'}."_Net", $dbh); $buffer = ""; if ($pa_config->{"pandora_master"} == 1){ my $id_server; # I am the master, we need to check another agents # if their server is down # So look for servers down and keep their id_server - $query_sql2 = "select * from tagente where disabled = 0 and id_server != $server_id "; + $query_sql2 = "select * from tagente where disabled = 0 and id_server != $server_id"; $exec_sql2 = $dbh->prepare($query_sql2); $exec_sql2 ->execute; while (@sql_data2 = $exec_sql2->fetchrow_array()) { @@ -133,7 +134,7 @@ sub pandora_network_subsystem { # I'm the master server, and there is an agent # with its agent down, so ADD to list $buffer = $buffer." OR id_agente = $id_agente "; - logger ($pa_config, "Added id_agente $id_agente for Master Network Server ".$pa_config->{"servername"}." agent pool",5); + logger ($pa_config, "Added id_agente $id_agente for Master Network Server ".$pa_config->{"servername"}."_Net"." agent pool",5); } } $exec_sql2->finish(); @@ -215,8 +216,8 @@ sub pandora_network_subsystem { $exec_sql->finish(); } $exec_sql2->finish(); - pandora_serverkeepaliver($pa_config,$dbh); - sleep($pa_config->{"server_threshold"}); + pandora_serverkeepaliver($pa_config,$opmode,$dbh); + sleep($pa_config->{"server_threshold"}); } $dbh->disconnect(); } diff --git a/pandora_server/bin/pandora_server.pl b/pandora_server/bin/pandora_server.pl index e842d1a9b5..0998fdb932 100755 --- a/pandora_server/bin/pandora_server.pl +++ b/pandora_server/bin/pandora_server.pl @@ -3,7 +3,7 @@ # Pandora Data Server ################################################################################## # Copyright (c) 2004-2006 Sancho Lerena, slerena@gmail.com -# Copyright (c) 2005-2006 Artica Soluciones Tecnológicas S.L +# Copyright (c) 2005-2006 Artica Soluciones Tecnol�icas S.L # #This program is free software; you can redistribute it and/or #modify it under the terms of the GNU General Public License @@ -163,7 +163,7 @@ sub pandora_keepalived { sleep $pa_config->{"server_threshold"}; threads->yield; keep_alive_check($pa_config,$dbh); - pandora_serverkeepaliver($pa_config,$dbh); + pandora_serverkeepaliver($pa_config,0,$dbh); # 0 for dataserver } } diff --git a/pandora_server/bin/pandora_snmpconsole.pl b/pandora_server/bin/pandora_snmpconsole.pl index f5df8d9377..eab994fb30 100755 --- a/pandora_server/bin/pandora_snmpconsole.pl +++ b/pandora_server/bin/pandora_snmpconsole.pl @@ -3,7 +3,7 @@ # Pandora Server. SNMP Console ################################################################################## # Copyright (c) 2004-2006 Sancho Lerena, slerena@gmail.com -# Copyright (c) 2005-2006 Artica Soluciones Tecnológicas S.L +# Copyright (c) 2005-2006 Artica Soluciones Tecnol�icas S.L # #This program is free software; you can redistribute it and/or #modify it under the terms of the GNU General Public License @@ -163,7 +163,7 @@ sub pandora_snmptrapd { } } sleep ($pa_config{'server_threshold'}); - pandora_serverkeepaliver($pa_config,$dbh); + pandora_serverkeepaliver($pa_config,2,$dbh); } $dbh->disconnect(); } diff --git a/pandora_server/conf/pandora_server.conf b/pandora_server/conf/pandora_server.conf index cb85bff59a..d3aab016ed 100755 --- a/pandora_server/conf/pandora_server.conf +++ b/pandora_server/conf/pandora_server.conf @@ -60,3 +60,6 @@ dataserver 1 # Network timeout (in seconds) for timeout in network connections for Network agents network_timeout 10 + +# Server keepalive (in seconds) +server_keepalive 60