2009-11-13 Ramon Novoa <rnovoa@artica.es>
* conf/pandora_server.conf: Updated configuration tokens. * lib/PandoraFMS/SNMPServer.pm, lib/PandoraFMS/Config.pm, lib/PandoraFMS/PluginServer.pm, lib/PandoraFMS/PredictionServer.pm, lib/PandoraFMS/Core.pm, lib/PandoraFMS/ReconServer.pm, lib/PandoraFMS/DataServer.pm, lib/PandoraFMS/NetworkServer.pm, lib/PandoraFMS/Tools.pm, lib/PandoraFMS/WMIServer.pm, bin/pandora_server: Standardized and improved logging. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@2108 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
eee26aad4e
commit
6586957f8d
|
@ -1,3 +1,14 @@
|
|||
2009-11-13 Ramon Novoa <rnovoa@artica.es>
|
||||
|
||||
* conf/pandora_server.conf: Updated configuration tokens.
|
||||
|
||||
* lib/PandoraFMS/SNMPServer.pm, lib/PandoraFMS/Config.pm,
|
||||
lib/PandoraFMS/PluginServer.pm, lib/PandoraFMS/PredictionServer.pm,
|
||||
lib/PandoraFMS/Core.pm, lib/PandoraFMS/ReconServer.pm,
|
||||
lib/PandoraFMS/DataServer.pm, lib/PandoraFMS/NetworkServer.pm,
|
||||
lib/PandoraFMS/Tools.pm, lib/PandoraFMS/WMIServer.pm,
|
||||
bin/pandora_server: Standardized and improved logging.
|
||||
|
||||
2009-11-10 Ramon Novoa <rnovoa@artica.es>
|
||||
|
||||
* lib/PandoraFMS/Core.pm: Fixed forced alert execution. Substitute alert
|
||||
|
|
|
@ -43,7 +43,7 @@ my $DBH;
|
|||
# Server shutdown. Handler to do a controlled shutdown.
|
||||
########################################################################################
|
||||
sub pandora_shutdown () {
|
||||
logger (\%Config, 'Pandora FMS Server \'' . $Config{'servername'} . '\' Shutdown by signal ', 0);
|
||||
logger (\%Config, 'Pandora FMS Server \'' . $Config{'servername'} . '\' Shutdown by signal ', 1);
|
||||
|
||||
# Stop servers
|
||||
foreach my $server (@Servers) {
|
||||
|
@ -51,7 +51,7 @@ sub pandora_shutdown () {
|
|||
$server->stop ();
|
||||
}
|
||||
|
||||
print_message (\%Config, ' [*] Shutting down ' . $Config{'servername'} . "(received signal)...\n", 0);
|
||||
print_message (\%Config, ' [*] Shutting down ' . $Config{'servername'} . "(received signal)...\n", 1);
|
||||
db_disconnect ($DBH);
|
||||
exit (0);
|
||||
}
|
||||
|
@ -119,13 +119,12 @@ sub pandora_restart () {
|
|||
########################################################################################
|
||||
sub pandora_crash () {
|
||||
|
||||
logger (\%Config, 'Pandora FMS Server \'' . $Config{'servername'} . '\' unhandled error', 0);
|
||||
print_message (\%Config, '[E] Unhandled error in "' . $Config{'servername'} . "\". See more information in logfiles at '/var/log/pandora' \n", 0);
|
||||
my(@array) = @_;
|
||||
logger (\%Config, 'Pandora FMS Server \'' . $Config{'servername'} . '\' unhandled error.', 1);
|
||||
#print_message (\%Config, '[E] Unhandled error in "' . $Config{'servername'} . "\". See more information in logfiles at '/var/log/pandora' \n", 0);
|
||||
|
||||
foreach my $error_line (@array) {
|
||||
logger (\%Config, '[E] \'' . $Config{'servername'} . "': $error_line", 0);
|
||||
print_message (\%Config, "[E] $error_line \n", 0);
|
||||
foreach my $error_line (@_) {
|
||||
logger (\%Config, '[E] \'' . $Config{'servername'} . "': $error_line", 1);
|
||||
#print_message (\%Config, "[E] $error_line \n", 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -133,7 +132,7 @@ $SIG{'TERM'} = 'pandora_shutdown';
|
|||
$SIG{'INT'} = 'pandora_shutdown';
|
||||
|
||||
# Error handler needs to be reviewed, Enterprise not found errors are too nasty :(
|
||||
#$SIG{__DIE__} = 'pandora_crash';
|
||||
$SIG{__DIE__} = 'pandora_crash';
|
||||
|
||||
# Prevent alarm from bombing the main thread when called within a thread
|
||||
$SIG{'ALRM'} = 'IGNORE';
|
||||
|
@ -143,15 +142,15 @@ pandora_init(\%Config, 'Pandora FMS Server');
|
|||
pandora_load_config (\%Config);
|
||||
|
||||
# Load enterprise module
|
||||
if (enterprise_load () == 0) {
|
||||
print " [*] Pandora FMS Enterprise module not available.\n";
|
||||
if (enterprise_load (\%Config) == 0) {
|
||||
print_message (\%Config, " [*] Pandora FMS Enterprise module not available.", 1);
|
||||
} else {
|
||||
print " [*] Pandora FMS Enterprise module loaded.\n";
|
||||
print_message (\%Config, " [*] Pandora FMS Enterprise module loaded.", 1);
|
||||
}
|
||||
|
||||
# Daemonize and put in background
|
||||
if ($Config{'daemon'} == 1) {
|
||||
print_message (\%Config, " [*] Backgrounding Pandora FMS Server process.\n\n", 0);
|
||||
print_message (\%Config, " [*] Backgrounding Pandora FMS Server process.\n", 1);
|
||||
pandora_daemonize (\%Config);
|
||||
}
|
||||
|
||||
|
@ -195,12 +194,17 @@ while (1) {
|
|||
# Restart on error or auto restart
|
||||
if ($@) {
|
||||
|
||||
if ($Config{'restart'} eq '0') {
|
||||
print_message (\%Config, $@, 1);
|
||||
pandora_shutdown ();
|
||||
}
|
||||
|
||||
# Generate 'restarting' events
|
||||
foreach my $server (@Servers) {
|
||||
$server->restartEvent ($@);
|
||||
}
|
||||
|
||||
logger (\%Config, 'Pandora FMS Server restarting (' . $@ . ') in ' . $Config{'restart_delay'} . ' seconds.', 0);
|
||||
logger (\%Config, 'Pandora FMS Server restarting (' . $@ . ') in ' . $Config{'restart_delay'} . ' seconds.', 1);
|
||||
pandora_restart ();
|
||||
} elsif (($Config{'auto_restart'} > 0) && (time () - $time_ref > $Config{'auto_restart'})) {
|
||||
$time_ref = time ();
|
||||
|
|
|
@ -227,3 +227,9 @@ max_queue_files 250
|
|||
# shutting down threads, or other stability problems.
|
||||
|
||||
# auto_restart 86400
|
||||
|
||||
# Pandora FMS will restart after restart_delay seconds on critical errors.
|
||||
|
||||
# restart 0
|
||||
# restart_delay 60
|
||||
|
||||
|
|
|
@ -50,15 +50,15 @@ my %pa_config;
|
|||
##########################################################################
|
||||
|
||||
sub help_screen {
|
||||
printf "\nSyntax: \n\n pandora_server [ options ] < fullpathname to configuration file (pandora_server.conf) > \n\n";
|
||||
printf "Following options are optional : \n";
|
||||
printf " -v : Verbose mode activated. Writes more information in the logfile \n";
|
||||
printf " -d : Debug mode activated. Writes extensive information in the logfile \n";
|
||||
printf " -D : Daemon mode (runs in background)\n";
|
||||
printf " -P <file> : Store PID to file.\n";
|
||||
printf " -q : Quiet startup \n";
|
||||
printf " -h : This screen. Shows a little help screen \n";
|
||||
printf " \n";
|
||||
print "\nSyntax: \n\n pandora_server [ options ] < fullpathname to configuration file (pandora_server.conf) > \n\n";
|
||||
print "Following options are optional : \n";
|
||||
print " -v : Verbose mode activated. Writes more information in the logfile \n";
|
||||
print " -d : Debug mode activated. Writes extensive information in the logfile \n";
|
||||
print " -D : Daemon mode (runs in background)\n";
|
||||
print " -P <file> : Store PID to file.\n";
|
||||
print " -q : Quiet startup \n";
|
||||
print " -h : This screen. Shows a little help screen \n";
|
||||
print " \n";
|
||||
exit;
|
||||
}
|
||||
|
||||
|
@ -70,9 +70,9 @@ sub help_screen {
|
|||
sub pandora_init {
|
||||
my $pa_config = $_[0];
|
||||
my $init_string = $_[1];
|
||||
printf "\n$init_string $pandora_version Build $pandora_build Copyright (c) 2004-2009 ArticaST\n";
|
||||
printf "This program is OpenSource, licensed under the terms of GPL License version 2.\n";
|
||||
printf "You can download latest versions and documentation at http://www.pandorafms.org \n\n";
|
||||
print "\n$init_string $pandora_version Build $pandora_build Copyright (c) 2004-2009 ArticaST\n";
|
||||
print "This program is OpenSource, licensed under the terms of GPL License version 2.\n";
|
||||
print "You can download latest versions and documentation at http://www.pandorafms.org \n\n";
|
||||
|
||||
# Load config file from command line
|
||||
if ($#ARGV == -1 ){
|
||||
|
@ -233,6 +233,9 @@ sub pandora_load_config {
|
|||
# Auto restart every x seconds
|
||||
$pa_config->{'auto_restart'} = 0;
|
||||
|
||||
# Restart server on error
|
||||
$pa_config->{'restart'} = 0;
|
||||
|
||||
# Check for UID0
|
||||
if ($pa_config->{"quiet"} != 0){
|
||||
if ($> == 0){
|
||||
|
@ -504,6 +507,9 @@ sub pandora_load_config {
|
|||
elsif ($parametro =~ m/^auto_restart\s+(\d+)/i) {
|
||||
$pa_config->{'auto_restart'} = clean_blank($1);
|
||||
}
|
||||
elsif ($parametro =~ m/^restart\s+([0-1])/i) {
|
||||
$pa_config->{'restart'} = clean_blank($1);
|
||||
}
|
||||
} # end of loop for parameter #
|
||||
|
||||
|
||||
|
@ -533,7 +539,7 @@ sub pandora_load_config {
|
|||
}
|
||||
}
|
||||
|
||||
logger ($pa_config, "Launching $pa_config->{'version'} $pa_config->{'build'}", 0);
|
||||
logger ($pa_config, "Launching $pa_config->{'version'} $pa_config->{'build'}", 1);
|
||||
my $config_options = "Logfile at ".$pa_config->{"logfile"}.", Basepath is ".$pa_config->{"basepath"}.", Checksum is ".$pa_config->{"pandora_check"}.", Master is ".$pa_config->{"pandora_master"}.", SNMP Console is ".$pa_config->{"snmpconsole"}.", Server Threshold at ".$pa_config->{"server_threshold"}." sec, verbosity at ".$pa_config->{"verbosity"}.", Alert Threshold at $pa_config->{'alert_threshold'}, ServerName is '".$pa_config->{'servername'}.$pa_config->{"servermode"}."'";
|
||||
logger ($pa_config, "Config options: $config_options", 1);
|
||||
}
|
||||
|
@ -544,7 +550,7 @@ sub pandora_start_log ($){
|
|||
|
||||
# Dump all errors to errorlog
|
||||
open (STDERR, ">> " . $pa_config->{'errorlogfile'}) or die " [ERROR] Pandora FMS can't write to Errorlog. Aborting : \n $! \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";
|
||||
print STDERR strftime ("%Y-%m-%d %H:%M:%S", localtime()) . ' - ' . $pa_config->{'servername'} . $pa_config->{'servermode'} . " Starting Pandora FMS Server. Error logging activated.\n";
|
||||
}
|
||||
|
||||
# End of function declaration
|
||||
|
|
|
@ -68,6 +68,7 @@ our @EXPORT = qw(
|
|||
# Some global variables
|
||||
our @DayNames = qw(monday tuesday wednesday thursday friday saturday sunday);
|
||||
our @ServerTypes = qw (dataserver networkserver snmpconsole reconserver pluginserver predictionserver wmiserver exportserver inventoryserver webserver);
|
||||
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');
|
||||
|
||||
##########################################################################
|
||||
# Generate alerts for a given module.
|
||||
|
@ -88,7 +89,7 @@ sub pandora_generate_alerts ($$$$$$$) {
|
|||
AND id_agent_module = ? AND disabled = 0', $module->{'id_agente_modulo'});
|
||||
|
||||
foreach my $alert (@alerts) {
|
||||
my $rc = pandora_evaluate_alert($pa_config, $data, $status, $alert,
|
||||
my $rc = pandora_evaluate_alert($pa_config, $agent, $data, $status, $alert,
|
||||
$utimestamp, $dbh);
|
||||
|
||||
pandora_process_alert ($pa_config, $data, $agent, $module,
|
||||
|
@ -110,8 +111,10 @@ sub pandora_generate_alerts ($$$$$$$) {
|
|||
# 4 Recover the alert.
|
||||
# 5 Reset internal counter (alert not fired, interval elapsed).
|
||||
##########################################################################
|
||||
sub pandora_evaluate_alert ($$$$$$) {
|
||||
my ($pa_config, $data, $last_status, $alert, $utimestamp, $dbh) = @_;
|
||||
sub pandora_evaluate_alert ($$$$$$$) {
|
||||
my ($pa_config, $agent, $data, $last_status, $alert, $utimestamp, $dbh) = @_;
|
||||
|
||||
logger ($pa_config, "Evaluating alert '" . $alert->{'name'} . "' for agent '" . $agent->{'nombre'} . "'.", 10);
|
||||
|
||||
# Value returned on valid data
|
||||
my $status = 1;
|
||||
|
@ -179,7 +182,7 @@ sub pandora_evaluate_alert ($$$$$$) {
|
|||
return $status if ($last_status != 2 && $alert->{'type'} eq 'warning');
|
||||
}
|
||||
# Compound alert
|
||||
elsif (pandora_evaluate_compound_alert($pa_config, $alert->{'id'}, $dbh) == 0) {
|
||||
elsif (pandora_evaluate_compound_alert($pa_config, $alert->{'id'}, $alert->{'name'}, $dbh) == 0) {
|
||||
return $status
|
||||
}
|
||||
|
||||
|
@ -196,6 +199,8 @@ sub pandora_evaluate_alert ($$$$$$) {
|
|||
sub pandora_process_alert ($$$$$$$) {
|
||||
my ($pa_config, $data, $agent, $module, $alert, $rc, $dbh) = @_;
|
||||
|
||||
logger ($pa_config, "Processing alert '" . $alert->{'name'} . "' for agent '" . $agent->{'nombre'} . "': " . (defined ($AlertStatus[$rc]) ? $AlertStatus[$rc] : 'Unknown status') . ".", 10);
|
||||
|
||||
# Simple or compound alert?
|
||||
my $id = defined ($alert->{'id_template_module'}) ? $alert->{'id_template_module'} : $alert->{'id'};
|
||||
my $table = defined ($alert->{'id_template_module'}) ? 'talert_template_modules' : 'talert_compound';
|
||||
|
@ -276,8 +281,10 @@ sub pandora_process_alert ($$$$$$$) {
|
|||
# Evaluate the given compound alert. Returns 1 if the alert should be
|
||||
# fired, 0 if not.
|
||||
##########################################################################
|
||||
sub pandora_evaluate_compound_alert ($$$) {
|
||||
my ($pa_config, $id, $dbh) = @_;
|
||||
sub pandora_evaluate_compound_alert ($$$$) {
|
||||
my ($pa_config, $id, $name, $dbh) = @_;
|
||||
|
||||
logger ($pa_config, "Evaluating compound alert '$name'.", 10);
|
||||
|
||||
# Return value
|
||||
my $status = 0;
|
||||
|
@ -318,6 +325,8 @@ sub pandora_evaluate_compound_alert ($$$) {
|
|||
}
|
||||
elsif ($operation eq "NOP") {
|
||||
$status = $fired;
|
||||
} else {
|
||||
logger ($pa_config, "Unknown operation: $operation.", 3);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -342,7 +351,7 @@ sub pandora_generate_compound_alerts ($$$$$$$$) {
|
|||
next unless defined ($compound_alert);
|
||||
|
||||
# Evaluate the alert
|
||||
my $rc = pandora_evaluate_alert ($pa_config, $data, $status, $compound_alert,
|
||||
my $rc = pandora_evaluate_alert ($pa_config, $agent, $data, $status, $compound_alert,
|
||||
$utimestamp, $dbh);
|
||||
|
||||
pandora_process_alert ($pa_config, $data, $agent, $module,
|
||||
|
@ -357,6 +366,8 @@ sub pandora_execute_alert ($$$$$$$) {
|
|||
my ($pa_config, $data, $agent, $module,
|
||||
$alert, $alert_mode, $dbh) = @_;
|
||||
|
||||
logger ($pa_config, "Executing alert '" . $alert->{'name'} . "' for module '" . $module->{'nombre'} . "'.", 10);
|
||||
|
||||
# Get active actions/commands
|
||||
my @actions;
|
||||
|
||||
|
@ -389,11 +400,13 @@ sub pandora_execute_alert ($$$$$$$) {
|
|||
}
|
||||
|
||||
# No actions defined
|
||||
return if ($#actions < 0);
|
||||
if ($#actions < 0) {
|
||||
logger ($pa_config, "No actions defined for alert '" . $alert->{'name'} . "' module '" . $module->{'nombre'} . "'.", 10);
|
||||
return;
|
||||
}
|
||||
|
||||
# Execute actions
|
||||
foreach my $action (@actions) {
|
||||
logger($pa_config, "Alert (" . $alert->{'name'} . ") executed for agent " . $agent->{'nombre'}, 2);
|
||||
pandora_execute_action ($pa_config, $data, $agent, $alert, $alert_mode, $action, $module, $dbh);
|
||||
}
|
||||
|
||||
|
@ -412,6 +425,8 @@ sub pandora_execute_action ($$$$$$$$) {
|
|||
my ($pa_config, $data, $agent, $alert,
|
||||
$alert_mode, $action, $module, $dbh) = @_;
|
||||
|
||||
logger($pa_config, "Executing action '" . $action->{'name'} . "' for alert '". $alert->{'name'} . "' agent '" . (defined ($agent) ? $agent->{'nombre'} : 'N/A') . "'.", 10);
|
||||
|
||||
my $field1 = $action->{'field1'} ne "" ? $action->{'field1'} : $alert->{'field1'};
|
||||
my $field2 = $action->{'field2'} ne "" ? $action->{'field2'} : $alert->{'field2'};
|
||||
my $field3 = $action->{'field3'} ne "" ? $action->{'field3'} : $alert->{'field3'};
|
||||
|
@ -454,24 +469,20 @@ sub pandora_execute_action ($$$$$$$$) {
|
|||
if ($action->{'internal'} == 0) {
|
||||
my $command = subst_alert_macros (decode_entities ($action->{'command'}), \%macros);
|
||||
$command = subst_alert_macros ($command, \%macros);
|
||||
logger($pa_config, "Executing command $command", 4);
|
||||
logger($pa_config, "Executing command '$command' for action '" . $action->{'name'} . "' alert '". $alert->{'name'} . "' agent '" . (defined ($agent) ? $agent->{'nombre'} : 'N/A') . "'.", 8);
|
||||
|
||||
eval {
|
||||
system ($command);
|
||||
if ($? != 0) {
|
||||
logger($pa_config, 'Executed command for alert ' . $alert->{'name'} . ' returned with errorlevel ' . ($? >> 8), 1);
|
||||
}
|
||||
logger($pa_config, "Command '$command' for action '" . $action->{'name'} . "' alert '". $alert->{'name'} . "' agent '" . (defined ($agent) ? $agent->{'nombre'} : 'N/A') . "' returned with errorlevel " . ($? >> 8), 8);
|
||||
};
|
||||
|
||||
if ($@){
|
||||
logger($pa_config, "Error $@ executing command $command", 1);
|
||||
logger($pa_config, "Error $@ executing command '$command' for action '" . $action->{'name'} . "' alert '". $alert->{'name'} . "' agent '" . (defined ($agent) ? $agent->{'nombre'} : 'N/A') ."'.", 8);
|
||||
}
|
||||
|
||||
# Internal Audit
|
||||
} elsif ($action->{'name'} eq "Internal Audit") {
|
||||
|
||||
$field1 = subst_alert_macros ($field1, \%macros);
|
||||
|
||||
pandora_audit ($pa_config, $field1, defined ($agent) ? $agent->{'nombre'} : 'N/A', 'Alert (' . $alert->{'description'} . ')', $dbh);
|
||||
|
||||
# Email
|
||||
|
@ -489,7 +500,7 @@ sub pandora_execute_action ($$$$$$$$) {
|
|||
|
||||
# Unknown
|
||||
} else {
|
||||
logger($pa_config, "Unknown action " . $action->{'name'}, 1);
|
||||
logger($pa_config, "Unknown action '" . $action->{'name'} . "' for alert '". $alert->{'name'} . "' agent '" . (defined ($agent) ? $agent->{'nombre'} : 'N/A') . "'.", 3);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -514,52 +525,55 @@ sub pandora_process_module ($$$$$$$$$) {
|
|||
my ($pa_config, $data, $agent, $module, $module_type,
|
||||
$timestamp, $utimestamp, $server_id, $dbh) = @_;
|
||||
|
||||
logger($pa_config, "Processing module '" . $module->{'nombre'} . "' for agent " . (defined ($agent) ? "'" . $agent->{'nombre'} . "'" : 'ID ' . $module->{'id_agente'}) . ".", 10);
|
||||
|
||||
# Get module type
|
||||
if ($module_type eq '') {
|
||||
if (! defined ($module_type)) {
|
||||
$module_type = get_db_value ($dbh, 'SELECT nombre FROM ttipo_modulo WHERE id_tipo = ?', $module->{'id_tipo_modulo'});
|
||||
if (! defined ($module_type)) {
|
||||
logger($pa_config, "Invalid module type ID " . $module->{'id_tipo_modulo'} . " module '" . $module->{'nombre'} . "' agent " . (defined ($agent) ? "'" . $agent->{'nombre'} . "'" : 'ID ' . $module->{'id_agente'}) . ".", 10);
|
||||
pandora_update_module_on_error ($pa_config, $module->{'id_agente_modulo'}, $dbh);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# Get agent information
|
||||
if (! defined ($agent)) {
|
||||
$agent = get_db_single_row ($dbh, 'SELECT * FROM tagente WHERE id_agente = ?', $module->{'id_agente'});
|
||||
if (! defined ($agent)) {
|
||||
logger($pa_config, "Agent ID " . $module->{'id_agente'} . " not found while processing module '" . $module->{'nombre'} . "'.", 3);
|
||||
pandora_update_module_on_error ($pa_config, $module->{'id_agente_modulo'}, $dbh);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# Process data
|
||||
$data = process_data ($data, $module, $module_type, $utimestamp, $dbh);
|
||||
my $processed_data = process_data ($data, $module, $module_type, $utimestamp, $dbh);
|
||||
if (! defined ($data)) {
|
||||
logger($pa_config, "Received invalid data from module '" . $module->{'nombre'} . "'", 3);
|
||||
logger($pa_config, "Received invalid data '" . $data . "' from agent '" . $agent->{'nombre'} . "' module '" . $module->{'nombre'} . "' agent " . (defined ($agent) ? "'" . $agent->{'nombre'} . "'" : 'ID ' . $module->{'id_agente'}) . ".", 3);
|
||||
pandora_update_module_on_error ($pa_config, $module->{'id_agente_modulo'}, $dbh);
|
||||
return;
|
||||
}
|
||||
|
||||
# Get agent information
|
||||
if ($agent eq '') {
|
||||
$agent = get_db_single_row ($dbh, 'SELECT * FROM tagente WHERE id_agente = ?', $module->{'id_agente'});
|
||||
if (! defined ($agent)) {
|
||||
pandora_update_module_on_error ($pa_config, $module->{'id_agente_modulo'}, $dbh);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if ($timestamp eq '') {
|
||||
$timestamp = strftime ("%Y-%m-%d %H:%M:%S", localtime($utimestamp));
|
||||
}
|
||||
$timestamp = strftime ("%Y-%m-%d %H:%M:%S", localtime($utimestamp)) if (! defined ($timestamp) || $timestamp eq '');
|
||||
|
||||
# Export data
|
||||
export_module_data ($data, $agent, $module, $module_type, $timestamp, $dbh);
|
||||
export_module_data ($pa_config, $processed_data, $agent, $module, $module_type, $timestamp, $dbh);
|
||||
|
||||
# Get previous status
|
||||
my $agent_status = get_db_single_row ($dbh, 'SELECT * FROM tagente_estado WHERE id_agente_modulo = ?', $module->{'id_agente_modulo'});
|
||||
if (! defined ($agent_status)) {
|
||||
logger($pa_config, "Status for agent '" . $agent->{'nombre'} . "' not found while processing module " . $module->{'nombre'} . ".", 3);
|
||||
pandora_update_module_on_error ($pa_config, $module->{'id_agente_modulo'}, $dbh);
|
||||
return;
|
||||
}
|
||||
|
||||
# Get current status
|
||||
my $status = get_module_status ($data, $module, $module_type);
|
||||
my $status = get_module_status ($processed_data, $module, $module_type);
|
||||
|
||||
# Generate alerts
|
||||
if (pandora_inhibit_alerts ($pa_config, $agent, $dbh) == 0) {
|
||||
pandora_generate_alerts ($pa_config, $data, $status, $agent, $module, $utimestamp, $dbh);
|
||||
pandora_generate_alerts ($pa_config, $processed_data, $status, $agent, $module, $utimestamp, $dbh);
|
||||
}
|
||||
|
||||
#Update module status
|
||||
|
@ -570,7 +584,7 @@ sub pandora_process_module ($$$$$$$$$) {
|
|||
|
||||
# Generate events
|
||||
if ($status_changes == $module->{'min_ff_event'} + 1) {
|
||||
generate_status_event ($pa_config, $data, $agent, $module, $status, $last_status, $dbh);
|
||||
generate_status_event ($pa_config, $processed_data, $agent, $module, $status, $last_status, $dbh);
|
||||
}
|
||||
|
||||
# tagente_estado.last_try defaults to NULL, should default to '0000-00-00 00:00:00'
|
||||
|
@ -578,22 +592,23 @@ sub pandora_process_module ($$$$$$$$$) {
|
|||
|
||||
# Do we have to save module data?
|
||||
if ($agent_status->{'last_try'} !~ /(\d+)\-(\d+)\-(\d+) +(\d+):(\d+):(\d+)/) {
|
||||
logger($pa_config, "Invalid last try timestamp '" . $agent_status->{'last_try'} . "' for agent '" . $agent->{'nombre'} . "' not found while processing module '" . $module->{'nombre'} . "'.", 3);
|
||||
pandora_update_module_on_error ($pa_config, $module->{'id_agente_modulo'}, $dbh);
|
||||
return;
|
||||
}
|
||||
|
||||
my $last_try = ($1 == 0) ? 0 : timelocal($6, $5, $4, $3, $2 - 1, $1 - 1900);
|
||||
my $save = ($module->{'history_data'} == 1 && ($agent_status->{'datos'} ne $data || $last_try < (time() - 86400))) ? 1 : 0;
|
||||
my $save = ($module->{'history_data'} == 1 && ($agent_status->{'datos'} ne $processed_data || $last_try < (time() - 86400))) ? 1 : 0;
|
||||
|
||||
db_do ($dbh, 'UPDATE tagente_estado SET datos = ?, estado = ?, last_status = ?, status_changes = ?, utimestamp = ?, timestamp = ?,
|
||||
id_agente = ?, current_interval = ?, running_by = ?, last_execution_try = ?, last_try = ?
|
||||
WHERE id_agente_modulo = ?', $data, $status, $last_status, $status_changes,
|
||||
WHERE id_agente_modulo = ?', $processed_data, $status, $last_status, $status_changes,
|
||||
$current_utimestamp, $timestamp, $module->{'id_agente'}, $module->{'module_interval'}, $server_id,
|
||||
$utimestamp, ($save == 1) ? $timestamp : $agent_status->{'last_try'}, $module->{'id_agente_modulo'});
|
||||
|
||||
# Save module data
|
||||
if ($save == 1) {
|
||||
save_module_data ($data, $module, $module_type, $utimestamp, $dbh);
|
||||
save_module_data ($processed_data, $module, $module_type, $utimestamp, $dbh);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -602,7 +617,6 @@ sub pandora_process_module ($$$$$$$$$) {
|
|||
##########################################################################
|
||||
sub pandora_planned_downtime ($$) {
|
||||
my ($pa_config, $dbh) = @_;
|
||||
|
||||
my $utimestamp = time();
|
||||
|
||||
# Start pending downtimes (disable agents)
|
||||
|
@ -610,13 +624,15 @@ sub pandora_planned_downtime ($$) {
|
|||
|
||||
foreach my $downtime (@downtimes) {
|
||||
|
||||
logger($pa_config, "Starting planned downtime '" . $downtime->{'nombre'} . "'.", 10);
|
||||
|
||||
db_do($dbh, 'UPDATE tplanned_downtime SET executed = 1 WHERE id = ?', $downtime->{'id'});
|
||||
pandora_event ($pa_config, "Server ".$pa_config->{'servername'}." started planned downtime: ".$downtime->{'description'}, 0, 0, 1, 0, 0, 'system', $dbh);
|
||||
|
||||
my @downtime_agents = db_do($dbh, 'SELECT * FROM tplanned_downtime_agents WHERE id_downtime = ' . $downtime->{'id'});
|
||||
|
||||
foreach my $downtime_agent (@downtime_agents) {
|
||||
db_do ($dbh, 'UPDATE tagente SET disabled = 1 WHERE id_agente = ?', $downtime_agent->{'id_agent'});
|
||||
db_do ($dbh, 'UPDATE tagente SET disabled = 1 WHERE id_grupo = ?', $downtime_agent->{'id_group'});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -624,13 +640,15 @@ sub pandora_planned_downtime ($$) {
|
|||
@downtimes = get_db_rows($dbh, 'SELECT * FROM tplanned_downtime WHERE executed = 1 AND date_to <= ?', $utimestamp);
|
||||
foreach my $downtime (@downtimes) {
|
||||
|
||||
logger($pa_config, "Ending planned downtime '" . $downtime->{'nombre'} . "'.", 10);
|
||||
|
||||
db_do($dbh, 'UPDATE tplanned_downtime SET executed = 0 WHERE id = ?', $downtime->{'id'});
|
||||
pandora_event ($pa_config, 'Server ' . $pa_config->{'servername'} . ' stopped planned downtime: ' . $downtime->{'description'}, 0, 0, 1, 0, 0, 'system', $dbh);
|
||||
|
||||
my @downtime_agents = get_db_rows($dbh, 'SELECT * FROM tplanned_downtime_agents WHERE id_downtime = ' . $downtime->{'id'});
|
||||
|
||||
foreach my $downtime_agent (@downtime_agents) {
|
||||
db_do ($dbh, 'UPDATE tagente SET disabled = 0 WHERE id_agente = ?', $downtime_agent->{'id_agent'});
|
||||
db_do ($dbh, 'UPDATE tagente SET disabled = 0 WHERE id_agrupo = ?', $downtime_agent->{'id_group'});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -666,7 +684,10 @@ sub pandora_update_server ($$$$$;$$) {
|
|||
$server = get_db_single_row ($dbh, 'SELECT * FROM tserver
|
||||
WHERE id_server = ?',
|
||||
$server_id);
|
||||
return unless defined ($server);
|
||||
if (! defined ($server)) {
|
||||
logger($pa_config, "Server '" . $pa_config->{'servername'} . "' not found.", 3);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# Server going up
|
||||
|
@ -711,6 +732,8 @@ sub pandora_update_agent ($$$$$$$) {
|
|||
sub pandora_module_keep_alive ($$$$$) {
|
||||
my ($pa_config, $id_agent, $agent_name, $server_id, $dbh) = @_;
|
||||
|
||||
logger($pa_config, "Updating keep_alive module for agent '" . $agent_name . "'.", 10);
|
||||
|
||||
# Update keepalive module
|
||||
my $module = get_db_single_row ($dbh, 'SELECT * FROM tagente_modulo WHERE id_agente = ? AND id_tipo_modulo = 100', $id_agent);
|
||||
return unless defined ($module);
|
||||
|
@ -725,6 +748,8 @@ sub pandora_create_incident ($$$$$$$$) {
|
|||
my ($pa_config, $dbh, $title, $text,
|
||||
$priority, $status, $origin, $id_group) = @_;
|
||||
|
||||
logger($pa_config, "Creating incident '$text' source '$origin'.", 8);
|
||||
|
||||
db_do($dbh, 'INSERT INTO tincidencia (`inicio`, `titulo`, `descripcion`, `origen`, `estado`, `prioridad`, `id_grupo`)
|
||||
VALUES (NOW(), ?, ?, ?, ?, ?, ?)', $title, $text, $origin, $status, $priority, $id_group);
|
||||
}
|
||||
|
@ -737,6 +762,8 @@ sub pandora_audit ($$$$$) {
|
|||
my ($pa_config, $description, $name, $action, $dbh) = @_;
|
||||
my $disconnect = 0;
|
||||
|
||||
logger($pa_config, "Creating audit entry '$description' name '$name' action '$action'.", 10);
|
||||
|
||||
my $utimestamp = time();
|
||||
my $timestamp = strftime ("%Y-%m-%d %H:%M:%S", localtime($utimestamp));
|
||||
|
||||
|
@ -751,10 +778,12 @@ sub pandora_audit ($$$$$) {
|
|||
# Create a new entry in tagente_modulo and the corresponding entry in
|
||||
# tagente_estado.
|
||||
##########################################################################
|
||||
sub pandora_create_module ($$$$$$$$$) {
|
||||
my ($agent_id, $module_type_id, $module_name, $max,
|
||||
sub pandora_create_module ($$$$$$$$$$) {
|
||||
my ($pa_config, $agent_id, $module_type_id, $module_name, $max,
|
||||
$min, $post_process, $description, $interval, $dbh) = @_;
|
||||
|
||||
logger($pa_config, "Creating module '$module_name' for agent ID $agent_id.", 10);
|
||||
|
||||
# Provide some default values
|
||||
$max = 0 if ($max eq '');
|
||||
$min = 0 if ($min eq '');
|
||||
|
@ -775,7 +804,7 @@ sub pandora_create_agent ($$$$$$$$$$) {
|
|||
$address_id, $group_id, $parent_id, $os_id,
|
||||
$description, $dbh) = @_;
|
||||
|
||||
logger ($pa_config, "$server_name: Creating agent $agent_name ($address)", 1);
|
||||
logger ($pa_config, "Server '$server_name' creating agent '$agent_name' address '$address'.", 10);
|
||||
|
||||
$description = "Created by $server_name" unless ($description ne '');
|
||||
|
||||
|
@ -793,6 +822,8 @@ sub pandora_event (%$$$$$$$$) {
|
|||
my ($pa_config, $evento, $id_grupo, $id_agente, $severity,
|
||||
$id_alert_am, $id_agentmodule, $event_type, $dbh) = @_;
|
||||
|
||||
logger($pa_config, "Generating event '$evento' for agent ID $id_agente module ID $id_agentmodule.", 10);
|
||||
|
||||
my $utimestamp = time ();
|
||||
my $timestamp = strftime ("%Y-%m-%d %H:%M:%S", localtime ($utimestamp));
|
||||
$id_agentmodule = 0 unless defined ($id_agentmodule);
|
||||
|
@ -807,6 +838,8 @@ sub pandora_event (%$$$$$$$$) {
|
|||
sub pandora_update_module_on_error ($$$) {
|
||||
my ($pa_config, $id_agent_module, $dbh) = @_;
|
||||
|
||||
logger($pa_config, "Updating module ID $id_agent_module on error.", 10);
|
||||
|
||||
# Update last_execution_try
|
||||
db_do ($dbh, 'UPDATE tagente_estado SET last_execution_try = ?
|
||||
WHERE id_agente_modulo = ?', time (), $id_agent_module);
|
||||
|
@ -828,9 +861,15 @@ sub pandora_exec_forced_alerts {
|
|||
|
||||
# Get the agent and module associated with the alert
|
||||
my $module = get_db_single_row ($dbh, 'SELECT * FROM tagente_modulo WHERE id_agente_modulo = ?', $alert->{'id_agent_module'});
|
||||
next unless defined ($module);
|
||||
if (! defined ($module)) {
|
||||
logger($pa_config, "Module ID " . $alert->{'id_agent_module'} . " not found for alert ID " . $alert->{'id_template_module'} . ".", 10);
|
||||
next;
|
||||
}
|
||||
my $agent = get_db_single_row ($dbh, 'SELECT * FROM tagente WHERE id_agente = ?', $module->{'id_agente'});
|
||||
next unless defined ($agent);
|
||||
if (! defined ($agent)) {
|
||||
logger($pa_config, "Agent ID " . $module->{'id_agente'} . " not found for module ID " . $module->{'id_agente_modulo'} . " alert ID " . $alert->{'id_template_module'} . ".", 10);
|
||||
next;
|
||||
}
|
||||
|
||||
pandora_execute_alert ($pa_config, 'N/A', $agent, $module, $alert, 1, $dbh);
|
||||
|
||||
|
@ -857,6 +896,7 @@ sub pandora_module_keep_alive_nd {
|
|||
AND ( tagente_estado.utimestamp + (tagente.intervalo * 2) < UNIX_TIMESTAMP())');
|
||||
|
||||
foreach my $module (@modules) {
|
||||
logger($pa_config, "Updating keep_alive module for module '" . $module->{'nombre'} . "' agent ID " . $module->{'id_agente'} . " (agent without data).", 10);
|
||||
pandora_process_module ($pa_config, 0, '', $module, 'keep_alive', '', time (), 0, $dbh);
|
||||
}
|
||||
}
|
||||
|
@ -873,6 +913,9 @@ sub pandora_evaluate_snmp_alerts ($$$$$$$$) {
|
|||
|
||||
# Find those that apply to the given SNMP trap
|
||||
foreach my $alert (@snmp_alerts) {
|
||||
|
||||
logger($pa_config, "Evaluating SNMP alert ID " . $alert->{'id_as'} . ".", 10);
|
||||
|
||||
my ($fire_alert, $alert_data) = (0, '');
|
||||
my ($times_fired, $internal_counter, $alert_type) =
|
||||
($alert->{'times_fired'}, $alert->{'internal_counter'}, $alert->{'alert_type'});
|
||||
|
@ -1136,7 +1179,6 @@ sub get_module_status ($$) {
|
|||
sub generate_status_event ($$$$$$$) {
|
||||
my ($pa_config, $data, $agent, $module, $status, $last_status, $dbh) = @_;
|
||||
my ($event_type, $severity);
|
||||
|
||||
my $description = "Module " . $module->{'nombre'} . " ($data) is ";
|
||||
|
||||
# Normal
|
||||
|
@ -1168,6 +1210,7 @@ sub generate_status_event ($$$$$$$) {
|
|||
enterprise_hook('mcast_change_report', [$pa_config, $module->{'nombre'}, $module->{'custom_id'}, strftime ("%Y-%m-%d %H:%M:%S", localtime()), 'WARN', $dbh]);
|
||||
} else {
|
||||
# Unknown status
|
||||
logger($pa_config, "Unknown status $status for module '" . $module->{'nombre'} . "' agent '" . $agent->{'nombre'} . "'.", 10);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1191,12 +1234,13 @@ sub save_module_data ($$$$$) {
|
|||
##########################################################################
|
||||
# Export module data.
|
||||
##########################################################################
|
||||
sub export_module_data ($$$$$$) {
|
||||
my ($data, $agent, $module, $module_type, $timestamp, $dbh) = @_;
|
||||
sub export_module_data ($$$$$$$) {
|
||||
my ($pa_config, $data, $agent, $module, $module_type, $timestamp, $dbh) = @_;
|
||||
|
||||
# Data export is disabled
|
||||
return if ($module->{'id_export'} < 1);
|
||||
|
||||
logger($pa_config, "Exporting data for module '" . $module->{'nombre'} . "' agent '" . $agent->{'nombre'} . "'.", 10);
|
||||
db_do($dbh, 'INSERT INTO tserver_export_data
|
||||
(`id_export_server`, `agent_name` , `module_name`, `module_type`, `data`, `timestamp`) VALUES
|
||||
(?, ?, ?, ?, ?, ?)', $module->{'id_export'}, $agent->{'nombre'}, $module->{'nombre'}, $module_type, $data, $timestamp);
|
||||
|
|
|
@ -42,6 +42,7 @@ my %PendingTasks :shared;
|
|||
my $Sem :shared = Thread::Semaphore->new;
|
||||
my $TaskSem :shared = Thread::Semaphore->new (0);
|
||||
my $AgentSem :shared = Thread::Semaphore->new (1);
|
||||
my $ModuleSem :shared = Thread::Semaphore->new (1);
|
||||
|
||||
########################################################################################
|
||||
# Data Server class constructor.
|
||||
|
@ -65,7 +66,7 @@ sub run ($) {
|
|||
my $self = shift;
|
||||
my $pa_config = $self->getConfig ();
|
||||
|
||||
print " [*] Starting Pandora FMS Data Server. \n";
|
||||
print_message ($pa_config, " [*] Starting Pandora FMS Data Server.", 1);
|
||||
$self->setNumThreads ($pa_config->{'dataserver_threads'});
|
||||
$self->SUPER::run (\@TaskQueue, \%PendingTasks, $Sem, $TaskSem);
|
||||
}
|
||||
|
@ -138,7 +139,7 @@ sub data_consumer ($$) {
|
|||
$xml_data->{'timestamp'} = strftime ("%Y-%m-%d %H:%M:%S", localtime((stat($file_name))[9])) if ($pa_config->{'use_xml_timestamp'} eq '1' || ! defined ($xml_data->{'timestamp'}));
|
||||
|
||||
unlink ($file_name);
|
||||
process_xml_data ($self->getConfig (), $xml_data, $self->getServerID (), $self->getDBH ());
|
||||
process_xml_data ($self->getConfig (), $file_name, $xml_data, $self->getServerID (), $self->getDBH ());
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -149,8 +150,8 @@ sub data_consumer ($$) {
|
|||
###############################################################################
|
||||
# Process XML data coming from an agent.
|
||||
###############################################################################
|
||||
sub process_xml_data ($$$$) {
|
||||
my ($pa_config, $data, $server_id, $dbh) = @_;
|
||||
sub process_xml_data ($$$$$) {
|
||||
my ($pa_config, $file_name, $data, $server_id, $dbh) = @_;
|
||||
|
||||
my ($agent_name, $agent_version, $timestamp, $interval, $os_version) =
|
||||
($data->{'agent_name'}, $data->{'version'}, $data->{'timestamp'},
|
||||
|
@ -158,7 +159,7 @@ sub process_xml_data ($$$$) {
|
|||
|
||||
# Unknown agent!
|
||||
if (! defined ($agent_name) || $agent_name eq '') {
|
||||
logger($pa_config, 'ERROR: Received data from an unnamed agent', 2);
|
||||
logger($pa_config, "$file_name has data from an unnamed agent", 3);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -252,21 +253,37 @@ sub process_module_data ($$$$$$$$$) {
|
|||
|
||||
# Get agent data
|
||||
my $agent = get_db_single_row ($dbh, 'SELECT * FROM tagente WHERE nombre = ?', $agent_name);
|
||||
return unless defined ($agent);
|
||||
if (! defined ($agent)) {
|
||||
logger($pa_config, "Invalid agent '$agent_name' for module '$module_name'.", 3);
|
||||
return;
|
||||
}
|
||||
|
||||
# Get module data or create it if it does not exist
|
||||
$ModuleSem->down ();
|
||||
my $module = get_db_single_row ($dbh, 'SELECT * FROM tagente_modulo WHERE id_agente = ? AND nombre = ?', $agent->{'id_agente'}, $module_name);
|
||||
if (! defined ($module)) {
|
||||
|
||||
# Do not auto create modules
|
||||
return unless ($pa_config->{'autocreate'} == 1);
|
||||
if ($pa_config->{'autocreate'} ne '1') {
|
||||
logger($pa_config, "Module '$module_name' not found for agent '$agent_name' and module auto-creation disabled.", 10);
|
||||
$ModuleSem->up ();
|
||||
return;
|
||||
}
|
||||
|
||||
# Is the agent learning?
|
||||
return unless ($agent->{'modo'} eq '1');
|
||||
if ($agent->{'modo'} ne '1') {
|
||||
logger($pa_config, "Learning mode disabled. Skipping module '$module_name' agent '$agent_name'.", 10);
|
||||
$ModuleSem->up ();
|
||||
return;
|
||||
}
|
||||
|
||||
# Get the module type
|
||||
my $module_id = get_module_id ($dbh, $module_type);
|
||||
return unless ($module_id > 0);
|
||||
if ($module_id <= 0) {
|
||||
logger($pa_config, "Invalid module type '$module_type' for module '$module_name' agent '$agent_name'.", 3);
|
||||
$ModuleSem->up ();
|
||||
return;
|
||||
}
|
||||
|
||||
# Get min/max/description/post process
|
||||
my $max = get_tag_value ($data, 'max', 0);
|
||||
|
@ -278,23 +295,34 @@ sub process_module_data ($$$$$$$$$) {
|
|||
$post_process =~ s/,/./;
|
||||
|
||||
# Create the module
|
||||
pandora_create_module ($agent->{'id_agente'}, $module_id, $module_name,
|
||||
pandora_create_module ($pa_config, $agent->{'id_agente'}, $module_id, $module_name,
|
||||
$max, $min, $post_process, $description, $interval, $dbh);
|
||||
$module = get_db_single_row ($dbh, 'SELECT * FROM tagente_modulo WHERE id_agente = ? AND nombre = ?', $agent->{'id_agente'}, $module_name);
|
||||
return unless defined $module;
|
||||
if (! defined ($module)) {
|
||||
logger($pa_config, "Could not create module '$module_name' for agent '$agent_name'.", 3);
|
||||
$ModuleSem->up ();
|
||||
return;
|
||||
}
|
||||
}
|
||||
$ModuleSem->up ();
|
||||
|
||||
# Module disabled!
|
||||
return if ($module->{'disabled'} eq '1');
|
||||
if ($module->{'disabled'} eq '1') {
|
||||
logger($pa_config, "Skipping disabled module '$module_name' agent '$agent_name'.", 10);
|
||||
return;
|
||||
}
|
||||
|
||||
# Parse the timestamp and process the module
|
||||
if ($timestamp =~ /(\d+)\/(\d+)\/(\d+) +(\d+):(\d+):(\d+)/ ||
|
||||
$timestamp =~ /(\d+)\-(\d+)\-(\d+) +(\d+):(\d+):(\d+)/) {
|
||||
if ($timestamp !~ /(\d+)\/(\d+)\/(\d+) +(\d+):(\d+):(\d+)/ &&
|
||||
$timestamp !~ /(\d+)\-(\d+)\-(\d+) +(\d+):(\d+):(\d+)/) {
|
||||
logger($pa_config, "Invalid timestamp '$timestamp' from module '$module_name' agent '$agent_name'.", 3);
|
||||
return;
|
||||
}
|
||||
|
||||
my $utimestamp = timelocal($6, $5, $4, $3, $2 - 1, $1 - 1900);
|
||||
my $value = get_tag_value ($data, 'data', '');
|
||||
pandora_process_module ($pa_config, $value, $agent, $module, $module_type, $timestamp, $utimestamp, $server_id, $dbh);
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
__END__
|
||||
|
|
|
@ -50,8 +50,8 @@ sub new ($$$) {
|
|||
return undef unless $config->{'networkserver'} == 1;
|
||||
|
||||
if (! -e $config->{'snmpget'}) {
|
||||
logger ($config, ' [E] ' . $config->{'snmpget'} . " needed by Pandora FMS Network Server not found.", 0);
|
||||
print ' [E] ' . $config->{'snmpget'} . " needed by Pandora FMS Network Server not found.\n\n";
|
||||
logger ($config, ' [E] ' . $config->{'snmpget'} . " needed by Pandora FMS Network Server not found.", 1);
|
||||
print_message ($config, ' [E] ' . $config->{'snmpget'} . " needed by Pandora FMS Network Server not found.", 1);
|
||||
return undef;
|
||||
}
|
||||
|
||||
|
@ -69,7 +69,7 @@ sub run ($) {
|
|||
my $self = shift;
|
||||
my $pa_config = $self->getConfig ();
|
||||
|
||||
print " [*] Starting Pandora FMS Network Server. \n";
|
||||
print_message ($pa_config, " [*] Starting Pandora FMS Network Server.", 1);
|
||||
$self->setNumThreads ($pa_config->{'network_threads'});
|
||||
$self->SUPER::run (\@TaskQueue, \%PendingTasks, $Sem, $TaskSem);
|
||||
}
|
||||
|
@ -376,7 +376,7 @@ sub exec_network_module ($$$$) {
|
|||
|
||||
# Is everything goes ok
|
||||
if ($module_result == 0) {
|
||||
pandora_process_module ($pa_config, $module_data, '', $module, '', $timestamp, $utimestamp, $server_id, $dbh);
|
||||
pandora_process_module ($pa_config, $module_data, undef, $module, undef, $timestamp, $utimestamp, $server_id, $dbh);
|
||||
|
||||
# Update agent last contact using Pandora version as agent version
|
||||
pandora_update_agent ($pa_config, $timestamp, $id_agente, $pa_config->{'servername'}.'_Net', $pa_config->{'version'}, -1, $dbh);
|
||||
|
|
|
@ -51,8 +51,8 @@ sub new ($$;$) {
|
|||
|
||||
# Check for pandora_exec
|
||||
if (system($config->{'plugin_exec'} . ' > /dev/null 2>&1') != 256) {
|
||||
logger ($config, " [E] pandora_exec not found. Plugin Server not started.", 0);
|
||||
print " [E] pandora_exec not found. Plugin Server not started.\n\n";
|
||||
logger ($config, " [E] pandora_exec not found. Plugin Server not started.", 1);
|
||||
print_message ($config, " [E] pandora_exec not found. Plugin Server not started.", 1);
|
||||
return undef;
|
||||
}
|
||||
|
||||
|
@ -70,7 +70,7 @@ sub run ($) {
|
|||
my $self = shift;
|
||||
my $pa_config = $self->getConfig ();
|
||||
|
||||
print " [*] Starting Pandora FMS Plugin Server. \n";
|
||||
print_message ($pa_config, " [*] Starting Pandora FMS Plugin Server.", 1);
|
||||
$self->setNumThreads ($pa_config->{'plugin_threads'});
|
||||
$self->SUPER::run (\@TaskQueue, \%PendingTasks, $Sem, $TaskSem);
|
||||
}
|
||||
|
@ -206,7 +206,7 @@ sub data_consumer ($$) {
|
|||
my $utimestamp = time ();
|
||||
my $timestamp = strftime ("%Y-%m-%d %H:%M:%S", localtime($utimestamp));
|
||||
|
||||
pandora_process_module ($pa_config, $module_data, '', $module, '', $timestamp, $utimestamp, $self->getServerID (), $dbh);
|
||||
pandora_process_module ($pa_config, $module_data, undef, $module, undef, $timestamp, $utimestamp, $self->getServerID (), $dbh);
|
||||
pandora_update_agent ($pa_config, $timestamp, $module->{'id_agente'}, $pa_config->{'servername'}.'_Plugin', $pa_config->{'version'}, -1, $dbh);
|
||||
}
|
||||
|
||||
|
|
|
@ -64,7 +64,7 @@ sub run ($) {
|
|||
my $self = shift;
|
||||
my $pa_config = $self->getConfig ();
|
||||
|
||||
print " [*] Starting Pandora FMS Prediction Server. \n";
|
||||
print_message ($pa_config, " [*] Starting Pandora FMS Prediction Server.", 1);
|
||||
$self->setNumThreads ($pa_config->{'prediction_threads'});
|
||||
$self->SUPER::run (\@TaskQueue, \%PendingTasks, $Sem, $TaskSem);
|
||||
}
|
||||
|
@ -235,7 +235,7 @@ sub exec_prediction_module ($$$$) {
|
|||
$module_data = $average;
|
||||
}
|
||||
|
||||
pandora_process_module ($pa_config, $module_data, '', $agent_module, '', $timestamp, $utimestamp, $server_id, $dbh);
|
||||
pandora_process_module ($pa_config, $module_data, undef, $agent_module, undef, $timestamp, $utimestamp, $server_id, $dbh);
|
||||
pandora_update_agent ($pa_config, $timestamp, $agent_module->{'id_agente'}, $pa_config->{'servername'}.'_Prediction', $pa_config->{'version'}, -1, $dbh);
|
||||
}
|
||||
|
||||
|
|
|
@ -65,7 +65,7 @@ sub run ($) {
|
|||
my $self = shift;
|
||||
my $pa_config = $self->getConfig ();
|
||||
|
||||
print " [*] Starting Pandora FMS Recon Server. \n";
|
||||
print_message ($pa_config, " [*] Starting Pandora FMS Recon Server.", 1);
|
||||
$self->setNumThreads ($pa_config->{'recon_threads'});
|
||||
$self->SUPER::run (\@TaskQueue, \%PendingTasks, $Sem, $TaskSem);
|
||||
}
|
||||
|
@ -110,7 +110,7 @@ sub data_consumer ($$) {
|
|||
# Get a NetAddr::IP object for the target network
|
||||
my $net_addr = new NetAddr::IP ($task->{'subnet'});
|
||||
if (! defined ($net_addr)) {
|
||||
logger ($pa_config, 'Invalid network ' . $task->{'subnet'} . ' for task ' . $task->{'name'}, 2);
|
||||
logger ($pa_config, "Invalid network " . $task->{'subnet'} . " for task '" . $task->{'name'} . "'.", 3);
|
||||
update_recon_task ($dbh, $task_id, -1);
|
||||
return -1;
|
||||
}
|
||||
|
@ -137,10 +137,14 @@ sub data_consumer ($$) {
|
|||
}
|
||||
|
||||
next unless ($alive > 0);
|
||||
logger($pa_config, "Found host $addr.", 10);
|
||||
|
||||
# Guess the OS and filter
|
||||
my $id_os = guess_os ($pa_config, $addr);
|
||||
next if ($task->{'id_os'} > 0 && $task->{'id_os'} != $id_os);
|
||||
if ($task->{'id_os'} > 0 && $task->{'id_os'} != $id_os) {
|
||||
logger($pa_config, "Skipping host $addr os ID $id_os.", 10);
|
||||
next;
|
||||
}
|
||||
|
||||
$hosts_found ++;
|
||||
$addr_found .= $addr . " ";
|
||||
|
@ -155,7 +159,10 @@ sub data_consumer ($$) {
|
|||
# Add the new address if it does not exist
|
||||
my $addr_id = get_addr_id ($dbh, $addr);
|
||||
$addr_id = add_address ($dbh, $addr) unless ($addr_id > 0);
|
||||
next unless ($addr_id > 0);
|
||||
if ($addr_id <= 0) {
|
||||
logger($pa_config, "Could not add address '$addr' for host '$host_name'.", 3);
|
||||
next;
|
||||
}
|
||||
|
||||
# Crate a new agent
|
||||
my $agent_id = pandora_create_agent ($pa_config, $pa_config->{'servername'},
|
||||
|
@ -285,7 +292,12 @@ sub create_network_profile_modules {
|
|||
|
||||
# Get network component data
|
||||
my $component = get_db_single_row ($dbh, 'SELECT * FROM tnetwork_component wHERE id_nc = ?', $np_component->{'id_nc'});
|
||||
next unless defined ($component);
|
||||
if (! defined ($component)) {
|
||||
logger($pa_config, "Network component ID " . $np_component->{'id_nc'} . " for agent $addr not found.", 3);
|
||||
next;
|
||||
}
|
||||
|
||||
logger($pa_config, "Processing network component '" . $component->{'name'} . "' for agent $addr.", 10);
|
||||
|
||||
# Create the module
|
||||
my $module_id = db_insert ($dbh, 'INSERT INTO tagente_modulo (id_agente, id_tipo_modulo, descripcion, nombre, max, min, module_interval, tcp_port, tcp_send, tcp_rcv, snmp_community, snmp_oid, ip_target, id_module_group, flag, disabled, plugin_user, plugin_pass, plugin_parameter, max_timeout, id_modulo )
|
||||
|
@ -293,13 +305,11 @@ sub create_network_profile_modules {
|
|||
$agent_id, $component->{'type'}, $component->{'description'}, $component->{'name'}, $component->{'max'}, $component->{'min'}, $component->{'module_interval'}, $component->{'tcp_port'}, $component->{'tcp_send'}, $component->{'tcp_rcv'}, $component->{'snmp_community'},
|
||||
$component->{'snmp_oid'}, $addr, $component->{'id_module_group'}, $component->{'plugin_user'}, $component->{'plugin_pass'}, $component->{'plugin_parameter'}, $component->{'max_timeout'}, $component->{'id_modulo'});
|
||||
|
||||
logger($pa_config, 'Recon Server: Creating module ' . $component->{'name'} . " for agent $addr", 3);
|
||||
|
||||
# An entry in tagente_estado is necessary for the module to work
|
||||
db_insert ($dbh, 'INSERT INTO tagente_estado (id_agente_modulo, datos, timestamp, estado, id_agente, last_try, utimestamp, current_interval, running_by)
|
||||
VALUES (?, \'\', \'0000-00-00 00:00:00\', 1, ?, \'0000-00-00 00:00:00\', 0, ?, 0)',
|
||||
$module_id, $agent_id, $component->{'module_interval'});
|
||||
|
||||
logger($pa_config, 'Creating module ' . $component->{'name'} . " for agent $addr from network component '" . $component->{'name'} . "'.", 10);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -45,8 +45,8 @@ sub new ($$;$) {
|
|||
|
||||
# Start snmptrapd
|
||||
if (system ($config->{'snmp_trapd'} . ' -t -On -n -a -Lf ' . $config->{'snmp_logfile'} . ' -p /var/run/pandora_snmptrapd.pid -F %4y-%02.2m-%l[**]%02.2h:%02.2j:%02.2k[**]%a[**]%N[**]%w[**]%W[**]%q[**]%v\\\n >/dev/null 2>&1') != 0) {
|
||||
logger ($config, " [E] Could not start snmptrapd.\n\n", 0);
|
||||
print " [E] Could not start snmptrapd.\n\n";
|
||||
logger ($config, " [E] Could not start snmptrapd.", 1);
|
||||
print_message ($config, " [E] Could not start snmptrapd.", 1);
|
||||
return undef;
|
||||
}
|
||||
|
||||
|
@ -62,8 +62,9 @@ sub new ($$;$) {
|
|||
###############################################################################
|
||||
sub run ($) {
|
||||
my $self = shift;
|
||||
my $pa_config = $self->getConfig ();
|
||||
|
||||
print " [*] Starting Pandora FMS SNMP Console. \n";
|
||||
print_message ($pa_config, " [*] Starting Pandora FMS SNMP Console.", 1);
|
||||
$self->SUPER::run (\&PandoraFMS::SNMPServer::pandora_snmptrapd);
|
||||
}
|
||||
|
||||
|
@ -124,6 +125,7 @@ sub pandora_snmptrapd {
|
|||
# Unknown data
|
||||
next if ($line !~ m/\[\*\*\]/);
|
||||
|
||||
logger($pa_config, "Reading trap '$line'", 10);
|
||||
my ($date, $time, $source, $oid,
|
||||
$type, $type_desc, $value, $data) = split(/\[\*\*\]/, $line);
|
||||
|
||||
|
|
|
@ -247,47 +247,25 @@ sub md5check {
|
|||
}
|
||||
|
||||
##########################################################################
|
||||
# SUB logger (pa_config, param_1, param_2)
|
||||
# SUB logger (pa_config, message, level)
|
||||
# Log to file
|
||||
##########################################################################
|
||||
# param_1 : Data file
|
||||
# param_2 : Data
|
||||
sub logger ($$;$) {
|
||||
my ($pa_config, $message, $level) = @_;
|
||||
|
||||
sub logger {
|
||||
my $pa_config = $_[0];
|
||||
my $fichero = $pa_config->{"logfile"};
|
||||
my $datos = $_[1];
|
||||
my $param2= $_[2];
|
||||
my $verbose_level = 2; # if parameter not passed, verbosity is 2
|
||||
return if ($level > $pa_config->{'verbosity'});
|
||||
|
||||
if (!defined $pa_config->{"verbosity"}){
|
||||
$pa_config->{"verbosity"} = 0;
|
||||
my $file = $pa_config->{'logfile'};
|
||||
|
||||
# Log rotation
|
||||
if (-e $file && (stat($file))[7] > $pa_config->{'max_log_size'}) {
|
||||
rename ($file, $file.'.old');
|
||||
}
|
||||
|
||||
if (defined $param2){
|
||||
if (is_numeric($param2)){
|
||||
$verbose_level = $param2;
|
||||
}
|
||||
}
|
||||
|
||||
if ($verbose_level <= $pa_config->{"verbosity"}) {
|
||||
if ($verbose_level > 0) {
|
||||
$datos = "[V".$verbose_level."] ".$datos;
|
||||
}
|
||||
|
||||
my $time_now = strftime ("%Y-%m-%d %H:%M:%S", localtime());
|
||||
if (-e $fichero){
|
||||
my $filesize = (stat($fichero))[7];
|
||||
if ( $filesize > $pa_config->{'max_log_size'}) {
|
||||
rename ($fichero, $fichero.".old");
|
||||
}
|
||||
}
|
||||
open (FILE, ">> $fichero") or die "[FATAL] Cannot open logfile at $fichero";
|
||||
my $server_name = $pa_config->{'servername'}.$pa_config->{"servermode"};
|
||||
print FILE "$time_now $server_name $datos \n";
|
||||
open (FILE, ">> $file") or die "[FATAL] Could not open logfile '$fichero'";
|
||||
print FILE strftime ("%Y-%m-%d %H:%M:%S", localtime()) . " " . $pa_config->{'servername'} . $pa_config->{'servermode'} . " [V". $level ."] " . $message . "\n";
|
||||
close (FILE);
|
||||
}
|
||||
}
|
||||
|
||||
##########################################################################
|
||||
# limpia_cadena (string) - Purge a string for any forbidden characters (esc, etc)
|
||||
|
@ -342,7 +320,15 @@ sub float_equal {
|
|||
# Tries to load the PandoraEnterprise module. Must be called once before
|
||||
# enterprise_hook ().
|
||||
##########################################################################
|
||||
sub enterprise_load () {
|
||||
sub enterprise_load ($) {
|
||||
my $pa_config = shift;
|
||||
|
||||
# Check dependencies
|
||||
eval 'local $SIG{__DIE__}; require IO::Socket::Multicast';
|
||||
if ($@) {
|
||||
print_message ($pa_config, " [*] Error loading Pandora FMS Enterprise: IO::Socket::Multicast not found.", 1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
# Already loaded
|
||||
#return 1 if (is_loaded ('PandoraFMS::Enterprise'));
|
||||
|
@ -387,9 +373,7 @@ sub enterprise_hook ($$) {
|
|||
sub print_message ($$$) {
|
||||
my ($pa_config, $message, $log_level) = @_;
|
||||
|
||||
if ($pa_config->{'verbosity'} > $log_level){
|
||||
print STDOUT $message . "\n";
|
||||
}
|
||||
print STDOUT $message . "\n" if ($pa_config->{'verbosity'} >= $log_level);
|
||||
}
|
||||
|
||||
##########################################################################
|
||||
|
|
|
@ -51,8 +51,8 @@ sub new ($$;$) {
|
|||
|
||||
# Check for a WMI client
|
||||
if (system ($config->{'wmi_client'} . ' > /dev/null 2>&1') != 256) {
|
||||
logger ($config, ' [E] ' . $config->{'wmi_client'} . " not found. Pandora FMS WMI Server needs a DCOM/WMI client.", 0);
|
||||
print ' [E] ' . $config->{'wmi_client'} . " not found. Pandora FMS WMI Server needs a DCOM/WMI client.\n\n";
|
||||
logger ($config, ' [E] ' . $config->{'wmi_client'} . " not found. Pandora FMS WMI Server needs a DCOM/WMI client.", 1);
|
||||
print_message ($config, ' [E] ' . $config->{'wmi_client'} . " not found. Pandora FMS WMI Server needs a DCOM/WMI client.", 1);
|
||||
return undef;
|
||||
}
|
||||
|
||||
|
@ -70,7 +70,7 @@ sub run ($) {
|
|||
my $self = shift;
|
||||
my $pa_config = $self->getConfig ();
|
||||
|
||||
print " [*] Starting Pandora FMS WMI Server. \n";
|
||||
print_message ($pa_config, " [*] Starting Pandora FMS WMI Server.", 1);
|
||||
$self->setNumThreads ($pa_config->{'wmi_threads'});
|
||||
$self->SUPER::run (\@TaskQueue, \%PendingTasks, $Sem, $TaskSem);
|
||||
}
|
||||
|
@ -192,7 +192,7 @@ sub data_consumer ($$) {
|
|||
my $utimestamp = time ();
|
||||
my $timestamp = strftime ("%Y-%m-%d %H:%M:%S", localtime($utimestamp));
|
||||
|
||||
pandora_process_module ($pa_config, $module_data, '', $module, '', $timestamp, $utimestamp, $self->getServerID (), $dbh);
|
||||
pandora_process_module ($pa_config, $module_data, undef, $module, undef, $timestamp, $utimestamp, $self->getServerID (), $dbh);
|
||||
pandora_update_agent ($pa_config, $timestamp, $module->{'id_agente'}, $pa_config->{'servername'} . '_WMI', $pa_config->{'version'}, -1, $dbh);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue