diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 40c7a12898..f67c496824 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,17 @@ +2013-09-05 Ramon Novoa + + * 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, + pandoradb.postgreSQL.sql, + pandoradb.oracle.sql, + godmode/agentes/configurar_agente.php, + godmode/agentes/agent_template.php, + godmode/agentes/module_manager_editor_common.php, + godmode/agentes/module_manager_editor.php, + include/functions_modules.php, + pandoradb.sql: Added support for module macros. + 2013-09-05 Sergio Martin * godmode/agentes/module_manager.php 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 afa50b178b..27d77448ff 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 @@ -185,6 +185,7 @@ ALTER TABLE `tagente_modulo` ADD COLUMN `cron_interval` varchar(100) default ''; ALTER TABLE `tagente_modulo` ADD COLUMN `max_retries` int(4) UNSIGNED NOT NULL default 0; ALTER TABLE `tagente_modulo` ADD COLUMN `id_category` int(10) NOT NULL DEFAULT '0'; ALTER TABLE `tagente_modulo` ADD COLUMN `disabled_types_event` TEXT NOT NULL DEFAULT ''; +ALTER TABLE `tagente_modulo` ADD COLUMN `module_macros` TEXT NOT NULL DEFAULT ''; -- Move the number of retries for web modules from plugin_pass to max_retries UPDATE `tagente_modulo` SET max_retries=plugin_pass WHERE id_modulo=7; @@ -205,6 +206,7 @@ ALTER TABLE `tnetwork_component` ADD COLUMN `max_retries` int(4) UNSIGNED NOT NU ALTER TABLE `tnetwork_component` ADD COLUMN `id_category` int(10) NOT NULL DEFAULT '0'; ALTER TABLE `tnetwork_component` ADD COLUMN `tags` TEXT NOT NULL default ''; ALTER TABLE `tnetwork_component` ADD COLUMN `disabled_types_event` TEXT NOT NULL DEFAULT ''; +ALTER TABLE `tnetwork_component` ADD COLUMN `module_macros` TEXT NOT NULL DEFAULT ''; -- ---------------------------------------------------------------------- -- Table `tgraph_source` Alter table to allow negative values in weight 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 5c636cf90a..badb0d7f7d 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 @@ -320,6 +320,7 @@ ALTER TABLE tnetwork_component ADD (wizard_level VARCHAR2(100) default 'nowizard ALTER TABLE tnetwork_component ADD CONSTRAINT t_network_component_wizard_level_cons CHECK (wizard_level IN ('basic','advanced','nowizard')); ALTER TABLE tnetwork_component ADD (macros CLOB default ''); ALTER TABLE tnetwork_component ADD (disabled_types_event CLOB default ''); +ALTER TABLE tnetwork_component ADD (module_macros CLOB default ''); -- ----------------------------------------------------- @@ -332,6 +333,7 @@ ALTER TABLE tagente_modulo ADD (quiet NUMBER(5, 0) default 0 NOT NULL); ALTER TABLE tagente_modulo ADD (cron_interval VARCHAR2(100) DEFAULT ''); ALTER TABLE tagente_modulo ADD (max_retries NUMBER(10, 0) default 0); ALTER TABLE tagente_modulo ADD (disabled_types_event CLOB default ''); +ALTER TABLE tagente_modulo ADD (module_macros CLOB default ''); -- Move the number of retries for web modules from plugin_pass to max_retries 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 b357607252..c9e14994a6 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 @@ -208,6 +208,7 @@ ALTER TABLE "tagente_modulo" ADD COLUMN "cron_interval" varchar(100) default ''; ALTER TABLE "tagente_modulo" ADD COLUMN "max_retries" INTEGER default 0; ALTER TABLE "tagente_modulo" ADD COLUMN "id_category" INTEGER default 0; ALTER TABLE "tagente_modulo" ADD COLUMN "disabled_types_event" TEXT default ''; +ALTER TABLE "tagente_modulo" ADD COLUMN "module_macros" TEXT default ''; -- Move the number of retries for web modules from plugin_pass to max_retries UPDATE "tagente_modulo" SET max_retries=CAST(plugin_pass AS INT) WHERE id_modulo=7; @@ -289,6 +290,7 @@ ALTER TABLE "tnetwork_component" ADD COLUMN "critical_inverse" SMALLINT NOT NULL ALTER TABLE "tnetwork_component" ADD COLUMN "warning_inverse" SMALLINT NOT NULL default 0; ALTER TABLE "tnetwork_component" ADD COLUMN "tags" text default ''; ALTER TABLE "tnetwork_component" ADD COLUMN "disabled_types_event" TEXT default ''; +ALTER TABLE "tnetwork_component" ADD COLUMN "module_macros" TEXT default ''; -- ----------------------------------------------------- -- Table "talert_commands" diff --git a/pandora_console/godmode/agentes/agent_template.php b/pandora_console/godmode/agentes/agent_template.php index e615a55037..bbdfec82ef 100644 --- a/pandora_console/godmode/agentes/agent_template.php +++ b/pandora_console/godmode/agentes/agent_template.php @@ -95,7 +95,8 @@ if (isset ($_POST["template_id"])) { 'critical_instructions' => $row2['critical_instructions'], 'warning_instructions' => $row2['warning_instructions'], 'unknown_instructions' => $row2['unknown_instructions'], - 'id_category' => $row2['id_category'] + 'id_category' => $row2['id_category'], + 'module_macros' => $row2['module_macros'] ); $name = $row2["name"]; diff --git a/pandora_console/godmode/agentes/configurar_agente.php b/pandora_console/godmode/agentes/configurar_agente.php index 8ec7470d01..dcd95f3714 100644 --- a/pandora_console/godmode/agentes/configurar_agente.php +++ b/pandora_console/godmode/agentes/configurar_agente.php @@ -142,6 +142,7 @@ $quiet = 0; $macros = ''; $create_agent = (bool)get_parameter('create_agent'); +$module_macros = array (); // Create agent if ($create_agent) { @@ -894,6 +895,10 @@ if ($update_module || $create_module) { //Set the event type that can show. $disabled_types_event = array(EVENTS_GOING_UNKNOWN => (int)!$throw_unknown_events); $disabled_types_event = json_encode($disabled_types_event); + + $module_macro_names = (array) get_parameter('module_macro_names', array()); + $module_macro_values = (array) get_parameter('module_macro_values', array()); + $module_macros = modules_get_module_macros_json ($module_macro_names, $module_macro_values); // Make changes in the conf file if necessary enterprise_include_once('include/functions_config_agents.php'); @@ -953,7 +958,8 @@ if ($update_module) { 'warning_inverse' => $warning_inverse, 'cron_interval' => $cron_interval, 'id_category' => $id_category, - 'disabled_types_event' => $disabled_types_event); + 'disabled_types_event' => $disabled_types_event, + 'module_macros' => $module_macros); if ($prediction_module == 3 && $serialize_ops == '') { $result = false; @@ -1076,7 +1082,8 @@ if ($create_module) { 'warning_inverse' => $warning_inverse, 'cron_interval' => $cron_interval, 'id_category' => $id_category, - 'disabled_types_event' => $disabled_types_event); + 'disabled_types_event' => $disabled_types_event, + 'module_macros' => $module_macros); if ($prediction_module == 3 && $serialize_ops == '') { $id_agent_module = false; diff --git a/pandora_console/godmode/agentes/module_manager_editor.php b/pandora_console/godmode/agentes/module_manager_editor.php index 64580dd958..ae3a176f07 100644 --- a/pandora_console/godmode/agentes/module_manager_editor.php +++ b/pandora_console/godmode/agentes/module_manager_editor.php @@ -230,6 +230,8 @@ if ($id_agent_module) { $month = '*'; $wday = '*'; } + + $module_macros = json_decode(base64_decode($module['module_macros'])); } else { if (!isset ($moduletype)) { @@ -302,6 +304,8 @@ else { $wday = '*'; $ff_interval = 0; + + $module_macros = array (); } } @@ -422,6 +426,7 @@ echo '
'; html_print_table ($table_simple); ui_toggle(html_print_table ($table_advanced, true), __('Advanced options')); +ui_toggle(html_print_table ($table_macros, true), __('Module macros')); // Submit diff --git a/pandora_console/godmode/agentes/module_manager_editor_common.php b/pandora_console/godmode/agentes/module_manager_editor_common.php index 16b5682bb1..9bd0d5be06 100644 --- a/pandora_console/godmode/agentes/module_manager_editor_common.php +++ b/pandora_console/godmode/agentes/module_manager_editor_common.php @@ -471,6 +471,32 @@ else { $table_advanced->data[12][4] .= html_print_input_hidden ('id_category', $id_category, true); } +/* Advanced form part */ +$table_macros->id = 'module_macros'; +$table_macros->width = '98%'; +$table_macros->class = 'databox_color'; +$table_macros->data = array (); +$table_macros->style = array (); +$table_macros->style[0] = 'font-weight: bold; vertical-align: top'; +$table_macros->style[2] = 'font-weight: bold; vertical-align: top'; +$table_macros->style[5] = 'width: 10px'; +$table_macros->colspan = array (); + +$macro_count = 0; +foreach ($module_macros as $macro_name => $macro_value) { + $table_macros->data[$macro_count][0] = __('Name'); + $table_macros->data[$macro_count][1] = html_print_input_text ('module_macro_names[]', $macro_name, '', 50, 60, true); + $table_macros->data[$macro_count][2] = __('Value'); + $table_macros->data[$macro_count][3] = html_print_input_text ('module_macro_values[]', $macro_value, '', 50, 60, true); + $table_macros->data[$macro_count][4] = '' . html_print_image('images/cross.png', true) . ''; + $macro_count++; +} +$table_macros->data[$macro_count][0] = ''.__('Add module macro').' '.html_print_image('images/add.png',true).''; +$table_macros->colspan[$macro_count][0] = 5; +$macro_count++; + +html_print_input_hidden ('module_macro_count', $macro_count); + ui_require_jquery_file('json'); ?> @@ -542,5 +568,31 @@ $(document).ready (function () { $("#id_module_type").trigger('change'); }); + +// Add a new module macro +function add_macro () { + var macro_count = parseInt($("#hidden-module_macro_count").val()); + var delete_icon = ''; + + // Add inputs for the new macro + $("#module_macros").append('Name \ + \ + Value \ + \ + ' + delete_icon + ''); + + // Update the macro count + $("#hidden-module_macro_count").val(macro_count + 1); +} + +// Delete an existing module macro +function delete_macro (num) { + if ($("#module_macros-" + num).length) { + $("#module_macros-" + num).remove(); + } + + // Do not decrease the macro counter or new macros may overlap existing ones! +} + /* ]]> */ diff --git a/pandora_console/include/functions_modules.php b/pandora_console/include/functions_modules.php index 798926042c..407ebaa70d 100644 --- a/pandora_console/include/functions_modules.php +++ b/pandora_console/include/functions_modules.php @@ -1661,4 +1661,17 @@ function modules_group_agent_warning ($module_group) { AND critical_count = 0 AND warning_count > 0 AND id_module_group = $module_group"); } + +// Return a base64 encoded JSON document to store module macros inside the database +function modules_get_module_macros_json ($macro_names, $macro_values) { + $module_macros = array (); + for ($i = 0; $i < count($macro_names); $i++) { + if (isset ($macro_values[$i])) { + $module_macros[$macro_names[$i]] = $macro_values[$i]; + } + } + + return base64_encode(json_encode ($module_macros)); +} + ?> diff --git a/pandora_console/pandoradb.oracle.sql b/pandora_console/pandoradb.oracle.sql index 9f2a4e1dae..e6fece988d 100644 --- a/pandora_console/pandoradb.oracle.sql +++ b/pandora_console/pandoradb.oracle.sql @@ -248,6 +248,7 @@ CREATE TABLE tagente_modulo ( warning_inverse NUMBER(1, 0) default 0 NOT NULL, id_category NUMBER(10, 0) default 0 NOT NULL, disabled_types_event CLOB default '', + module_macros CLOB default '', CONSTRAINT t_agente_modulo_wizard_level_cons CHECK (wizard_level IN ('basic','advanced','nowizard')) ); @@ -702,6 +703,7 @@ CREATE TABLE tnetwork_component ( id_category NUMBER(10, 0) default 0 NOT NULL, tags CLOB, disabled_types_event CLOB default '', + module_macros CLOB default '', CONSTRAINT t_network_component_wizard_level_cons CHECK (wizard_level IN ('basic','advanced','nowizard')) ); diff --git a/pandora_console/pandoradb.postgreSQL.sql b/pandora_console/pandoradb.postgreSQL.sql index 9b51c86659..8ddc790431 100644 --- a/pandora_console/pandoradb.postgreSQL.sql +++ b/pandora_console/pandoradb.postgreSQL.sql @@ -236,7 +236,8 @@ CREATE TABLE "tagente_modulo" ( "critical_inverse" SMALLINT NOT NULL default 0, "warning_inverse" SMALLINT NOT NULL default 0, "id_category" INTEGER NOT NULL default 0, - "disabled_types_event" TEXT default '' + "disabled_types_event" TEXT default '', + "module_macros" TEXT default '' ); CREATE INDEX "tagente_modulo_id_agente_idx" ON "tagente_modulo"("id_agente"); CREATE INDEX "tagente_modulo_id_tipo_modulo_idx" ON "tagente_modulo"("id_tipo_modulo"); @@ -599,7 +600,8 @@ CREATE TABLE "tnetwork_component" ( "warning_inverse" SMALLINT NOT NULL default 0, "id_category" INTEGER NOT NULL default 0, "tags" text NOT NULL, - "disabled_types_event" TEXT default '' + "disabled_types_event" TEXT default '', + "module_macros" TEXT default '' ); -- --------------------------------------------------------------------- diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index d05dfd7609..f4df405d55 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -233,6 +233,7 @@ CREATE TABLE IF NOT EXISTS `tagente_modulo` ( `warning_inverse` tinyint(1) unsigned default '0', `id_category` int(10) default 0, `disabled_types_event` TEXT NOT NULL default '', + `module_macros` TEXT NOT NULL default '', PRIMARY KEY (`id_agente_modulo`), KEY `main_idx` (`id_agente_modulo`,`id_agente`), KEY `tam_agente` (`id_agente`), @@ -653,6 +654,7 @@ CREATE TABLE IF NOT EXISTS `tnetwork_component` ( `id_category` int(10) default 0, `tags` text NOT NULL, `disabled_types_event` TEXT NOT NULL default '', + `module_macros` TEXT NOT NULL default '', PRIMARY KEY (`id_nc`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;