From 5804d2f404d467735537b0a7dacbcea1e7e441ee Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Wed, 2 Feb 2022 11:29:25 +0100 Subject: [PATCH] Alerts in slots --- pandora_server/lib/PandoraFMS/Core.pm | 30 ++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index 3136055549..a6f55857ae 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -550,16 +550,32 @@ sub pandora_evaluate_alert ($$$$$$$;$$$$) { else { return $status if ($alert->{$DayNames[$wday]} != 1); } - - # Check time slot + + my $schedule = PandoraFMS::Tools::p_decode_json($pa_config, $alert->{'schedule'}); + + return $status unless defined($schedule) && ref $schedule eq "HASH"; + + return $status unless defined($schedule->{$DayNames[$wday]}); + + return $status unless ref($schedule->{$DayNames[$wday]}) eq "ARRAY"; + 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'})); + + # + # 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; # Check time threshold my $limit_utimestamp = $alert->{'last_reference'} + $alert->{'time_threshold'};