diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 7d7067a138..9ef079613b 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,22 @@ +2012-08-29 Miguel de Dios + + * pandoradb.sql, pandoradb.postgreSQL.sql, pandoradb.oracle.sql, + include/db/mysql.php, + extras/pandoradb_migrate_4.0.x_to_5.0.postgreSQL.sql, + extras/pandoradb_migrate_4.0.x_to_5.0.mysql.sql, + extras/pandoradb_migrate_4.0.x_to_5.0.oracle.sql, + godmode/agentes/planned_downtime.list.php, + godmode/agentes/planned_downtime.editor.php, godmode/menu.php, + include/ajax/planned_downtime.ajax.php: refactoriced the code for + planned downtime, now this have new feature such as set a downtime + with a periodicity each week, each month and set the agents and + the modules with Quiet state instead the old form (but the old still + is). And the page is more easy and quickly to set or config a + planned downtime. + + * godmode/alerts/configure_alert_template.php, + include/javascript/pandora.js: cleaned source code style. + 2012-06-27 Vanessa Gil * extras/pandoradb_migrate_4.0.x_to_5.0.postgreSQL.sql, diff --git a/pandora_console/extras/pandoradb_migrate_4.0.x_to_5.0.mysql.sql b/pandora_console/extras/pandoradb_migrate_4.0.x_to_5.0.mysql.sql index 1c907e5698..fa5f1c2c6e 100644 --- a/pandora_console/extras/pandoradb_migrate_4.0.x_to_5.0.mysql.sql +++ b/pandora_console/extras/pandoradb_migrate_4.0.x_to_5.0.mysql.sql @@ -73,6 +73,24 @@ CREATE TABLE IF NOT EXISTS `talert_special_days` ( -- ----------------------------------------------------- ALTER TABLE `talert_templates` ADD COLUMN `special_day` tinyint(1) DEFAULT '0'; +-- ----------------------------------------------------- +-- Table `tplanned_downtime` +-- ----------------------------------------------------- +ALTER TABLE `tplanned_downtime` ADD COLUMN `monday` tinyint(1) default 0; +ALTER TABLE `tplanned_downtime` ADD COLUMN `tuesday` tinyint(1) default 0; +ALTER TABLE `tplanned_downtime` ADD COLUMN `wednesday` tinyint(1) default 0; +ALTER TABLE `tplanned_downtime` ADD COLUMN `thursday` tinyint(1) default 0; +ALTER TABLE `tplanned_downtime` ADD COLUMN `friday` tinyint(1) default 0; +ALTER TABLE `tplanned_downtime` ADD COLUMN `saturday` tinyint(1) default 0; +ALTER TABLE `tplanned_downtime` ADD COLUMN `sunday` tinyint(1) default 0; +ALTER TABLE `tplanned_downtime` ADD COLUMN `periodically_time_from` time NULL default NULL; +ALTER TABLE `tplanned_downtime` ADD COLUMN `periodically_time_to` time NULL default NULL; +ALTER TABLE `tplanned_downtime` ADD COLUMN `periodically_day_from` int(100) unsigned default NULL; +ALTER TABLE `tplanned_downtime` ADD COLUMN `periodically_day_to` int(100) unsigned default NULL; +ALTER TABLE `tplanned_downtime` ADD COLUMN `type_downtime` varchar(100) NOT NULL default 'disabled_agents_alerts'; +ALTER TABLE `tplanned_downtime` ADD COLUMN `type_execution` varchar(100) NOT NULL default 'once'; +ALTER TABLE `tplanned_downtime` ADD COLUMN `type_periodicity` varchar(100) NOT NULL default 'weekly'; + -- ----------------------------------------------------- -- Table `tplanned_downtime_agents` -- ----------------------------------------------------- @@ -83,6 +101,21 @@ ALTER TABLE tplanned_downtime_agents ADD FOREIGN KEY(`id_downtime`) REFERENCES tplanned_downtime(`id`) ON DELETE CASCADE; +ALTER TABLE `tplanned_downtime_agents` ADD COLUMN `all_modules` tinyint(1) default 1; + + +-- ----------------------------------------------------- +-- Table `tplanned_downtime_modules` +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS `tplanned_downtime_modules` ( + `id` int(20) unsigned NOT NULL auto_increment, + `id_agent` mediumint(8) unsigned NOT NULL default '0', + `id_agent_module` int(10) NOT NULL, + `id_downtime` mediumint(8) NOT NULL default '0', + PRIMARY KEY (`id`), + FOREIGN KEY (`id_downtime`) REFERENCES tplanned_downtime(`id`) + ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- ----------------------------------------------------- -- Table `tevento` -- ----------------------------------------------------- diff --git a/pandora_console/extras/pandoradb_migrate_4.0.x_to_5.0.oracle.sql b/pandora_console/extras/pandoradb_migrate_4.0.x_to_5.0.oracle.sql index f4c1d312e1..bb27221682 100644 --- a/pandora_console/extras/pandoradb_migrate_4.0.x_to_5.0.oracle.sql +++ b/pandora_console/extras/pandoradb_migrate_4.0.x_to_5.0.oracle.sql @@ -68,13 +68,13 @@ CREATE OR REPLACE TRIGGER tnetflow_report_content_inc BEFORE INSERT ON tnetflow_ -- ----------------------------------------------------- -- Table `tincidencia` -- ----------------------------------------------------- -alter table tincidencia add (id_agent NUMBER(10,0) default 0 NULL); +ALTER TABLE tincidencia ADD (id_agent NUMBER(10,0) default 0 NULL); -- ----------------------------------------------------- -- Table `tagente` -- ----------------------------------------------------- -alter table tagente add (url_address CLOB default '' NULL); -alter table tagente add (quiet NUMBER(5, 0) default 0 NOT NULL); +ALTER TABLE tagente ADD (url_address CLOB default '' NULL); +ALTER TABLE tagente ADD (quiet NUMBER(5, 0) default 0 NOT NULL); -- ----------------------------------------------------- -- Table `talert_special_days` @@ -93,39 +93,69 @@ CREATE OR REPLACE TRIGGER talert_special_days_inc BEFORE INSERT ON talert_specia -- ----------------------------------------------------- -- Table `talert_templates` -- ----------------------------------------------------- -alter table talert_templates add (special_day NUMBER(5,0) default 0); +ALTER TABLE talert_templates ADD (special_day NUMBER(5,0) default 0); + +-- ----------------------------------------------------- +-- Table `talert_templates` +-- ----------------------------------------------------- +ALTER TABLE tplanned_downtime ADD (monday NUMBER(5, 0) default 0); +ALTER TABLE tplanned_downtime ADD (tuesday NUMBER(5, 0) default 0); +ALTER TABLE tplanned_downtime ADD (wednesday NUMBER(5, 0) default 0); +ALTER TABLE tplanned_downtime ADD (thursday NUMBER(5, 0) default 0); +ALTER TABLE tplanned_downtime ADD (friday NUMBER(5, 0) default 0); +ALTER TABLE tplanned_downtime ADD (saturday NUMBER(5, 0) default 0); +ALTER TABLE tplanned_downtime ADD (sunday NUMBER(5, 0) default 0); +ALTER TABLE tplanned_downtime ADD (periodically_time_from DATE default NULL); +ALTER TABLE tplanned_downtime ADD (periodically_time_to DATE default NULL); +ALTER TABLE tplanned_downtime ADD (periodically_day_from NUMBER(19, 0) default NULL); +ALTER TABLE tplanned_downtime ADD (periodically_day_to NUMBER(19, 0) default NULL); +ALTER TABLE tplanned_downtime ADD (type_downtime VARCHAR2(100) NOT NULL default 'disabled_agents_alerts'); +ALTER TABLE tplanned_downtime ADD (type_execution VARCHAR2(100) NOT NULL default 'once'); +ALTER TABLE tplanned_downtime ADD (type_periodicity VARCHAR2(100) NOT NULL default 'weekly'); -- ----------------------------------------------------- -- Table `tplanned_downtime_agents` -- ----------------------------------------------------- - DELETE FROM tplanned_downtime_agents WHERE id_downtime NOT IN (SELECT id FROM tplanned_downtime); -alter table tplanned_downtime_agents +ALTER TABLE tplanned_downtime_agents add constraint tplanned_downtimes_foreign_key foreign key (id_downtime) references tplanned_downtime (id); +ALTER TABLE tplanned_downtime_agents ADD (all_modules NUMBER(5, 0) default 1); + +-- ----------------------------------------------------- +-- Table `tplanned_downtime_modules` +-- ----------------------------------------------------- +CREATE TABLE tplanned_downtime_modules ( + id NUMBER(19, 0) NOT NULL PRIMARY KEY, + id_agent NUMBER(19, 0) default 0 NOT NULL, + id_agent_module NUMBER(10, 0) NOT NULL PRIMARY KEY, + id_downtime NUMBER(19, 0) default 0 NOT NULL REFERENCES tplanned_downtime(id) ON DELETE CASCADE +); +CREATE SEQUENCE tplanned_downtime_modules_s INCREMENT BY 1 START WITH 1; +CREATE OR REPLACE TRIGGER tplanned_downtime_modules_inc BEFORE INSERT ON tplanned_downtime_modules REFERENCING NEW AS NEW FOR EACH ROW BEGIN SELECT tplanned_downtime_modules_s.nextval INTO :NEW.ID FROM dual; END tplanned_downtime_modules_inc;; + -- ----------------------------------------------------- -- Table `tevento` -- ----------------------------------------------------- - -alter table tevento add (source VARCHAR2(100) default '' NOT NULL); -alter table tevento add (id_extra VARCHAR2(100) default '' NOT NULL); +ALTER TABLE tevento ADD (source VARCHAR2(100) default '' NOT NULL); +ALTER TABLE tevento ADD (id_extra VARCHAR2(100) default '' NOT NULL); -- ----------------------------------------------------- -- Table `talert_snmp` -- ----------------------------------------------------- -ALTER TABLE talert_snmp add (_snmp_f1_ CLOB default ''); -ALTER TABLE talert_snmp add (_snmp_f2_ CLOB default ''); -ALTER TABLE talert_snmp add (_snmp_f3_ CLOB default ''); -ALTER TABLE talert_snmp add (_snmp_f4_ CLOB default ''); -ALTER TABLE talert_snmp add (_snmp_f5_ CLOB default ''); -ALTER TABLE talert_snmp add (_snmp_f6_ CLOB default ''); -ALTER TABLE talert_snmp add (trap_type NUMBER(10, 0) DEFAULT -1 NOT NULL); -ALTER TABLE talert_snmp add (single_value VARCHAR2(255) DEFAULT ''); +ALTER TABLE talert_snmp ADD (_snmp_f1_ CLOB default ''); +ALTER TABLE talert_snmp ADD (_snmp_f2_ CLOB default ''); +ALTER TABLE talert_snmp ADD (_snmp_f3_ CLOB default ''); +ALTER TABLE talert_snmp ADD (_snmp_f4_ CLOB default ''); +ALTER TABLE talert_snmp ADD (_snmp_f5_ CLOB default ''); +ALTER TABLE talert_snmp ADD (_snmp_f6_ CLOB default ''); +ALTER TABLE talert_snmp ADD (trap_type NUMBER(10, 0) DEFAULT -1 NOT NULL); +ALTER TABLE talert_snmp ADD (single_value VARCHAR2(255) DEFAULT ''); -- ----------------------------------------------------- -- Table `tevent_filter` @@ -190,7 +220,7 @@ ALTER TABLE tmensajes MODIFY mensaje VARCHAR2(255) NOT NULL DEFAULT ''; -- Table `talert_compound` -- ----------------------------------------------------- -alter table talert_compound add (special_day NUMBER(5,0) default 0); +ALTER TABLE talert_compound ADD (special_day NUMBER(5,0) default 0); -- ----------------------------------------------------- -- Table `tnetwork_component` diff --git a/pandora_console/extras/pandoradb_migrate_4.0.x_to_5.0.postgreSQL.sql b/pandora_console/extras/pandoradb_migrate_4.0.x_to_5.0.postgreSQL.sql index a71ad9a99c..d259cacc86 100644 --- a/pandora_console/extras/pandoradb_migrate_4.0.x_to_5.0.postgreSQL.sql +++ b/pandora_console/extras/pandoradb_migrate_4.0.x_to_5.0.postgreSQL.sql @@ -23,11 +23,11 @@ ALTER TABLE "tusuario" ADD COLUMN "not_login" SMALLINT NOT NULL default 0; -- ----------------------------------------------------- CREATE TABLE "tnetflow_filter" ( "id_sg" SERIAL NOT NULL PRIMARY KEY, - "id_name" varchar(600) NOT NULL default '', - "id_group" INTEGER, - "ip_dst" TEXT NOT NULL, + "id_name" varchar(600) NOT NULL default '', + "id_group" INTEGER, + "ip_dst" TEXT NOT NULL, "ip_src" TEXT NOT NULL, - "dst_port" TEXT NOT NULL, + "dst_port" TEXT NOT NULL, "src_port" TEXT NOT NULL, "advanced_filter" TEXT NOT NULL, "filter_args" TEXT NOT NULL, @@ -39,19 +39,19 @@ CREATE TABLE "tnetflow_filter" ( -- Table `tnetflow_report` -- ----------------------------------------------------- CREATE TABLE "tnetflow_report" ( - "id_report" SERIAL NOT NULL PRIMARY KEY, - "id_name" varchar(150) NOT NULL default '', + "id_report" SERIAL NOT NULL PRIMARY KEY, + "id_name" varchar(150) NOT NULL default '', "description" TEXT, - "id_group" INTEGER + "id_group" INTEGER ); -- ----------------------------------------------------- -- Table `tnetflow_report_content` -- ----------------------------------------------------- CREATE TABLE "tnetflow_report_content" ( - "id_rc" SERIAL NOT NULL PRIMARY KEY, + "id_rc" SERIAL NOT NULL PRIMARY KEY, "id_report" INTEGER NOT NULL default 0 REFERENCES tnetflow_report("id_report") ON DELETE CASCADE, - "id_filter" INTEGER NOT NULL default 0 REFERENCES tnetflow_filter("id_sg") ON DELETE CASCADE, + "id_filter" INTEGER NOT NULL default 0 REFERENCES tnetflow_filter("id_sg") ON DELETE CASCADE, "date" BIGINT NOT NULL default 0, "period" INTEGER NOT NULL default 0, "max" INTEGER NOT NULL default 0, @@ -88,6 +88,24 @@ CREATE TABLE "talert_special_days" ( ALTER TABLE "talert_templates" ADD COLUMN "special_day" SMALLINT default 0; +-- ----------------------------------------------------- +-- Table `tplanned_downtime` +-- ----------------------------------------------------- +ALTER TABLE "tplanned_downtime" ADD COLUMN "monday" SMALLINT default 0; +ALTER TABLE "tplanned_downtime" ADD COLUMN "tuesday" SMALLINT default 0; +ALTER TABLE "tplanned_downtime" ADD COLUMN "wednesday" SMALLINT default 0; +ALTER TABLE "tplanned_downtime" ADD COLUMN "thursday" SMALLINT default 0; +ALTER TABLE "tplanned_downtime" ADD COLUMN "friday" SMALLINT default 0; +ALTER TABLE "tplanned_downtime" ADD COLUMN "saturday" SMALLINT default 0; +ALTER TABLE "tplanned_downtime" ADD COLUMN "sunday" SMALLINT default 0; +ALTER TABLE "tplanned_downtime" ADD COLUMN "periodically_time_from" TIME default NULL; +ALTER TABLE "tplanned_downtime" ADD COLUMN "periodically_time_to" TIME default NULL; +ALTER TABLE "tplanned_downtime" ADD COLUMN "periodically_day_from" SMALLINT default NULL; +ALTER TABLE "tplanned_downtime" ADD COLUMN "periodically_day_to" SMALLINT default NULL; +ALTER TABLE "tplanned_downtime" ADD COLUMN "type_downtime" VARCHAR( 100 ) NOT NULL default 'disabled_agents_alerts'; +ALTER TABLE "tplanned_downtime" ADD COLUMN "type_execution" VARCHAR( 100 ) NOT NULL default 'once'; +ALTER TABLE "tplanned_downtime" ADD COLUMN "type_periodicity" VARCHAR( 100 ) NOT NULL default 'weekly'; + -- ----------------------------------------------------- -- Table `tplanned_downtime_agents` -- ----------------------------------------------------- @@ -99,6 +117,18 @@ ADD CONSTRAINT downtime_foreign FOREIGN KEY("id_downtime") REFERENCES "tplanned_downtime"("id"); +ALTER TABLE "tplanned_downtime_agents" ADD COLUMN "all_modules" SMALLINT default 1; + +-- ----------------------------------------------------- +-- Table "tplanned_downtime_modules" +-- ----------------------------------------------------- +CREATE TABLE "tplanned_downtime_modules" ( + "id" BIGSERIAL NOT NULL PRIMARY KEY, + "id_agent" BIGINT NOT NULL default 0, + "id_agent_module" INTEGER NOT NULL default 0, + "id_downtime" BIGINT NOT NULL REFERENCES tplanned_downtime("id") ON DELETE CASCADE +); + -- ----------------------------------------------------- -- Table `tevento` -- ----------------------------------------------------- diff --git a/pandora_console/godmode/agentes/planned_downtime.editor.php b/pandora_console/godmode/agentes/planned_downtime.editor.php index 5612e2b0ee..2a088ca1d6 100755 --- a/pandora_console/godmode/agentes/planned_downtime.editor.php +++ b/pandora_console/godmode/agentes/planned_downtime.editor.php @@ -44,15 +44,18 @@ check_login(); //Initialize data $id_agent = get_parameter ("id_agent"); $id_group = (int) get_parameter ("id_group", 0); -$name = ''; -$description = ''; -$date_from = (string) get_parameter ('date_from', date ('Y-m-j')); -$time_from = (string) get_parameter ('time_from', date ('h:iA')); -$date_to = (string) get_parameter ('date_to', date ('Y-m-j')); -$time_to = (string) get_parameter ('time_to', date ('h:iA')); +$name = (string) get_parameter ('name', ''); +$description = (string) get_parameter ('description', ''); +$once_date_from = (string) get_parameter ('date_from', date ('Y-m-j')); +$once_time_from = (string) get_parameter ('time_from', date ('h:iA')); +$once_date_to = (string) get_parameter ('date_to', date ('Y-m-j')); +$once_time_to = (string) get_parameter ('time_to', date ('h:iA')); +$periodically_day_from = (int) get_parameter ('periodically_day_from', 1); +$periodically_day_to = (int) get_parameter ('periodically_day_to', 31); +$periodically_time_from = (string) get_parameter ('periodically_time_from', date ('h:iA')); +$periodically_time_to = (string) get_parameter ('periodically_time_to', date ('h:iA')); $first_create = (int) get_parameter ('first_create', 0); -$first_update = (int) get_parameter ('first_update', 0); $create_downtime = (int) get_parameter ('create_downtime'); @@ -66,7 +69,17 @@ $delete_downtime_agent = (int) get_parameter ("delete_downtime_agent", 0); $groups = users_get_groups (); -$only_alerts = (bool) get_parameter ('only_alerts', 0); +$type_downtime = get_parameter('type_downtime', 'quiet'); +$type_execution = get_parameter('type_execution', 'once'); +$type_periodicity = get_parameter('type_periodicity', 'weekly'); + +$monday = (bool) get_parameter ('monday'); +$tuesday = (bool) get_parameter ('tuesday'); +$wednesday = (bool) get_parameter ('wednesday'); +$thursday = (bool) get_parameter ('thursday'); +$friday = (bool) get_parameter ('friday'); +$saturday = (bool) get_parameter ('saturday'); +$sunday = (bool) get_parameter ('sunday'); // STOP DOWNTIME if ($stop_downtime == 1) { @@ -80,7 +93,7 @@ if ($stop_downtime == 1) { $only_alerts = $result['only_alerts']; $date_stop = date ("Y-m-j",get_system_time ()); $time_stop = date ("h:iA",get_system_time ()); - $date_time_stop = strtotime ($date_stop.' '.$time_stop); + $date_time_stop = strtotime ($date_stop . ' ' . $time_stop); $values = array( 'name' => $name, @@ -97,33 +110,66 @@ if ($stop_downtime == 1) { // INSERT A NEW DOWNTIME_AGENT ASSOCIATION if ($insert_downtime_agent == 1) { - $agents = $_POST["id_agent"]; + $agents = (array)get_parameter("id_agents", array()); + $module_names = (array)get_parameter("module", array()); + $all_modules = false; + if (empty($module_names)) + $all_modules = true; + else { + //It is empty. + if ($module_names[0] === 0) + $all_modules = true; + } + for ($a=0;$a $id_downtime, - 'id_agent' => $id_agente_dt); + 'id_agent' => $id_agente_dt, + 'all_modules' => $all_modules); + $result = db_process_sql_insert('tplanned_downtime_agents', $values); + if ($result && !$all_modules) { + foreach ($module_names as $module_name) { + $module = + modules_get_agentmodule_id($module_name, $id_agente_dt); + $values = array( + 'id_downtime' => $id_downtime, + 'id_agent' => $id_agente_dt, + 'id_agent_module' => $module["id_agente_modulo"]); + $result = db_process_sql_insert('tplanned_downtime_modules', $values); + } + } } } // DELETE A DOWNTIME_AGENT ASSOCIATION if ($delete_downtime_agent == 1) { - $id_da = get_parameter ("id_downtime_agent"); + $id_da = (int)get_parameter ("id_downtime_agent", 0); + $id_agent_delete = (int)get_parameter('id_agent', 0); - $result = db_process_sql_delete('tplanned_downtime_agents', array('id' => $id_da)); + $row_to_delete = db_get_row('tplanned_downtime_agents', 'id', $id_da); + + $result = db_process_sql_delete('tplanned_downtime_agents', + array('id' => $id_da)); + + if ($result) { + //Delete modules in downtime + db_process_sql_delete('tplanned_downtime_modules', + array('id_downtime' => $row_to_delete['id_downtime'], + 'id_agent' => $id_agent_delete)); + } } // UPDATE OR CREATE A DOWNTIME (MAIN DATA, NOT AGENT ASSOCIATION) if ($create_downtime || $update_downtime) { - $description = (string) get_parameter ('description'); - $name = (string) get_parameter ('name'); $check = db_get_value ('name', 'tplanned_downtime', 'name', $name); - $datetime_from = strtotime ($date_from.' '.$time_from); - $datetime_to = strtotime ($date_to.' '.$time_to); + $datetime_from = strtotime ($once_date_from.' '.$once_time_from); + $datetime_to = strtotime ($once_date_to.' '.$once_time_to); if ($datetime_from > $datetime_to) { echo '

'.__('Not created. Error inserting data').': START > END

'; @@ -138,9 +184,26 @@ if ($create_downtime || $update_downtime) { 'description' => $description, 'date_from' => $datetime_from, 'date_to' => $datetime_to, + 'executed' => 0, 'id_group' => $id_group, - 'only_alerts' => (int)$only_alerts); - $result = db_process_sql_insert('tplanned_downtime', $values); + 'only_alerts' => 0, + 'monday' => $monday, + 'tuesday' => $tuesday, + 'wednesday' => $wednesday, + 'thursday' => $thursday, + 'friday' => $friday, + 'saturday' => $saturday, + 'sunday' => $sunday, + 'periodically_time_from' => $periodically_time_from, + 'periodically_time_to' => $periodically_time_to, + 'periodically_day_from' => $periodically_day_from, + 'periodically_day_to' => $periodically_day_to, + 'type_downtime' => $type_downtime, + 'type_execution' => $type_execution, + 'type_periodicity' => $type_periodicity + ); + $result = db_process_sql_insert( + 'tplanned_downtime', $values); } else { echo "

" . @@ -159,8 +222,24 @@ if ($create_downtime || $update_downtime) { 'description' => $description, 'date_from' => $datetime_from, 'date_to' => $datetime_to, + 'executed' => 0, 'id_group' => $id_group, - 'only_alerts' => (int)$only_alerts); + 'only_alerts' => 0, + 'monday' => $monday, + 'tuesday' => $tuesday, + 'wednesday' => $wednesday, + 'thursday' => $thursday, + 'friday' => $friday, + 'saturday' => $saturday, + 'sunday' => $sunday, + 'periodically_time_from' => $periodically_time_from, + 'periodically_time_to' => $periodically_time_to, + 'periodically_day_from' => $periodically_day_from, + 'periodically_day_to' => $periodically_day_to, + 'type_downtime' => $type_downtime, + 'type_execution' => $type_execution, + 'type_periodicity' => $type_periodicity + ); $result = db_process_sql_update('tplanned_downtime', $values, array('id' => $id_downtime)); } else { @@ -192,17 +271,17 @@ if ($create_downtime || $update_downtime) { if ($id_downtime > 0) { switch ($config["dbtype"]) { case "mysql": - $sql = sprintf ("SELECT `id`, `name`, `description`, `date_from`, `date_to`, `id_group`, `only_alerts` + $sql = sprintf ("SELECT * FROM `tplanned_downtime` WHERE `id` = %d", $id_downtime); break; case "postgresql": - $sql = sprintf ("SELECT \"id\", \"name\", \"description\", \"date_from\", \"date_to\", \"id_group\", \"only_alerts\" + $sql = sprintf ("SELECT * FROM \"tplanned_downtime\" WHERE \"id\" = %d", $id_downtime); break; case "oracle": - $sql = sprintf ("SELECT id, name, description, date_from, date_to, id_group, only_alerts + $sql = sprintf ("SELECT * FROM tplanned_downtime WHERE id = %d", $id_downtime); break; @@ -215,7 +294,20 @@ if ($id_downtime > 0) { $date_to = strftime ('%Y-%m-%d', $result["date_to"]); $time_from = strftime ('%I:%M%p', $result["date_from"]); $time_to = strftime ('%I:%M%p', $result["date_to"]); - $only_alerts = $result["only_alerts"]; + $monday = $result['monday']; + $tuesday = $result['tuesday']; + $wednesday = $result['wednesday']; + $thursday = $result['thursday']; + $friday = $result['friday']; + $saturday = $result['saturday']; + $sunday = $result['sunday']; + $periodically_time_from = $result['periodically_time_from']; + $periodically_time_to = $result['periodically_time_to']; + $periodically_day_from = $result['periodically_day_from']; + $periodically_day_to = $result['periodically_day_to']; + $type_downtime = $result['type_downtime']; + $type_execution = $result['type_execution']; + $type_periodicity = $result['type_periodicity']; if ($id_group == 0) $id_group = $result['id_group']; @@ -226,20 +318,120 @@ $table->width = '98%'; $table->data = array (); $table->data[0][0] = __('Name'); $table->data[0][1] = html_print_input_text ('name', $name, '', 25, 40, true); +$table->data[1][0] = __('Group'); +$table->data[1][1] = html_print_select_groups(false, "AR", true, 'id_group', $id_group, '', '', 0, true); $table->data[2][0] = __('Description'); $table->data[2][1] = html_print_textarea ('description', 3, 35, $description, '', true); -$table->data[3][0] = __('Timestamp from'); -$table->data[3][1] = html_print_input_text ('date_from', $date_from, '', 10, 10, true); -$table->data[3][1] .= html_print_input_text ('time_from', $time_from, '', 7, 7, true); +$disabled_type = false; -$table->data[4][0] = __('Timestamp to'); -$table->data[4][1] = html_print_input_text ('date_to', $date_to, '', 10, 10, true); -$table->data[4][1] .= html_print_input_text ('time_to', $time_to, '', 7, 7, true); +if ($id_downtime > 0) { + $disabled_type = true; +} +$table->data[3][0] = __('Type'); +$table->data[3][1] = html_print_select(array('quiet' => __('Quiet'), + 'disable_agents' => __('Disabled Agents'), + 'disable_agents_alerts' => __('Disabled Agents and Alerts')), + 'type_downtime', $type_downtime, '', '', 0, true, false, true, + '', $disabled_type); +$table->data[4][0] = __('Execution'); +$table->data[4][1] = html_print_select(array('once' => __('once'), + 'periodically' => __('Periodically')), + 'type_execution', $type_execution, 'change_type_execution();', '', 0, true); + +$days = array_combine(range(1, 31), range(1, 31)); +$table->data[5][0] = __('Configure the time'); +$table->data[5][1] = " + + "; -$table->data[5][0] = __('Group'); -$table->data[5][1] = html_print_select_groups(false, "AR", true, 'id_group', $id_group, '', '', 0, true); -$table->data[6][0] = __('Only alerts'); -$table->data[6][1] = html_print_checkbox('only_alerts', 1, $only_alerts, true); echo '
'; if ($id_downtime > 0) { @@ -268,14 +460,15 @@ if ($id_downtime > 0) { echo ""; // Show available agents to include into downtime - echo '

'.__('Available agents').':

'; + echo '

' . __('Available agents') . ':

'; $filter_group = get_parameter("filter_group", 0); $filter_cond = ''; if($filter_group > 0) $filter_cond = " AND id_grupo = $filter_group "; - $sql = sprintf ("SELECT tagente.id_agente, tagente.nombre, tagente.id_grupo + $sql = sprintf ("SELECT tagente.id_agente, tagente.nombre, + tagente.id_grupo FROM tagente WHERE tagente.id_agente NOT IN ( SELECT tagente.id_agente @@ -299,7 +492,7 @@ if ($id_downtime > 0) { $disabled_add_button = true; } - echo ""; + echo ""; html_print_select_groups(false, "AR", true, 'filter_group', $filter_group, '', '', '', false, false, true, '', false, 'width:180px'); @@ -307,9 +500,16 @@ if ($id_downtime > 0) { html_print_submit_button (__('Filter by group'), '', false, 'class="sub next"',false); echo "
"; - echo "
"; + echo ""; - echo html_print_select ($data, "id_agent[]", '', '', '', 0, false, true, true, '', false, 'width: 180px;'); + echo html_print_select ($data, "id_agents[]", '', '', '', 0, false, true, true, '', false, 'width: 180px;'); + echo '

' . __('Available modules:') . + ui_print_help_tip (__('Only for type Quiet for downtimes.'), true) . '

'; + + if ($type_downtime != 'quiet') + echo '
'; + echo html_print_select (array(), "module[]", '', '', '', 0, false, true, true, '', false, 'width: 180px;'); + echo "
"; echo "


"; html_print_submit_button (__('Add'), '', $disabled_add_button, 'class="sub next"',false); echo "
"; @@ -320,7 +520,7 @@ if ($id_downtime > 0) { $sql = sprintf ("SELECT tagente.nombre, tplanned_downtime_agents.id, tagente.id_os, tagente.id_agente, tagente.id_grupo, - tagente.ultimo_contacto + tagente.ultimo_contacto, tplanned_downtime_agents.all_modules FROM tagente, tplanned_downtime_agents WHERE tplanned_downtime_agents.id_agent = tagente.id_agente AND tplanned_downtime_agents.id_downtime = %d ",$id_downtime); @@ -330,6 +530,7 @@ if ($id_downtime > 0) { echo '
'. __('There are no scheduled downtimes').'
'; } else { + $table->id = 'list'; $table->class = 'databox'; $table->width = '98%'; $table->data = array (); @@ -338,63 +539,396 @@ if ($id_downtime > 0) { $table->head[1] = __('Group'); $table->head[2] = __('OS'); $table->head[3] = __('Last contact'); - $table->head[4] = __('Remove'); - $table->align[4] = "center";; + $table->head['count_modules'] = __('Modules'); + $table->head[5] = __('Actions'); + $table->align[5] = "center"; + $table->size[5] = "5%"; foreach ($downtimes as $downtime) { $data = array (); $data[0] = $downtime['nombre']; - $data[1] = db_get_sql ("SELECT nombre FROM tgrupo WHERE id_grupo = ". $downtime["id_grupo"]); + $data[1] = db_get_sql ("SELECT nombre + FROM tgrupo + WHERE id_grupo = ". $downtime["id_grupo"]); $data[2] = ui_print_os_icon ($downtime["id_os"], true, true); $data[3] = $downtime["ultimo_contacto"]; - $data[4] = '' . - html_print_image("images/cross.png", true, array("border" => '0', "alt" => __('Delete'))); + if ($downtime["all_modules"]) { + $data['count_modules'] = __("All modules"); + } + else { + $data['count_modules'] = __("Some modules"); + } - array_push ($table->data, $data); + $data[5] = '' . + html_print_image("images/config.png", true, array("border" => '0', "alt" => __('Delete'))) . ""; + $data[5] .= '' . + html_print_image("images/cross.png", true, array("border" => '0', "alt" => __('Delete'))) . ""; + + $table->data['agent_' . $downtime["id_agente"]] = $data; } html_print_table ($table); } } -ui_require_css_file ('datepicker'); -ui_require_jquery_file ('ui.core'); -ui_require_jquery_file ('ui.datepicker'); +$table = null; +$table->id = 'loading'; +$table->colspan['loading'][0] = '6'; +$table->style[0] = 'text-align: center;'; +$table->data = array(); +$table->data['loading'] = array(); +$table->data['loading'][0] = html_print_image("images/spinner.gif", true); +echo "
"; +html_print_table ($table); +echo "
"; + +$table = null; +$table->id = 'editor'; +$table->colspan['module'][1] = '5'; +$table->data = array(); +$table->data['module'] = array(); +$table->data['module'][0] = ''; +$table->data['module'][1] = "

" . __('Modules') . "

"; + +//List of modules, empty, it is populated by javascript. +$table->data['module'][1] = " + + + + + + + + + + + + + + + + +
" . __('Module') . "" . __('Action') . "
" + . __("Add Module:") . ' ' + . html_print_select(array(), + 'modules', '', '', '', 0, true) + . "" + . '' + . "" + . "
"; + +echo "
"; +html_print_table ($table); +echo "
"; + +echo "
"; +echo "
"; +html_print_image("images/spinner.gif"); +echo "
"; +echo "
"; + +echo ""; + +echo ""; + +echo ""; + ui_require_jquery_file ('timeentry'); ?> \ No newline at end of file diff --git a/pandora_console/godmode/agentes/planned_downtime.list.php b/pandora_console/godmode/agentes/planned_downtime.list.php index 3a7a368922..dae05f238d 100755 --- a/pandora_console/godmode/agentes/planned_downtime.list.php +++ b/pandora_console/godmode/agentes/planned_downtime.list.php @@ -64,15 +64,15 @@ $table->head = array (); $table->head[0] = __('Name #Ag.'); $table->head[1] = __('Description'); $table->head[2] = __('Group'); -$table->head[3] = __('From'); -$table->head[4] = __('To'); -$table->head[5] = __('Affect'); +$table->head[3] = __('Type'); +$table->head[4] = __('Execution'); +$table->head[5] = __('Configuration'); $table->head[6] = __('Delete'); $table->head[7] = __('Update'); $table->head[8] = __('Running'); $table->head[9] = __('Stop downtime'); $table->align[2] = "center"; -$table->align[5] = "center"; +//$table->align[5] = "center"; $table->align[6] = "center"; $table->align[7] = "center"; $table->align[8] = "center"; @@ -101,14 +101,68 @@ else { $data[0] = $downtime['name']. " ($total)"; $data[1] = $downtime['description']; $data[2] = ui_print_group_icon ($downtime['id_group'], true); - $data[3] = date ("Y-m-d H:i", $downtime['date_from']); - $data[4] = date ("Y-m-d H:i", $downtime['date_to']); - if ($downtime['only_alerts']) { - $data[5] = __('Only alerts'); - } - else { - $data[5] = __('All'); + + $type_text = array('quiet' => __('Quiet'), + 'disable_agents' => __('Disabled Agents'), + 'disable_agents_alerts' => __('Disabled Agents and Alerts')); + + $data[3] = $type_text[$downtime['type_downtime']]; + + $execution_text = array('once' => __('once'), + 'periodically' => __('Periodically')); + + $data[4] = $execution_text[$downtime['type_execution']]; + + switch ($downtime['type_execution']) { + case 'once': + $data[5] = date ("Y-m-d H:i", $downtime['date_from']) . + " " . __('to') . " ". + date ("Y-m-d H:i", $downtime['date_to']); + break; + case 'periodically': + switch ($downtime['type_periodicity']) { + case 'weekly': + $data[5] = __('Weekly:'); + $data[5] .= " "; + if ($downtime['monday']) { + $data[5] .= __('Mon'); + $data[5] .= " "; + } + if ($downtime['tuesday']) { + $data[5] .= __('Tue'); + $data[5] .= " "; + } + if ($downtime['wednesday']) { + $data[5] .= __('Wed'); + $data[5] .= " "; + } + if ($downtime['thursday']) { + $data[5] .= __('Thu'); + $data[5] .= " "; + } + if ($downtime['friday']) { + $data[5] .= __('Fri'); + $data[5] .= " "; + } + if ($downtime['saturday']) { + $data[5] .= __('Sat'); + $data[5] .= " "; + } + if ($downtime['sunday']) { + $data[5] .= __('Sun'); + $data[5] .= " "; + } + break; + case 'monthly': + $data[5] = __('Monthly:'); + $data[5] .= $downtime['periodically_day_from']; + $data[5] .= " " . __('to') . " "; + $data[5] .= $downtime['periodically_day_to']; + break; + } + break; } + if ($downtime["executed"] == 0) { $data[6] = '' . diff --git a/pandora_console/godmode/alerts/configure_alert_template.php b/pandora_console/godmode/alerts/configure_alert_template.php index f54bddc7fb..0397e98e74 100644 --- a/pandora_console/godmode/alerts/configure_alert_template.php +++ b/pandora_console/godmode/alerts/configure_alert_template.php @@ -182,17 +182,17 @@ function update_template ($step) { $priority = (int) get_parameter ('priority'); $id_group = get_parameter ("id_group"); $name_check = db_get_value ('name', 'talert_templates', 'name', $name); - + $values = array ('name' => $name, - 'type' => $type, - 'description' => $description, - 'value' => $value, - 'max_value' => $max, - 'min_value' => $min, - 'id_group' => $id_group, - 'matches_value' => $matches, - 'priority' => $priority); - + 'type' => $type, + 'description' => $description, + 'value' => $value, + 'max_value' => $max, + 'min_value' => $min, + 'id_group' => $id_group, + 'matches_value' => $matches, + 'priority' => $priority); + $result = alerts_update_alert_template ($id,$values); } elseif ($step == 2) { @@ -260,14 +260,14 @@ function update_template ($step) { 'min_alerts' => $min_alerts ); break; - } + } $result = alerts_update_alert_template ($id, $values); } elseif ($step == 3) { $recovery_notify = (bool) get_parameter ('recovery_notify'); $field2_recovery = (string) get_parameter ('field2_recovery'); $field3_recovery = (string) get_parameter ('field3_recovery'); - + $values = array ('recovery_notify' => $recovery_notify, 'field2_recovery' => $field2_recovery, 'field3_recovery' => $field3_recovery); diff --git a/pandora_console/godmode/menu.php b/pandora_console/godmode/menu.php index 6c1042979c..357fab407b 100644 --- a/pandora_console/godmode/menu.php +++ b/pandora_console/godmode/menu.php @@ -176,7 +176,7 @@ if (check_acl ($config['id_user'], 0, "AW")) { $menu_godmode["gservers"]["sub"] = $sub; } -if (check_acl ($config['id_user'], 0, "LW")) { +if (check_acl ($config['id_user'], 0, "LW")) { enterprise_hook ('snmpconsole_menu'); } diff --git a/pandora_console/include/ajax/planned_downtime.ajax.php b/pandora_console/include/ajax/planned_downtime.ajax.php new file mode 100644 index 0000000000..f3e22ccdd3 --- /dev/null +++ b/pandora_console/include/ajax/planned_downtime.ajax.php @@ -0,0 +1,135 @@ + $id_agent, 'id_downtime' => $id_downtime)); + if (empty($rows)) + $rows = array(); + $id_modules_downtime = array(); + foreach ($rows as $row) { + $id_modules_downtime[$row['id_agent_module']] = true; + } + + $modules = db_get_all_rows_filter('tagente_modulo', array('id_agente' => $id_agent)); + if (empty($modules)) + $modules = array(); + + foreach ($modules as $module) { + if (empty($id_modules_downtime[$module['id_agente_modulo']])) { + $return['in_agent'][$module['id_agente_modulo']] = io_safe_output($module['nombre']); + } + else { + $return['in_downtime'][$module['id_agente_modulo']] = io_safe_output($module['nombre']); + } + } + + if ($none_value) { + $return['in_agent'][0] = __('None'); + } + + echo json_encode($return); + exit; +} + +if ($delete_module_from_downtime) { + $return = array(); + $return['correct'] = 0; + $return['all_modules'] = 0; + $return['id_agent'] = 0; + + $id_module = (int)get_parameter('id_module', 0); + $id_downtime = (int)get_parameter('id_downtime', 0); + + $row = db_get_row_filter('tplanned_downtime_modules', + array('id_agent_module' => $id_module, + 'id_downtime' => $id_downtime)); + $return['id_agent'] = $row['id_agent']; + + $result = db_process_sql_delete('tplanned_downtime_modules', + array('id_downtime' => $id_downtime, + 'id_agent_module' => $id_module)); + + if ($result) { + $rows = db_get_all_rows_filter('tplanned_downtime_modules', + array('id_downtime' => $id_downtime, + 'id_agent' => $row['id_agent'])); + + if (empty($rows)) { + db_process_sql_update('tplanned_downtime_agents', + array('all_modules' => 1), + array('id_agent' => $row['id_agent'], + 'id_downtime' => $id_downtime)); + + $return['all_modules'] = 1; + $return['id_agent'] = $row['id_agent']; + } + + $return['correct'] = 1; + } + + echo json_encode($return); + exit; +} + +if ($add_module_into_downtime) { + $return = array(); + $return['correct'] = 0; + $return['name'] = ''; + + $id_agent = (int)get_parameter('id_agent', 0); + $id_module = (int)get_parameter('id_module', 0); + $id_downtime = (int)get_parameter('id_downtime', 0); + + $values = array(); + $values['id_agent'] = $id_agent; + $values['id_agent_module'] = $id_module; + $values['id_downtime'] = $id_downtime; + + $correct = db_process_sql_insert('tplanned_downtime_modules', $values); + + if ($correct) { + db_process_sql_update('tplanned_downtime_agents', + array('all_modules' => 0), + array('id_agent' => $id_agent, + 'id_downtime' => $id_downtime)); + $return['correct'] = 1; + + $return['name'] = db_get_value('nombre', 'tagente_modulo', + 'id_agente_modulo', $id_module); + } + + echo json_encode($return); + exit; +} +?> \ No newline at end of file diff --git a/pandora_console/include/db/mysql.php b/pandora_console/include/db/mysql.php index 27bbd1b96e..98ae714d7a 100644 --- a/pandora_console/include/db/mysql.php +++ b/pandora_console/include/db/mysql.php @@ -198,8 +198,8 @@ function mysql_db_get_all_rows_in_table($table, $order_field = "", $order = 'ASC * @return mixed False in case of error or invalid values passed. Affected rows otherwise */ function mysql_db_process_sql_insert($table, $values) { - //Empty rows or values not processed - + //Empty rows or values not processed + if (empty ($values)) return false; @@ -239,7 +239,7 @@ function mysql_db_process_sql_insert($table, $values) { $query .= '('.implode (', ', $fields).')'; $query .= ' VALUES ('.$values_str.')'; - + return db_process_sql ($query, 'insert_id'); } diff --git a/pandora_console/include/javascript/pandora.js b/pandora_console/include/javascript/pandora.js index e49d303fc0..657dde3abe 100644 --- a/pandora_console/include/javascript/pandora.js +++ b/pandora_console/include/javascript/pandora.js @@ -209,13 +209,13 @@ function agent_changed_by_multiple_agents (event, id_agent, selected) { $('#module').append ($('').html (s).attr ("value", val)); $('#module').fadeIn ('normal'); }); - if (selected != undefined) - $('#module').attr ('value', selected); - $('#module').css ("width", "auto"); - $('#module').css ("max-width", ""); - - - $('#module').removeAttr('disabled'); + if (selected != undefined) + $('#module').attr ('value', selected); + $('#module').css ("width", "auto"); + $('#module').css ("max-width", ""); + + + $('#module').removeAttr('disabled'); }, "json" ); diff --git a/pandora_console/pandoradb.oracle.sql b/pandora_console/pandoradb.oracle.sql index a9fb414559..10db72bb51 100644 --- a/pandora_console/pandoradb.oracle.sql +++ b/pandora_console/pandoradb.oracle.sql @@ -472,11 +472,11 @@ CREATE OR REPLACE TRIGGER talert_compound_actions_update AFTER UPDATE OF ID ON t 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')) + 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 @@ -1188,6 +1188,9 @@ CREATE SEQUENCE tserver_export_data_s INCREMENT BY 1 START WITH 1; CREATE OR REPLACE TRIGGER tserver_export_data_inc BEFORE INSERT ON tserver_export_data REFERENCING NEW AS NEW FOR EACH ROW BEGIN SELECT tserver_export_data_s.nextval INTO :NEW.ID FROM dual; END tserver_export_data_inc;; +-- ----------------------------------------------------- +-- Table `tplanned_downtime` +-- ----------------------------------------------------- CREATE TABLE tplanned_downtime ( id NUMBER(19, 0) NOT NULL PRIMARY KEY, name VARCHAR2(100) NOT NULL, @@ -1196,22 +1199,50 @@ CREATE TABLE tplanned_downtime ( date_to NUMBER(19, 0) default 0 NOT NULL, executed NUMBER(5, 0) default 0 NOT NULL, id_group NUMBER(19, 0) default 0 NOT NULL, - only_alerts NUMBER(5, 0) default 0 NOT NULL + only_alerts NUMBER(5, 0) default 0 NOT NULL, + monday NUMBER(5, 0) default 0, + tuesday NUMBER(5, 0) default 0, + wednesday NUMBER(5, 0) default 0, + thursday NUMBER(5, 0) default 0, + friday NUMBER(5, 0) default 0, + saturday NUMBER(5, 0) default 0, + sunday NUMBER(5, 0) default 0, + -- Need to set better datatype + periodically_time_from DATE default NULL, + periodically_time_to DATE default NULL, + -- + periodically_day_from NUMBER(19, 0) default NULL, + periodically_day_to NUMBER(19, 0) default NULL, + type_downtime VARCHAR2(100) NOT NULL default 'disabled_agents_alerts', + type_execution VARCHAR2(100) NOT NULL default 'once', + type_periodicity VARCHAR2(100) NOT NULL default 'weekly' ); - CREATE SEQUENCE tplanned_downtime_s INCREMENT BY 1 START WITH 1; - CREATE OR REPLACE TRIGGER tplanned_downtime_inc BEFORE INSERT ON tplanned_downtime REFERENCING NEW AS NEW FOR EACH ROW BEGIN SELECT tplanned_downtime_s.nextval INTO :NEW.ID FROM dual; END tplanned_downtime_inc;; +-- ----------------------------------------------------- +-- Table `tplanned_downtime_agents` +-- ----------------------------------------------------- CREATE TABLE tplanned_downtime_agents ( id NUMBER(19, 0) NOT NULL PRIMARY KEY, id_agent NUMBER(19, 0) default 0 NOT NULL, + id_downtime NUMBER(19, 0) default 0 NOT NULL REFERENCES tplanned_downtime(id) ON DELETE CASCADE, + all_modules NUMBER(5, 0) default 1 +); +CREATE SEQUENCE tplanned_downtime_agents_s INCREMENT BY 1 START WITH 1; +CREATE OR REPLACE TRIGGER tplanned_downtime_agents_inc BEFORE INSERT ON tplanned_downtime_agents REFERENCING NEW AS NEW FOR EACH ROW BEGIN SELECT tplanned_downtime_agents_s.nextval INTO :NEW.ID FROM dual; END tplanned_downtime_agents_inc;; + +-- ----------------------------------------------------- +-- Table `tplanned_downtime_modules` +-- ----------------------------------------------------- +CREATE TABLE tplanned_downtime_modules ( + id NUMBER(19, 0) NOT NULL PRIMARY KEY, + id_agent NUMBER(19, 0) default 0 NOT NULL, + id_agent_module NUMBER(10, 0) NOT NULL PRIMARY KEY, id_downtime NUMBER(19, 0) default 0 NOT NULL REFERENCES tplanned_downtime(id) ON DELETE CASCADE ); - -CREATE SEQUENCE tplanned_downtime_agents_s INCREMENT BY 1 START WITH 1; - -CREATE OR REPLACE TRIGGER tplanned_downtime_agents_inc BEFORE INSERT ON tplanned_downtime_agents REFERENCING NEW AS NEW FOR EACH ROW BEGIN SELECT tplanned_downtime_agents_s.nextval INTO :NEW.ID FROM dual; END tplanned_downtime_agents_inc;; +CREATE SEQUENCE tplanned_downtime_modules_s INCREMENT BY 1 START WITH 1; +CREATE OR REPLACE TRIGGER tplanned_downtime_modules_inc BEFORE INSERT ON tplanned_downtime_modules REFERENCING NEW AS NEW FOR EACH ROW BEGIN SELECT tplanned_downtime_modules_s.nextval INTO :NEW.ID FROM dual; END tplanned_downtime_modules_inc;; -- GIS extension Tables diff --git a/pandora_console/pandoradb.postgreSQL.sql b/pandora_console/pandoradb.postgreSQL.sql index b58d8b4958..f6af1820a5 100644 --- a/pandora_console/pandoradb.postgreSQL.sql +++ b/pandora_console/pandoradb.postgreSQL.sql @@ -993,6 +993,9 @@ CREATE TABLE "tserver_export_data" ( "timestamp" TIMESTAMP without time zone default '1970-01-01 00:00:00' ); +-- ----------------------------------------------------- +-- Table "tplanned_downtime" +-- ----------------------------------------------------- CREATE TABLE "tplanned_downtime" ( "id" BIGSERIAL NOT NULL PRIMARY KEY, "name" VARCHAR( 100 ) NOT NULL, @@ -1001,17 +1004,45 @@ CREATE TABLE "tplanned_downtime" ( "date_to" BIGINT NOT NULL default 0, "executed" SMALLINT NOT NULL default 0, "id_group" BIGINT NOT NULL default 0, - "only_alerts" SMALLINT NOT NULL default 0 + "only_alerts" SMALLINT NOT NULL default 0, + "monday" SMALLINT default 0, + "tuesday" SMALLINT default 0, + "wednesday" SMALLINT default 0, + "thursday" SMALLINT default 0, + "friday" SMALLINT default 0, + "saturday" SMALLINT default 0, + "sunday" SMALLINT default 0, + "periodically_time_from" TIME default NULL, + "periodically_time_to" TIME default NULL, + "periodically_day_from" SMALLINT default NULL, + "periodically_day_to" SMALLINT default NULL, + "type_downtime" VARCHAR( 100 ) NOT NULL default 'disabled_agents_alerts', + "type_execution" VARCHAR( 100 ) NOT NULL default 'once', + "type_periodicity" VARCHAR( 100 ) NOT NULL default 'weekly' ); +-- ----------------------------------------------------- +-- Table "tplanned_downtime_agents" +-- ----------------------------------------------------- CREATE TABLE "tplanned_downtime_agents" ( "id" BIGSERIAL NOT NULL PRIMARY KEY, "id_agent" BIGINT NOT NULL default 0, "id_downtime" BIGINT NOT NULL REFERENCES tplanned_downtime("id") ON DELETE CASCADE + "all_modules" SMALLINT default 1 ); --- GIS extension Tables +-- ----------------------------------------------------- +-- Table "tplanned_downtime_modules" +-- ----------------------------------------------------- +CREATE TABLE "tplanned_downtime_modules" ( + "id" BIGSERIAL NOT NULL PRIMARY KEY, + "id_agent" BIGINT NOT NULL default 0, + "id_agent_module" INTEGER NOT NULL default 0, + "id_downtime" BIGINT NOT NULL REFERENCES tplanned_downtime("id") ON DELETE CASCADE +); + +-- GIS extension Tables -- ----------------------------------------------------- -- Table "tgis_data_history" -- ----------------------------------------------------- diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index 02d30e2a7d..dcf1826b26 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -546,59 +546,71 @@ CREATE TABLE IF NOT EXISTS `tgrupo` ( PRIMARY KEY (`id_grupo`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; +-- ----------------------------------------------------- +-- Table `tincidencia` +-- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `tincidencia` ( - `id_incidencia` bigint(6) unsigned zerofill NOT NULL auto_increment, - `inicio` datetime NOT NULL default '1970-01-01 00:00:00', - `cierre` datetime NOT NULL default '1970-01-01 00:00:00', - `titulo` text NOT NULL, - `descripcion` text NOT NULL, - `id_usuario` varchar(60) NOT NULL default '', - `origen` varchar(100) NOT NULL default '', - `estado` int(10) NOT NULL default '0', - `prioridad` int(10) NOT NULL default '0', - `id_grupo` mediumint(4) unsigned NOT NULL default '0', - `actualizacion` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, - `id_creator` varchar(60) default NULL, - `id_lastupdate` varchar(60) default NULL, - `id_agente_modulo` bigint(100) NOT NULL, - `notify_email` tinyint(3) unsigned NOT NULL default '0', - `id_agent` int(10) unsigned NULL default 0, - PRIMARY KEY (`id_incidencia`), - KEY `incident_index_1` (`id_usuario`,`id_incidencia`), - KEY `id_agente_modulo` (`id_agente_modulo`) + `id_incidencia` bigint(6) unsigned zerofill NOT NULL auto_increment, + `inicio` datetime NOT NULL default '1970-01-01 00:00:00', + `cierre` datetime NOT NULL default '1970-01-01 00:00:00', + `titulo` text NOT NULL, + `descripcion` text NOT NULL, + `id_usuario` varchar(60) NOT NULL default '', + `origen` varchar(100) NOT NULL default '', + `estado` int(10) NOT NULL default '0', + `prioridad` int(10) NOT NULL default '0', + `id_grupo` mediumint(4) unsigned NOT NULL default '0', + `actualizacion` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, + `id_creator` varchar(60) default NULL, + `id_lastupdate` varchar(60) default NULL, + `id_agente_modulo` bigint(100) NOT NULL, + `notify_email` tinyint(3) unsigned NOT NULL default '0', + `id_agent` int(10) unsigned NULL default 0, + PRIMARY KEY (`id_incidencia`), + KEY `incident_index_1` (`id_usuario`,`id_incidencia`), + KEY `id_agente_modulo` (`id_agente_modulo`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; +-- ----------------------------------------------------- +-- Table `tlanguage` +-- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS`tlanguage` ( - `id_language` varchar(6) NOT NULL default '', - `name` varchar(100) NOT NULL default '', - PRIMARY KEY (`id_language`) + `id_language` varchar(6) NOT NULL default '', + `name` varchar(100) NOT NULL default '', + PRIMARY KEY (`id_language`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; - +-- ----------------------------------------------------- +-- Table `tlink` +-- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `tlink` ( - `id_link` int(10) unsigned zerofill NOT NULL auto_increment, - `name` varchar(100) NOT NULL default '', - `link` varchar(255) NOT NULL default '', - PRIMARY KEY (`id_link`) + `id_link` int(10) unsigned zerofill NOT NULL auto_increment, + `name` varchar(100) NOT NULL default '', + `link` varchar(255) NOT NULL default '', + PRIMARY KEY (`id_link`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; - +-- ----------------------------------------------------- +-- Table `tmensajes` +-- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `tmensajes` ( - `id_mensaje` int(10) unsigned NOT NULL auto_increment, - `id_usuario_origen` varchar(60) NOT NULL default '', - `id_usuario_destino` varchar(60) NOT NULL default '', - `mensaje` text NOT NULL, - `timestamp` bigint (20) unsigned NOT NULL default '0', - `subject` varchar(255) NOT NULL default '', - `estado` int(4) unsigned NOT NULL default '0', - PRIMARY KEY (`id_mensaje`) + `id_mensaje` int(10) unsigned NOT NULL auto_increment, + `id_usuario_origen` varchar(60) NOT NULL default '', + `id_usuario_destino` varchar(60) NOT NULL default '', + `mensaje` text NOT NULL, + `timestamp` bigint (20) unsigned NOT NULL default '0', + `subject` varchar(255) NOT NULL default '', + `estado` int(4) unsigned NOT NULL default '0', + PRIMARY KEY (`id_mensaje`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; - +-- ----------------------------------------------------- +-- Table `tmodule_group` +-- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `tmodule_group` ( - `id_mg` tinyint(4) unsigned NOT NULL auto_increment, - `name` varchar(150) NOT NULL default '', - PRIMARY KEY (`id_mg`) + `id_mg` tinyint(4) unsigned NOT NULL auto_increment, + `name` varchar(150) NOT NULL default '', + PRIMARY KEY (`id_mg`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; @@ -1126,46 +1138,79 @@ CREATE TABLE IF NOT EXISTS `tserver_export_data` ( PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; +-- ----------------------------------------------------- +-- Table `tplanned_downtime` +-- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `tplanned_downtime` ( - `id` MEDIUMINT( 8 ) NOT NULL AUTO_INCREMENT, - `name` VARCHAR( 100 ) NOT NULL, - `description` TEXT NOT NULL, - `date_from` bigint(20) NOT NULL default '0', - `date_to` bigint(20) NOT NULL default '0', - `executed` tinyint(1) UNSIGNED NOT NULL default 0, - `id_group` mediumint(8) unsigned NULL default 0, - `only_alerts` tinyint(1) UNSIGNED NOT NULL default 0, - PRIMARY KEY ( `id` ) + `id` MEDIUMINT( 8 ) NOT NULL AUTO_INCREMENT, + `name` VARCHAR( 100 ) NOT NULL, + `description` TEXT NOT NULL, + `date_from` bigint(20) NOT NULL default '0', + `date_to` bigint(20) NOT NULL default '0', + `executed` tinyint(1) UNSIGNED NOT NULL default 0, + `id_group` mediumint(8) unsigned NULL default 0, + `only_alerts` tinyint(1) UNSIGNED NOT NULL default 0, + `monday` tinyint(1) default 0, + `tuesday` tinyint(1) default 0, + `wednesday` tinyint(1) default 0, + `thursday` tinyint(1) default 0, + `friday` tinyint(1) default 0, + `saturday` tinyint(1) default 0, + `sunday` tinyint(1) default 0, + `periodically_time_from` time NULL default NULL, + `periodically_time_to` time NULL default NULL, + `periodically_day_from` int(100) unsigned default NULL, + `periodically_day_to` int(100) unsigned default NULL, + `type_downtime` varchar(100) NOT NULL default 'disabled_agents_alerts', + `type_execution` varchar(100) NOT NULL default 'once', + `type_periodicity` varchar(100) NOT NULL default 'weekly', + PRIMARY KEY ( `id` ) ) ENGINE = InnoDB DEFAULT CHARSET=utf8; +-- ----------------------------------------------------- +-- Table `tplanned_downtime_agents` +-- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `tplanned_downtime_agents` ( - `id` int(20) unsigned NOT NULL auto_increment, - `id_agent` mediumint(8) unsigned NOT NULL default '0', - `id_downtime` mediumint(8) NOT NULL default '0', - PRIMARY KEY (`id`), - FOREIGN KEY (`id_downtime`) REFERENCES tplanned_downtime(`id`) - ON DELETE CASCADE + `id` int(20) unsigned NOT NULL auto_increment, + `id_agent` mediumint(8) unsigned NOT NULL default '0', + `id_downtime` mediumint(8) NOT NULL default '0', + `all_modules` tinyint(1) default 1, + PRIMARY KEY (`id`), + FOREIGN KEY (`id_downtime`) REFERENCES tplanned_downtime(`id`) + ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +-- ----------------------------------------------------- +-- Table `tplanned_downtime_modules` +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS `tplanned_downtime_modules` ( + `id` int(20) unsigned NOT NULL auto_increment, + `id_agent` mediumint(8) unsigned NOT NULL default '0', + `id_agent_module` int(10) NOT NULL, + `id_downtime` mediumint(8) NOT NULL default '0', + PRIMARY KEY (`id`), + FOREIGN KEY (`id_downtime`) REFERENCES tplanned_downtime(`id`) + ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- GIS extension Tables - -- ----------------------------------------------------- -- Table `tgis_data_history` -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `tgis_data_history` ( - `id_tgis_data` INT NOT NULL AUTO_INCREMENT COMMENT 'key of the table' , - `longitude` DOUBLE NOT NULL , - `latitude` DOUBLE NOT NULL , - `altitude` DOUBLE NULL , - `start_timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'timestamp on wich the agente started to be in this position' , - `end_timestamp` TIMESTAMP NULL COMMENT 'timestamp on wich the agent was placed for last time on this position' , - `description` TEXT NULL COMMENT 'description of the region correoponding to this placemnt' , - `manual_placement` TINYINT(1) NOT NULL DEFAULT 0 COMMENT '0 to show that the position cames from the agent, 1 to show that the position was established manualy' , - `number_of_packages` INT NOT NULL DEFAULT 1 COMMENT 'Number of data packages received with this position from the start_timestampa to the_end_timestamp' , - `tagente_id_agente` INT(10) UNSIGNED NOT NULL COMMENT 'reference to the agent' , - PRIMARY KEY (`id_tgis_data`) , - INDEX `start_timestamp_index` USING BTREE (`start_timestamp` ASC), - INDEX `end_timestamp_index` USING BTREE (`end_timestamp` ASC) ) + `id_tgis_data` INT NOT NULL AUTO_INCREMENT COMMENT 'key of the table' , + `longitude` DOUBLE NOT NULL , + `latitude` DOUBLE NOT NULL , + `altitude` DOUBLE NULL , + `start_timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'timestamp on wich the agente started to be in this position' , + `end_timestamp` TIMESTAMP NULL COMMENT 'timestamp on wich the agent was placed for last time on this position' , + `description` TEXT NULL COMMENT 'description of the region correoponding to this placemnt' , + `manual_placement` TINYINT(1) NOT NULL DEFAULT 0 COMMENT '0 to show that the position cames from the agent, 1 to show that the position was established manualy' , + `number_of_packages` INT NOT NULL DEFAULT 1 COMMENT 'Number of data packages received with this position from the start_timestampa to the_end_timestamp' , + `tagente_id_agente` INT(10) UNSIGNED NOT NULL COMMENT 'reference to the agent' , + PRIMARY KEY (`id_tgis_data`) , + INDEX `start_timestamp_index` USING BTREE (`start_timestamp` ASC), + INDEX `end_timestamp_index` USING BTREE (`end_timestamp` ASC) ) ENGINE = InnoDB COMMENT = 'Table to store historical GIS information of the agents';