From a7c0010ec519b6c3ce2673e8c63cde38f0268c30 Mon Sep 17 00:00:00 2001 From: Ramon Novoa Date: Wed, 10 Sep 2014 13:18:02 +0200 Subject: [PATCH] Added constants for server types. --- pandora_server/lib/PandoraFMS/Core.pm | 17 +++++------ pandora_server/lib/PandoraFMS/DataServer.pm | 2 +- .../lib/PandoraFMS/NetworkServer.pm | 2 +- pandora_server/lib/PandoraFMS/PluginServer.pm | 2 +- .../lib/PandoraFMS/PredictionServer.pm | 2 +- pandora_server/lib/PandoraFMS/ReconServer.pm | 2 +- pandora_server/lib/PandoraFMS/SNMPServer.pm | 2 +- pandora_server/lib/PandoraFMS/Tools.pm | 28 +++++++++++++++++++ pandora_server/lib/PandoraFMS/WMIServer.pm | 2 +- 9 files changed, 44 insertions(+), 15 deletions(-) diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index f351d19d8d..e393b2effe 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -3789,7 +3789,7 @@ sub pandora_server_statistics ($$) { foreach my $server (@servers) { # Inventory server - if ($server->{"server_type"} == 8) { + if ($server->{"server_type"} == INVENTORYSERVER) { # Get modules exported by this server $server->{"modules"} = get_db_value ($dbh, "SELECT COUNT(tagent_module_inventory.id_agent_module_inventory) FROM tagente, tagent_module_inventory WHERE tagente.disabled=0 AND tagent_module_inventory.id_agente = tagente.id_agente AND tagente.server_name = ?", $server->{"name"}); @@ -3809,7 +3809,7 @@ sub pandora_server_statistics ($$) { $server->{"lag"} = $lag_row->{"lag"}; } # Export server - elsif ($server->{"server_type"} == 7) { + elsif ($server->{"server_type"} == EXPORTSERVER) { # Get modules exported by this server $server->{"modules"} = get_db_value ($dbh, "SELECT COUNT(tagente_modulo.id_agente_modulo) FROM tagente, tagente_modulo, tserver_export WHERE tagente.disabled=0 AND tagente_modulo.id_agente = tagente.id_agente AND tagente_modulo.id_export = tserver_export.id AND tserver_export.id_export_server = ?", $server->{"id_server"}); @@ -3820,7 +3820,7 @@ sub pandora_server_statistics ($$) { $server->{"lag"} = 0; $server->{"module_lag"} = 0; # Recon server - } elsif ($server->{"server_type"} == 3) { + } elsif ($server->{"server_type"} == RECONSERVER) { # Total jobs running on this recon server $server->{"modules"} = get_db_value ($dbh, "SELECT COUNT(id_rt) FROM trecon_task WHERE id_recon_server = ?", $server->{"id_server"}); @@ -3842,10 +3842,9 @@ sub pandora_server_statistics ($$) { $server->{"modules_total"} = get_db_value ($dbh,"SELECT count(tagente_estado.id_agente_modulo) FROM tserver, tagente_estado, tagente_modulo, tagente WHERE tagente.disabled=0 AND tagente_modulo.id_agente = tagente.id_agente AND tagente_modulo.disabled = 0 AND tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo AND tagente_estado.running_by = tserver.id_server AND tserver.server_type = ?", $server->{"server_type"}); - # Dataserver - if ($server->{"server_type"} != 0){ + # Non-dataserver LAG calculation: + if ($server->{"server_type"} != DATASERVER){ - # Local/Dataserver server LAG calculation: $lag_row = get_db_single_row ($dbh, "SELECT COUNT(tagente_modulo.id_agente_modulo) AS module_lag, AVG(UNIX_TIMESTAMP() - utimestamp - current_interval) AS lag FROM tagente_estado, tagente_modulo WHERE utimestamp > 0 @@ -3856,7 +3855,9 @@ sub pandora_server_statistics ($$) { AND (UNIX_TIMESTAMP() - utimestamp) < ( current_interval * 10) AND running_by = ? AND (UNIX_TIMESTAMP() - utimestamp) > (current_interval * 1.1)", $server->{"id_server"}); - } else { + } + # Dataserver LAG calculation: + else { $lag_row = get_db_single_row ($dbh, "SELECT COUNT(tagente_modulo.id_agente_modulo) AS module_lag, AVG(UNIX_TIMESTAMP() - utimestamp - current_interval) AS lag FROM tagente_estado, tagente_modulo WHERE utimestamp > 0 @@ -4111,7 +4112,7 @@ sub pandora_self_monitoring ($$) { $free_mem = '' unless defined ($free_mem); my $free_disk_spool = disk_free ($pa_config->{"incomingdir"}); $free_disk_spool = '' unless defined ($free_disk_spool); - my $my_data_server = get_db_value ($dbh, "SELECT id_server FROM tserver WHERE server_type = 0 AND name = '".$pa_config->{"servername"}."'"); + my $my_data_server = get_db_value ($dbh, "SELECT id_server FROM tserver WHERE server_type = ? AND name = '".$pa_config->{"servername"}."'", DATASERVER); # Number of unknown agents my $agents_unknown = 0; diff --git a/pandora_server/lib/PandoraFMS/DataServer.pm b/pandora_server/lib/PandoraFMS/DataServer.pm index 320084eafc..b9b6ef3f49 100644 --- a/pandora_server/lib/PandoraFMS/DataServer.pm +++ b/pandora_server/lib/PandoraFMS/DataServer.pm @@ -69,7 +69,7 @@ sub new ($$;$) { $ModuleSem = Thread::Semaphore->new (1); # Call the constructor of the parent class - my $self = $class->SUPER::new($config, 0, \&PandoraFMS::DataServer::data_producer, \&PandoraFMS::DataServer::data_consumer, $dbh); + my $self = $class->SUPER::new($config, DATASERVER, \&PandoraFMS::DataServer::data_producer, \&PandoraFMS::DataServer::data_consumer, $dbh); bless $self, $class; return $self; diff --git a/pandora_server/lib/PandoraFMS/NetworkServer.pm b/pandora_server/lib/PandoraFMS/NetworkServer.pm index 52f73184c0..a508558772 100644 --- a/pandora_server/lib/PandoraFMS/NetworkServer.pm +++ b/pandora_server/lib/PandoraFMS/NetworkServer.pm @@ -67,7 +67,7 @@ sub new ($$$) { $TaskSem = Thread::Semaphore->new (0); # Call the constructor of the parent class - my $self = $class->SUPER::new($config, 1, \&PandoraFMS::NetworkServer::data_producer, \&PandoraFMS::NetworkServer::data_consumer, $dbh); + my $self = $class->SUPER::new($config, NETWORKSERVER, \&PandoraFMS::NetworkServer::data_producer, \&PandoraFMS::NetworkServer::data_consumer, $dbh); bless $self, $class; return $self; diff --git a/pandora_server/lib/PandoraFMS/PluginServer.pm b/pandora_server/lib/PandoraFMS/PluginServer.pm index 0982143635..2da1043023 100644 --- a/pandora_server/lib/PandoraFMS/PluginServer.pm +++ b/pandora_server/lib/PandoraFMS/PluginServer.pm @@ -68,7 +68,7 @@ sub new ($$;$) { $TaskSem = Thread::Semaphore->new (0); # Call the constructor of the parent class - my $self = $class->SUPER::new($config, 4, \&PandoraFMS::PluginServer::data_producer, \&PandoraFMS::PluginServer::data_consumer, $dbh); + my $self = $class->SUPER::new($config, PLUGINSERVER, \&PandoraFMS::PluginServer::data_producer, \&PandoraFMS::PluginServer::data_consumer, $dbh); bless $self, $class; return $self; diff --git a/pandora_server/lib/PandoraFMS/PredictionServer.pm b/pandora_server/lib/PandoraFMS/PredictionServer.pm index 395d288a3d..3e7ec174d6 100644 --- a/pandora_server/lib/PandoraFMS/PredictionServer.pm +++ b/pandora_server/lib/PandoraFMS/PredictionServer.pm @@ -63,7 +63,7 @@ sub new ($$;$) { $TaskSem = Thread::Semaphore->new (0); # Call the constructor of the parent class - my $self = $class->SUPER::new($config, 5, \&PandoraFMS::PredictionServer::data_producer, \&PandoraFMS::PredictionServer::data_consumer, $dbh); + my $self = $class->SUPER::new($config, PREDICTIONSERVER, \&PandoraFMS::PredictionServer::data_producer, \&PandoraFMS::PredictionServer::data_consumer, $dbh); bless $self, $class; diff --git a/pandora_server/lib/PandoraFMS/ReconServer.pm b/pandora_server/lib/PandoraFMS/ReconServer.pm index d0d06e82bf..6416a257d0 100644 --- a/pandora_server/lib/PandoraFMS/ReconServer.pm +++ b/pandora_server/lib/PandoraFMS/ReconServer.pm @@ -71,7 +71,7 @@ sub new ($$$$$$) { $TaskSem = Thread::Semaphore->new (0); # Call the constructor of the parent class - my $self = $class->SUPER::new($config, 3, \&PandoraFMS::ReconServer::data_producer, \&PandoraFMS::ReconServer::data_consumer, $dbh); + my $self = $class->SUPER::new($config, RECONSERVER, \&PandoraFMS::ReconServer::data_producer, \&PandoraFMS::ReconServer::data_consumer, $dbh); bless $self, $class; return $self; diff --git a/pandora_server/lib/PandoraFMS/SNMPServer.pm b/pandora_server/lib/PandoraFMS/SNMPServer.pm index 91a49c6460..b765afa822 100644 --- a/pandora_server/lib/PandoraFMS/SNMPServer.pm +++ b/pandora_server/lib/PandoraFMS/SNMPServer.pm @@ -99,7 +99,7 @@ sub new ($$$) { $TaskSem = Thread::Semaphore->new (0); # Call the constructor of the parent class - my $self = $class->SUPER::new($config, 2, \&PandoraFMS::SNMPServer::data_producer, \&PandoraFMS::SNMPServer::data_consumer, $dbh); + my $self = $class->SUPER::new($config, SNMPCONSOLE, \&PandoraFMS::SNMPServer::data_producer, \&PandoraFMS::SNMPServer::data_consumer, $dbh); # Save the path of snmptrapd $self->{'snmp_trapd'} = $config->{'snmp_trapd'}; diff --git a/pandora_server/lib/PandoraFMS/Tools.pm b/pandora_server/lib/PandoraFMS/Tools.pm index dade12a293..68c10a10be 100644 --- a/pandora_server/lib/PandoraFMS/Tools.pm +++ b/pandora_server/lib/PandoraFMS/Tools.pm @@ -43,6 +43,19 @@ our @ISA = ("Exporter"); our %EXPORT_TAGS = ( 'all' => [ qw( ) ] ); our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); our @EXPORT = qw( + DATASERVER + NETWORKSERVER + SNMPCONSOLE + RECONSERVER + PLUGINSERVER + PREDICTIONSERVER + WMISERVER + EXPORTSERVER + INVENTORYSERVER + WEBSERVER + EVENTSERVER + ICMPSERVER + SNMPSERVER $DEVNULL cron_get_closest_in_range cron_next_execution @@ -77,6 +90,21 @@ our @EXPORT = qw( valid_regex ); +# ID of the different servers +use constant DATASERVER => 0; +use constant NETWORKSERVER => 1; +use constant SNMPCONSOLE => 2; +use constant RECONSERVER => 3; +use constant PLUGINSERVER => 4; +use constant PREDICTIONSERVER => 5; +use constant WMISERVER => 6; +use constant EXPORTSERVER => 7; +use constant INVENTORYSERVER => 8; +use constant WEBSERVER => 9; +use constant EVENTSERVER => 10; +use constant ICMPSERVER => 11; +use constant SNMPSERVER => 12; + # /dev/null our $DEVNULL = ($^O eq 'MSWin32') ? '/Nul' : '/dev/null'; diff --git a/pandora_server/lib/PandoraFMS/WMIServer.pm b/pandora_server/lib/PandoraFMS/WMIServer.pm index a53c9e976e..b37ba10ecb 100644 --- a/pandora_server/lib/PandoraFMS/WMIServer.pm +++ b/pandora_server/lib/PandoraFMS/WMIServer.pm @@ -66,7 +66,7 @@ sub new ($$;$) { $TaskSem = Thread::Semaphore->new (0); # Call the constructor of the parent class - my $self = $class->SUPER::new($config, 6, \&PandoraFMS::WMIServer::data_producer, \&PandoraFMS::WMIServer::data_consumer, $dbh); + my $self = $class->SUPER::new($config, WMISERVER, \&PandoraFMS::WMIServer::data_producer, \&PandoraFMS::WMIServer::data_consumer, $dbh); bless $self, $class; return $self;