diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 3032113c25..d72ad8e0af 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,17 @@ +2012-02-23 Vanessa Gil + * pandoradb.sql + pandoradb.oracle.sql + pandoradb.postgreSQL.sql + extras/pandoradb_migrate_4.0.x_to_4.1.mysql.sql + extras/pandoradb_migrate_4.0.x_to_4.1.oracle.sql + extras/pandoradb_migrate_4.0.x_to_4.1.postgreSQL.sql: Added + column 'id_graph_template' to 'tgraph' table. + + * include/functions_reporting.php: Added function to apply + templates for combined graphs. + + * godmode/reporting/graph_template_wizard.php: Added file. + 2012-02-22 Juan Manuel Ramon * pandoradb.sql diff --git a/pandora_console/extras/pandoradb_migrate_4.0.x_to_4.1.mysql.sql b/pandora_console/extras/pandoradb_migrate_4.0.x_to_4.1.mysql.sql index 96d2bb56c4..804ade60f9 100644 --- a/pandora_console/extras/pandoradb_migrate_4.0.x_to_4.1.mysql.sql +++ b/pandora_console/extras/pandoradb_migrate_4.0.x_to_4.1.mysql.sql @@ -199,3 +199,8 @@ ALTER TABLE treport_content_item ADD FOREIGN KEY (`id_report_content`) REFERENCE -- Table `treport` -- ----------------------------------------------------- ALTER TABLE treport ADD COLUMN `id_template` INTEGER UNSIGNED DEFAULT 0; + +-- ----------------------------------------------------- +-- Table `tgraph` +-- ----------------------------------------------------- +ALTER TABLE `tgraph` ADD COLUMN `id_graph_template` int(11) NOT NULL DEFAULT 0; diff --git a/pandora_console/extras/pandoradb_migrate_4.0.x_to_4.1.oracle.sql b/pandora_console/extras/pandoradb_migrate_4.0.x_to_4.1.oracle.sql index 6c07fd4eee..e497a58956 100644 --- a/pandora_console/extras/pandoradb_migrate_4.0.x_to_4.1.oracle.sql +++ b/pandora_console/extras/pandoradb_migrate_4.0.x_to_4.1.oracle.sql @@ -192,3 +192,8 @@ ALTER TABLE treport_content_item ADD FOREIGN KEY (id_report_content) REFERENCES -- Table `treport` -- ----------------------------------------------------- ALTER TABLE treport ADD (id_template NUMBER(10, 0) default 0 NOT NULL); + +-- ----------------------------------------------------- +-- Table `tgraph` +-- ----------------------------------------------------- +ALTER TABLE tgraph ADD (id_graph_template NUMBER(11, 0) default 0 NOT NULL); diff --git a/pandora_console/extras/pandoradb_migrate_4.0.x_to_4.1.postgreSQL.sql b/pandora_console/extras/pandoradb_migrate_4.0.x_to_4.1.postgreSQL.sql index 27a38715d3..fdbdc9846d 100644 --- a/pandora_console/extras/pandoradb_migrate_4.0.x_to_4.1.postgreSQL.sql +++ b/pandora_console/extras/pandoradb_migrate_4.0.x_to_4.1.postgreSQL.sql @@ -177,3 +177,8 @@ CREATE TABLE IF NOT EXISTS "tgraph_source_template" ( -- Table `treport` -- ----------------------------------------------------- ALTER TABLE "treport" ADD COLUMN "id_template" INTEGER NOT NULL default 0; + +-- ----------------------------------------------------- +-- Table `tgraph` +-- ----------------------------------------------------- +ALTER TABLE "tgraph" ADD COLUMN "id_graph_template" INTEGER NOT NULL default 0; diff --git a/pandora_console/godmode/reporting/graph_template_wizard.php b/pandora_console/godmode/reporting/graph_template_wizard.php new file mode 100644 index 0000000000..003eeb0a45 --- /dev/null +++ b/pandora_console/godmode/reporting/graph_template_wizard.php @@ -0,0 +1,423 @@ + $id_template_cleanup)); + + if($result) { + foreach ($id_graphs as $id_graph) { + $result_aux = db_process_sql_delete('tgraph_source', array('id_graph' => $id_graph)); + } + echo 1; + } else { + echo 0; + } + } + + return; +} + +// Result for cleanup functionality +echo ''; +echo ''; + +$buttons['template_list'] = '' + . html_print_image ("images/god6.png", true, array ("title" => __('Template list'))) + . ''; + +// Header +ui_print_page_header (__('Wizard template'), "", false, "", true, $buttons); + +// Apply templates action +if ($action_wizard == 'apply') { + $agents_selected = (array) get_parameter ('id_agents2'); + $template_selected = get_parameter('templates'); + + if (empty($agents_selected) || empty($template_selected)) + $result = false; + else { + $result = reporting_apply_report_template_graph($agents_selected, $template_selected); + } +} + +?> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ '; + + // List all available templates + $own_info = get_user_info ($config['id_user']); + if ($own_info['is_admin'] || check_acl ($config['id_user'], 0, "PM")) + $return_all_group = true; + else + $return_all_group = false; + + $templates = reporting_template_graphs_get_user ($config['id_user'], false, true, 'IW'); + + if ($templates === false) + $template_select = array(); + else{ + foreach ($templates as $template){ + $template_select[$template['id_graph_template']] = $template['name']; + } + } + + echo __('Templates') . "    "; + html_print_select($template_select, 'templates', $template_selected, '', __('None'), '0', false, false, true, '', false, 'width:180px;'); + echo "  "; + echo ''; + + html_print_image ('images/clean.png', false, array ('title' => __('Clean up template'))); + echo ''; + ?> +
+ "; + ?> +
+ "; + ?> +
+ " . __('Agents available')."  " . html_print_submit_button (__('Select all'), 'select_all', false, 'class="sub upd"', true); + ?> + + " . __('Agents to apply')."  " . html_print_submit_button (__('Select all'), 'select_all2', false, 'class="sub upd"', true); + ?> +
+ + +
+ 'right', 'title' => __('Add agents to template'))); + ?> +



