From 4dbcecb951eb8f1799330b22ec330e842b5e682e Mon Sep 17 00:00:00 2001 From: daniel Date: Tue, 13 Nov 2018 15:46:44 +0100 Subject: [PATCH] WIP custom fields view --- pandora_console/extras/mr/22.sql | 13 + .../pandoradb_migrate_6.0_to_7.0.mysql.sql | 15 + .../godmode/users/configure_user.php | 13 +- pandora_console/include/ajax/module.php | 293 +++++++++++++++++- pandora_console/include/functions_agents.php | 29 ++ pandora_console/pandoradb.sql | 15 + 6 files changed, 367 insertions(+), 11 deletions(-) diff --git a/pandora_console/extras/mr/22.sql b/pandora_console/extras/mr/22.sql index d0a099460b..39c18cad6c 100644 --- a/pandora_console/extras/mr/22.sql +++ b/pandora_console/extras/mr/22.sql @@ -2,6 +2,19 @@ START TRANSACTION; ALTER TABLE `tusuario` DROP COLUMN `flash_chart`; +ALTER TABLE `tusuario` ADD COLUMN `default_custom_view` int(10) unsigned NULL default '0'; + ALTER TABLE tlayout_template MODIFY `name` varchar(600) NOT NULL; +CREATE TABLE IF NOT EXISTS `tagent_custom_fields_filter` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `name` varchar(600) NOT NULL, + `id_group` int(10) unsigned default '0', + `id_custom_field` varchar(600) default '', + `id_custom_fields_data` varchar(600) default '', + `id_status` varchar(600) default '', + `module_search` varchar(600) default '', + PRIMARY KEY(`id`) +) ENGINE = InnoDB DEFAULT CHARSET=utf8; + COMMIT; diff --git a/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql b/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql index 8980cf0982..a2d81b64d9 100644 --- a/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql +++ b/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql @@ -1231,6 +1231,7 @@ ALTER TABLE tusuario ADD COLUMN `session_time` int(10) signed NOT NULL default ' alter table tusuario add autorefresh_white_list text not null default ''; ALTER TABLE tusuario ADD COLUMN `time_autorefresh` int(5) unsigned NOT NULL default '30'; ALTER TABLE `tusuario` DROP COLUMN `flash_chart`; +ALTER TABLE `tusuario` ADD COLUMN `default_custom_view` int(10) unsigned NULL default '0'; -- --------------------------------------------------------------------- -- Table `tagente_modulo` @@ -1811,3 +1812,17 @@ ALTER TABLE `trecon_task` ADD COLUMN `snmp_auth_method` varchar(25) NOT NULL def ALTER TABLE `trecon_task` ADD COLUMN `snmp_privacy_method` varchar(25) NOT NULL default ''; ALTER TABLE `trecon_task` ADD COLUMN `snmp_privacy_pass` varchar(255) NOT NULL default ''; ALTER TABLE `trecon_task` ADD COLUMN `snmp_security_level` varchar(25) NOT NULL default ''; + +-- --------------------------------------------------------------------- +-- Table `tagent_custom_fields_filter` +-- --------------------------------------------------------------------- +CREATE TABLE IF NOT EXISTS `tagent_custom_fields_filter` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `name` varchar(600) NOT NULL, + `id_group` int(10) unsigned default '0', + `id_custom_field` varchar(600) default '', + `id_custom_fields_data` varchar(600) default '', + `id_status` varchar(600) default '', + `module_search` varchar(600) default '', + PRIMARY KEY(`id`) +) ENGINE = InnoDB DEFAULT CHARSET=utf8; diff --git a/pandora_console/godmode/users/configure_user.php b/pandora_console/godmode/users/configure_user.php index 7334985178..d215485694 100644 --- a/pandora_console/godmode/users/configure_user.php +++ b/pandora_console/godmode/users/configure_user.php @@ -169,6 +169,7 @@ if ($create_user) { $values['language'] = get_parameter ('language', 'default'); $values['timezone'] = (string) get_parameter('timezone'); $values['default_event_filter'] = (int) get_parameter('default_event_filter'); + $values['default_custom_view'] = (int) get_parameter('default_custom_view'); $dashboard = get_parameter('dashboard', ''); $visual_console = get_parameter('visual_console', ''); @@ -281,6 +282,7 @@ if ($update_user) { $values['language'] = (string) get_parameter ('language'); $values['timezone'] = (string) get_parameter('timezone'); $values['default_event_filter'] = (int) get_parameter('default_event_filter'); + $values['default_custom_view'] = (int) get_parameter('default_custom_view'); $dashboard = get_parameter('dashboard', ''); $visual_console = get_parameter('visual_console', ''); @@ -570,7 +572,16 @@ if (!$meta) { } } -$table->data[11][0] = __('Interactive charts').' '.ui_print_help_tip(__('Whether to use Javascript or static PNG graphs'), true) ; +if($meta){ + $array_filters = get_filters_custom_fields_view(0, true); + $table->data[11][0] = __('Search custom field view').' '.ui_print_help_tip(__('Load by default the selected view in custom field view'), true); + $table->data[11][1] =html_print_select( + $array_filters, 'default_custom_view', + $user_info['default_custom_view'], '', __('None'), 0, + true, false, true, '', false + ); +} + $values = array(-1 => __('Use global conf'), 1 => __('Yes'), 0 => __('No')); $table->data[12][0] = __('Home screen'). diff --git a/pandora_console/include/ajax/module.php b/pandora_console/include/ajax/module.php index 8d4fca2cb8..90df3419e8 100755 --- a/pandora_console/include/ajax/module.php +++ b/pandora_console/include/ajax/module.php @@ -35,9 +35,15 @@ $get_id_tag = (bool) get_parameter('get_id_tag', 0); $get_type = (bool) get_parameter('get_type', 0); $list_modules = (bool) get_parameter('list_modules', 0); $get_agent_modules_json_by_name = (bool) get_parameter('get_agent_modules_json_by_name', 0); + $get_custom_fields_data = (bool) get_parameter('get_custom_fields_data', 0); $build_table_custom_fields = (bool)get_parameter('build_table_custom_fields', 0); $build_table_child_custom_fields = (bool)get_parameter('build_table_child_custom_fields', 0); +$build_table_save_filter = (bool)get_parameter('build_table_save_filter', 0); +$append_tab_filter = (bool)get_parameter('append_tab_filter', 0); +$create_filter_cf = (bool)get_parameter('create_filter_cf', 0); +$update_filter_cf = (bool)get_parameter('update_filter_cf', 0); +$delete_filter_cf = (bool)get_parameter('delete_filter_cf', 0); if ($get_agent_modules_json_by_name) { $agent_name = get_parameter('agent_name'); @@ -1326,8 +1332,6 @@ if($build_table_child_custom_fields){ $name_where ); - hd($query, true, true); - $modules = db_get_all_rows_sql ($query); $table_modules = new stdClass(); @@ -1335,15 +1339,15 @@ if($build_table_child_custom_fields){ $table_modules->class="databox data"; $table_modules->head = array(); - $table_modules->head[0] = __('Name'); - $table_modules->head[1] = __('Data'); - $table_modules->head[2] = __('Min Warning'); - $table_modules->head[3] = __('Max Warning'); - $table_modules->head[4] = __('Min Critical'); - $table_modules->head[5] = __('Max Critical'); + $table_modules->head[0] = __('Module name'); + $table_modules->head[1] = __('Min Warning'); + $table_modules->head[2] = __('Max Warning'); + $table_modules->head[3] = __('Min Critical'); + $table_modules->head[4] = __('Max Critical'); + $table_modules->head[5] = __('Status'); $table_modules->head[6] = __('Current interval'); $table_modules->head[7] = __('Date'); - $table_modules->head[8] = __('Status'); + $table_modules->head[8] = __('Status'); $table_modules->data = array(); if(isset($modules) && is_array($modules)){ @@ -1355,7 +1359,7 @@ if($build_table_child_custom_fields){ $table_modules->data[$key][4] = $value['min_critical']; $table_modules->data[$key][5] = $value['max_critical']; $table_modules->data[$key][6] = $value['current_interval']; - $table_modules->data[$key][7] = date('d/m/Y h:i:s', $value['utimestamp']); + $table_modules->data[$key][7] = date('d/m/Y h:i:s', $value['utimestamp']); switch ($value['estado']) { case 0: case 300: @@ -1428,6 +1432,275 @@ if($build_table_child_custom_fields){ return; } +if($build_table_save_filter){ + $type_form = get_parameter("type_form", ''); + + if($type_form == 'save'){ + $tabs = '
'; + $tabs .= ""; + + $tabs .= '
'; + $tabs .= '
'; + $tabs .= '
'; + $tabs .= '
'; + $tabs .= "
"; + echo $tabs; + } + else{ + $table = new StdClass; + $table->id = 'save_filter_form'; + $table->width = '100%'; + $table->class = 'databox'; + + $array_filters = get_filters_custom_fields_view(0, true); + $table->data[0][0] = __('Filter name'); + $table->data[0][1] = html_print_select( + $array_filters, 'id_name', + '', '', '', '', + true, false, true, '', false + ); + $table->data[0][3] = html_print_submit_button (__('Load filter'), 'load_filter', false, 'class="sub upd"', true); + + echo "
"; + html_print_table($table); + echo "
"; + } + return; +} + +if($append_tab_filter){ + $filters = json_decode(io_safe_output(get_parameter("filters", '')), true); + + $table = new StdClass; + $table->id = 'save_filter_form'; + $table->width = '100%'; + $table->class = 'databox'; + + if($filters['id'] == 'extended_create_filter'){ + echo "
"; + $table->data[0][0] = __('Filter name'); + $table->data[0][1] = html_print_input_text('id_name', '', '', 15, 255, true); + $table->data[0][2] = html_print_submit_button (__('Create filter'), 'create_filter', false, 'class="sub upd"', true); + } + else{ + echo "
"; + echo "
"; + $array_filters = get_filters_custom_fields_view(0, true); + $table->data[0][0] = __('Filter name'); + $table->data[0][1] = html_print_select( + $array_filters, 'id_name', + '', '', __('None'), -1, + true, false, true, '', false + ); + $table->data[0][2] = html_print_submit_button (__('Delete filter'), 'delete_filter', false, 'class="sub upd"', true); + $table->data[0][3] = html_print_submit_button (__('Update filter'), 'update_filter', false, 'class="sub upd"', true); + } + + html_print_table($table); + return; +} + +if($create_filter_cf){ + //initialize result + $result_array = array(); + $result_array['error'] = 0; + $result_array['msg'] = ''; + + //initialize vars + $filters = json_decode(io_safe_output(get_parameter("filters", '')), true); + $name_filter = get_parameter("name_filter", ''); + + //check that the name is not empty + if($name_filter == ''){ + $result_array['error'] = 1; + $result_array['msg'] = ui_print_error_message( + __('The name must not be empty'), + '', true + ); + echo json_encode($result_array); + return; + } + + $name_exists = get_filters_custom_fields_view(0, false, $name_filter); + + if($name_exists){ + $result_array['error'] = 1; + $result_array['msg'] = ui_print_error_message( + __('Filter name already exists in the bbdd'), + '', true + ); + echo json_encode($result_array); + return; + } + + //check custom field is not empty + if($filters['id_custom_fields'] == ''){ + $result_array['error'] = 1; + $result_array['msg'] = ui_print_error_message( + __('Please, select a custom field'), + '', true + ); + echo json_encode($result_array); + return; + } + + //insert + $values = array(); + $values['name'] = $name_filter; + $values['id_group'] = $filters['group']; + $values['id_custom_field'] = $filters['id_custom_fields']; + $values['id_custom_fields_data'] = json_encode($filters['id_custom_fields_data']); + $values['id_status'] = json_encode($filters['id_status']); + $values['module_search'] = $filters['module_search']; + + $insert = db_process_sql_insert('tagent_custom_fields_filter', $values); + + //check error insert + if($insert) { + $result_array['error'] = 0; + $result_array['msg'] = ui_print_success_message( + __("Success create filter."), + '', true + ); + } else { + $result_array['error'] = 1; + $result_array['msg'] = ui_print_error_message( + __("Error create filter."), + '', true + ); + } + + echo json_encode($result_array); + return; +} + +if($update_filter_cf){ + //initialize result + $result_array = array(); + $result_array['error'] = 0; + $result_array['msg'] = ''; + + //initialize vars + $filters = json_decode(io_safe_output(get_parameter("filters", '')), true); + $id_filter = get_parameter("id_filter", ''); + + //check selected filter + if($id_filter == -1){ + $result_array['error'] = 1; + $result_array['msg'] = ui_print_error_message( + __('please, select a filter'), + '', true + ); + echo json_encode($result_array); + return; + } + + //array condition update + $condition = array(); + $condition['id'] = $id_filter; + + //check selected custom fields + if($filters['id_custom_fields'] == ''){ + $result_array['error'] = 1; + $result_array['msg'] = ui_print_error_message( + __('please, select a custom field'), + '', true + ); + echo json_encode($result_array); + return; + } + + //array values update + $values = array(); + $values['id_group'] = $filters['group']; + $values['id_custom_field'] = $filters['id_custom_fields']; + $values['id_custom_fields_data'] = json_encode($filters['id_custom_fields_data']); + $values['id_status'] = json_encode($filters['id_status']); + $values['module_search'] = $filters['module_search']; + + //update + $update = db_process_sql_update('tagent_custom_fields_filter', $values, $condition); + + //check error insert + if($update) { + $result_array['error'] = 0; + $result_array['msg'] = ui_print_success_message( + __("Success update filter."), + '', true + ); + } else { + $result_array['error'] = 1; + $result_array['msg'] = ui_print_error_message( + __("Error update filter."), + '', true + ); + } + + echo json_encode($result_array); + return; +} + +if($delete_filter_cf){ + //Initialize result + $result_array = array(); + $result_array['error'] = 0; + $result_array['msg'] = ''; + + //Initialize vars + $filters = json_decode(io_safe_output(get_parameter("filters", '')), true); + $id_filter = get_parameter("id_filter", ''); + + //Check selected filter + if($id_filter == -1){ + $result_array['error'] = 1; + $result_array['msg'] = ui_print_error_message( + __('please, select a filter'), + '', true + ); + echo json_encode($result_array); + return; + } + + //Array condition update + $condition = array(); + $condition['id'] = $id_filter; + + //Delete + $delete = db_process_sql_delete('tagent_custom_fields_filter', $condition); + + //Check error insert + if($delete) { + $result_array['error'] = 0; + $result_array['msg'] = ui_print_success_message( + __("Success delete filter."), + '', true + ); + } else { + $result_array['error'] = 1; + $result_array['msg'] = ui_print_error_message( + __("Error delete filter."), + '', true + ); + } + + echo json_encode($result_array); + return; +} + } ?> diff --git a/pandora_console/include/functions_agents.php b/pandora_console/include/functions_agents.php index fe9972e9db..533d9665a2 100644 --- a/pandora_console/include/functions_agents.php +++ b/pandora_console/include/functions_agents.php @@ -3204,4 +3204,33 @@ function agent_counters_custom_fields($filters){ return $final_result; } + +function get_filters_custom_fields_view($id = 0, $for_select = false, $name = ""){ + if($for_select){ + $query = "SELECT id, `name` FROM tagent_custom_fields_filter"; + $rs = db_get_all_rows_sql($query); + if(isset($rs) && is_array($rs)){ + foreach ($rs as $key => $value) { + $result[$value['id']] = $value['name']; + } + } + else{ + $result = false; + } + } + else{ + $query = "SELECT * FROM tagent_custom_fields_filter WHERE 1=1"; + + if($id){ + $query .= " AND id = " . $id; + } + + if($name){ + $query .= " AND `name` = '" . $name . "'"; + } + + $result = db_get_all_rows_sql($query); + } + return $result; +} ?> \ No newline at end of file diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index 00e1b63aba..66bb3f6f14 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -1133,6 +1133,7 @@ CREATE TABLE IF NOT EXISTS `tusuario` ( `default_event_filter` int(10) unsigned NOT NULL default 0, `autorefresh_white_list` text not null default '', `time_autorefresh` int(5) unsigned NOT NULL default '30', + `default_custom_view` int(10) unsigned NULL default '0', CONSTRAINT `fk_filter_id` FOREIGN KEY (`id_filter`) REFERENCES tevent_filter (`id_filter`) ON DELETE SET NULL, UNIQUE KEY `id_user` (`id_user`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; @@ -3357,3 +3358,17 @@ CREATE TABLE IF NOT EXISTS `tlog_graph_models` ( `average` tinyint(1) NOT NULL default '0', PRIMARY KEY(`id`) ) ENGINE = InnoDB DEFAULT CHARSET=utf8; + +-- --------------------------------------------------------------------- +-- Table `tagent_custom_fields_filter` +-- --------------------------------------------------------------------- +CREATE TABLE IF NOT EXISTS `tagent_custom_fields_filter` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `name` varchar(600) NOT NULL, + `id_group` int(10) unsigned default '0', + `id_custom_field` varchar(600) default '', + `id_custom_fields_data` varchar(600) default '', + `id_status` varchar(600) default '', + `module_search` varchar(600) default '', + PRIMARY KEY(`id`) +) ENGINE = InnoDB DEFAULT CHARSET=utf8; \ No newline at end of file