From c6ce58d5f93bdefe8d65c389d41720ee7465b2df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Gonz=C3=A1lez?= Date: Tue, 11 Oct 2022 11:02:42 +0200 Subject: [PATCH 1/9] Added feature for create event and notify where snmptrampd is stuck --- pandora_server/bin/pandora_server | 3 +++ pandora_server/lib/PandoraFMS/Core.pm | 37 +++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/pandora_server/bin/pandora_server b/pandora_server/bin/pandora_server index ce091872e2..e6ec7ed6dc 100755 --- a/pandora_server/bin/pandora_server +++ b/pandora_server/bin/pandora_server @@ -453,6 +453,9 @@ sub pandora_server_tasks ($) { } } + # Check if snmptrapd is freeze. + pandora_snmptrapd_still_working ($pa_config, $dbh); + # Event auto-expiry my $expiry_time = $pa_config->{"event_expiry_time"}; my $expiry_window = $pa_config->{"event_expiry_window"}; diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index cf3c0df901..c9fcd714a0 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -215,6 +215,7 @@ our @EXPORT = qw( pandora_module_keep_alive_nd pandora_module_unknown pandora_output_password + pandora_snmptrapd_still_working pandora_planned_downtime pandora_planned_downtime_set_quiet_elements pandora_planned_downtime_unset_quiet_elements @@ -7191,6 +7192,42 @@ sub notification_get_groups { return @results; } +######################################################################## + +=head2 C<< pandora_snmptrapd_still_working (I<$pa_config>, I<$dbh>) >> +snmptrapd sometimes freezes and eventually its status needs to be checked. +=cut + +######################################################################## +sub pandora_snmptrapd_still_working ($$) { + my ($pa_config, $dbh) = @_; + + if ($pa_config->{'snmpserver'} eq '1') { + # Variable that defines the maximum time of delay between kksks. + my $timeMaxLapse = 360; + # Check last snmptrapd saved in DB. + my $lastTimestampSaved = get_db_value($dbh, 'SELECT UNIX_TIMESTAMP(timestamp) + FROM ttrap + ORDER BY timestamp DESC + LIMIT 1'); + # Read the last log file line. + use Tie::File; + my $snmptrapdFile = $pa_config->{'snmp_logfile'}; + tie my @snmptrapdFileComplete, 'Tie::File', $snmptrapdFile; + my $lastTimestampLogFile = $snmptrapdFileComplete[-1]; + my ($protocol, $date, $time) = split(/\[\*\*\]/, $lastTimestampLogFile, 4); + my ($hour, $min, $sec) = split(/:/, $time, 3); + my ($year, $month, $day) = split(/-/, $date, 3); + $lastTimestampLogFile = timelocal($sec, $min, $hour, $day, $month, $year); + logger($pa_config, 'lastTimestampSaved: '.$lastTimestampSaved); + logger($pa_config, 'lastTimestampLogFile: '.$lastTimestampLogFile); + if ($lastTimestampSaved ne $lastTimestampLogFile && $lastTimestampSaved ge ($lastTimestampLogFile + $timeMaxLapse)) { + my $lapseMessage = "snmptrapd service probably is stuck. Please check the status." + logger($pa_config, $lapseMessage, 1); + pandora_event ($pa_config, $lapseMessage, 0, 0, 4, 0, 0, 'system', 0, $dbh); + } + } +} # End of function declaration # End of defined Code From c726904ec142a31e2e81d0528bef41b1ef26d477 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Gonz=C3=A1lez?= Date: Tue, 11 Oct 2022 11:12:02 +0200 Subject: [PATCH 2/9] Fix --- pandora_server/lib/PandoraFMS/Core.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index c9fcd714a0..3023cf611d 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -7222,7 +7222,7 @@ sub pandora_snmptrapd_still_working ($$) { logger($pa_config, 'lastTimestampSaved: '.$lastTimestampSaved); logger($pa_config, 'lastTimestampLogFile: '.$lastTimestampLogFile); if ($lastTimestampSaved ne $lastTimestampLogFile && $lastTimestampSaved ge ($lastTimestampLogFile + $timeMaxLapse)) { - my $lapseMessage = "snmptrapd service probably is stuck. Please check the status." + my $lapseMessage = "snmptrapd service probably is stuck."; logger($pa_config, $lapseMessage, 1); pandora_event ($pa_config, $lapseMessage, 0, 0, 4, 0, 0, 'system', 0, $dbh); } From 70aef3220aaa02834ca0f245fad2243692c65ac4 Mon Sep 17 00:00:00 2001 From: "jose.gonzalez@pandorafms.com" Date: Fri, 28 Oct 2022 10:06:38 +0200 Subject: [PATCH 3/9] Fix --- pandora_server/lib/PandoraFMS/Core.pm | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index 3023cf611d..972aae2e6f 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -7204,7 +7204,7 @@ sub pandora_snmptrapd_still_working ($$) { if ($pa_config->{'snmpserver'} eq '1') { # Variable that defines the maximum time of delay between kksks. - my $timeMaxLapse = 360; + my $timeMaxLapse = 3600; # Check last snmptrapd saved in DB. my $lastTimestampSaved = get_db_value($dbh, 'SELECT UNIX_TIMESTAMP(timestamp) FROM ttrap @@ -7219,9 +7219,7 @@ sub pandora_snmptrapd_still_working ($$) { my ($hour, $min, $sec) = split(/:/, $time, 3); my ($year, $month, $day) = split(/-/, $date, 3); $lastTimestampLogFile = timelocal($sec, $min, $hour, $day, $month, $year); - logger($pa_config, 'lastTimestampSaved: '.$lastTimestampSaved); - logger($pa_config, 'lastTimestampLogFile: '.$lastTimestampLogFile); - if ($lastTimestampSaved ne $lastTimestampLogFile && $lastTimestampSaved ge ($lastTimestampLogFile + $timeMaxLapse)) { + if ($lastTimestampSaved ne $lastTimestampLogFile && $lastTimestampSaved gt ($lastTimestampLogFile + $timeMaxLapse)) { my $lapseMessage = "snmptrapd service probably is stuck."; logger($pa_config, $lapseMessage, 1); pandora_event ($pa_config, $lapseMessage, 0, 0, 4, 0, 0, 'system', 0, $dbh); From 071764bfd3a715f742fa564c4485cd5c4474b5db Mon Sep 17 00:00:00 2001 From: "jose.gonzalez@pandorafms.com" Date: Wed, 2 Nov 2022 11:19:44 +0100 Subject: [PATCH 4/9] Fix and added control when snmptraps are not filled --- pandora_server/lib/PandoraFMS/Core.pm | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index 972aae2e6f..4cfba7760a 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -7216,14 +7216,18 @@ sub pandora_snmptrapd_still_working ($$) { tie my @snmptrapdFileComplete, 'Tie::File', $snmptrapdFile; my $lastTimestampLogFile = $snmptrapdFileComplete[-1]; my ($protocol, $date, $time) = split(/\[\*\*\]/, $lastTimestampLogFile, 4); - my ($hour, $min, $sec) = split(/:/, $time, 3); - my ($year, $month, $day) = split(/-/, $date, 3); - $lastTimestampLogFile = timelocal($sec, $min, $hour, $day, $month, $year); - if ($lastTimestampSaved ne $lastTimestampLogFile && $lastTimestampSaved gt ($lastTimestampLogFile + $timeMaxLapse)) { - my $lapseMessage = "snmptrapd service probably is stuck."; - logger($pa_config, $lapseMessage, 1); - pandora_event ($pa_config, $lapseMessage, 0, 0, 4, 0, 0, 'system', 0, $dbh); + # If time or date not filled in, probably havent caught any snmptraps yet. + if ($time ne '' && $date ne '') { + my ($hour, $min, $sec) = split(/:/, $time, 3); + my ($year, $month, $day) = split(/-/, $date, 3); + $lastTimestampLogFile = timelocal($sec, $min, $hour, $day, $month, $year); + if ($lastTimestampSaved ne $lastTimestampLogFile && $lastTimestampSaved gt ($lastTimestampLogFile + $timeMaxLapse)) { + my $lapseMessage = "snmptrapd service probably is stuck."; + logger($pa_config, $lapseMessage, 1); + pandora_event ($pa_config, $lapseMessage, 0, 0, 4, 0, 0, 'system', 0, $dbh); + } } + } } From 1d04f777e2cdf09b6f39988bef1f6352f39da2ce Mon Sep 17 00:00:00 2001 From: "jose.gonzalez@pandorafms.com" Date: Wed, 2 Nov 2022 15:18:33 +0100 Subject: [PATCH 5/9] Fix mistake --- pandora_server/lib/PandoraFMS/Core.pm | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index 4cfba7760a..26cdd00d4e 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -7212,6 +7212,7 @@ sub pandora_snmptrapd_still_working ($$) { LIMIT 1'); # Read the last log file line. use Tie::File; + use Time::Piece; my $snmptrapdFile = $pa_config->{'snmp_logfile'}; tie my @snmptrapdFileComplete, 'Tie::File', $snmptrapdFile; my $lastTimestampLogFile = $snmptrapdFileComplete[-1]; @@ -7220,7 +7221,8 @@ sub pandora_snmptrapd_still_working ($$) { if ($time ne '' && $date ne '') { my ($hour, $min, $sec) = split(/:/, $time, 3); my ($year, $month, $day) = split(/-/, $date, 3); - $lastTimestampLogFile = timelocal($sec, $min, $hour, $day, $month, $year); + my $completeDate = Time::Piece->strptime("$sec $min $hour $day $month $year", '%S %M %H %d %m %Y'); + $lastTimestampLogFile = $completeDate->epoch; if ($lastTimestampSaved ne $lastTimestampLogFile && $lastTimestampSaved gt ($lastTimestampLogFile + $timeMaxLapse)) { my $lapseMessage = "snmptrapd service probably is stuck."; logger($pa_config, $lapseMessage, 1); From eb2d4e5de71bb3e696bc1b4e1e9cf0d395194259 Mon Sep 17 00:00:00 2001 From: "jose.gonzalez@pandorafms.com" Date: Wed, 2 Nov 2022 15:41:05 +0100 Subject: [PATCH 6/9] Fix --- pandora_server/lib/PandoraFMS/Core.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index 26cdd00d4e..e2dbcf4952 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -114,7 +114,9 @@ use Encode; use Encode::CN; use XML::Simple; use HTML::Entities; +use Tie::File; use Time::Local; +use Time::Piece; use Time::HiRes qw(time); eval "use POSIX::strftime::GNU;1" if ($^O =~ /win/i); use POSIX qw(strftime); @@ -7211,8 +7213,6 @@ sub pandora_snmptrapd_still_working ($$) { ORDER BY timestamp DESC LIMIT 1'); # Read the last log file line. - use Tie::File; - use Time::Piece; my $snmptrapdFile = $pa_config->{'snmp_logfile'}; tie my @snmptrapdFileComplete, 'Tie::File', $snmptrapdFile; my $lastTimestampLogFile = $snmptrapdFileComplete[-1]; From 4d2ef83366bf7a1c91d72e05484d1a5e1c8641f7 Mon Sep 17 00:00:00 2001 From: "jose.gonzalez@pandorafms.com" Date: Wed, 2 Nov 2022 15:58:24 +0100 Subject: [PATCH 7/9] Fix --- pandora_server/lib/PandoraFMS/Core.pm | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index e2dbcf4952..4823ba39bf 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -116,7 +116,6 @@ use XML::Simple; use HTML::Entities; use Tie::File; use Time::Local; -use Time::Piece; use Time::HiRes qw(time); eval "use POSIX::strftime::GNU;1" if ($^O =~ /win/i); use POSIX qw(strftime); @@ -7221,8 +7220,7 @@ sub pandora_snmptrapd_still_working ($$) { if ($time ne '' && $date ne '') { my ($hour, $min, $sec) = split(/:/, $time, 3); my ($year, $month, $day) = split(/-/, $date, 3); - my $completeDate = Time::Piece->strptime("$sec $min $hour $day $month $year", '%S %M %H %d %m %Y'); - $lastTimestampLogFile = $completeDate->epoch; + my $lastTimestampLogFile = timelocal($sec,$min,$hour,$day,$month-1,$year); if ($lastTimestampSaved ne $lastTimestampLogFile && $lastTimestampSaved gt ($lastTimestampLogFile + $timeMaxLapse)) { my $lapseMessage = "snmptrapd service probably is stuck."; logger($pa_config, $lapseMessage, 1); From b3cac09d0cf77e3e6854acf67cef9bd5c1e6efec Mon Sep 17 00:00:00 2001 From: "jose.gonzalez@pandorafms.com" Date: Thu, 3 Nov 2022 14:25:05 +0100 Subject: [PATCH 8/9] Mistake solved --- pandora_server/lib/PandoraFMS/Core.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index 4823ba39bf..676efb8158 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -127,7 +127,7 @@ use Text::ParseWords; use Math::Trig; # Math functions # Debugging -#use Data::Dumper; +use Data::Dumper; # Force XML::Simple to use XML::Parser instead SAX to manage XML # due a bug processing some XML with blank spaces. @@ -7221,7 +7221,7 @@ sub pandora_snmptrapd_still_working ($$) { my ($hour, $min, $sec) = split(/:/, $time, 3); my ($year, $month, $day) = split(/-/, $date, 3); my $lastTimestampLogFile = timelocal($sec,$min,$hour,$day,$month-1,$year); - if ($lastTimestampSaved ne $lastTimestampLogFile && $lastTimestampSaved gt ($lastTimestampLogFile + $timeMaxLapse)) { + if ($lastTimestampSaved ne $lastTimestampLogFile && $lastTimestampLogFile gt ($lastTimestampSaved + $timeMaxLapse)) { my $lapseMessage = "snmptrapd service probably is stuck."; logger($pa_config, $lapseMessage, 1); pandora_event ($pa_config, $lapseMessage, 0, 0, 4, 0, 0, 'system', 0, $dbh); From d1305c48124c04c3af95e9bc0ac0f56d67bf71aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Gonz=C3=A1lez?= <79-jose.gonzalez@users.noreply.brutus.artica.es> Date: Thu, 3 Nov 2022 15:49:05 +0000 Subject: [PATCH 9/9] Update pandora_server/lib/PandoraFMS/Core.pm --- pandora_server/lib/PandoraFMS/Core.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index 676efb8158..36de519fd4 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -127,7 +127,7 @@ use Text::ParseWords; use Math::Trig; # Math functions # Debugging -use Data::Dumper; +#use Data::Dumper; # Force XML::Simple to use XML::Parser instead SAX to manage XML # due a bug processing some XML with blank spaces.