mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-28 08:14:38 +02:00
2012-01-24 Ramon Novoa <rnovoa@artica.es>
* lib/PandoraFMS/Config.pm, lib/PandoraFMS/PredictionServer.pm, lib/PandoraFMS/Core.pm, bin/pandora_server: Added support for enterprise netflow modules. * lib/PandoraFMS/PluginServer.pm: Run plugins inside eval to avoid server crashes. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@5417 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
037c9c54a9
commit
821ee50be2
@ -1,3 +1,13 @@
|
|||||||
|
2012-01-24 Ramon Novoa <rnovoa@artica.es>
|
||||||
|
|
||||||
|
* lib/PandoraFMS/Config.pm,
|
||||||
|
lib/PandoraFMS/PredictionServer.pm,
|
||||||
|
lib/PandoraFMS/Core.pm,
|
||||||
|
bin/pandora_server: Added support for enterprise netflow modules.
|
||||||
|
|
||||||
|
* lib/PandoraFMS/PluginServer.pm: Run plugins inside eval to avoid
|
||||||
|
server crashes.
|
||||||
|
|
||||||
2012-01-23 Hirofumi Kosaka <kosaka@rworks.jp>
|
2012-01-23 Hirofumi Kosaka <kosaka@rworks.jp>
|
||||||
|
|
||||||
* util/pandora_manage.pl: Fixed mismatch arguments call of
|
* util/pandora_manage.pl: Fixed mismatch arguments call of
|
||||||
|
@ -54,6 +54,9 @@ sub pandora_shutdown () {
|
|||||||
$server->stop ();
|
$server->stop ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Stop the netflow daemon
|
||||||
|
pandora_stop_netflow_daemon ();
|
||||||
|
|
||||||
print_message (\%Config, ' [*] Shutting down ' . $Config{'servername'} . "(received signal)...\n", 1);
|
print_message (\%Config, ' [*] Shutting down ' . $Config{'servername'} . "(received signal)...\n", 1);
|
||||||
db_disconnect ($DBH);
|
db_disconnect ($DBH);
|
||||||
if ($Config{'PID'} ne "") {
|
if ($Config{'PID'} ne "") {
|
||||||
@ -92,6 +95,9 @@ sub pandora_startup () {
|
|||||||
|
|
||||||
enterprise_hook('load_enterprise_servers', [\@Servers, \%Config, $DBH]);
|
enterprise_hook('load_enterprise_servers', [\@Servers, \%Config, $DBH]);
|
||||||
|
|
||||||
|
# Start the netflow daemon if necessary
|
||||||
|
pandora_start_netflow_daemon ();
|
||||||
|
|
||||||
# Remove disabled servers
|
# Remove disabled servers
|
||||||
@Servers = grep { defined ($_) } @Servers;
|
@Servers = grep { defined ($_) } @Servers;
|
||||||
|
|
||||||
@ -172,6 +178,62 @@ sub pandora_crash () {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
########################################################################################
|
||||||
|
# Start the netflow daemon if necessary.
|
||||||
|
########################################################################################
|
||||||
|
sub pandora_start_netflow_daemon () {
|
||||||
|
my $pid_file = '/var/run/pandora_nfcapd.pid';
|
||||||
|
|
||||||
|
# Check if netflow is enabled
|
||||||
|
if ($Config{'activate_netflow'} != 1) {
|
||||||
|
logger (\%Config, "Netflow daemon disabled.", 1);
|
||||||
|
print_message (\%Config, "Netflow daemon disabled.", 1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Stop nfcapd if it's already running
|
||||||
|
my $pid = pandora_stop_netflow_daemon ();
|
||||||
|
if (pandora_stop_netflow_daemon () != 0) {
|
||||||
|
logger (\%Config, "nfcapd (pid $pid) is already running, attempting to kill it...", 1);
|
||||||
|
print_message (\%Config, "nfcapd (pid $pid) is already running, attempting to kill it...", 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
# Start nfcapd
|
||||||
|
my $command = $Config{'netflow_daemon'} . ' -D -T all -w -t ' . $Config{'netflow_interval'} . ' -P ' . $pid_file . ' -l ' . $Config{'netflow_path'};
|
||||||
|
if (system ("$command >/dev/null 2>&1") != 0) {
|
||||||
|
logger (\%Config, " [E] Could not start nfcapd: $command", 1);
|
||||||
|
print_message (\%Config, " [E] Could not start nfcapd: $command", 1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
logger (\%Config, "Netflow daemon started.", 1);
|
||||||
|
print_message (\%Config, "Netflow daemon started.", 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
########################################################################################
|
||||||
|
# Stop the netflow daemon if it's running.
|
||||||
|
########################################################################################
|
||||||
|
sub pandora_stop_netflow_daemon () {
|
||||||
|
|
||||||
|
my $pid_file = '/var/run/pandora_nfcapd.pid';
|
||||||
|
|
||||||
|
# Open the pid file
|
||||||
|
if ( ! (-e $pid_file && open (PIDFILE, $pid_file))) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
my $pid = <PIDFILE>;
|
||||||
|
close PIDFILE;
|
||||||
|
|
||||||
|
# Check if nfcapd is running
|
||||||
|
if (kill (0, $pid) > 0) {
|
||||||
|
kill (9, $pid);
|
||||||
|
return $pid;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
$SIG{'TERM'} = 'pandora_shutdown';
|
$SIG{'TERM'} = 'pandora_shutdown';
|
||||||
$SIG{'INT'} = 'pandora_shutdown';
|
$SIG{'INT'} = 'pandora_shutdown';
|
||||||
|
|
||||||
|
@ -38,6 +38,7 @@ our @EXPORT = qw(
|
|||||||
pandora_load_config
|
pandora_load_config
|
||||||
pandora_start_log
|
pandora_start_log
|
||||||
pandora_get_sharedconfig
|
pandora_get_sharedconfig
|
||||||
|
pandora_get_tconfig_token
|
||||||
);
|
);
|
||||||
|
|
||||||
# version: Defines actual version of Pandora Server for this module only
|
# version: Defines actual version of Pandora Server for this module only
|
||||||
@ -128,36 +129,25 @@ sub pandora_init {
|
|||||||
##########################################################################
|
##########################################################################
|
||||||
# Read some config tokens from database set by the console
|
# Read some config tokens from database set by the console
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
sub pandora_get_sharedconfig ($$) {
|
sub pandora_get_sharedconfig ($$) {
|
||||||
my $pa_config = $_[0];
|
my ($pa_config, $dbh) = @_;
|
||||||
my $dbh = $_[1];
|
|
||||||
|
|
||||||
my $temp;
|
|
||||||
|
|
||||||
# Agentaccess option
|
# Agentaccess option
|
||||||
|
$pa_config->{"agentaccess"} = pandora_get_tconfig_token ($dbh, 'agentaccess', 1);
|
||||||
$temp = get_db_value ($dbh, "SELECT value FROM tconfig WHERE token = 'agentaccess'");
|
|
||||||
if (defined($temp)) {
|
|
||||||
$pa_config->{"agentaccess"} = $temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
# Realtimestats 0 disabled, 1 enabled.
|
# Realtimestats 0 disabled, 1 enabled.
|
||||||
# Master servers will generate all the information (global tactical stats).
|
# Master servers will generate all the information (global tactical stats).
|
||||||
# and each server will generate it's own server stats (lag, etc).
|
# and each server will generate it's own server stats (lag, etc).
|
||||||
|
$pa_config->{"realtimestats"} = pandora_get_tconfig_token ($dbh, 'realtimestats', 0);
|
||||||
$temp = get_db_value ($dbh, "SELECT value FROM tconfig WHERE token = 'realtimestats'");
|
|
||||||
if (defined($temp)) {
|
|
||||||
$pa_config->{"realtimestats"} = $temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
# Stats_interval option
|
# Stats_interval option
|
||||||
|
$pa_config->{"stats_interval"} = pandora_get_tconfig_token ($dbh, 'stats_interval', 300);
|
||||||
|
|
||||||
$temp = get_db_value ($dbh, "SELECT value FROM tconfig WHERE token = 'stats_interval'");
|
# Netflow configuration options
|
||||||
if (defined($temp)) {
|
$pa_config->{"activate_netflow"} = pandora_get_tconfig_token ($dbh, 'activate_netflow', 0);
|
||||||
$pa_config->{"stats_interval"} = $temp;
|
$pa_config->{"netflow_path"} = pandora_get_tconfig_token ($dbh, 'netflow_path', '/var/spool/pandora/data_in/netflow');
|
||||||
}
|
$pa_config->{"netflow_interval"} = pandora_get_tconfig_token ($dbh, 'netflow_interval', 300);
|
||||||
|
$pa_config->{"netflow_daemon"} = pandora_get_tconfig_token ($dbh, 'netflow_daemon', '/usr/bin/nfcapd');
|
||||||
}
|
}
|
||||||
|
|
||||||
##########################################################################
|
##########################################################################
|
||||||
@ -296,12 +286,6 @@ sub pandora_load_config {
|
|||||||
$pa_config->{"agentaccess"} = 1;
|
$pa_config->{"agentaccess"} = 1;
|
||||||
# -------------------------------------------------------------------------
|
# -------------------------------------------------------------------------
|
||||||
|
|
||||||
# Netflow server (4.1)
|
|
||||||
$pa_config->{'netflowserver'} = 0;
|
|
||||||
$pa_config->{'netflow_daemon'} = '/usr/bin/nfcapd';
|
|
||||||
$pa_config->{'netflow_interval'} = 300;
|
|
||||||
$pa_config->{'netflow_basedir'} = '/var/spool/pandora/data_in/netflow';
|
|
||||||
|
|
||||||
# Check for UID0
|
# Check for UID0
|
||||||
if ($pa_config->{"quiet"} != 0){
|
if ($pa_config->{"quiet"} != 0){
|
||||||
if ($> == 0){
|
if ($> == 0){
|
||||||
@ -620,18 +604,6 @@ sub pandora_load_config {
|
|||||||
elsif ($parametro =~ m/^block_size\s+([0-9]*)/i) {
|
elsif ($parametro =~ m/^block_size\s+([0-9]*)/i) {
|
||||||
$pa_config->{'block_size'}= clean_blank($1);
|
$pa_config->{'block_size'}= clean_blank($1);
|
||||||
}
|
}
|
||||||
elsif ($parametro =~ m/^netflowserver\s+([0-9]*)/i) {
|
|
||||||
$pa_config->{'netflowserver'}= clean_blank($1);
|
|
||||||
}
|
|
||||||
elsif ($parametro =~ m/^netflow_daemon\s+(.*)/i) {
|
|
||||||
$pa_config->{'netflow_daemon'}= clean_blank($1);
|
|
||||||
}
|
|
||||||
elsif ($parametro =~ m/^netflow_interval\s+([0-9]*)/i) {
|
|
||||||
$pa_config->{'netflow_interval'}= clean_blank($1);
|
|
||||||
}
|
|
||||||
elsif ($parametro =~ m/^netflow_basedir\s+(.*)/i) {
|
|
||||||
$pa_config->{'netflow_basedir'}= clean_blank($1);
|
|
||||||
}
|
|
||||||
} # end of loop for parameter #
|
} # end of loop for parameter #
|
||||||
|
|
||||||
if (($pa_config->{"verbosity"} > 4) && ($pa_config->{"quiet"} == 0)){
|
if (($pa_config->{"verbosity"} > 4) && ($pa_config->{"quiet"} == 0)){
|
||||||
@ -666,6 +638,9 @@ sub pandora_load_config {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
##########################################################################
|
||||||
|
# Open the log file and start logging.
|
||||||
|
##########################################################################
|
||||||
sub pandora_start_log ($){
|
sub pandora_start_log ($){
|
||||||
my $pa_config = shift;
|
my $pa_config = shift;
|
||||||
|
|
||||||
@ -674,6 +649,20 @@ sub pandora_start_log ($){
|
|||||||
print STDERR strftime ("%Y-%m-%d %H:%M:%S", localtime()) . ' - ' . $pa_config->{'servername'} . $pa_config->{'servermode'} . " Starting Pandora FMS Server. Error logging activated.\n";
|
print STDERR strftime ("%Y-%m-%d %H:%M:%S", localtime()) . ' - ' . $pa_config->{'servername'} . $pa_config->{'servermode'} . " Starting Pandora FMS Server. Error logging activated.\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
##########################################################################
|
||||||
|
# Read the given token from the tconfig table.
|
||||||
|
##########################################################################
|
||||||
|
sub pandora_get_tconfig_token ($$$) {
|
||||||
|
my ($dbh, $token, $default_value) = @_;
|
||||||
|
|
||||||
|
my $token_value = get_db_value ($dbh, "SELECT value FROM tconfig WHERE token = ?", $token);
|
||||||
|
if (defined ($token_value)) {
|
||||||
|
return safe_output ($token_value);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $default_value;
|
||||||
|
}
|
||||||
|
|
||||||
# End of function declaration
|
# End of function declaration
|
||||||
# End of defined Code
|
# End of defined Code
|
||||||
|
|
||||||
|
@ -178,7 +178,7 @@ our @EXPORT = qw(
|
|||||||
|
|
||||||
# Some global variables
|
# Some global variables
|
||||||
our @DayNames = qw(sunday monday tuesday wednesday thursday friday saturday);
|
our @DayNames = qw(sunday monday tuesday wednesday thursday friday saturday);
|
||||||
our @ServerTypes = qw (dataserver networkserver snmpconsole reconserver pluginserver predictionserver wmiserver exportserver inventoryserver webserver eventserver icmpserver snmpserver netflowserver);
|
our @ServerTypes = qw (dataserver networkserver snmpconsole reconserver pluginserver predictionserver wmiserver exportserver inventoryserver webserver eventserver icmpserver snmpserver);
|
||||||
our @AlertStatus = ('Execute the alert', 'Do not execute the alert', 'Do not execute the alert, but increment its internal counter', 'Cease the alert', 'Recover the alert', 'Reset internal counter');
|
our @AlertStatus = ('Execute the alert', 'Do not execute the alert', 'Do not execute the alert, but increment its internal counter', 'Cease the alert', 'Recover the alert', 'Reset internal counter');
|
||||||
|
|
||||||
|
|
||||||
|
@ -170,7 +170,10 @@ sub data_consumer ($$) {
|
|||||||
# Execute command
|
# Execute command
|
||||||
$command = $pa_config->{'plugin_exec'} . ' ' . $timeout . ' ' . quotemeta ($command);
|
$command = $pa_config->{'plugin_exec'} . ' ' . $timeout . ' ' . quotemeta ($command);
|
||||||
|
|
||||||
my $module_data = `$command`;
|
my $module_data;
|
||||||
|
eval {
|
||||||
|
$module_data = `$command`;
|
||||||
|
};
|
||||||
my $ReturnCode = ($? >> 8) & 0xff;
|
my $ReturnCode = ($? >> 8) & 0xff;
|
||||||
|
|
||||||
|
|
||||||
|
@ -155,6 +155,13 @@ sub exec_prediction_module ($$$$) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Netflow modules
|
||||||
|
if ($agent_module->{'prediction_module'} == 4) {
|
||||||
|
logger ($pa_config, "Executing netflow module " . $agent_module->{'nombre'}, 10);
|
||||||
|
enterprise_hook ('exec_netflow_module', [$pa_config, $agent_module, $server_id, $dbh]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
# Get a full hash for target agent_module record reference ($target_module)
|
# Get a full hash for target agent_module record reference ($target_module)
|
||||||
my $target_module = get_db_single_row ($dbh, 'SELECT * FROM tagente_modulo WHERE id_agente_modulo = ?', $agent_module->{'prediction_module'});
|
my $target_module = get_db_single_row ($dbh, 'SELECT * FROM tagente_modulo WHERE id_agente_modulo = ?', $agent_module->{'prediction_module'});
|
||||||
return unless defined $target_module;
|
return unless defined $target_module;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user