diff --git a/pandora_console/godmode/alerts/alert_view.php b/pandora_console/godmode/alerts/alert_view.php index 26dba4cc47..8d4d07e578 100644 --- a/pandora_console/godmode/alerts/alert_view.php +++ b/pandora_console/godmode/alerts/alert_view.php @@ -262,7 +262,7 @@ $data[1] = ''; $table_conditions->data[] = $data; $data[0] = __('Use special days list'); -$data[1] = (isset($alert['special_day']) && $alert['special_day'] == 1) ? __('Yes') : __('No'); +$data[1] = (isset($template['special_day']) && (int) $template['special_day'] !== 0) ? __('Yes') : __('No'); $table_conditions->data[] = $data; $data[0] = __('Time threshold'); diff --git a/pandora_console/include/lib/SpecialDay.php b/pandora_console/include/lib/SpecialDay.php index 0cd42abdb5..92ab6f04f0 100644 --- a/pandora_console/include/lib/SpecialDay.php +++ b/pandora_console/include/lib/SpecialDay.php @@ -78,6 +78,17 @@ class SpecialDay extends Entity // Update. $updates = $this->fields; + $exist_special_days = $this->specialDays( + [ '`talert_special_days`.*' ], + ['date_match' => $updates['date']] + ); + + if (count($exist_special_days) > 0) { + throw new \Exception( + __('Already exist special day in this day.'), + ); + } + $rs = \db_process_sql_update( $this->table, $updates, @@ -94,6 +105,17 @@ class SpecialDay extends Entity // Creation. $inserts = $this->fields; + $exist_special_days = $this->specialDays( + [ '`talert_special_days`.*' ], + ['date_match' => $inserts['date']] + ); + + if (count($exist_special_days) > 0) { + throw new \Exception( + __('Already exist special day in this day.'), + ); + } + // Clean null fields. foreach ($inserts as $k => $v) { if ($v === null) { diff --git a/pandora_console/views/calendar/special_days.php b/pandora_console/views/calendar/special_days.php index 26573aa06a..aa0954e51a 100644 --- a/pandora_console/views/calendar/special_days.php +++ b/pandora_console/views/calendar/special_days.php @@ -331,7 +331,7 @@ for ($month = 1; $month <= 12; $month++) { } } - if ($week == 0 || $week == 6) { + if ($week == 0 || $week == 6 || isset($specialDays[$display_year][$display_month][$day]) === true) { $cal_table->cellstyle[$cal_line][$week] = 'color: red;'; } @@ -341,7 +341,7 @@ for ($month = 1; $month <= 12; $month++) { $cal_table->cellstyle[$cal_line][$week] .= 'font-size: 18px;'; $cal_table->data[$cal_line][$week] = $day.' '; - if ($is_management_allowed === true) { + if ($is_management_allowed === true && isset($specialDays[$display_year][$display_month][$day]) === false) { $cal_table->data[$cal_line][$week] .= 'data[$cal_line][$week] .= '>'.html_print_image( diff --git a/pandora_console/views/calendar/special_days_edit.php b/pandora_console/views/calendar/special_days_edit.php index 5bfaa540b4..7ea8c17462 100644 --- a/pandora_console/views/calendar/special_days_edit.php +++ b/pandora_console/views/calendar/special_days_edit.php @@ -108,6 +108,7 @@ $inputs[] = [ 'returnAllGroup' => $display_all_group, 'name' => 'id_group', 'selected' => $specialDay->id_group(), + 'required' => true, ], ]; diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index 31774f61c5..460d9dc260 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -535,20 +535,22 @@ sub pandora_evaluate_alert ($$$$$$$;$$$$) { # Get current time my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime(time()); - + + my @weeks = ( 'none', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday', 'holiday'); + my $special_day; + # Check weekday if ($alert->{'special_day'}) { logger ($pa_config, "Checking special days '" . $alert->{'name'} . "'.", 10); my $date = sprintf("%4d%02d%02d", $year + 1900, $mon + 1, $mday); # '0001' means every year. my $date_every_year = sprintf("0001%02d%02d", $mon + 1, $mday); - my $special_day = get_db_value ($dbh, 'SELECT day_code FROM talert_special_days WHERE (date = ? OR date = ?) AND (id_group = 0 OR id_group = ?) AND (id_calendar = ?) ORDER BY date DESC', $date, $date_every_year, $alert->{'id_group'}, $alert->{'special_day'}); + $special_day = get_db_value ($dbh, 'SELECT day_code FROM talert_special_days WHERE (date = ? OR date = ?) AND (id_group = 0 OR id_group = ?) AND (id_calendar = ?) ORDER BY date DESC', $date, $date_every_year, $alert->{'id_group'}, $alert->{'special_day'}); if (!defined($special_day)) { $special_day = 0; } - my @weeks = ( 'none', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday', 'holiday'); if ($special_day != 0) { logger ($pa_config, $date . " is a special day for " . $alert->{'name'} . ". (as a " . $weeks[$special_day] . ")", 10); return $status if (!defined($alert->{$weeks[$special_day]}) || $alert->{$weeks[$special_day]} == 0); @@ -565,6 +567,9 @@ sub pandora_evaluate_alert ($$$$$$$;$$$$) { my $schedule; if (defined($alert->{'schedule'}) && $alert->{'schedule'} ne '') { $schedule = PandoraFMS::Tools::p_decode_json($pa_config, $alert->{'schedule'}); + if ($special_day != 0) { + return $status if (!defined($schedule->{$weeks[$special_day]})); + } } if (defined($schedule)) { @@ -577,11 +582,18 @@ sub pandora_evaluate_alert ($$$$$$$;$$$$) { my $time = sprintf ("%.2d:%.2d:%.2d", $hour, $min, $sec); + my $schedule_day; + if ($special_day != 0 && defined($schedule->{$weeks[$special_day]})) { + $schedule_day = $weeks[$special_day]; + } else { + $schedule_day = $DayNames[$wday]; + } + # # Check time slots # my $inSlot = 0; - foreach my $timeBlock (@{$schedule->{$DayNames[$wday]}}) { + foreach my $timeBlock (@{$schedule->{$schedule_day}}) { if ($timeBlock->{'start'} eq $timeBlock->{'end'}) { # All day. $inSlot = 1;