From 15ada6694250d35ccf9e078d4e5dc54d75a60e9b Mon Sep 17 00:00:00 2001 From: Daniel Barbero Martin Date: Mon, 31 Jan 2022 16:50:48 +0100 Subject: [PATCH] alert template schedule pandora_enterprise#3943 --- pandora_console/extras/mr/52.sql | 5 +++ .../extras/mr/procedures/alertEvents.sql | 40 +++++++++++++++++++ .../alerts/configure_alert_template.php | 2 +- pandora_console/include/functions_alerts.php | 33 --------------- .../javascript/pandora_fullcalendar.js | 2 +- pandora_console/pandoradb.sql | 1 + 6 files changed, 48 insertions(+), 35 deletions(-) create mode 100644 pandora_console/extras/mr/procedures/alertEvents.sql diff --git a/pandora_console/extras/mr/52.sql b/pandora_console/extras/mr/52.sql index a9a29a9873..7d8d1e6e72 100644 --- a/pandora_console/extras/mr/52.sql +++ b/pandora_console/extras/mr/52.sql @@ -3,9 +3,14 @@ ALTER TABLE `tpolicy_queue` MODIFY COLUMN `progress` int(10) NOT NULL default '0 CREATE INDEX `IDX_tservice_element` ON `tservice_element`(`id_service`,`id_agente_modulo`); ALTER TABLE `talert_templates` ADD COLUMN `schedule` TEXT DEFAULT NULL; +ALTER TABLE `tevent_alert` ADD COLUMN `schedule` TEXT DEFAULT NULL; SOURCE procedures/alertTemplates.sql; CALL `migrateRanges`(); DROP PROCEDURE `migrateRanges`; +SOURCE procedures/alertEvents.sql; +CALL `migrateEventRanges`(); +DROP PROCEDURE `migrateEventRanges`; + COMMIT; \ No newline at end of file diff --git a/pandora_console/extras/mr/procedures/alertEvents.sql b/pandora_console/extras/mr/procedures/alertEvents.sql new file mode 100644 index 0000000000..070a464ea2 --- /dev/null +++ b/pandora_console/extras/mr/procedures/alertEvents.sql @@ -0,0 +1,40 @@ + +CREATE PROCEDURE migrateEventRanges() +BEGIN + DECLARE done INT DEFAULT FALSE; + DECLARE i INT; + DECLARE r TEXT; + DECLARE cur1 CURSOR FOR SELECT `id` FROM `tevent_alert`; + DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; + + UPDATE `tevent_alert` SET `schedule` = '{"monday":_1_,"tuesday":_2_,"wednesday":_3_,"thursday":_4_,"friday":_5_,"saturday":_6_,"sunday":_7_}'; + UPDATE `tevent_alert` SET `time_from` = "00:00:00", `time_to` = "00:00:00" WHERE `time_from` = `time_to`; + + OPEN cur1; + read_loop: LOOP + FETCH cur1 INTO i; + + IF done THEN + LEAVE read_loop; + END IF; + + SELECT concat('[{"start":"', `time_from`, '","end":"', `time_to`, '"}]') into r FROM `tevent_alert` WHERE `id` = i; + + UPDATE `tevent_alert` SET `schedule` = REPLACE(`schedule`, "_1_", r) WHERE `monday` > 0 AND `id` = i; + UPDATE `tevent_alert` SET `schedule` = REPLACE(`schedule`, "_2_", r) WHERE `tuesday` > 0 AND `id` = i; + UPDATE `tevent_alert` SET `schedule` = REPLACE(`schedule`, "_3_", r) WHERE `wednesday` > 0 AND `id` = i; + UPDATE `tevent_alert` SET `schedule` = REPLACE(`schedule`, "_4_", r) WHERE `thursday` > 0 AND `id` = i; + UPDATE `tevent_alert` SET `schedule` = REPLACE(`schedule`, "_5_", r) WHERE `friday` > 0 AND `id` = i; + UPDATE `tevent_alert` SET `schedule` = REPLACE(`schedule`, "_6_", r) WHERE `saturday` > 0 AND `id` = i; + UPDATE `tevent_alert` SET `schedule` = REPLACE(`schedule`, "_7_", r) WHERE `sunday` > 0 AND `id` = i; + + UPDATE `tevent_alert` SET `schedule` = REPLACE(`schedule`, "_1_", '""') WHERE `monday` = 0 AND `id` = i; + UPDATE `tevent_alert` SET `schedule` = REPLACE(`schedule`, "_2_", '""') WHERE `tuesday` = 0 AND `id` = i; + UPDATE `tevent_alert` SET `schedule` = REPLACE(`schedule`, "_3_", '""') WHERE `wednesday` = 0 AND `id` = i; + UPDATE `tevent_alert` SET `schedule` = REPLACE(`schedule`, "_4_", '""') WHERE `thursday` = 0 AND `id` = i; + UPDATE `tevent_alert` SET `schedule` = REPLACE(`schedule`, "_5_", '""') WHERE `friday` = 0 AND `id` = i; + UPDATE `tevent_alert` SET `schedule` = REPLACE(`schedule`, "_6_", '""') WHERE `saturday` = 0 AND `id` = i; + UPDATE `tevent_alert` SET `schedule` = REPLACE(`schedule`, "_7_", '""') WHERE `sunday` = 0 AND `id` = i; + END LOOP; + CLOSE cur1; +END ; \ No newline at end of file diff --git a/pandora_console/godmode/alerts/configure_alert_template.php b/pandora_console/godmode/alerts/configure_alert_template.php index 7460945d63..399b30ba86 100644 --- a/pandora_console/godmode/alerts/configure_alert_template.php +++ b/pandora_console/godmode/alerts/configure_alert_template.php @@ -617,7 +617,7 @@ if ($step == 2) { $table->colspan[1][1] = 3; $table->data[1][1] = ui_print_warning_message( [ - 'message' => __('Not selected any day'), + 'message' => __('No alert has been scheduled yet'), 'force_style' => 'display:none;', ], '', diff --git a/pandora_console/include/functions_alerts.php b/pandora_console/include/functions_alerts.php index 03ec9d8049..2b44308ebc 100644 --- a/pandora_console/include/functions_alerts.php +++ b/pandora_console/include/functions_alerts.php @@ -1059,39 +1059,6 @@ function alerts_get_alert_template_time_to($id_alert_template) } -/** - * Get alert template in weekday format. - * - * @param int Id of an alert template. - * - * @return mixed Alert template in weekday format or false if something goes wrong. - */ -function alerts_get_alert_template_weekdays($id_alert_template) -{ - $alert = alerts_get_alert_template($id_alert_template); - - if ($alert === false) { - return false; - } - - $retval = []; - $days = [ - 'monday', - 'tuesday', - 'wednesday', - 'thursday', - 'friday', - 'saturday', - 'sunday', - ]; - foreach ($days as $day) { - $retval[$day] = (bool) $alert[$day]; - } - - return $retval; -} - - /** * Get recovery_notify of talert_templates table. * diff --git a/pandora_console/include/javascript/pandora_fullcalendar.js b/pandora_console/include/javascript/pandora_fullcalendar.js index fa7d9a4ede..d99d0ffcf5 100644 --- a/pandora_console/include/javascript/pandora_fullcalendar.js +++ b/pandora_console/include/javascript/pandora_fullcalendar.js @@ -364,7 +364,7 @@ function save_data_input(calendar) { // eslint-disable-next-line no-unused-vars function loadEventBBDD(events) { - if (events === null || events === "") { + if (events == undefined || events === null || events === "") { $(".warning").show(); return {}; } diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index 802c7f9b54..13c630f54d 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -3051,6 +3051,7 @@ CREATE TABLE IF NOT EXISTS `tevent_alert` ( `id_template_fields` int(10) unsigned NOT NULL default 0, `last_evaluation` bigint(20) NOT NULL default 0, `pool_occurrences` int unsigned not null default 0, + `schedule` text default null, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;