diff --git a/pandora_server/conf/pandora_server.conf.new b/pandora_server/conf/pandora_server.conf.new index 1945cbd08f..f7d4df74aa 100644 --- a/pandora_server/conf/pandora_server.conf.new +++ b/pandora_server/conf/pandora_server.conf.new @@ -816,5 +816,8 @@ madeserver_autofit 7d # Model sensitivity. A lower value triggers less anomalies (PANDORA FMS ENTERPRISE ONLY). madeserver_sensitivity 0.1 +# If greater than 0, generate an event when more than the specified number of XML data files are queued for an agent. +too_many_xml 10 + # Encoding to use on mail subject (MIME-Header by default) -# mail_subject_encoding MIME-Header-ISO_2022_JP \ No newline at end of file +# mail_subject_encoding MIME-Header-ISO_2022_JP diff --git a/pandora_server/lib/PandoraFMS/Config.pm b/pandora_server/lib/PandoraFMS/Config.pm index 7447fe8236..f6a4170360 100644 --- a/pandora_server/lib/PandoraFMS/Config.pm +++ b/pandora_server/lib/PandoraFMS/Config.pm @@ -589,6 +589,8 @@ sub pandora_load_config { $pa_config->{"madeserver"} = 0; # 774. + $pa_config->{"too_many_xml"} = 10; # 776. + $pa_config->{"mail_subject_encoding"} = 'MIME-Header'; # 776. # Check for UID0 @@ -1417,6 +1419,9 @@ sub pandora_load_config { elsif ($parametro =~ m/^madeserver\s+([0-1])/i){ $pa_config->{'madeserver'}= clean_blank($1); } + elsif ($parametro =~ m/^too_many_xml\s+([0-9]*)/i){ + $pa_config->{'too_many_xml'}= clean_blank($1); + } } # end of loop for parameter # # The DB host was overridden by pandora_ha. diff --git a/pandora_server/lib/PandoraFMS/DataServer.pm b/pandora_server/lib/PandoraFMS/DataServer.pm index 6125a68e20..8a72ef7605 100644 --- a/pandora_server/lib/PandoraFMS/DataServer.pm +++ b/pandora_server/lib/PandoraFMS/DataServer.pm @@ -56,6 +56,7 @@ our @ISA = qw(PandoraFMS::ProducerConsumerServer); my @TaskQueue :shared; my %PendingTasks :shared; my %Agents :shared; +my %AgentCounts; my $Sem :shared; my $TaskSem :shared; my $AgentSem :shared; @@ -73,6 +74,7 @@ sub new ($$;$) { @TaskQueue = (); %PendingTasks = (); %Agents = (); + %AgentCounts = (); $Sem = Thread::Semaphore->new; $TaskSem = Thread::Semaphore->new (0); $AgentSem = Thread::Semaphore->new (1); @@ -142,6 +144,9 @@ sub data_producer ($) { opendir (DIR, $pa_config->{'incomingdir'}) || die "[FATAL] Cannot open Incoming data directory at " . $pa_config->{'incomingdir'} . ": $!"; + # Reset agent XML file counts + %AgentCounts = (); + # Do not read more than max_queue_files files my $file_count = 0; while (my $file = readdir (DIR)) { @@ -177,11 +182,21 @@ sub data_producer ($) { next if ($file !~ /^(.*)[\._]\d+\.data$/); my $agent_name = $1; + $AgentCounts{$agent_name} = defined($AgentCounts{$agent_name}) ? $AgentCounts{$agent_name} + 1 : 1; next if (agent_lock($pa_config, $dbh, $agent_name) == 0); push (@tasks, $file); } + # Generate an event if there are too many XML files for a given agent. + if ($pa_config->{'too_many_xml'} > 0) { + while (my ($agent_name, $xml_count) = each(%AgentCounts)) { + if ($xml_count > $pa_config->{'too_many_xml'}) { + pandora_timed_event(300, $pa_config, "More than " . $pa_config->{'too_many_xml'} . " XML files queued for agent $agent_name", 0, 0, 0, 0, 0, 'warning', 0, $dbh); + } + } + } + return @tasks; } @@ -200,6 +215,9 @@ sub data_producer_smart_queue ($) { opendir (DIR, $pa_config->{'incomingdir'}) || die "[FATAL] Cannot open Incoming data directory at " . $pa_config->{'incomingdir'} . ": $!"; + # Reset agent XML file counts + %AgentCounts = (); + # Do not read more than max_queue_files files my $smart_queue = {}; while (my $file = readdir (DIR)) { @@ -209,6 +227,9 @@ sub data_producer_smart_queue ($) { next if ($file !~ /^(.*)[\._]\d+\.data$/); my $agent_name = $1; + # Update per agent XML counts. + $AgentCounts{$agent_name} = defined($AgentCounts{$agent_name}) ? $AgentCounts{$agent_name} + 1 : 1; + # Queue a new file. if (!defined($smart_queue->{$agent_name})) { $smart_queue->{$agent_name} = $file; @@ -229,6 +250,15 @@ sub data_producer_smart_queue ($) { push (@tasks, $file); } + # Generate an event if there are too many XML files for a given agent. + if ($pa_config->{'too_many_xml'} > 0) { + while (my ($agent_name, $xml_count) = each(%AgentCounts)) { + if ($xml_count > $pa_config->{'too_many_xml'}) { + pandora_timed_event(300, $pa_config, "More than " . $pa_config->{'too_many_xml'} . " XML files queued for agent $agent_name", 0, 0, 0, 0, 0, 'warning', 0, $dbh); + } + } + } + return @tasks; }