diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 8c4f7932bc..768086bce6 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,16 @@ +2012-01-25 Junichi Satoh + + * godmode/menu.php, godmode/alerts/alert_special_days.php, + godmode/alerts/configure_alert_special_days.php, + godmode/alerts/configure_alert_template.php, + extras/pandoradb_migrate_4.0.x_to_4.1.mysql.sql, + extras/pandoradb_migrate_4.0.x_to_4.1.oracle.sql, + extras/pandoradb_migrate_4.0.x_to_4.1.postgreSQL.sql, + pandoradb.oracle.sql, pandoradb.postgreSQL.sql, pandoradb.sql, + include/functions_alerts.php: Added special days feature. It allows + to define special days (holidays and special working days) for + alert templates. + 2012-01-24 Juan Manuel Ramon * operation/incidents/incident.php diff --git a/pandora_console/extras/pandoradb_migrate_4.0.x_to_4.1.mysql.sql b/pandora_console/extras/pandoradb_migrate_4.0.x_to_4.1.mysql.sql index c77a6bdb95..a829d9afc1 100644 --- a/pandora_console/extras/pandoradb_migrate_4.0.x_to_4.1.mysql.sql +++ b/pandora_console/extras/pandoradb_migrate_4.0.x_to_4.1.mysql.sql @@ -47,7 +47,7 @@ CREATE TABLE IF NOT EXISTS `tnetflow_report_content` ( ON DELETE CASCADE, FOREIGN KEY (`id_filter`) REFERENCES tnetflow_filter(`id_sg`) ON DELETE CASCADE -) ENGINE = InnoDB DEFAULT CHARSET=utf8 +) ENGINE = InnoDB DEFAULT CHARSET=utf8; -- ----------------------------------------------------- -- Table `tusuario` @@ -66,3 +66,21 @@ ALTER TABLE `tincidencia` ADD COLUMN `id_agent` int(10) unsigned NULL default 0; -- ----------------------------------------------------- ALTER TABLE `tagente` ADD COLUMN `url_address` mediumtext NULL default ''; + +-- ----------------------------------------------------- +-- Table `talert_special_days` +-- ----------------------------------------------------- + +CREATE TABLE IF NOT EXISTS `talert_special_days` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `date` date NOT NULL DEFAULT '0000-00-00', + `same_day` enum('monday','tuesday','wednesday','thursday','friday','saturday','sunday') NOT NULL DEFAULT 'sunday', + `description` text, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +-- ----------------------------------------------------- +-- Table `talert_templates` +-- ----------------------------------------------------- + +ALTER TABLE `talert_templates` ADD COLUMN `special_day` tinyint(1) DEFAULT '0'; diff --git a/pandora_console/extras/pandoradb_migrate_4.0.x_to_4.1.oracle.sql b/pandora_console/extras/pandoradb_migrate_4.0.x_to_4.1.oracle.sql index 118aec008b..cca821e0cc 100644 --- a/pandora_console/extras/pandoradb_migrate_4.0.x_to_4.1.oracle.sql +++ b/pandora_console/extras/pandoradb_migrate_4.0.x_to_4.1.oracle.sql @@ -67,3 +67,24 @@ alter table tincidencia add (id_agent NUMBER(10,0) default 0 NULL); -- Table `tagente` -- ----------------------------------------------------- alter table tagente add (url_address CLOB default '' NULL); + +-- ----------------------------------------------------- +-- Table `talert_special_days` +-- ----------------------------------------------------- + +CREATE TABLE talert_special_days ( +id NUMBER(10,0) NOT NULL PRIMARY KEY, +date DATE default '0000-00-00' NOT NULL, +same_day VARCHAR2(20) default 'sunday', +description CLOB, +CONSTRAINT talert_special_days_same_day_cons CHECK (same_day IN ('monday','tuesday','wednesday','thursday','friday','saturday','sunday')) +); + +CREATE SEQUENCE talert_special_days_s INCREMENT BY 1 START WITH 1; +CREATE OR REPLACE TRIGGER talert_special_days_inc BEFORE INSERT ON talert_special_days REFERENCING NEW AS NEW FOR EACH ROW BEGIN SELECT talert_special_days_s.nextval INTO :NEW.ID FROM dual; END talert_special_days_inc;; + +-- ----------------------------------------------------- +-- Table `talert_templates` +-- ----------------------------------------------------- + +alter table talert_templates add (special_day NUMBER(5,0) default 0); diff --git a/pandora_console/extras/pandoradb_migrate_4.0.x_to_4.1.postgreSQL.sql b/pandora_console/extras/pandoradb_migrate_4.0.x_to_4.1.postgreSQL.sql index 682ec367e8..f0bf525322 100644 --- a/pandora_console/extras/pandoradb_migrate_4.0.x_to_4.1.postgreSQL.sql +++ b/pandora_console/extras/pandoradb_migrate_4.0.x_to_4.1.postgreSQL.sql @@ -56,3 +56,21 @@ ALTER TABLE "tincidencia" ADD COLUMN "id_agent" INTEGER(10) NULL DEFAULT 0; -- ----------------------------------------------------- ALTER TABLE "tagente" ADD COLUMN "url_address" text NULL default ''; + +-- ----------------------------------------------------- +-- Table `talert_special_days` +-- ----------------------------------------------------- + +CREATE TYPE type_talert_special_days_same_day AS ENUM ('monday','tuesday','wednesday','thursday','friday','saturday','sunday'); +CREATE TABLE "talert_special_days" ( + "id" SERIAL NOT NULL PRIMARY KEY, + "date" DATE NOT NULL default '0000-00-00', + "same_day" type_talert_special_days_same_day NOT NULL default 'sunday', + "description" TEXT +); + +-- ----------------------------------------------------- +-- Table `talert_templates` +-- ----------------------------------------------------- + +ALTER TABLE "talert_templates" ADD COLUMN "special_day" SMALLINT default 0; diff --git a/pandora_console/godmode/alerts/alert_special_days.php b/pandora_console/godmode/alerts/alert_special_days.php new file mode 100644 index 0000000000..af353d9322 --- /dev/null +++ b/pandora_console/godmode/alerts/alert_special_days.php @@ -0,0 +1,218 @@ + $description)); + $info = 'Date: ' . $date . ' Same day of the week: ' . $same_day . ' Description: ' . $description; + } + } + + if ($result) { + db_pandora_audit("Command management", "Create special day " . $result, false, false, $info); + } + else { + db_pandora_audit("Command management", "Fail try to create special day", false, false); + } + + ui_print_result_message ($result, + __('Successfully created'), + __('Could not be created')); +} + +if ($update_special_day) { + $id = (int) get_parameter ('id'); + $alert = alerts_get_alert_special_day ($id); + $date = (string) get_parameter ('date'); + $same_day = (string) get_parameter ('same_day'); + $description = (string) get_parameter ('description'); + + list($year, $month, $day) = explode("-", $date); + if ($year == '*') { + # '0001' means every year. + $year = '0001'; + $date = $year . '-' . $month . '-' . $day; + } + + $values = array (); + $values['date'] = $date; + $values['same_day'] = $same_day; + $values['description'] = $description; + + if (!checkdate ($month, $day, $year)) { + $result = ''; + } + else { + $result = alerts_update_alert_special_day ($id, $values); + $info = 'Date: ' . $date . ' Same day of the week: ' . $same_day . ' Description: ' . $description; + } + + if ($result) { + db_pandora_audit("Command management", "Update special day " . $id, false, false, $info); + } + else { + db_pandora_audit("Command management", "Fail to update special day " . $id, false, false); + } + + ui_print_result_message ($result, + __('Successfully updated'), + __('Could not be updated')); +} + +if ($delete_special_day) { + $id = (int) get_parameter ('id'); + + $result = alerts_delete_alert_special_day ($id); + + if ($result) { + db_pandora_audit("Command management", "Delete special day " . $id); + } + else { + db_pandora_audit("Command management", "Fail to delete special day " . $id); + } + + ui_print_result_message ($result, + __('Successfully deleted'), + __('Could not be deleted')); +} + +$table->width = '98%'; +$table->data = array (); +$table->head = array (); +$table->head[0] = __('Date'); +$table->head[1] = __('Same day of the week'); +$table->head[2] = __('Description'); +$table->head[3] = __('Delete'); +$table->style = array (); +$table->style[0] = 'font-weight: bold'; +$table->size = array (); +$table->size[0] = '20%'; +$table->size[1] = '15%'; +$table->size[2] = '60%'; +$table->size[3] = '5%'; +$table->align = array (); +$table->align[3] = 'center'; + +$special_days = db_get_all_rows_in_table ('talert_special_days', 'date'); +if ($special_days === false) + $special_days = array (); + +foreach ($special_days as $special_day) { + $data = array (); + + $data[0] = ''; + # '0001' means every year. + $data[0] .= ''. + str_replace('0001', '*', $special_day['date']) . ''; + $data[0] .= ''; + switch ($special_day['same_day']) { + case 'monday': + $data[1] = __('Monday'); + break; + case 'tuesday': + $data[1] = __('Tuesday'); + break; + case 'wednesday': + $data[1] = __('Wednesday'); + break; + case 'thursday': + $data[1] = __('Thursday'); + break; + case 'friday': + $data[1] = __('Friday'); + break; + case 'saturday': + $data[1] = __('Saturday'); + break; + case 'sunday': + $data[1] = __('Sunday'); + break; + } + $data[2] = $special_day['description']; + $data[3] = ''; + $data[3] = ''. + html_print_image("images/cross.png", true) . ''; + + array_push ($table->data, $data); +} + +if(isset($data)) { + html_print_table ($table); +} +else { + echo "
".__('No special days configured')."
"; +} + +echo '
'; +echo '
'; +html_print_submit_button (__('Create'), 'create', false, 'class="sub next"'); +html_print_input_hidden ('create_special_day', 1); +echo '
'; +echo '
'; +?> diff --git a/pandora_console/godmode/alerts/configure_alert_special_days.php b/pandora_console/godmode/alerts/configure_alert_special_days.php new file mode 100644 index 0000000000..99bb52cc54 --- /dev/null +++ b/pandora_console/godmode/alerts/configure_alert_special_days.php @@ -0,0 +1,92 @@ +width = '98%'; +$table->style = array (); +$table->style[0] = 'font-weight: bold'; +$table->size = array (); +$table->size[0] = '20%'; +$table->data = array (); +$table->data[0][0] = __('Date'); +$table->data[0][1] = html_print_input_text ('date', $date, '', 10, 10, true); +$table->data[0][1] .= html_print_image ("images/calendar_view_day.png", true, array ("alt" => "calendar", "onclick" => "scwShow(scwID('text-date'),this);")); +$table->data[1][0] = __('Same day of the week'); +$days = array (); +$days["monday"] = __('Monday'); +$days["tuesday"] = __('Tuesday'); +$days["wednesday"] = __('Wednesday'); +$days["thursday"] = __('Thursday'); +$days["friday"] = __('Friday'); +$days["saturday"] = __('Saturday'); +$days["sunday"] = __('Sunday'); +$table->data[1][1] = html_print_select ($days, "same_day", $same_day, '', '', 0, true, false, false); + +#$table->data[1][1] = html_print_input_text ('same_day', $same_day, '', 80, 255, true); + +$table->data[2][0] = __('Description'); +$table->data[2][1] = html_print_textarea ('description', 10, 30, $description, '', true); + +echo '
'; +html_print_table ($table); + +echo '
'; +if ($id) { + html_print_input_hidden ('id', $id); + html_print_input_hidden ('update_special_day', 1); + html_print_submit_button (__('Update'), 'create', false, 'class="sub upd"'); +} else { + html_print_input_hidden ('create_special_day', 1); + html_print_submit_button (__('Create'), 'create', false, 'class="sub wand"'); +} +echo '
'; +echo '
'; +?> diff --git a/pandora_console/godmode/alerts/configure_alert_template.php b/pandora_console/godmode/alerts/configure_alert_template.php index ec7f5590ea..ae3f240af6 100644 --- a/pandora_console/godmode/alerts/configure_alert_template.php +++ b/pandora_console/godmode/alerts/configure_alert_template.php @@ -200,6 +200,7 @@ function update_template ($step) { $friday = (bool) get_parameter ('friday'); $saturday = (bool) get_parameter ('saturday'); $sunday = (bool) get_parameter ('sunday'); + $special_day = (bool) get_parameter ('special_day'); $time_from = (string) get_parameter ('time_from'); $time_from = date ("H:i:00", strtotime ($time_from)); $time_to = (string) get_parameter ('time_to'); @@ -226,6 +227,7 @@ function update_template ($step) { 'friday' => $friday, 'saturday' => $saturday, 'sunday' => $sunday, + 'special_day' => $special_day, 'time_from' => $time_from, 'time_to' => $time_to, 'time_threshold' => $threshold, @@ -245,6 +247,7 @@ function update_template ($step) { 'friday' => $friday, 'saturday' => $saturday, 'sunday' => $sunday, + 'special_day' => $special_day, 'time_from' => "#to_date('" . $time_from . "','hh24:mi:ss')", 'time_to' => "#to_date('" . $time_to . "','hh24:mi:ss')", 'time_threshold' => $threshold, @@ -307,6 +310,7 @@ $thursday = true; $friday = true; $saturday = true; $sunday = true; +$special_day = false; $default_action = 0; $field1 = ''; $field2 = ''; @@ -409,6 +413,7 @@ if ($id && ! $create_template) { $friday = (bool) $template['friday']; $saturday = (bool) $template['saturday']; $sunday = (bool) $template['sunday']; + $special_day = (bool) $template['special_day']; $max_alerts = $template['max_alerts']; $min_alerts = $template['min_alerts']; $threshold = $template['time_threshold']; @@ -447,7 +452,6 @@ if ($step == 2) { } $table->colspan = array (); - $table->colspan[0][1] = 3; $table->colspan[4][1] = 3; $table->colspan['field1'][1] = 3; $table->colspan['field2'][1] = 3; @@ -468,6 +472,9 @@ if ($step == 2) { $table->data[0][1] .= html_print_checkbox ('saturday', 1, $saturday, true); $table->data[0][1] .= __('Sun'); $table->data[0][1] .= html_print_checkbox ('sunday', 1, $sunday, true); + + $table->data[0][2] = __('Use special days list'); + $table->data[0][3] = html_print_checkbox ('special_day', 1, $special_day, true); $table->data[1][0] = __('Time from'); $table->data[1][1] = html_print_input_text ('time_from', $time_from, '', 7, 7, diff --git a/pandora_console/godmode/menu.php b/pandora_console/godmode/menu.php index 5492602ee0..a3e4f5b43d 100644 --- a/pandora_console/godmode/menu.php +++ b/pandora_console/godmode/menu.php @@ -92,6 +92,7 @@ if (check_acl ($config['id_user'], 0, "LM")) { $sub["godmode/alerts/alert_commands"]["text"] = __('Commands'); } $sub["godmode/alerts/alert_compounds"]["text"] = __('Correlation'); + $sub["godmode/alerts/alert_special_days"]["text"] = __('Special days list'); enterprise_hook('eventalerts_submenu'); $menu["galertas"]["sub"] = $sub; diff --git a/pandora_console/include/functions_alerts.php b/pandora_console/include/functions_alerts.php index 90c09a2dce..dad259ede2 100644 --- a/pandora_console/include/functions_alerts.php +++ b/pandora_console/include/functions_alerts.php @@ -1830,4 +1830,77 @@ function get_alert_last_fire_timestamp_in_period ($id_alert_module, $period, $da return db_get_sql ($sql); } +/** + * Insert in talert_special_days a new special day. + * + * @param date of special day. + * @param same day of the week. + * @param mixed A single value or array of values to insert (can be a multiple a mount of rows). + * + * @return mixed False in case of error or invalid values passed. Affected rows otherwise. + */ +function alerts_create_alert_special_day ($date, $same_day, $values = false) { + if (empty ($date)) + return false; + if (empty ($same_day)) + return false; + if (! is_array ($values)) + $values = array (); + $values['date'] = $date; + $values['same_day'] = $same_day; + + return @db_process_sql_insert ('talert_special_days', $values); +} + +/** + * Update a special day in talert_special_days. + * + * @param int special day Id. + * @param mixed Array of values to update. + * + * @return mixed False in case of error or invalid values passed. Affected rows otherwise + */ +function alerts_update_alert_special_day ($id_special_day, $values) { + $id_special_day = safe_int ($id_special_day, 1); + if (empty ($id_special_day)) + return false; + if (! is_array ($values)) + return false; + + return (@db_process_sql_update ('talert_special_days', + $values, + array ('id' => $id_special_day))) !== false; +} + +/** + * Delete a special day in talert_special_days. + * + * @param int special day Id. + * + * @return mixed False in case of error or invalid values passed. Affected rows otherwise + */ +function alerts_delete_alert_special_day ($id_special_day) { + $id_special_day = safe_int ($id_special_day, 1); + if (empty ($id_special_day)) + return false; + + return (@db_process_sql_delete ('talert_special_days', + array ('id' => $id_special_day))) !== false; +} + +/** + * Get a special day in talert_special_days. + * + * @param int special day Id. + * + * @return mixed False in case of error or invalid values passed. All row of the selected command otherwise + */ +function alerts_get_alert_special_day ($id_special_day) { + $id_special_day = safe_int ($id_special_day, 1); + if (empty ($id_special_day)) + return false; + + return db_get_row ('talert_special_days', 'id', $id_special_day); +} + ?> diff --git a/pandora_console/pandoradb.oracle.sql b/pandora_console/pandoradb.oracle.sql index 1327cb8209..bdd7e9440d 100644 --- a/pandora_console/pandoradb.oracle.sql +++ b/pandora_console/pandoradb.oracle.sql @@ -312,6 +312,7 @@ CREATE TABLE talert_templates ( field3_recovery CLOB NOT NULL, priority NUMBER(10, 0) default 0 NOT NULL, id_group NUMBER(10, 0) default 0 NOT NULL, + special_day NUMBER(5, 0) default 0, CONSTRAINT t_alert_templates_type_cons CHECK (type IN ('regex', 'max_min', 'max', 'min', 'equal', 'not_equal', 'warning', 'critical', 'onchange', 'unknown', 'always')) ); CREATE INDEX talert_templates_id_al_act_idx ON talert_templates(id_alert_action); @@ -439,6 +440,18 @@ CREATE OR REPLACE TRIGGER talert_compound_actions_update AFTER UPDATE OF ID ON t -- on update trigger 1 CREATE OR REPLACE TRIGGER talert_compound_action_update1 AFTER UPDATE OF ID ON talert_actions FOR EACH ROW BEGIN UPDATE talert_compound_actions SET ID_ALERT_ACTION = :NEW.ID WHERE ID_ALERT_ACTION = :OLD.ID; END;; +CREATE TABLE talert_special_days ( +id NUMBER(10,0) NOT NULL PRIMARY KEY, +date DATE default '0000-00-00' NOT NULL, +same_day VARCHAR2(20) default 'sunday', +description CLOB, +CONSTRAINT talert_special_days_same_day_cons CHECK (same_day IN ('monday','tuesday','wednesday','thursday','friday','saturday','sunday')) +); + +-- on update trigger +CREATE SEQUENCE talert_special_days_s INCREMENT BY 1 START WITH 1; +CREATE OR REPLACE TRIGGER talert_special_days_inc BEFORE INSERT ON talert_special_days REFERENCING NEW AS NEW FOR EACH ROW BEGIN SELECT talert_special_days_s.nextval INTO :NEW.ID FROM dual; END talert_special_days_inc;; + -- Priority : 0 - Maintance (grey) -- Priority : 1 - Low (green) -- Priority : 2 - Normal (blue) diff --git a/pandora_console/pandoradb.postgreSQL.sql b/pandora_console/pandoradb.postgreSQL.sql index a7d6cc05d4..d9792fd182 100644 --- a/pandora_console/pandoradb.postgreSQL.sql +++ b/pandora_console/pandoradb.postgreSQL.sql @@ -269,7 +269,8 @@ CREATE TABLE "talert_templates" ( "field2_recovery" text NOT NULL default '', "field3_recovery" text NOT NULL, "priority" INTEGER NOT NULL default 0, - "id_group" INTEGER NOT NULL default 0 + "id_group" INTEGER NOT NULL default 0, + "special_day" SMALLINT default 0 ); CREATE INDEX "talert_templates_id_alert_action_idx" ON "talert_templates"("id_alert_action"); @@ -342,6 +343,14 @@ CREATE TABLE "talert_compound_actions" ( "fires_max" INTEGER default 0 ); +CREATE TYPE type_talert_special_days_same_day AS ENUM ('monday','tuesday','wednesday','thursday','friday','saturday','sunday'); +CREATE TABLE "talert_special_days" ( + "id" SERIAL NOT NULL PRIMARY KEY, + "date" DATE NOT NULL default '0000-00-00', + "same_day" type_talert_special_days_same_day NOT NULL default 'sunday', + "description" TEXT +); + -- Priority : 0 - Maintance (grey) -- Priority : 1 - Low (green) -- Priority : 2 - Normal (blue) diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index 9d5aa1fcbf..094955741f 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -281,6 +281,7 @@ CREATE TABLE IF NOT EXISTS `talert_templates` ( `field3_recovery` text NOT NULL, `priority` tinyint(4) default '0', `id_group` mediumint(8) unsigned NULL default 0, + `special_day` tinyint(1) default 0, PRIMARY KEY (`id`), KEY `idx_template_action` (`id_alert_action`), FOREIGN KEY (`id_alert_action`) REFERENCES talert_actions(`id`) @@ -381,6 +382,14 @@ CREATE TABLE IF NOT EXISTS `talert_compound_actions` ( ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8; +CREATE TABLE IF NOT EXISTS `talert_special_days` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `date` date NOT NULL DEFAULT '0000-00-00', + `same_day` enum('monday','tuesday','wednesday','thursday','friday','saturday','sunday') NOT NULL DEFAULT 'sunday', + `description` text, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + -- Priority : 0 - Maintance (grey) -- Priority : 1 - Low (green) -- Priority : 2 - Normal (blue)