From 3e0b0f231be803b1d5adfcfe14accaf21f91ad26 Mon Sep 17 00:00:00 2001 From: Arturo Gonzalez Date: Mon, 6 Feb 2017 16:20:39 +0100 Subject: [PATCH] Added more fields to alert macro fields. Ticket #233 --- .../pandoradb_migrate_6.0_to_6.1.mysql.sql | 10 ++++++ .../pandoradb_migrate_6.0_to_6.1.oracle.sql | 10 ++++++ ...andoradb_migrate_6.0_to_6.1.postgreSQL.sql | 14 +++++++++ .../alerts/configure_alert_command.php | 4 +-- .../alerts/configure_alert_template.php | 31 ++++++++++++++----- pandora_console/godmode/setup/performance.php | 20 ++++++++++-- pandora_console/include/functions_config.php | 6 ++++ pandora_console/pandoradb.oracle.sql | 10 ++++++ pandora_console/pandoradb.postgreSQL.sql | 10 ++++++ pandora_console/pandoradb.sql | 10 ++++++ 10 files changed, 113 insertions(+), 12 deletions(-) diff --git a/pandora_console/extras/pandoradb_migrate_6.0_to_6.1.mysql.sql b/pandora_console/extras/pandoradb_migrate_6.0_to_6.1.mysql.sql index 86e43afe33..df75d4ab37 100644 --- a/pandora_console/extras/pandoradb_migrate_6.0_to_6.1.mysql.sql +++ b/pandora_console/extras/pandoradb_migrate_6.0_to_6.1.mysql.sql @@ -65,6 +65,16 @@ CREATE TABLE IF NOT EXISTS `trel_item` ( -- Table `talert_templates` -- --------------------------------------------------------------------- ALTER TABLE talert_templates ADD COLUMN `min_alerts_reset_counter` tinyint(1) DEFAULT 0; +ALTER TABLE talert_templates ADD COLUMN `field11` TEXT NOT NULL DEFAULT ""; +ALTER TABLE talert_templates ADD COLUMN `field12` TEXT NOT NULL DEFAULT ""; +ALTER TABLE talert_templates ADD COLUMN `field13` TEXT NOT NULL DEFAULT ""; +ALTER TABLE talert_templates ADD COLUMN `field14` TEXT NOT NULL DEFAULT ""; +ALTER TABLE talert_templates ADD COLUMN `field15` TEXT NOT NULL DEFAULT ""; +ALTER TABLE talert_templates ADD COLUMN `field11_recovery` TEXT NOT NULL DEFAULT ""; +ALTER TABLE talert_templates ADD COLUMN `field12_recovery` TEXT NOT NULL DEFAULT ""; +ALTER TABLE talert_templates ADD COLUMN `field13_recovery` TEXT NOT NULL DEFAULT ""; +ALTER TABLE talert_templates ADD COLUMN `field14_recovery` TEXT NOT NULL DEFAULT ""; +ALTER TABLE talert_templates ADD COLUMN `field15_recovery` TEXT NOT NULL DEFAULT ""; -- ---------------------------------------------------------------------- -- Table `tserver` diff --git a/pandora_console/extras/pandoradb_migrate_6.0_to_6.1.oracle.sql b/pandora_console/extras/pandoradb_migrate_6.0_to_6.1.oracle.sql index a9823dcdfe..401b0a5f65 100644 --- a/pandora_console/extras/pandoradb_migrate_6.0_to_6.1.oracle.sql +++ b/pandora_console/extras/pandoradb_migrate_6.0_to_6.1.oracle.sql @@ -3,6 +3,16 @@ -- --------------------------------------------------------------------- ALTER TABLE talert_templates ADD COLUMN min_alerts_reset_counter NUMBER(5, 0) DEFAULT 0; +ALTER TABLE talert_templates ADD COLUMN field11 CLOB DEFAULT ""; +ALTER TABLE talert_templates ADD COLUMN field12 CLOB DEFAULT ""; +ALTER TABLE talert_templates ADD COLUMN field13 CLOB DEFAULT ""; +ALTER TABLE talert_templates ADD COLUMN field14 CLOB DEFAULT ""; +ALTER TABLE talert_templates ADD COLUMN field15 CLOB DEFAULT ""; +ALTER TABLE talert_templates ADD COLUMN field11_recovery CLOB DEFAULT ""; +ALTER TABLE talert_templates ADD COLUMN field12_recovery CLOB DEFAULT ""; +ALTER TABLE talert_templates ADD COLUMN field13_recovery CLOB DEFAULT ""; +ALTER TABLE talert_templates ADD COLUMN field14_recovery CLOB DEFAULT ""; +ALTER TABLE talert_templates ADD COLUMN field15_recovery CLOB DEFAULT ""; -- ---------------------------------------------------------------------- -- Table `tserver` diff --git a/pandora_console/extras/pandoradb_migrate_6.0_to_6.1.postgreSQL.sql b/pandora_console/extras/pandoradb_migrate_6.0_to_6.1.postgreSQL.sql index f15e45788e..5a4c5e90c9 100644 --- a/pandora_console/extras/pandoradb_migrate_6.0_to_6.1.postgreSQL.sql +++ b/pandora_console/extras/pandoradb_migrate_6.0_to_6.1.postgreSQL.sql @@ -40,3 +40,17 @@ ALTER TABLE tlayout ADD COLUMN background_color varchar(50) NOT NULL default '#F -- --------------------------------------------------------------------- ALTER TABLE tlayout_data ADD COLUMN type_graph varchar(50) NOT NULL default 'area'; ALTER TABLE tlayout_data ADD COLUMN label_position varchar(50) NOT NULL default 'down'; + +-- --------------------------------------------------------------------- +-- Table `talert_templates` +-- --------------------------------------------------------------------- +ALTER TABLE talert_templates ADD COLUMN field11 TEXT NOT NULL DEFAULT ""; +ALTER TABLE talert_templates ADD COLUMN field12 TEXT NOT NULL DEFAULT ""; +ALTER TABLE talert_templates ADD COLUMN field13 TEXT NOT NULL DEFAULT ""; +ALTER TABLE talert_templates ADD COLUMN field14 TEXT NOT NULL DEFAULT ""; +ALTER TABLE talert_templates ADD COLUMN field15 TEXT NOT NULL DEFAULT ""; +ALTER TABLE talert_templates ADD COLUMN field11_recovery TEXT NOT NULL DEFAULT ""; +ALTER TABLE talert_templates ADD COLUMN field12_recovery TEXT NOT NULL DEFAULT ""; +ALTER TABLE talert_templates ADD COLUMN field13_recovery TEXT NOT NULL DEFAULT ""; +ALTER TABLE talert_templates ADD COLUMN field14_recovery TEXT NOT NULL DEFAULT ""; +ALTER TABLE talert_templates ADD COLUMN field15_recovery TEXT NOT NULL DEFAULT ""; diff --git a/pandora_console/godmode/alerts/configure_alert_command.php b/pandora_console/godmode/alerts/configure_alert_command.php index 7ebf89e34d..ca173e4569 100644 --- a/pandora_console/godmode/alerts/configure_alert_command.php +++ b/pandora_console/godmode/alerts/configure_alert_command.php @@ -59,7 +59,7 @@ if ($update_command) { $fields_values = array(); $info_fields = ''; $values = array(); - for ($i=1;$i<=10;$i++) { + for ($i=1;$i<=$config['max_macro_fields'];$i++) { $fields_descriptions[] = (string) get_parameter ('field'.$i.'_description'); $fields_values[] = (string) get_parameter ('field'.$i.'_values'); $info_fields .= ' Field'.$i.': ' . $fields_values[$i - 1]; @@ -155,7 +155,7 @@ $table->colspan[2][1] = 3; $table->data[2][0] = __('Description'); $table->data[2][1] = html_print_textarea ('description', 10, 30, $description, '', true); -for ($i = 1; $i <= 10; $i++) { +for ($i = 1; $i <= $config['max_macro_fields']; $i++) { $table->data['field'.$i][0] = sprintf(__('Field %s description'), $i); diff --git a/pandora_console/godmode/alerts/configure_alert_template.php b/pandora_console/godmode/alerts/configure_alert_template.php index a10ebe9b02..915d4a9107 100644 --- a/pandora_console/godmode/alerts/configure_alert_template.php +++ b/pandora_console/godmode/alerts/configure_alert_template.php @@ -304,7 +304,7 @@ function update_template ($step) { } elseif ($step == 3) { $recovery_notify = (bool) get_parameter ('recovery_notify'); - for($i=1;$i<=10;$i++) { + for($i=1;$i<=$config['max_macro_fields'];$i++) { $values['field'.$i] = (string) get_parameter ('field'.$i); $values['field'.$i.'_recovery'] = $recovery_notify ? (string) get_parameter ('field'.$i.'_recovery') : ''; } @@ -354,10 +354,10 @@ $sunday = true; $special_day = false; $default_action = 0; $fields = array(); -for ($i = 1; $i <= 10; $i++) { +for ($i = 1; $i <= $config['max_macro_fields']; $i++) { $fields[$i] = ''; } -for ($i = 1; $i <= 10; $i++) { +for ($i = 1; $i <= $config['max_macro_fields']; $i++) { $fields_recovery[$i] = ''; } $priority = 1; @@ -473,13 +473,13 @@ if ($id && ! $create_template) { $min_alerts_reset_counter = $template['min_alerts_reset_counter']; $threshold = $template['time_threshold']; $fields = array(); - for ($i = 1; $i <= 10; $i++) { + for ($i = 1; $i <= $config['max_macro_fields']; $i++) { $fields[$i] = $template['field'.$i]; } $recovery_notify = $template['recovery_notify']; $fields_recovery = array(); - for ($i = 1; $i <= 10; $i++) { + for ($i = 1; $i <= $config['max_macro_fields']; $i++) { $fields_recovery[$i] = $template['field'.$i.'_recovery']; } @@ -643,6 +643,10 @@ else if ($step == 3) { /* Alert recover */ if (! $recovery_notify) { $table->cellstyle['label_fields'][2] = 'display:none;'; + for ($i = 1; $i <= $config['max_macro_fields']; $i++) { + $table->cellstyle['field' . $i][2] = 'display:none;'; + } + /* $table->cellstyle['field1'][2] = 'display:none;'; $table->cellstyle['field2'][2] = 'display:none;'; $table->cellstyle['field3'][2] = 'display:none;'; @@ -653,6 +657,7 @@ else if ($step == 3) { $table->cellstyle['field8'][2] = 'display:none;'; $table->cellstyle['field9'][2] = 'display:none;'; $table->cellstyle['field10'][2] = 'display:none;'; + */ } $table->data[0][0] = __('Alert recovery'); $values = array (false => __('Disabled'), true => __('Enabled')); @@ -665,7 +670,7 @@ else if ($step == 3) { $table->data['label_fields'][1] = __('Firing fields'); $table->data['label_fields'][2] = __('Recovery fields'); - for ($i = 1; $i <= 10; $i++) { + for ($i = 1; $i <= $config['max_macro_fields']; $i++) { if (isset($template[$name])) { $value = $template[$name]; } @@ -1090,11 +1095,21 @@ if ($step == 2) { elseif ($step == 3) { ?> $("#recovery_notify").change (function () { + var max_fields = parseInt(''); + if (this.value == 1) { - $("#template-label_fields-2, #template-field1-2, #template-field2-2, #template-field3-2, #template-field4-2, #template-field5-2, #template-field6-2, #template-field7-2, #template-field8-2, #template-field9-2, #template-field10-2").show (); + $("#template-label_fields-2").show(); + for (i = 1; i <= max_fields; i++) { + $("#template-field" + i + "-2").show(); + } + //$("#template-label_fields-2, #template-field1-2, #template-field2-2, #template-field3-2, #template-field4-2, #template-field5-2, #template-field6-2, #template-field7-2, #template-field8-2, #template-field9-2, #template-field10-2").show (); } else { - $("#template-label_fields-2, #template-field1-2, #template-field2-2, #template-field3-2, #template-field4-2, #template-field5-2, #template-field6-2, #template-field7-2, #template-field8-2, #template-field9-2, #template-field10-2").hide (); + $("#template-label_fields-2").hide(); + for (i = 1; i <= max_fields; i++) { + $("#template-field" + i + "-2").hide(); + } + //$("#template-label_fields-2, #template-field1-2, #template-field2-2, #template-field3-2, #template-field4-2, #template-field5-2, #template-field6-2, #template-field7-2, #template-field8-2, #template-field9-2, #template-field10-2").hide (); } }); diff --git a/pandora_console/godmode/setup/performance.php b/pandora_console/godmode/setup/performance.php index b88b5c33fd..e3f2b9c519 100644 --- a/pandora_console/godmode/setup/performance.php +++ b/pandora_console/godmode/setup/performance.php @@ -76,9 +76,12 @@ $table->data[9][1] = html_print_input_text ('days_autodisable_deletion', $config $table->data[10][0] = __('Retention period of past special days') . ui_print_help_tip(__('This number is days to keep past special days. 0 means never remove.'), true); $table->data[10][1] = html_print_input_text ('num_past_special_days', $config["num_past_special_days"], '', 5, 5, true); +$table->data[11][0] = __('Max. macro data fields') . ui_print_help_tip(__('Number of macro fields in alerts and templates between 1 and 50'), true); +$table->data[11][1] = html_print_input_text ('max_macro_fields', $config["max_macro_fields"], '', 5, 5, true, false, false, "onChange=\"change_macro_fields()\""); + if (enterprise_installed ()) { - $table->data[11][0] = __('Max. days before delete inventory data'); - $table->data[11][1] = html_print_input_text ('inventory_purge', $config["inventory_purge"], '', 5, 5, true); + $table->data[12][0] = __('Max. days before delete inventory data'); + $table->data[12][1] = html_print_input_text ('inventory_purge', $config["inventory_purge"], '', 5, 5, true); } $table_other = new stdClass(); @@ -153,4 +156,17 @@ echo ''; echo ''; ?> + diff --git a/pandora_console/include/functions_config.php b/pandora_console/include/functions_config.php index deb9b0abda..58ae2f2fa0 100644 --- a/pandora_console/include/functions_config.php +++ b/pandora_console/include/functions_config.php @@ -407,6 +407,8 @@ function config_update_config () { $error_update[] = __('Small Operation Step to purge old data'); if (!config_update_value ('num_past_special_days', get_parameter ('num_past_special_days'))) $error_update[] = __('Retention period of past special days'); + if (!config_update_value ('max_macro_fields', get_parameter ('max_macro_fields'))) + $error_update[] = __('Max. macro data fields'); if (isset($config['enterprise_installed']) && $config['enterprise_installed'] == 1) { if (!config_update_value ('inventory_purge', get_parameter ('inventory_purge'))) $error_update[] = __('Max. days before delete inventory data'); @@ -876,6 +878,10 @@ function config_process_config () { } } + if (!isset($config['max_macro_fields'])) { + config_update_value ('max_macro_fields', 10); + } + if (!isset ($config["event_purge"])) { config_update_value ('event_purge', 15); } diff --git a/pandora_console/pandoradb.oracle.sql b/pandora_console/pandoradb.oracle.sql index 165170ddea..cf6ba00da6 100644 --- a/pandora_console/pandoradb.oracle.sql +++ b/pandora_console/pandoradb.oracle.sql @@ -464,6 +464,11 @@ CREATE TABLE talert_templates ( field8 CLOB DEFAULT '', field9 CLOB DEFAULT '', field10 CLOB DEFAULT '', + field11 CLOB DEFAULT '', + field12 CLOB DEFAULT '', + field13 CLOB DEFAULT '', + field14 CLOB DEFAULT '', + field15 CLOB DEFAULT '', type VARCHAR2(50), value VARCHAR2(255) DEFAULT '', matches_value NUMBER(5, 0) DEFAULT 0, @@ -492,6 +497,11 @@ CREATE TABLE talert_templates ( field8_recovery CLOB DEFAULT '', field9_recovery CLOB DEFAULT '', field10_recovery CLOB DEFAULT '', + field11_recovery CLOB DEFAULT '', + field12_recovery CLOB DEFAULT '', + field13_recovery CLOB DEFAULT '', + field14_recovery CLOB DEFAULT '', + field15_recovery CLOB DEFAULT '', priority NUMBER(10, 0) DEFAULT 0, id_group NUMBER(10, 0) DEFAULT 0, special_day NUMBER(5, 0) DEFAULT 0, diff --git a/pandora_console/pandoradb.postgreSQL.sql b/pandora_console/pandoradb.postgreSQL.sql index d7c525ea4b..380a871282 100644 --- a/pandora_console/pandoradb.postgreSQL.sql +++ b/pandora_console/pandoradb.postgreSQL.sql @@ -393,6 +393,11 @@ CREATE TABLE "talert_templates" ( "field8" text NOT NULL default '', "field9" text NOT NULL default '', "field10" text NOT NULL default '', + "field11" text NOT NULL default '', + "field12" text NOT NULL default '', + "field13" text NOT NULL default '', + "field14" text NOT NULL default '', + "field15" text NOT NULL default '', "type" type_talert_templates_alert_template, "value" varchar(255) default '', "matches_value" SMALLINT default 0, @@ -421,6 +426,11 @@ CREATE TABLE "talert_templates" ( "field8_recovery" text NOT NULL default '', "field9_recovery" text NOT NULL default '', "field10_recovery" text NOT NULL default '', + "field11_recovery" text NOT NULL default '', + "field12_recovery" text NOT NULL default '', + "field13_recovery" text NOT NULL default '', + "field14_recovery" text NOT NULL default '', + "field15_recovery" text NOT NULL default '', "priority" INTEGER NOT NULL default 0, "id_group" INTEGER NOT NULL default 0, "special_day" SMALLINT default 0, diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index 97e73a75d2..0a02246054 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -415,6 +415,11 @@ CREATE TABLE IF NOT EXISTS `talert_templates` ( `field8` text NOT NULL, `field9` text NOT NULL, `field10` text NOT NULL, + `field11` text NOT NULL, + `field12` text NOT NULL, + `field13` text NOT NULL, + `field14` text NOT NULL, + `field15` text NOT NULL, `type` ENUM ('regex', 'max_min', 'max', 'min', 'equal', 'not_equal', 'warning', 'critical', 'onchange', 'unknown', 'always'), `value` varchar(255) default '', `matches_value` tinyint(1) default 0, @@ -443,6 +448,11 @@ CREATE TABLE IF NOT EXISTS `talert_templates` ( `field8_recovery` text NOT NULL, `field9_recovery` text NOT NULL, `field10_recovery` text NOT NULL, + `field11_recovery` text NOT NULL, + `field12_recovery` text NOT NULL, + `field13_recovery` text NOT NULL, + `field14_recovery` text NOT NULL, + `field15_recovery` text NOT NULL, `priority` tinyint(4) default '0', `id_group` mediumint(8) unsigned NULL default 0, `special_day` tinyint(1) default 0,