+ 'left', 'title' => __('Undo agents to template'))); + ?> +


+
+ +
+ +'; +html_print_input_hidden('action_wizard', 'apply'); +html_print_submit_button (__('Apply template'), 'apply', false, 'class="sub next"'); +echo ''; +echo ''; + +// Choose a weird separator +$separator = ';;..;;..;;'; + +html_print_input_hidden('separator', $separator); +html_print_input_hidden('agents_in', implode($separator, $template_agents_in)); +html_print_input_hidden('agents_in_keys', implode($separator, $template_agents_in_keys)); +html_print_input_hidden('agents_out', implode($separator, $template_agents_out)); +html_print_input_hidden('agents_out_keys', implode($separator, $template_agents_out_keys)); +?> + + diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index af9347d6d3..250396259f 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -4689,4 +4689,81 @@ function reporting_template_graphs_get_user ($id_user = 0, $only_names = false, return $templates; } + +/** + * Apply a template graph + * + * @param array $agents_selected to apply the template. + * @param $template_selected + * + * @return + */ +function reporting_apply_report_template_graph ($agents_selected, $template_selected) { + + if ($agents_selected[0] == '') { + unset($agents_selected[0]); + } + + if ($agents_selected != null) { + + $template_data = db_get_row('tgraph_template','id_graph_template', $template_selected); + + foreach ($agents_selected as $id_agent) { + $values = array( + 'id_user' => $template_data['id_user'], + 'name' => $template_data['name'], + 'description' => $template_data['description'], + 'period' => $template_data['period'], + 'width' => $template_data['width'], + 'height' => $template_data['height'], + 'private' => $template_data['private'], + 'events' => $template_data['events'], + 'stacked' => $template_data['stacked'], + 'id_group' => $template_data['id_group'], + 'id_graph_template' => $template_selected + ); + + $id_graph = db_process_sql_insert('tgraph', $values); + + $sql = "SELECT * FROM tgraph_source_template WHERE id_template=$template_selected"; + $source_templates = db_get_all_rows_sql($sql); + + foreach ($source_templates as $source) { + $modules = agents_get_modules($id_agent, false, array('disabled' => 0)); + $exact_match = $source['exact_match']; + + foreach ($modules as $key => $module) { + $insert_module = false; + if ($exact_match) { + if ($module == $source['module']) { + $insert_module = true; + } + } else { + $result = preg_match('/[.]*'.$source['module'].'[.]*/i', $module); + if ($result) { + $insert_module = true; + } + } + if ($insert_module) { + $values_aux = array( + 'id_graph' => $id_graph, + 'id_agent_module' => $key, + 'weight' => $source['weight'] + ); + $id_gs = db_process_sql_insert('tgraph_source', $values_aux); + } + } + } + } + if ($id_graph) { + ui_print_success_message ('Template applied successfully'); + //return true; + } else { + ui_print_error_message ('An error has ocurred apllying template'); + } + } else { + ui_print_error_message ('Agent must be selected'); + } + return false; +} ?> diff --git a/pandora_console/pandoradb.oracle.sql b/pandora_console/pandoradb.oracle.sql index 473b6dd4fe..023cc49f0a 100644 --- a/pandora_console/pandoradb.oracle.sql +++ b/pandora_console/pandoradb.oracle.sql @@ -907,7 +907,8 @@ CREATE TABLE tgraph ( private NUMBER(5, 0) default 0 NOT NULL, events NUMBER(5, 0) default 0 NOT NULL, stacked NUMBER(5, 0) default 0 NOT NULL, - id_group NUMBER(19, 0) default 0 NOT NULL + id_group NUMBER(19, 0) default 0 NOT NULL, + id_graph_template NUMBER(11, 0) default 0 NOT NULL ); CREATE SEQUENCE tgraph_s INCREMENT BY 1 START WITH 1; diff --git a/pandora_console/pandoradb.postgreSQL.sql b/pandora_console/pandoradb.postgreSQL.sql index 046f82eff0..85106d03ef 100644 --- a/pandora_console/pandoradb.postgreSQL.sql +++ b/pandora_console/pandoradb.postgreSQL.sql @@ -729,7 +729,8 @@ CREATE TABLE "tgraph" ( "private" SMALLINT NOT NULL default 0, "events" SMALLINT NOT NULL default 0, "stacked" SMALLINT NOT NULL default 0, - "id_group" BIGINT NOT NULL default 0 + "id_group" BIGINT NOT NULL default 0, + "id_graph_template" INTEGER NOT NULL default 0 ); CREATE TABLE "tgraph_source" ( diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index 47750dd090..af1c546ebc 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -809,6 +809,7 @@ CREATE TABLE IF NOT EXISTS `tgraph` ( `events` tinyint(1) UNSIGNED NOT NULL default 0, `stacked` tinyint(1) UNSIGNED NOT NULL default 0, `id_group` mediumint(8) unsigned NULL default 0, + `id_graph_template` int(11) NOT NULL default 0, PRIMARY KEY(`id_graph`) ) ENGINE = InnoDB DEFAULT CHARSET=utf8;