Added constants for server types.

This commit is contained in:
Ramon Novoa 2014-09-10 13:18:02 +02:00 committed by mdtrooper
parent 5093927c62
commit a7c0010ec5
9 changed files with 44 additions and 15 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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'};

View File

@ -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';

View File

@ -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;