From a2a6875091d96942b0500689548338609e473fa4 Mon Sep 17 00:00:00 2001 From: alexhigh Date: Tue, 18 Mar 2014 11:49:33 +0000 Subject: [PATCH] 2014-03-18 Alejandro Gallardo * pandoradb.data.oracle.sql, pandoradb.data.postgreSQL.sql, pandoradb.sql, extras/pandoradb_migrate_5.0.x_to_5.1.mysql.sql, extras/pandoradb_migrate_5.0.x_to_5.1.oracle.sql, extras/pandoradb_migrate_5.0.x_to_5.1.postgreSQL.sql: Added the table "tmodule_relationship". * operation/agentes/estado_generalagente.php: Added a new table to show the network interfaces of the agent. Minor fixes. * include/styles/pandora.css: Added properties for the class transparent'. * include/ajax/module.php: Fixed an error and added code to retrieve a module autocomplete input or add, remove or update a module relation via ajax. * include/functions_modules.php: Added the functions "modules_get_relations", "modules_relation_exists", "modules_add_relation", "modules_delete_relation" and "modules_change_relation_lock". * godmode/agentes/module_manager_editor_common.php: Added a table and control to show, add or delete relations with other modules. Added the javascript functions "change_modules_autocomplete_input", "add_new_relation", "change_lock_relation" and "delete_relation". * godmode/agentes/module_manager_editor.php: Added a line to show the module relations table and control. * godmode/agentes/module_manager_editor_network.php: Minor fix. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@9610 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_console/ChangeLog | 39 +++ .../pandoradb_migrate_5.0.x_to_5.1.mysql.sql | 16 + .../pandoradb_migrate_5.0.x_to_5.1.oracle.sql | 17 + ...doradb_migrate_5.0.x_to_5.1.postgreSQL.sql | 13 + .../godmode/agentes/module_manager_editor.php | 1 + .../agentes/module_manager_editor_common.php | 300 ++++++++++++++++++ .../agentes/module_manager_editor_network.php | 2 +- pandora_console/include/ajax/module.php | 73 ++++- pandora_console/include/functions_modules.php | 143 ++++++++- pandora_console/include/styles/pandora.css | 7 + .../agentes/estado_generalagente.php | 146 +++++++-- pandora_console/pandoradb.oracle.sql | 19 ++ pandora_console/pandoradb.postgreSQL.sql | 12 + pandora_console/pandoradb.sql | 15 + 14 files changed, 773 insertions(+), 30 deletions(-) diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 8ad5858ec1..490ab55b50 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,42 @@ +2014-03-18 Alejandro Gallardo + + * pandoradb.data.oracle.sql, + pandoradb.data.postgreSQL.sql, + pandoradb.sql, + extras/pandoradb_migrate_5.0.x_to_5.1.mysql.sql, + extras/pandoradb_migrate_5.0.x_to_5.1.oracle.sql, + extras/pandoradb_migrate_5.0.x_to_5.1.postgreSQL.sql: + Added the table "tmodule_relationship". + + * operation/agentes/estado_generalagente.php: Added a + new table to show the network interfaces of the agent. + Minor fixes. + + * include/styles/pandora.css: Added properties for the + class transparent'. + + * include/ajax/module.php: Fixed an error and added code + to retrieve a module autocomplete input or add, remove + or update a module relation via ajax. + + * include/functions_modules.php: Added the functions + "modules_get_relations", "modules_relation_exists", + "modules_add_relation", "modules_delete_relation" and + "modules_change_relation_lock". + + * godmode/agentes/module_manager_editor_common.php: + Added a table and control to show, add or delete + relations with other modules. Added the javascript + functions "change_modules_autocomplete_input", + "add_new_relation", "change_lock_relation" and + "delete_relation". + + * godmode/agentes/module_manager_editor.php: Added a + line to show the module relations table and control. + + * godmode/agentes/module_manager_editor_network.php: + Minor fix. + 2014-03-17 Vanessa Gil * pandoradb.sql diff --git a/pandora_console/extras/pandoradb_migrate_5.0.x_to_5.1.mysql.sql b/pandora_console/extras/pandoradb_migrate_5.0.x_to_5.1.mysql.sql index 3fbdb2b006..6332a7c4e5 100644 --- a/pandora_console/extras/pandoradb_migrate_5.0.x_to_5.1.mysql.sql +++ b/pandora_console/extras/pandoradb_migrate_5.0.x_to_5.1.mysql.sql @@ -41,3 +41,19 @@ ALTER TABLE tgraph_source MODIFY COLUMN `weight` float(8,3) NOT NULL DEFAULT 0; -- Table `tagente_modulo` -- --------------------------------------------------------------------- ALTER TABLE `pandora`.`tagente_modulo` MODIFY COLUMN `post_process` DOUBLE DEFAULT NULL; + +/* 2014/03/18 */ +-- ---------------------------------------------------------------------- +-- Table `tmodule_relationship` +-- ---------------------------------------------------------------------- +CREATE TABLE IF NOT EXISTS `tmodule_relationship` ( + `id` int(10) unsigned NOT NULL auto_increment, + `module_a` int(10) unsigned NOT NULL, + `module_b` int(10) unsigned NOT NULL, + `disable_update` tinyint(1) unsigned NOT NULL default '0', + PRIMARY KEY (`id`), + FOREIGN KEY (`module_a`) REFERENCES tagente_modulo(`id_agente_modulo`) + ON DELETE CASCADE, + FOREIGN KEY (`module_b`) REFERENCES tagente_modulo(`id_agente_modulo`) + ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/pandora_console/extras/pandoradb_migrate_5.0.x_to_5.1.oracle.sql b/pandora_console/extras/pandoradb_migrate_5.0.x_to_5.1.oracle.sql index e46ffee381..6c7829b775 100644 --- a/pandora_console/extras/pandoradb_migrate_5.0.x_to_5.1.oracle.sql +++ b/pandora_console/extras/pandoradb_migrate_5.0.x_to_5.1.oracle.sql @@ -30,3 +30,20 @@ INSERT INTO tconfig (token, value) VALUES ('graph_color10', '#6666FF'); UPDATE tconfig SET value='#FFFF00' WHERE token='graph_color2'; UPDATE tconfig SET value='#FF6600' WHERE token='graph_color3'; + +/* 2014/03/18 */ +-- ---------------------------------------------------------------------- +-- Table `tmodule_relationship` +-- ---------------------------------------------------------------------- +CREATE TABLE IF NOT EXISTS tmodule_relationship ( + id NUMBER(10, 0) NOT NULL PRIMARY KEY, + module_a NUMBER(10, 0) NOT NULL REFERENCES tagente_modulo(id_agente_modulo) + ON DELETE CASCADE, + module_b NUMBER(10, 0) NOT NULL REFERENCES tagente_modulo(id_agente_modulo) + ON DELETE CASCADE, + disable_update NUMBER(1, 0) default 0 NOT NULL +); + +CREATE SEQUENCE tmodule_relationship_s INCREMENT BY 1 START WITH 1; + +CREATE OR REPLACE TRIGGER tmodule_relationship_inc BEFORE INSERT ON tmodule_relationship REFERENCING NEW AS NEW FOR EACH ROW BEGIN SELECT tmodule_relationship_s.nextval INTO :NEW.ID FROM dual; END;; diff --git a/pandora_console/extras/pandoradb_migrate_5.0.x_to_5.1.postgreSQL.sql b/pandora_console/extras/pandoradb_migrate_5.0.x_to_5.1.postgreSQL.sql index 9aa2d77a05..f2f286e9b5 100644 --- a/pandora_console/extras/pandoradb_migrate_5.0.x_to_5.1.postgreSQL.sql +++ b/pandora_console/extras/pandoradb_migrate_5.0.x_to_5.1.postgreSQL.sql @@ -31,3 +31,16 @@ INSERT INTO "tconfig" ("token", "value") VALUES UPDATE "tconfig" SET "value"='#FFFF00' WHERE "token"='graph_color2'; UPDATE "tconfig" SET "value"='#FF6600' WHERE "token"='graph_color3'; + +/* 2014/03/18 */ +-- ---------------------------------------------------------------------- +-- Table `tmodule_relationship` +-- ---------------------------------------------------------------------- +CREATE TABLE "tmodule_relationship" ( + "id" SERIAL NOT NULL PRIMARY KEY, + "module_a" INTEGER NOT NULL REFERENCES tagente_modulo("id_agente_modulo") + ON DELETE CASCADE, + "module_b" INTEGER NOT NULL REFERENCES tagente_modulo("id_agente_modulo") + ON DELETE CASCADE, + "disable_update" SMALLINT NOT NULL default 0 +); diff --git a/pandora_console/godmode/agentes/module_manager_editor.php b/pandora_console/godmode/agentes/module_manager_editor.php index 8babb9a15c..2d258aa0c4 100644 --- a/pandora_console/godmode/agentes/module_manager_editor.php +++ b/pandora_console/godmode/agentes/module_manager_editor.php @@ -430,6 +430,7 @@ 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') . ui_print_help_icon ('module_macros', true)); +ui_toggle(html_print_table ($table_new_relations, true) . html_print_table ($table_relations, true), __('Module relations')); // Submit diff --git a/pandora_console/godmode/agentes/module_manager_editor_common.php b/pandora_console/godmode/agentes/module_manager_editor_common.php index 096b62e299..c47fe57c8d 100644 --- a/pandora_console/godmode/agentes/module_manager_editor_common.php +++ b/pandora_console/godmode/agentes/module_manager_editor_common.php @@ -519,6 +519,106 @@ $macro_count++; html_print_input_hidden ('module_macro_count', $macro_count); +/* Advanced form part */ +// Add relationships +$table_new_relations = new stdClass(); +$table_new_relations->id = 'module_new_relations'; +$table_new_relations->width = '98%'; +$table_new_relations->class = 'databox_color'; +$table_new_relations->data = array (); +$table_new_relations->style = array (); +$table_new_relations->style[0] = 'width: 10%; font-weight: bold;'; +$table_new_relations->style[1] = 'width: 25%; text-align: center;'; +$table_new_relations->style[2] = 'width: 10%; font-weight: bold;'; +$table_new_relations->style[3] = 'width: 25%; text-align: center;'; +$table_new_relations->style[4] = 'width: 30%; text-align: center;'; + +$table_new_relations->data[0][0] = __('Agent'); +$params = array(); +$params['return'] = true; +$params['show_helptip'] = true; +$params['input_name'] = 'autocomplete_agent_name'; +$params['use_hidden_input_idagent'] = true; +$params['print_hidden_input_idagent'] = true; +$params['hidden_input_idagent_id'] = 'hidden-autocomplete_id_agent'; +$params['javascript_function_action_after_select_js_call'] = 'change_modules_autocomplete_input();'; +$table_new_relations->data[0][1] = ui_print_agent_autocomplete_input($params); +$table_new_relations->data[0][2] = __('Module'); +$table_new_relations->data[0][3] = "
"; +$table_new_relations->data[0][4] = html_print_button (__('Add relationship'), 'add_relation', false, 'javascript: add_new_relation();', 'class="sub add"', true); +$table_new_relations->data[0][4] .= "  
"; + +// Relationship list +$table_relations = new stdClass(); +$table_relations->id = 'module_relations'; +$table_relations->width = '98%'; +$table_relations->class = 'databox'; +$table_relations->head = array (); +$table_relations->data = array (); +$table_relations->rowstyle = array (); +$table_relations->rowstyle[-1] = 'display: none;'; +$table_relations->style = array (); +$table_relations->style[2] = 'width: 10%; text-align: center;'; +$table_relations->style[3] = 'width: 10%; text-align: center;'; + +$table_relations->head[0] = __('Agent'); +$table_relations->head[1] = __('Module'); +$table_relations->head[2] = __('Changes'); +$table_relations->head[3] = __('Delete'); + +// Create an invisible row to use their html to add new rows +$table_relations->data[-1][0] = ""; +$table_relations->data[-1][1] = ""; +$table_relations->data[-1][2] = '' . html_print_image('images/lock.png', true) . ''; +$table_relations->data[-1][3] = '' . html_print_image('images/cross.png', true) . ''; + +$module_relations = modules_get_relations(array('id_module' => $id_agent_module)); +if (!$module_relations) { + $module_relations = array(); +} + +$relations_count = 0; +foreach ($module_relations as $key => $module_relation) { + + if ($module_relation['module_a'] == $id_agent_module) { + $module_id = $module_relation['module_b']; + $agent_id = modules_give_agent_id_from_module_id ($module_relation['module_b']); + } else { + $module_id = $module_relation['module_a']; + $agent_id = modules_give_agent_id_from_module_id ($module_relation['module_a']); + } + + $agent_name = ui_print_agent_name ($agent_id, true); + + $module_name = modules_get_agentmodule_name($module_id); + if (empty($module_name) || $module_name == 'false') { + $module_name = $module_id; + } + + if ($module_relation['disable_update']) { + $disabled_update_class = ""; + } else { + $disabled_update_class = "transparent"; + } + + // Agent name + $table_relations->data[$relations_count][0] = $agent_name; + // Module name + $table_relations->data[$relations_count][1] = "" . + ui_print_truncate_text($module_name, 'module_medium', true, true, true, '[…]') . ""; + // Lock relationship updates + $table_relations->data[$relations_count][2] = '' + . html_print_image('images/lock.png', true) . ''; + // Delete relationship + $table_relations->data[$relations_count][3] = '' + . html_print_image('images/cross.png', true) . ''; + $relations_count++; +} + +html_print_input_hidden ('module_relations_count', $relations_count); + ui_require_jquery_file('json'); ?> @@ -589,6 +689,14 @@ $(document).ready (function () { }); $("#id_module_type").trigger('change'); + + // Prevent the form submission when the user hits the enter button from the relationship autocomplete inputs + $("#text-autocomplete_agent_name").keydown(function(event){ + if(event.keyCode == 13) { // key code 13 is the enter button + event.preventDefault(); + } + }); + }); // Add a new module macro @@ -616,5 +724,197 @@ function delete_macro (num) { // Do not decrease the macro counter or new macros may overlap existing ones! } + +/* Relationship javascript */ + +// Change the modules autocomplete input depending on the result of the agents autocomplete input +function change_modules_autocomplete_input () { + var id_agent = parseInt($("#hidden-autocomplete_id_agent").val()); + var module_autocomplete = $("#module_autocomplete"); + var load_icon = ''; + var error_icon = ''; + + if (!module_autocomplete.hasClass('working')) { + module_autocomplete.addClass('working'); + module_autocomplete.html(load_icon); + + $.ajax({ + type: "POST", + url: "ajax.php", + dataType: "html", + data: { + page: "include/ajax/module", + get_module_autocomplete_input: true, + id_agent: id_agent + }, + success: function (data) { + module_autocomplete.removeClass('working'); + if (data) { + module_autocomplete.html(data); + // Prevent the form submission when the user hits the enter button from the relationship autocomplete inputs + $("#text-autocomplete_module_name").keydown(function(event){ + if(event.keyCode == 13) { // key code 13 is the enter button + event.preventDefault(); + } + }); + } else { + module_autocomplete.html(error_icon); + } + }, + error: function (data) { + module_autocomplete.removeClass('working'); + module_autocomplete.html(error_icon); + } + }); + } +} + +// Add a new relation +function add_new_relation () { + var module_a_id = parseInt($("#hidden-id_agent_module").val()); + var module_b_name = $("#text-autocomplete_module_name").val(); + var agent_b_name = $("#text-autocomplete_agent_name").val(); + var hiddenRow = $("#module_relations--1"); + var button = $("#button-add_relation"); + var iconPlaceholder = $("#add_relation_status"); + var load_icon = '"vertical-align:middle;")) ?>'; + var suc_icon = '"vertical-align:middle;")) ?>'; + var error_icon = '"vertical-align:middle;")) ?>'; + + if (!button.hasClass('working')) { + button.addClass('working'); + iconPlaceholder.html(load_icon); + + $.ajax({ + type: "POST", + url: "ajax.php", + dataType: "json", + data: { + page: "include/ajax/module", + add_module_relation: true, + id_module_a: module_a_id, + name_module_b: module_b_name + }, + success: function (data) { + button.removeClass('working'); + if (data === false) { + iconPlaceholder.html(error_icon); + setTimeout( function() { iconPlaceholder.html(''); }, 2000); + } else { + iconPlaceholder.html(suc_icon); + setTimeout( function() { iconPlaceholder.html(''); }, 2000); + + // Add the new row + var relationsCount = parseInt($("#hidden-module_relations_count").val()); + + var rowClass = "datos"; + if (relationsCount % 2 != 0) { + rowClass = "datos2"; + } + + var rowHTML = '' + + '' + agent_b_name + '' + + '' + module_b_name + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + ''; + $("#module_relations").find("tbody").append(rowHTML); + + $("#hidden-module_relations_count").val(relationsCount + 1); + $("#text-autocomplete_module_name").val(''); + } + }, + error: function (data) { + button.removeClass('working'); + iconPlaceholder.html(error_icon); + setTimeout( function() { iconPlaceholder.html(''); }, 2000); + } + }); + } +} + +// Delete an existing relation +function change_lock_relation (num_row, id_relation) { + var row = $("#module_relations-" + num_row); + var button = row.find("#disable_updates_button"); + var oldSrc = button.find("img").prop("src"); + var isEnabled = button.hasClass('transparent'); + + if (row.length > 0 && !button.hasClass('working')) { + button.addClass('working'); + button.removeClass('transparent'); + button.find("img").prop("src", 'images/spinner.gif'); + + $.ajax({ + type: "POST", + url: "ajax.php", + dataType: "json", + data: { + page: "include/ajax/module", + change_module_relation_updates: true, + id_relation: id_relation + }, + success: function (data) { + if (data === false) { + button.addClass('transparent'); + } + button.removeClass('working'); + button.find("img").prop("src", oldSrc); + }, + error: function (data) { + if (isEnabled) { + button.addClass('transparent'); + } + button.removeClass('working'); + button.find("img").prop("src", oldSrc); + } + }); + } +} + +// Delete an existing relation +function delete_relation (num_row, id_relation) { + var row = $("#module_relations-" + num_row); + var button = row.find("#delete_relation_button"); + var oldSrc = button.find("img").prop("src"); + + if (row.length > 0 && !button.hasClass('working')) { + button.addClass('working'); + button.find("img").prop("src", 'images/spinner.gif'); + + $.ajax({ + type: "POST", + url: "ajax.php", + dataType: "json", + data: { + page: "include/ajax/module", + remove_module_relation: true, + id_relation: id_relation + }, + success: function (data) { + button.removeClass('working'); + button.find("img").prop("src", oldSrc); + if (data === true) { + row.remove(); + } + }, + error: function (data) { + button.removeClass('working'); + button.find("img").prop("src", oldSrc); + } + }); + } +} + +/* End of relationship javascript */ + /* ]]> */ diff --git a/pandora_console/godmode/agentes/module_manager_editor_network.php b/pandora_console/godmode/agentes/module_manager_editor_network.php index f2d81c7ea6..e181c47620 100644 --- a/pandora_console/godmode/agentes/module_manager_editor_network.php +++ b/pandora_console/godmode/agentes/module_manager_editor_network.php @@ -125,7 +125,7 @@ push_table_simple ($data, 'snmp_2'); $data = array (); $data[0] = __('TCP send') . ' ' . ui_print_help_icon ("tcp_send", true); $data[1] = html_print_textarea ('tcp_send', 2, 65, $tcp_send, $disabledTextBecauseInPolicy, true); -$table_advanced->colspan['tcp_send'][1] = 3; +$table_simple->colspan['tcp_send'][1] = 3; push_table_simple ($data, 'tcp_send'); diff --git a/pandora_console/include/ajax/module.php b/pandora_console/include/ajax/module.php index eb2ec27424..a9938a7229 100644 --- a/pandora_console/include/ajax/module.php +++ b/pandora_console/include/ajax/module.php @@ -18,6 +18,7 @@ global $config; include_once($config['homedir'] . "/include/functions_agents.php"); +include_once($config['homedir'] . "/include/functions_modules.php"); include_once($config['homedir'] . "/include/functions_ui.php"); enterprise_include_once ('include/functions_metaconsole.php'); @@ -51,11 +52,17 @@ if ($search_modules) { $modules = io_safe_output($modules); echo json_encode($modules); + return; } $get_module_detail = get_parameter ('get_module_detail', 0); if ($get_module_detail) { + + ui_require_jquery_file ("ui-timepicker-addon"); + // This script is included manually to be included after jquery and avoid error + echo ''; + ui_require_jquery_file("ui.datepicker-" . get_user_language(), "include/javascript/i18n/"); ui_require_jquery_file ("ui-timepicker-addon"); // This script is included manually to be included after jquery and avoid error @@ -329,4 +336,68 @@ if ($get_module_detail) { return; } -?> + +$get_module_autocomplete_input = (bool) get_parameter('get_module_autocomplete_input'); +if ($get_module_autocomplete_input) { + $id_agent = (int) get_parameter("id_agent"); + + ob_clean(); + if ($id_agent > 0) { + html_print_autocomplete_modules('autocomplete_module_name', '', array($id_agent)); + return; + } + return; +} + +$add_module_relation = (bool) get_parameter('add_module_relation'); +if ($add_module_relation) { + $result = false; + $id_module_a = (int) get_parameter("id_module_a"); + $id_module_b = (int) get_parameter("id_module_b"); + + if ($id_module_a < 1) { + $name_module_a = get_parameter("name_module_a", ""); + if ($name_module_a) { + $id_module_a = (int) db_get_value('id_agente_modulo', 'tagente_modulo', 'nombre', $name_module_a); + } else { + echo json_encode($result); + return; + } + } + if ($id_module_b < 1) { + $name_module_b = get_parameter("name_module_b", ""); + if ($name_module_b) { + $id_module_b = (int) db_get_value('id_agente_modulo', 'tagente_modulo', 'nombre', $name_module_b); + } else { + echo json_encode($result); + return; + } + } + if ($id_module_a > 0 && $id_module_b > 0) { + $result = modules_add_relation($id_module_a, $id_module_b); + } + echo json_encode($result); + return; +} + +$remove_module_relation = (bool) get_parameter('remove_module_relation'); +if ($remove_module_relation) { + $id_relation = (int) get_parameter("id_relation"); + if ($id_relation > 0) { + $result = (bool) modules_delete_relation($id_relation); + } + echo json_encode($result); + return; +} + +$change_module_relation_updates = (bool) get_parameter('change_module_relation_updates'); +if ($change_module_relation_updates) { + $id_relation = (int) get_parameter("id_relation"); + if ($id_relation > 0) { + $result = (bool) modules_change_relation_lock($id_relation); + } + echo json_encode($result); + return; +} + +?> \ No newline at end of file diff --git a/pandora_console/include/functions_modules.php b/pandora_console/include/functions_modules.php index e387f762ca..d637fe107b 100644 --- a/pandora_console/include/functions_modules.php +++ b/pandora_console/include/functions_modules.php @@ -1763,4 +1763,145 @@ function modules_get_module_macros_json ($macro_names, $macro_values) { return base64_encode(json_encode ($module_macros)); } -?> +/** + * Returns the relations between modules. + * + * @param array Optional assoc array with parameters. + * (int) id_agent + * (int) id_module + * (bool) disabled_update + * (string) modules_type: The type of the two modules + * + * @return mixed Array with relations between modules. False if there were no data. + */ +function modules_get_relations ($params = array()) { + + $id_agent = 0; + if (isset($params['id_agent'])) { + $id_agent = $params['id_agent']; + } + + $id_module = 0; + if (isset($params['id_module'])) { + $id_module = $params['id_module']; + } + + $disabled_update = -1; + if (isset($params['disabled_update'])) { + $disabled_update = (int) $params['disabled_update']; + if ($disabled_update > 1) { + $disabled_update = 1; + } + } + + $modules_type = ""; + if (isset($params['modules_type'])) { + $modules_type = $params['modules_type']; + } + + $sql = "SELECT DISTINCT tmr.id, tmr.module_a, tmr.module_b, tmr.disable_update + FROM tmodule_relationship AS tmr, tagente_modulo AS tam, tagente AS ta, ttipo_modulo AS ttm + WHERE "; + + $agent_filter = ""; + if ($id_agent > 0) { + $agent_filter = sprintf("AND ta.id_agente = %d", $id_agent); + } + $module_a_filter = ""; + $module_b_filter = ""; + if ($id_module > 0) { + $module_a_filter = sprintf("AND tmr.module_a = %d", $id_module); + $module_b_filter = sprintf("AND tmr.module_b = %d", $id_module); + } + $disabled_update_filter = ""; + if ($disabled_update >= 0) { + $disabled_update_filter = sprintf("AND tmr.disable_update = %d", $disabled_update); + } + $modules_type_filter = ""; + if ($modules_type != "") { + $modules_type_filter = sprintf("AND (tam.id_tipo_modulo = ttm.id_tipo AND ttm.nombre = '%s')", $modules_type); + } + + $sql .= "( (tmr.module_a = tam.id_agente_modulo + $module_a_filter) + OR (tmr.module_b = tam.id_agente_modulo + $module_b_filter) ) + AND tam.id_agente = ta.id_agente + $agent_filter + $disabled_update_filter + $modules_type_filter"; + + return db_get_all_rows_sql($sql); +} + +/** + * Check if a relation already exists. + * + * @param int First module id. + * @param int Second module id. + * + * @return bool True if the relation exists, false otherwise. + */ +function modules_relation_exists ($id_module_a, $id_module_b) { + $sql = sprintf("SELECT id + FROM tmodule_relationship + WHERE (module_a = %d AND module_b = %d) + OR (module_b = %d AND module_a = %d)", + $id_module_a, $id_module_b, $id_module_a, $id_module_b); + + return (bool) db_get_row_sql($sql); +} + +/** + * Change the 'disabled_update' value of a relation row. + * + * @param int Relation id. + * + * @return bool True if the 'disabled_update' changes to 1, false otherwise. + */ +function modules_add_relation ($id_module_a, $id_module_b) { + $result = false; + + if (!modules_relation_exists($id_module_a, $id_module_b) && $id_module_a > 0 && $id_module_b > 0) { + $values = array( + 'module_a' => $id_module_a, + 'module_b' => $id_module_b + ); + $result = db_process_sql_insert('tmodule_relationship', $values); + } + + return $result; +} + +/** + * Change the 'disabled_update' value of a relation row. + * + * @param int Relation id. + * + * @return bool True if the 'disabled_update' changes to 1, false otherwise. + */ +function modules_delete_relation ($id_relation) { + $result = db_process_sql_delete('tmodule_relationship', array('id' => $id_relation)); + + return $result; +} + +/** + * Change the 'disabled_update' value of a relation row. + * + * @param int Relation id. + * + * @return bool True if the 'disabled_update' changes to 1, false otherwise. + */ +function modules_change_relation_lock ($id_relation) { + $old_value = (int) db_get_value('disable_update', 'tmodule_relationship', 'id', $id_relation); + $new_value = $old_value === 1 ? 0 : 1; + + $result = db_process_sql_update('tmodule_relationship', + array('disable_update' => $new_value), + array('id' => $id_relation)); + + return ($result !== false ? $new_value : $old_value); +} + +?> \ No newline at end of file diff --git a/pandora_console/include/styles/pandora.css b/pandora_console/include/styles/pandora.css index 12b30e5813..c4bda51b4a 100644 --- a/pandora_console/include/styles/pandora.css +++ b/pandora_console/include/styles/pandora.css @@ -1234,6 +1234,13 @@ div.title_line { width: 762px; } +.transparent { + filter:alpha(opacity=50); + -moz-opacity: 0.5; + opacity: 0.5; + -khtml-opacity: 0.5; +} + #menu_tab_frame { background:#FAFAFA; } diff --git a/pandora_console/operation/agentes/estado_generalagente.php b/pandora_console/operation/agentes/estado_generalagente.php index 07ac85f09c..89df9de434 100644 --- a/pandora_console/operation/agentes/estado_generalagente.php +++ b/pandora_console/operation/agentes/estado_generalagente.php @@ -311,6 +311,101 @@ foreach ($fields as $field) { // END: TABLE DATA BUILD +// START: TABLE INTERFACES + +$columns = array( + "id_agente_modulo", + "nombre", + "descripcion", + "ip_target" + ); +$filter = array( + "id_agente" => $id_agente, + "id_tipo_modulo" => (int)db_get_value("id_tipo", "ttipo_modulo", "nombre", "remote_snmp_proc") + ); +$modules = agents_get_modules ($id_agent, $columns, $filter); + +if (! empty($modules)) { + $table_interface = new stdClass(); + $table_interface->id = 'agent_interface_info'; + $table_interface->class = 'databox'; + $table_interface->width = '100%'; + $table_interface->style = array(); + $table_interface->style[1] = 'width: 30px;'; + $table_interface->head = array(); + $options = array( + "class" => "closed", + "style" => "vertical-align:middle; cursor:pointer;" + ); + $table_interface->head[0] = html_print_image("images/go.png", true, $options) . "  "; + $table_interface->head[0] .= '' . __('Interface information') .' (SNMP)'; + $table_interface->head_colspan = array(); + $table_interface->head_colspan[0] = 4; + $table_interface->data = array(); + + foreach ($modules as $key => $module) { + + // Trying to get the interface name from the module name + if (preg_match ("/_(\w+)/" , (string)$module['nombre'], $matches)) { + if ($matches[1]) { + $interface_name = $matches[1]; + + $module_id = $module['id_agente_modulo']; + $db_status = modules_get_agentmodule_status($module_id); + $module_value = modules_get_last_value ($module_id); + modules_get_status($module_id, $db_status, $module_value, $status, $title); + $status = ui_print_status_image($status, $title, true); + + $ip_target = "--"; + // Trying to get something like an IP from the description + if (preg_match ("/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/" , (string)$module['ip_target'], $matches)) { + if ($matches[0]) { + $ip_target = $matches[0]; + } + } + $description = "--"; + // Trying to get something like a mac from the description + if (preg_match ("/([0-9a-f]{1,2}[\.:-]){5}([0-9a-f]{1,2})/i" , (string)$module['descripcion'], $matches)) { + if ($matches[0]) { + $description = $matches[0]; + } + } + + $data = array(); + $data[0] = "" . $interface_name . ""; + $data[1] = $status; + $data[2] = $ip_target; + $data[3] = $description; + $table_interface->data[] = $data; + } + } + } + unset($modules); + + // This javascript piece of code is used to make expandible the body of the table + ?> + + id = 'agent_details'; $table->width = '98%'; @@ -321,8 +416,30 @@ $table->style = array_fill(0, 3, 'vertical-align: top;'); $data = array(); $data[0] = html_print_table($table_agent, true); -$data[1] = html_print_table($table_contact, true) . '
'; -$data[1] .= empty($table_data->data) ? '' : html_print_table($table_data, true); +$data[0] .= '
+ ' . + __('Events (24h)') . + '' . + '
' . + graph_graphic_agentevents ($id_agente, 300, 15, 86400, '', true) . + '
' . + '
'; + +// ACCESS RATE GRAPH +if ($config["agentaccess"]) { + $data[0] .= '
+ ' . + __('Agent access rate (24h)') . + '' . + '
' . + graphic_agentaccess($id_agente, 300, 100, 86400, true) . + '
' . + '
'; +} + +$data[1] = html_print_table($table_contact, true); +$data[1] .= empty($table_data->data) ? '' : '
' . html_print_table($table_data, true); +$data[1] .= !isset($table_interface) ? '' : '
' . html_print_table($table_interface, true); $table->rowspan[0][1] = 2; @@ -334,33 +451,8 @@ $data[2] .= ''; $table->data[] = $data; $table->rowclass[] = ''; -$data = array(); -$data[0] = '
- ' . - __('Events (24h)') . - '' . - '
' . - graph_graphic_agentevents ($id_agente, 300, 15, 86400, '', true) . - '
' . - '
'; - -// ACCESS RATE GRAPH -if ($config["agentaccess"]) { - $data[0] .= '
- ' . - __('Agent access rate (24h)') . - '' . - '
' . - graphic_agentaccess($id_agente, 300, 100, 86400, true) . - '
' . - '
'; -} - $table->cellstyle[1][0] = 'text-align:center;'; -$table->data[] = $data; -$table->rowclass[] = ''; - html_print_table($table); unset($table); ?> diff --git a/pandora_console/pandoradb.oracle.sql b/pandora_console/pandoradb.oracle.sql index 1dd2fd92e5..26e259af0e 100644 --- a/pandora_console/pandoradb.oracle.sql +++ b/pandora_console/pandoradb.oracle.sql @@ -667,6 +667,25 @@ CREATE SEQUENCE tmodule_group_s INCREMENT BY 1 START WITH 1; CREATE OR REPLACE TRIGGER tmodule_group_inc BEFORE INSERT ON tmodule_group REFERENCING NEW AS NEW FOR EACH ROW BEGIN SELECT tmodule_group_s.nextval INTO :NEW.ID_MG FROM dual; END;; +-- ---------------------------------------------------------------------- +-- Table `tmodule_relationship` +-- ---------------------------------------------------------------------- +CREATE TABLE IF NOT EXISTS tmodule_relationship ( + id NUMBER(10, 0) NOT NULL PRIMARY KEY, + module_a NUMBER(10, 0) NOT NULL REFERENCES tagente_modulo(id_agente_modulo) + ON DELETE CASCADE, + module_b NUMBER(10, 0) NOT NULL REFERENCES tagente_modulo(id_agente_modulo) + ON DELETE CASCADE, + disable_update NUMBER(1, 0) default 0 NOT NULL +); + +CREATE SEQUENCE tmodule_relationship_s INCREMENT BY 1 START WITH 1; + +CREATE OR REPLACE TRIGGER tmodule_relationship_inc BEFORE INSERT ON tmodule_relationship REFERENCING NEW AS NEW FOR EACH ROW BEGIN SELECT tmodule_relationship_s.nextval INTO :NEW.ID FROM dual; END;; + +-- ---------------------------------------------------------------------- +-- Table `tnetwork_component` +-- ---------------------------------------------------------------------- CREATE TABLE tnetwork_component ( id_nc NUMBER(10, 0) NOT NULL PRIMARY KEY, name CLOB NOT NULL, diff --git a/pandora_console/pandoradb.postgreSQL.sql b/pandora_console/pandoradb.postgreSQL.sql index aab591ce3c..dac6f866b8 100644 --- a/pandora_console/pandoradb.postgreSQL.sql +++ b/pandora_console/pandoradb.postgreSQL.sql @@ -562,6 +562,18 @@ CREATE TABLE "tmodule_group" ( "name" varchar(150) NOT NULL default '' ); +-- ---------------------------------------------------------------------- +-- Table `tmodule_relationship` +-- ---------------------------------------------------------------------- +CREATE TABLE "tmodule_relationship" ( + "id" SERIAL NOT NULL PRIMARY KEY, + "module_a" INTEGER NOT NULL REFERENCES tagente_modulo("id_agente_modulo") + ON DELETE CASCADE, + "module_b" INTEGER NOT NULL REFERENCES tagente_modulo("id_agente_modulo") + ON DELETE CASCADE, + "disable_update" SMALLINT NOT NULL default 0 +); + -- --------------------------------------------------------------------- -- Table `tnetwork_component` -- --------------------------------------------------------------------- diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index a636a8d455..bd0a748d1d 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -616,6 +616,21 @@ CREATE TABLE IF NOT EXISTS `tmodule_group` ( PRIMARY KEY (`id_mg`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; +-- ---------------------------------------------------------------------- +-- Table `tmodule_relationship` +-- ---------------------------------------------------------------------- +CREATE TABLE IF NOT EXISTS `tmodule_relationship` ( + `id` int(10) unsigned NOT NULL auto_increment, + `module_a` int(10) unsigned NOT NULL, + `module_b` int(10) unsigned NOT NULL, + `disable_update` tinyint(1) unsigned NOT NULL default '0', + PRIMARY KEY (`id`), + FOREIGN KEY (`module_a`) REFERENCES tagente_modulo(`id_agente_modulo`) + ON DELETE CASCADE, + FOREIGN KEY (`module_b`) REFERENCES tagente_modulo(`id_agente_modulo`) + ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + -- ---------------------------------------------------------------------- -- Table `tnetwork_component` -- ----------------------------------------------------------------------