From 6817278c2fb2b0cfc8f69711c7ffac3acf64030d Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Tue, 22 Feb 2022 11:58:53 +0100 Subject: [PATCH] Allow both behaviours in alert time slots --- pandora_server/lib/PandoraFMS/Core.pm | 47 +++++++++++++++++---------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index 8d74df5d68..1ff137a07d 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -552,30 +552,43 @@ sub pandora_evaluate_alert ($$$$$$$;$$$$) { } my $schedule = PandoraFMS::Tools::p_decode_json($pa_config, $alert->{'schedule'}); + if (defined($schedule)) { + # New behaviour. + return $status unless defined($schedule) && ref $schedule eq "HASH"; - return $status unless defined($schedule) && ref $schedule eq "HASH"; + return $status unless defined($schedule->{$DayNames[$wday]}); - return $status unless defined($schedule->{$DayNames[$wday]}); + return $status unless ref($schedule->{$DayNames[$wday]}) eq "ARRAY"; - return $status unless ref($schedule->{$DayNames[$wday]}) eq "ARRAY"; + my $time = sprintf ("%.2d:%.2d:%.2d", $hour, $min, $sec); - my $time = sprintf ("%.2d:%.2d:%.2d", $hour, $min, $sec); + # + # Check time slots + # + my $inSlot = 0; + foreach my $timeBlock (@{$schedule->{$DayNames[$wday]}}) { + if ($timeBlock->{'start'} eq $timeBlock->{'end'}) { + # All day. + $inSlot = 1; + } elsif ($timeBlock->{'start'} le $time && $timeBlock->{'end'} ge $time) { + # In range. + $inSlot = 1; + } + } - # - # Check time slots - # - my $inSlot = 0; - foreach my $timeBlock (@{$schedule->{$DayNames[$wday]}}) { - if ($timeBlock->{'start'} eq $timeBlock->{'end'}) { - # All day. - $inSlot = 1; - } elsif ($timeBlock->{'start'} le $time && $timeBlock->{'end'} ge $time) { - # In range. - $inSlot = 1; + return $status if $inSlot eq 0; + } else { + # Old behaviour. + # Check time slot + my $time = sprintf ("%.2d:%.2d:%.2d", $hour, $min, $sec); + if (($alert->{'time_from'} ne $alert->{'time_to'})) { + if ($alert->{'time_from'} lt $alert->{'time_to'}) { + return $status if (($time le $alert->{'time_from'}) || ($time ge $alert->{'time_to'})); + } else { + return $status if (($time le $alert->{'time_from'}) && ($time ge $alert->{'time_to'})); + } } } - - return $status if $inSlot eq 0; # Check time threshold my $limit_utimestamp = $alert->{'last_reference'} + $alert->{'time_threshold'};