* pandora_network.pl: Now launch 3 threads, one for each of this network modules: ICMP, TCP/UDP and SNMP. This will improve the max. capacity of each network server. This code was copied from Pandora Data Server code.

* pandora_db.pm: Corrected a small problem in server keepalive function. Now works fine, and create an event when server going up or server going down (also a Log line).
* pandora_server.pl: Fixed a damm bug when server was running in daemon: keepalive check function doesnt exec because thread starts before daemonize call. Fixed and workaround copied to Network Server code.

git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@74 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
slerena 2006-07-02 21:31:08 +00:00
parent 55c3be5754
commit 5d93666a1c
3 changed files with 65 additions and 23 deletions

View File

@ -862,10 +862,14 @@ sub pandora_serverkeepaliver (%$) {
my $s_idag = $dbh->prepare($query_idag);
$s_idag ->execute;
if ($s_idag->rows != 0) {
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);
while (@data = $s_idag->fetchrow_array()){
if ($data[3] != 0){ # only if it's currently not down
# Update server data
my $sql_update = "update tserver set status = 0 where id_server = $data[0]";
$dbh->do($sql_update);
pandora_event($pa_config, "Server ".$data[1]." going Down", 0, 0, $dbh);
logger( $pa_config, "Server ".$data[1]." going Down ",1);
}
}
}
$s_idag->finish();
@ -888,7 +892,6 @@ sub pandora_updateserver (%$$$) {
my $opmode = $_[3]; # 0 dataserver, 1 network server, 2 snmp console
my $dbh = $_[4];
my $sql_update;
my $pandorasuffix;
if ($opmode == 0){
$pandorasuffix = "_Data";
@ -904,16 +907,29 @@ sub pandora_updateserver (%$$$) {
$dbh->do($sql_server);
$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");
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";
my @data;
my $query_idag = "select * from tserver where id_server = $id_server";
my $s_idag = $dbh->prepare($query_idag);
$s_idag ->execute;
if ($s_idag->rows != 0) {
if (@data = $s_idag->fetchrow_array()){
if ($data[3] == 0){ # If down, update to get up the server
pandora_event($pa_config, "Server ".$data[1]." going UP", 0, 0, $dbh);
logger( $pa_config, "Server ".$data[1]." going UP ",1);
}
# Update server data
my $timestamp = &UnixDate("today","%Y-%m-%d %H:%M:%S");
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);
}
$s_idag->finish();
}
$dbh->do($sql_update);
}
#################################################################################

View File

@ -29,6 +29,7 @@ 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 threads;
# Pandora Modules
use pandora_config;
@ -47,7 +48,6 @@ pandora_init(\%pa_config, "Pandora Network Server");
# Read config file for Global variables
pandora_loadconfig (\%pa_config,1);
# Audit server starting
pandora_audit (\%pa_config, "Pandora Network Daemon starting", "SYSTEM", "System");
# Daemonize of configured
@ -57,7 +57,17 @@ if ( $pa_config{"daemon"} eq "1" ) {
}
# Runs main program (have a infinite loop inside)
pandora_network_subsystem(\%pa_config);
threads->new( \&pandora_network_subsystem, \%pa_config, 1);
sleep(1);
threads->new( \&pandora_network_subsystem, \%pa_config, 2);
sleep(1);
threads->new( \&pandora_network_subsystem, \%pa_config, 3);
while ( 1 ){
sleep(3600);
threads->yield;
}
#------------------------------------------------------------------------------------
#------------------------------------------------------------------------------------
@ -76,6 +86,8 @@ pandora_network_subsystem(\%pa_config);
sub pandora_network_subsystem {
# Init vars
my $pa_config = $_[0];
my $nettype = $_[1]; # 1 for ICMP, 2 for TCP/UDO, 3 for SNMP
my $nettypedesc;
# Connect ONCE to Database, we pass DBI handler to all subprocess.
my $dbh = DBI->connect("DBI:mysql:pandora:$pa_config->{'dbhost'}:3306", $pa_config->{'dbuser'}, $pa_config->{'dbpass'}, { RaiseError => 1, AutoCommit => 1 });
@ -152,7 +164,20 @@ sub pandora_network_subsystem {
# Second: Checkout for agent_modules with type > 4 (network modules) and
# owned by our selected agent
$query_sql = "select * from tagente_modulo where id_tipo_modulo > 4 and id_agente = $id_agente";
# $nettype 1 for ICMP, 2 for TCP/UDO, 3 for SNMP
if ($nettype == 1){ # ICMP
$query_sql = "select * from tagente_modulo where id_tipo_modulo > 5 and id_tipo_modulo < 8 and id_agente = $id_agente";
$nettypedesc="ICMP";
} elsif ($nettype == 2){ # UDP/TCP
$query_sql = "select * from tagente_modulo where id_tipo_modulo > 7 and id_tipo_modulo < 13 and id_agente = $id_agente";
$nettypedesc="TCP/UDP";
} elsif ($nettype == 3) { # SNMP
$query_sql = "select * from tagente_modulo where id_tipo_modulo > 14 and id_tipo_modulo < 19 and id_agente = $id_agente";
$nettypedesc="SNMP";
} else { # This section of code never will be executed
$query_sql = "select * from tagente_modulo where id_tipo_modulo > 4 and id_agente = $id_agente";
$nettypedesc="Global Network";
}
$exec_sql = $dbh->prepare($query_sql);
$exec_sql ->execute;
while (@sql_data = $exec_sql->fetchrow_array()) {
@ -208,7 +233,7 @@ sub pandora_network_subsystem {
$exec_sql3 ->execute;
$exec_sql3->finish();
}
logger ($pa_config, "Network Module Subsystem (Single): Exec Netmodule '$nombre'",5);
logger ($pa_config, "Network Module Subsystem ($nettypedesc): Exec Netmodule '$nombre'",5);
exec_network_module( $id_agente, $id_agente_estado, $id_tipo_modulo, $fecha_mysql, $nombre, $min, $max, $agent_interval, $tcp_port, $tcp_send, $tcp_rcv, $snmp_community, $snmp_oid, $ip_target, $module_result, $module_data, $estado_cambio, $estado_estado, $agent_name, $agent_osdata, $id_agente_modulo, $pa_config, $dbh);
} # Timelimit if
@ -217,6 +242,7 @@ sub pandora_network_subsystem {
}
$exec_sql2->finish();
pandora_serverkeepaliver($pa_config,$opmode,$dbh);
threads->yield;
sleep($pa_config->{"server_threshold"});
}
$dbh->disconnect();

View File

@ -50,14 +50,14 @@ pandora_loadconfig (\%pa_config,0);
# Audit server starting
pandora_audit (\%pa_config, "Pandora Daemon starting", "SYSTEM", "System");
# KeepAlive checks for Agents, only for master servers, in separate thread
threads->new( \&pandora_keepalived, \%pa_config);
# BE CAREFUL, if you daemonize, you need to launch threads BEFORE daemonizing.
if ($pa_config{"daemon"} eq "1" ){
&daemonize;
}
# KeepAlive checks for Agents, only for master servers, in separate thread
threads->new( \&pandora_keepalived, \%pa_config);
# Module processor subsystem
pandora_dataserver(\%pa_config);
@ -159,7 +159,7 @@ sub pandora_dataserver {
sub pandora_keepalived {
my $pa_config = $_[0];
my $dbh = DBI->connect("DBI:mysql:pandora:$pa_config->{'dbhost'}:3306",$pa_config->{"dbuser"}, $pa_config->{"dbpass"},{ RaiseError => 1, AutoCommit => 1 });
while (1){
while ( 1 ){
sleep $pa_config->{"server_threshold"};
threads->yield;
keep_alive_check($pa_config,$dbh);