127 lines
3.9 KiB
Perl
Executable File
127 lines
3.9 KiB
Perl
Executable File
#!/usr/bin/perl
|
|
##########################################################################
|
|
# Pandora FMS Server
|
|
# Pandora FMS. the Flexible Monitoring System. http://www.pandorafms.org
|
|
##########################################################################
|
|
# Copyright (c) 2005-2009 Artica Soluciones Tecnologicas S.L
|
|
#
|
|
# This program is free software; you can redistribute it and/or
|
|
# modify it under the terms of the GNU General Public License
|
|
# as published by the Free Software Foundation; version 2
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program; if not, write to the Free Software
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
##########################################################################
|
|
|
|
use strict;
|
|
use warnings;
|
|
|
|
# Pandora Modules
|
|
use PandoraFMS::DB;
|
|
use PandoraFMS::Config;
|
|
use PandoraFMS::Tools;
|
|
use PandoraFMS::Core;
|
|
use PandoraFMS::DataServer;
|
|
use PandoraFMS::NetworkServer;
|
|
use PandoraFMS::SNMPServer;
|
|
use PandoraFMS::ReconServer;
|
|
use PandoraFMS::WMIServer;
|
|
use PandoraFMS::PluginServer;
|
|
use PandoraFMS::PredictionServer;
|
|
|
|
# Load enterprise module
|
|
enterprise_load () && print " [*] Pandora FMS Enterprise module loaded.\n";
|
|
|
|
# Global vars
|
|
my %Config;
|
|
my @Servers;
|
|
my $DBH;
|
|
|
|
########################################################################################
|
|
# Server shutdown
|
|
########################################################################################
|
|
sub pandora_shutdown () {
|
|
logger (\%Config, 'Pandora FMS Server \'' . $Config{'servername'} . '\' Shutdown by signal ', 0);
|
|
|
|
# Stop servers
|
|
foreach my $server (@Servers) {
|
|
$server->stop ();
|
|
}
|
|
|
|
print_message (\%Config, ' [*] Shutting down ' . $Config{'servername'} . "(received signal)...\n", 0);
|
|
db_disconnect ($DBH);
|
|
exit (0);
|
|
}
|
|
|
|
$SIG{'TERM'} = 'pandora_shutdown';
|
|
$SIG{'INT'} = 'pandora_shutdown';
|
|
|
|
# Prevent alarm from bombing the main thread when called within a thread
|
|
$SIG{'ALRM'} = 'IGNORE';
|
|
|
|
# Initialize
|
|
pandora_init(\%Config, 'Pandora FMS Server');
|
|
pandora_load_config (\%Config);
|
|
|
|
# Daemonize and put in background
|
|
if ($Config{'daemon'} == 1) {
|
|
print_message (\%Config, " [*] Backgrounding Pandora FMS Server process.\n\n", 0);
|
|
pandora_daemonize (\%Config);
|
|
}
|
|
|
|
# Connect to the DB
|
|
$DBH = db_connect ('mysql', $Config{'dbname'}, $Config{'dbhost'}, 3306,
|
|
$Config{'dbuser'}, $Config{'dbpass'});
|
|
|
|
pandora_audit (\%Config, 'Pandora FMS Server Daemon starting', 'SYSTEM', 'System', $DBH);
|
|
|
|
# Start logging
|
|
pandora_start_log (\%Config);
|
|
|
|
# Load servers
|
|
pandora_reset_server (\%Config, $DBH);
|
|
push (@Servers, new PandoraFMS::DataServer (\%Config, $DBH));
|
|
push (@Servers, new PandoraFMS::NetworkServer (\%Config, $DBH));
|
|
push (@Servers, new PandoraFMS::ReconServer (\%Config, $DBH));
|
|
push (@Servers, new PandoraFMS::SNMPServer (\%Config, $DBH));
|
|
push (@Servers, new PandoraFMS::WMIServer (\%Config, $DBH));
|
|
push (@Servers, new PandoraFMS::PluginServer (\%Config, $DBH));
|
|
push (@Servers, new PandoraFMS::PredictionServer (\%Config, $DBH));
|
|
enterprise_hook('load_enterprise_servers', [\@Servers, \%Config, $DBH]);
|
|
|
|
# Remove disabled servers
|
|
@Servers = grep { defined ($_) } @Servers;
|
|
|
|
# Run
|
|
foreach my $server (@Servers) {
|
|
$server->run ();
|
|
$server->upEvent ();
|
|
}
|
|
|
|
# Main loop
|
|
while (1) {
|
|
|
|
# Update server status
|
|
foreach my $server (@Servers) {
|
|
pandora_shutdown () unless ($server->checkThreads () == 1);
|
|
$server->update ();
|
|
}
|
|
|
|
eval {
|
|
pandora_planned_downtime (\%Config, $DBH);
|
|
pandora_exec_forced_alerts (\%Config, $DBH);
|
|
pandora_module_keep_alive_nd (\%Config, $DBH);
|
|
};
|
|
|
|
if ($@) {
|
|
pandora_shutdown ();
|
|
}
|
|
|
|
threads->yield;
|
|
sleep ($Config{'server_threshold'});
|
|
}
|