From d6bffbade18f638b124fa62cf115b467f430425b Mon Sep 17 00:00:00 2001 From: "alejandro.campos@artica.es" Date: Mon, 20 Nov 2023 16:52:49 +0100 Subject: [PATCH] implement demo data load --- pandora_console/godmode/menu.php | 2 +- pandora_console/godmode/setup/demo.php | 21 +- .../include/ajax/demo_data.ajax.php | 1471 +++++++++++++---- .../include/class/WelcomeWindow.class.php | 2 +- pandora_console/include/db/mysql.php | 10 +- pandora_console/include/db/oracle.php | 4 +- pandora_console/include/db/postgresql.php | 4 +- pandora_console/include/functions_db.php | 8 +- 8 files changed, 1185 insertions(+), 337 deletions(-) diff --git a/pandora_console/godmode/menu.php b/pandora_console/godmode/menu.php index 059d19bae9..0e41b1925b 100644 --- a/pandora_console/godmode/menu.php +++ b/pandora_console/godmode/menu.php @@ -507,7 +507,7 @@ if ($access_console_node === true) { enterprise_hook('skins_submenu'); - $sub['godmode/setup/demo']['text'] = __('Demo'); + $sub['godmode/setup/demo']['text'] = __('Demo data'); $sub['godmode/setup/demo']['id'] = 'demo'; $menu_godmode['gsetup']['sub'] = $sub; diff --git a/pandora_console/godmode/setup/demo.php b/pandora_console/godmode/setup/demo.php index d0d65c748f..9edaedd957 100644 --- a/pandora_console/godmode/setup/demo.php +++ b/pandora_console/godmode/setup/demo.php @@ -38,6 +38,7 @@ config_update_value('demo_data_load_progress', 0); html_print_input_hidden('demo_items_count', 0); +$agents_num = (int) get_parameter('agents_num', 30); $submit_value = (string) get_parameter('update_button', ''); $demo_items_count = db_get_value('count(*)', 'tdemo_data'); $demo_agents_count = db_get_value('count(*)', 'tdemo_data', 'table_name', 'tagente'); @@ -130,7 +131,7 @@ $table_aux->data['row1'][] = html_print_label_input_block( 'content' => html_print_select( $arraySelectIcon, 'agents_num', - $config['gis_default_icon'], + $agents_num, '', '30', 30, @@ -291,10 +292,14 @@ $actionButtons[] = html_print_submit_button( true ); +echo ''; + echo ''; ?> @@ -308,9 +313,11 @@ echo ''; var agents_str = ''; var delete_demo_data_str = ''; - + + $('#btn-set').show(); if (demo_agents_count > 0) { $('#span-btn-delete-demo-data').text(delete_demo_data_str+' ('+demo_agents_count+')'); + $('#btn-create-demo-data').hide(); $('#btn-delete-demo-data').show(); } @@ -326,7 +333,7 @@ echo ''; var params = {}; params["action"] = "create_demo_data"; params["page"] = "include/ajax/demo_data.ajax"; - params["agents_num"] = $('#agents_num').val(); + params["agents_num"] = ; jQuery.ajax({ data: params, @@ -335,13 +342,16 @@ echo ''; dataType: 'json', success: function(data) { if (data.agents_count > 0) { + $('#btn-create-demo-data').hide(); $('#span-btn-delete-demo-data').text(delete_demo_data_str+' ('+data.agents_count+')'); $('#agent-count-span').text('('+(data.agents_count ?? 0)+' '+agent_count_span_str+')'); $('#btn-delete-demo-data').show(); } }, - error: function(XMLHttpRequest, textStatus, errorThrown) { - console.log("ERROR"); + error: function(jqXHR, textStatus, errorThrown) { + // Handle error + console.log('Error: ' + textStatus + ' - ' + errorThrown); + console.log(jqXHR.responseText); } }); } @@ -362,6 +372,7 @@ echo ''; $('#span-btn-delete-demo-data').text(delete_demo_data_str); $('#agent-count-span').text('('+(data.agents_count ?? 0)+' '+agent_count_span_str+')'); $('#btn-delete-demo-data').hide(); + $('#btn-create-demo-data').show(); }, error: function(XMLHttpRequest, textStatus, errorThrown) { console.log("ERROR"); diff --git a/pandora_console/include/ajax/demo_data.ajax.php b/pandora_console/include/ajax/demo_data.ajax.php index c2d163054a..66be29f692 100644 --- a/pandora_console/include/ajax/demo_data.ajax.php +++ b/pandora_console/include/ajax/demo_data.ajax.php @@ -1,6 +1,6 @@ 0) { - // Read all ini files. - $parsed_ini[] = parse_ini_file($config['homedir'].'/extras/demodata/agents/linux.ini', true, INI_SCANNER_TYPED); + // Read agent ini files. + $directories = [ + 'agents', + 'graphs', + 'network_maps', + 'services', + 'reports', + ]; - $ag_groups_num = ($agents_num / 10); + $demodata_directory = $config['homedir'].'/extras/demodata/'; - // Create new group per group of ten agents that are to be created. - for ($i=0; $i<$ag_groups_num; $i++) { - $group_name = db_get_value_sql( - 'SELECT tg.nombre - FROM tdemo_data tdd INNER JOIN tgrupo tg ON tdd.item_id = tg.id_grupo - WHERE tdd.table_name = "tgrupo" - ORDER BY tdd.id DESC' - ); + foreach ($directories as $directory) { + $directory_path = $demodata_directory.$directory; + if (is_dir($directory_path)) { + $files = scandir($directory_path); + $files = array_diff($files, ['.', '..']); + } - if ($group_name === false) { - $group_last_id = 0; - } else { - $group_last_id = (int) explode(' ', $group_name)[2]; - } + foreach ($files as $file) { + $parsed_ini[$directory][] = parse_ini_file($directory_path.'/'.$file, true, INI_SCANNER_TYPED); + } + } - if (!($group_last_id > -1)) { - echo json_encode(['msg' => 'Demo group ID not valid']); - return; - } + $total_agents_to_create = (int) get_parameter('agents_num', 0); - $demo_group_name = 'Demo group '.($i + $group_last_id + 1); + if ($total_agents_to_create > 0) { + $agents_to_create = 0; + $agents_created_count = []; - $created_group_id = groups_create_group($demo_group_name, []); - - if ($created_group_id > 0) { - $demo_group_ids[] = $created_group_id; - - // Register created demo item in tdemo_data. - $values = [ - 'item_id' => $created_group_id, - 'table_name' => 'tgrupo', - ]; - $result = (bool) db_process_sql_insert('tdemo_data', $values); - - if ($result === false) { - // Rollback group creation. - db_process_sql_delete('tgrupo', ['id_grupo' => $created_group_id]); - } - } else { - echo json_encode(['msg' => 'Could not create demo agent group']); - return; + // First loop over agents to get the total agents to be created and init agent created count for each agent. + foreach ($parsed_ini['agents'] as $ini_agent_data) { + if (isset($ini_agent_data['agent_data']['agents_number']) === true + && $ini_agent_data['agent_data']['agents_number'] > 0 + ) { + $agents_to_create += (int) $ini_agent_data['agent_data']['agents_number']; + $agents_created_count[$ini_agent_data['agent_data']['agent_name']] = 0; } } - $agents_created_count = 0; - $group_idx = 0; + $agent_created_total = 0; - $agent_alias = db_get_value_sql('SELECT ta.alias FROM tdemo_data tdd INNER JOIN tagente ta ON tdd.item_id = ta.id_agente WHERE tdd.table_name="tagente" ORDER BY tdd.id DESC'); + if ($total_agents_to_create > 0 && $agents_to_create > 0) { + while ($agent_created_total < $total_agents_to_create) { + // Traverse agent ini files and create agents. + foreach ($parsed_ini['agents'] as $ini_agent_data) { + // Read blocks: agent data, modules, inventory, inventory values. + $agent_data = $ini_agent_data['agent_data']; - if ($agent_alias === false) { - $agent_last_id = 0; - } else { - $agent_last_id = (int) explode(' ', $agent_alias)[1]; - } - - // Traverse ini files and create items. - foreach ($parsed_ini as $ini_so_data) { - $agent_data = $ini_so_data['agent_data']; - $modules_data = $ini_so_data['modules']; - $inventory = $ini_so_data['inventory']; - $inventory_values = $ini_so_data['inventory_values']; - - $address_network = $agent_data['address_network']; - $os_versions = $agent_data['os_versions']; - $os_name = $agent_data['os_name']; - - // Get OS id given OS name. - $id_os = db_get_value_filter('id_os', 'tconfig_os', ['name' => $os_name]); - - if ($id_os === false) { - // Create OS if does not exist. - $values = ['name' => $os_name]; - $id_os = (bool) db_process_sql_insert('tconfig_os', $values); - - if ($id_os === false) { - continue; - } - - if ($id_os > 0) { - // Register created OS in tdemo_data. - $values = [ - 'item_id' => $id_os, - 'table_name' => 'tconfig_os', - ]; - $result = (bool) db_process_sql_insert('tdemo_data', $values); - - if ($result === false) { - // Rollback OS creation if could not be registered in tdemo_data. - db_process_sql_delete('tconfig_os', ['id_os' => $id_os]); + if (isset($agent_data['agents_number']) === true + && !((int) $agent_data['agents_number'] > 0) + ) { + // No agents are specified to be created for this agent. continue; } - } - } - // Define agents to be created per group of 10. - $agents_per_os = [ - 'Linux' => 5, - 'Windows' => 2, - 'MAC OS' => 1, - 'BSD' => 1, - 'Cisco' => 1, - ]; + $iter_agents_to_create = $agent_data['agents_number']; - $agents_to_create = ($ag_groups_num * $agents_per_os[$os_name]); - - for ($i = 0; $i < $agents_to_create; $i++) { - $next_ip_address = calculateNextHostAddress($address_network); - - $os_version = current($os_versions); - next($os_versions); - - if (current($os_versions) === false) { - reset($os_versions); - } - - $agent_last_id++; - - $created_agent_id = agents_create_agent( - $agent_data['agent_alias'].' '.$agent_last_id, - $demo_group_ids[$group_idx], - // Default interval. - 300, - $next_ip_address, - false, - false, - $id_os, - $os_version - ); - - if ($created_agent_id > 0) { - // Register created demo item in tdemo_data. - $values = [ - 'item_id' => $created_agent_id, - 'table_name' => 'tagente', - ]; - $result = (bool) db_process_sql_insert('tdemo_data', $values); - - if ($result === false) { - // Rollback agent creation if could not be registered in tdemo_data. - db_process_sql_delete('tagente', ['id_agente' => $created_agent_id]); - continue; - } - } - - $agents_created_count++; - - $percentage_inc = ((($agents_created_count * 100) / $agents_to_create) / count($parsed_ini)); - $current_progress_val = db_get_value_filter('value', 'tconfig', ['token' => 'demo_data_load_progress']); - - if ($current_progress_val === false) { - $current_progress_val = 0; - } - - config_update_value('demo_data_load_progress', ($current_progress_val + $percentage_inc)); - - if (($agents_created_count % 10) === 0) { - $group_idx++; - } - - // Create agent modules. - $module_access_idx = 1; - - while (1) { - $modules_array = []; - foreach ($modules_data as $key => $value) { - $modules_array[$key] = ($value[$module_access_idx] ?? null); - } - - $test_empty_array = array_filter($modules_array); - - if (empty($test_empty_array) === true) { + if (($agent_created_total + $iter_agents_to_create) >= $total_agents_to_create) { + // Total agents limit specified by user has been reached. break; + } else { + // Calculate max number of agents that can be created in this iteration until max number specified by user is reached. + $max_agents_to_limit = ($total_agents_to_create - ($agent_created_total + $iter_agents_to_create)); } - $id_tipo = db_get_value_filter('id_tipo', 'ttipo_modulo', ['nombre' => $modules_array['type']]); + $modules_data = $ini_agent_data['modules']; + $inventory = $ini_agent_data['inventory']; + $inventory_values = $ini_agent_data['inventory_values']; + $traps = $ini_agent_data['traps']; - $values = [ - 'unit' => $modules_array['unit'], - 'descripcion' => $modules_array['description'], - 'id_tipo_modulo' => $id_tipo, - 'id_module_group' => ($modules_array['group'] ?? 0), - ]; + $address_network = $agent_data['address_network']; - $created_mod_id = modules_create_agent_module( - $created_agent_id, - io_safe_input($modules_array['name']), - $values - ); + if (isset($agent_data['mac']) === true && is_string($agent_data['mac']) === true) { + $mac = $agent_data['mac']; + if ($agent_data['mac'] === '__randomMAC__') { + $mac = generateRandomMacAddress(); + } + } - if ($created_mod_id > 0) { - // Register created demo item in tdemo_data. - $values = [ - 'item_id' => $created_mod_id, - 'table_name' => 'tagente_modulo', - ]; + if (isset($address_network) === false || is_string($address_network) === false) { + // Agent address is not specified or not valid. + continue; + } - $result = (bool) db_process_sql_insert('tdemo_data', $values); + $os_versions = $agent_data['os_versions']; + $os_name = $agent_data['os_name']; + $group_name = $agent_data['group']; - if ($result === false) { - // Rollback agent module creation if could not be registered in tdemo_data. - db_process_sql_delete('tagente_modulo', ['id_agente_modulo' => $created_mod_id]); + // Get OS id given OS name. + $id_os = db_get_value_filter('id_os', 'tconfig_os', ['name' => $os_name]); + + if ($id_os === false) { + // Create OS if does not exist. + $values = ['name' => $os_name]; + $id_os = (bool) db_process_sql_insert('tconfig_os', $values); + + if ($id_os === false) { + // Could not create OS. Skip agent creation. continue; } - // Insert module data. - $parsed = explode(';', $modules_array['values']); + if ($id_os > 0) { + // Register created OS in tdemo_data. + $values = [ + 'item_id' => $id_os, + 'table_name' => 'tconfig_os', + ]; + $result = (bool) db_process_sql_insert('tdemo_data', $values); - if ((string) $parsed[0] === 'RANDOM') { - $data = rand($parsed[1], $parsed[2]); - } else if ((string) $parsed[0] === 'PROC') { - $probability = (int) $parsed[1]; + if ($result === false) { + // Rollback OS creation if could not be registered in tdemo_data. + db_process_sql_delete('tconfig_os', ['id_os' => $id_os]); + continue; + } + } + } - $data = 0; + $group_id = get_group_or_create_demo_group($group_name); - if ($probability > 0) { - $randomNumber = rand(1, 100); + // Create agents (remaining number of agents to reach number specified by user). + for ($i = 0; $i < min($iter_agents_to_create, $max_agents_to_limit); $i++) { + $next_ip_address = calculateNextHostAddress($address_network); - if ($randomNumber <= $probability) { - $data = 1; + $os_version = current($os_versions); + next($os_versions); + + if (current($os_versions) === false) { + reset($os_versions); + } + + $created_agent_id = agents_create_agent( + $agent_data['agent_alias'].'-'.($agents_created_count[$agent_data['agent_name']] + 1), + $group_id, + // Default interval. + 300, + $next_ip_address, + false, + true, + $id_os, + $os_version + ); + + if ($created_agent_id > 0) { + // Register created demo item in tdemo_data. + $values = [ + 'item_id' => $created_agent_id, + 'table_name' => 'tagente', + ]; + $result = (bool) db_process_sql_insert('tdemo_data', $values); + + if ($result === false) { + // Rollback agent creation if could not be registered in tdemo_data. + db_process_sql_delete('tagente', ['id_agente' => $created_agent_id]); + continue; + } + } else { + // Could not create agent. Skip. + continue; + } + + $agents_created_count[$agent_data['agent_name']]++; + + // Calculate progress. + $percentage_inc = (100 / ($agents_to_create * count($parsed_ini))); + $current_progress_val = db_get_value_filter( + 'value', + 'tconfig', + ['token' => 'demo_data_load_progress'], + 'AND', + false, + false + ); + + if ($current_progress_val === false) { + $current_progress_val = 0; + } + + config_update_value('demo_data_load_progress', ($current_progress_val + $percentage_inc)); + + // Create agent modules. + $module_access_idx = 1; + + while (1) { + $modules_array = []; + foreach ($modules_data as $key => $value) { + $modules_array[$key] = ($value[$module_access_idx] ?? null); + } + + $module_access_idx++; + + $test_empty_array = array_filter($modules_array); + + if (empty($test_empty_array) === true) { + break; + } + + $id_tipo = db_get_value_filter('id_tipo', 'ttipo_modulo', ['nombre' => $modules_array['type']]); + + if (isset($modules_array['type']) === false + || is_string($modules_array['type']) === false + ) { + // Module type not defined. + continue; + } + + $module_description = ''; + + if (isset($modules_array['description']) === true && is_string($modules_array['description']) === true) { + $module_description = str_replace('_mac_', $mac, $modules_array['description']); + } + + $values = [ + 'unit' => $modules_array['unit'], + 'descripcion' => $module_description, + 'id_tipo_modulo' => $id_tipo, + 'id_module_group' => ($modules_array['group'] ?? 0), + ]; + + $created_mod_id = modules_create_agent_module( + $created_agent_id, + io_safe_input($modules_array['name']), + $values + ); + + if ($created_mod_id > 0) { + // Register created demo item in tdemo_data. + $values = [ + 'item_id' => $created_mod_id, + 'table_name' => 'tagente_modulo', + ]; + + $result = (bool) db_process_sql_insert('tdemo_data', $values); + + if ($result === false) { + // Rollback agent module creation if could not be registered in tdemo_data. + db_process_sql_delete('tagente_modulo', ['id_agente_modulo' => $created_mod_id]); + continue; + } + + // Insert module data. + $parsed = explode(';', $modules_array['values']); + + $date_time = new DateTime(); + $current_date_time = $date_time->format('Y-m-d H:i:s'); + $back_periods = 10; + $period_mins = 5; + + $utimestamp = time(); + + // Generate back_periods amounts of tagente_datos rows each period_mins minutes back in time. + for ($p = 0; $p < $back_periods; $p++) { + if ((string) $parsed[0] === 'RANDOM') { + $data = rand($parsed[1], $parsed[2]); + } else if ((string) $parsed[0] === 'PROC') { + $probability = (int) $parsed[1]; + + $data = 1; + + if ($probability > 0) { + $randomNumber = rand(1, 100); + + if ($randomNumber <= $probability) { + // Set to 0 with a certain probability. + $data = 0; + } + } + } + + $agent_data_values = [ + 'id_agente_modulo' => $created_mod_id, + 'datos' => $data, + 'utimestamp' => $utimestamp, + ]; + + $created_data_id = db_process_sql_insert('tagente_datos', $agent_data_values); + + if ($created_data_id > 0) { + // Register created demo item in tdemo_data. + $values = [ + 'item_id' => $created_data_id, + 'table_name' => 'tagente_datos', + ]; + + $result = (bool) db_process_sql_insert('tdemo_data', $values); + + if ($result === false) { + // Rollback demo item creation if could not be registered in tdemo_data. + db_process_sql_delete('tagente_datos', ['id_agente_modulo' => $created_data_id]); + continue; + } + } + + $utimestamp -= 300; + } + } + }; + + // Create inventory modules. + $module_access_idx = 1; + $date_time = new DateTime(); + $current_date_time = $date_time->format('Y-m-d H:i:s'); + + while (1) { + // Insert in tmodule_inventory. + $modules_array = []; + foreach ($inventory as $key => $value) { + $modules_array[$key] = ($value[$module_access_idx] ?? null); + } + + $module_access_idx++; + + $test_empty_array = array_filter($modules_array); + + if (empty($test_empty_array) === true) { + break; + } + + $values = [ + 'name' => $modules_array['name'], + 'data_format' => $modules_array['format'], + 'id_os' => $id_os, + ]; + + $created_inventory_mod_id = inventory_create_inventory_module($values); + + if ($created_inventory_mod_id > 0) { + // Register created demo item in tdemo_data. + $values = [ + 'item_id' => $created_inventory_mod_id, + 'table_name' => 'tmodule_inventory', + ]; + $result = (bool) db_process_sql_insert('tdemo_data', $values); + + if ($result === false) { + // Rollback inventory module if could not be registered in tdemo_data. + db_process_sql_delete('tmodule_inventory', ['id_module_inventory' => $created_inventory_mod_id]); + continue; + } + } + + // Insert in tagent_module_inventory and tagente_datos_inventory. + $field_idx = 1; + $values_array = explode(';', $modules_array['values']); + + $selected_inventory_values = array_filter( + $inventory_values, + function ($key) use ($values_array) { + return in_array($key, $values_array); + }, + ARRAY_FILTER_USE_KEY + ); + + $data_lines = []; + while (1) { + $line_values = array_column($selected_inventory_values, $field_idx); + + if (empty(array_filter($line_values)) === true) { + break; + } + + $data_lines[] = implode(';', $line_values); + $field_idx++; + } + + $data_str = implode('\n', $data_lines); + + $values = [ + 'id_agente' => $created_agent_id, + 'id_module_inventory' => $created_inventory_mod_id, + 'interval' => 300, + 'utimestamp' => time(), + 'timestamp' => $current_date_time, + 'data' => $data_str, + ]; + + $created_module_inventory_id = db_process_sql_insert('tagent_module_inventory', $values); + + if ($created_module_inventory_id > 0) { + // Register created demo item in tdemo_data. + $values = [ + 'item_id' => $created_module_inventory_id, + 'table_name' => 'tagent_module_inventory', + ]; + $result = (bool) db_process_sql_insert('tdemo_data', $values); + + if ($result === false) { + // Rollback inventory module if could not be registered in tdemo_data. + db_process_sql_delete('tagent_module_inventory', ['id_agent_module_inventory' => $created_module_inventory_id]); + continue; + } + } + + $inventory_data_values = [ + 'id_agent_module_inventory' => $created_module_inventory_id, + 'data' => $data_str, + 'utimestamp' => time(), + 'timestamp' => $current_date_time, + ]; + + $created_inventory_data = db_process_sql_insert('tagente_datos_inventory', $inventory_data_values); + + if ($created_inventory_data > 0) { + // Register created inventory data element in tdemo_data. + $values = [ + 'item_id' => $created_inventory_data, + 'table_name' => 'tagente_datos_inventory', + ]; + $result = (bool) db_process_sql_insert('tdemo_data', $values); + + if ($result === false) { + // Rollback inventory module if could not be registered in tdemo_data. + db_process_sql_delete( + 'tagente_datos_inventory', + ['id_agent_module_inventory' => $created_inventory_data] + ); + + continue; } } } - $agent_data_values = [ - 'id_agente_modulo' => $created_mod_id, - 'datos' => $data, - 'utimestamp' => time(), - ]; + // Create traps. + $date_time = new DateTime(); + $current_date_time = $date_time->format('Y-m-d H:i:s'); + $back_periods = 10; + $period_mins = 5; + $utimestamp = time(); - db_process_sql_insert('tagente_datos', $agent_data_values); - } + for ($p = 0; $p < $back_periods; $p++) { + $trap_access_idx = 1; - $module_access_idx++; - }; + while (1) { + $traps_array = []; + foreach ($traps as $key => $value) { + $traps_array[$key] = ($value[$trap_access_idx] ?? null); + } - // Create inventory modules. - $module_access_idx = 1; - $date_time = new DateTime(); - $current_date_time = $date_time->format('Y-m-d H:i:s'); + $trap_access_idx++; + $test_empty_array = array_filter($traps_array); - while (1) { - // Insert in tmodule_inventory. - $modules_array = []; - foreach ($inventory as $key => $value) { - $modules_array[$key] = ($value[$module_access_idx] ?? null); - } + if (empty($test_empty_array) === true) { + break; + } - $test_empty_array = array_filter($modules_array); + $create_trap = false; + if (isset($traps_array['chance_percent']) === false) { + // Chance percent must be specified. + continue; + } else { + $trap_creation_prob = (int) $traps_array['chance_percent']; - if (empty($test_empty_array) === true) { - break; - } + if ($trap_creation_prob > 0) { + $randomNumber = rand(1, 100); + if ($randomNumber <= $trap_creation_prob) { + $create_trap = true; + } + } + } - $values = [ - 'name' => $modules_array['name'], - 'data_format' => $modules_array['format'], - 'id_os' => 1, - ]; + if ($create_trap === false) { + continue; + } - $created_inventory_mod_id = inventory_create_inventory_module($values); + if (isset($traps_array['value']) === false || is_string($traps_array['value']) === false) { + // Trap value must be specified. + continue; + } else { + $parsed = explode(';', $traps_array['values']); - if ($created_inventory_mod_id > 0) { - // Register created demo item in tdemo_data. - $values = [ - 'item_id' => $created_inventory_mod_id, - 'table_name' => 'tmodule_inventory', - ]; - $result = (bool) db_process_sql_insert('tdemo_data', $values); + $data = ''; + if ((string) $parsed[0] === 'RANDOM') { + $data = rand($parsed[1], $parsed[2]); + } + } - if ($result === false) { - // Rollback inventory module if could not be registered in tdemo_data. - db_process_sql_delete('tmodule_inventory', ['id_module_inventory' => $created_inventory_mod_id]); - continue; + $values = [ + 'oid' => $traps_array['oid'], + 'value' => $data, + 'type' => $traps_array['snmp_type'], + 'timestamp' => $current_date_time, + 'utimestamp' => $utimestamp, + ]; + + $created_trap_id = db_process_sql_insert('ttrap', $values); + + if ($created_trap_id > 0) { + // Register created demo item in tdemo_data. + $values = [ + 'item_id' => $created_trap_id, + 'table_name' => 'ttrap', + ]; + $result = (bool) db_process_sql_insert('tdemo_data', $values); + + if ($result === false) { + // Rollback inventory module if could not be registered in tdemo_data. + db_process_sql_delete('ttrap', ['id_module_inventory' => $created_trap_id]); + continue; + } + } + } + + $date_time->sub(new DateInterval("PT{$period_mins}M")); + $current_date_time = $date_time->format('Y-m-d H:i:s'); + $utimestamp -= 300; } } + } - $module_access_idx++; + $agent_created_total = array_sum($agents_created_count); - // Insert in tagent_module_inventory and tagente_datos_inventory. - $field_idx = 1; - $values_array = explode(';', $modules_array['values']); - - $selected_inventory_values = array_filter( - $inventory_values, - function ($key) use ($values_array) { - return in_array($key, $values_array); - }, - ARRAY_FILTER_USE_KEY - ); - - $data_lines = []; - while (1) { - $line_values = array_column($selected_inventory_values, $field_idx); - - if (empty(array_filter($line_values)) === true) { - break; - } - - $data_lines[] = implode(';', $line_values); - $field_idx++; - } - - $data_str = implode('\n', $data_lines); - - $values = [ - 'id_agente' => $created_agent_id, - 'id_module_inventory' => $created_inventory_mod_id, - 'interval' => 300, - 'utimestamp' => time(), - 'timestamp' => $current_date_time, - 'data' => $data_str, - ]; - - $created_module_inventory_id = db_process_sql_insert('tagent_module_inventory', $values); - - if ($created_module_inventory_id > 0) { - // Register created demo item in tdemo_data. - $values = [ - 'item_id' => $created_module_inventory_id, - 'table_name' => 'tagent_module_inventory', - ]; - $result = (bool) db_process_sql_insert('tdemo_data', $values); - - if ($result === false) { - // Rollback inventory module if could not be registered in tdemo_data. - db_process_sql_delete('tagent_module_inventory', ['id_agent_module_inventory' => $created_module_inventory_id]); - continue; - } - } - - $inventory_data_values = [ - 'id_agent_module_inventory' => $created_module_inventory_id, - 'data' => $data_str, - 'utimestamp' => time(), - 'timestamp' => $current_date_time, - ]; - - $created_inventory_data = db_process_sql_insert('tagente_datos_inventory', $inventory_data_values); - - if ($created_inventory_data > 0) { - // Register created inventory data element in tdemo_data. - $values = [ - 'item_id' => $created_inventory_data, - 'table_name' => 'tagente_datos_inventory', - ]; - $result = (bool) db_process_sql_insert('tdemo_data', $values); - - if ($result === false) { - // Rollback inventory module if could not be registered in tdemo_data. - db_process_sql_delete( - 'tagente_datos_inventory', - ['id_agent_module_inventory' => $created_inventory_data] - ); - - continue; - } - } - }; + if ($agent_created_total === 0) { + // Stop traversing agent files if no agent could be created after first round. + break; + } } } } + // Create network maps. + foreach ($parsed_ini['network_maps'] as $ini_nm_data) { + $map_data = $ini_nm_data['map_data']; + $map_items = $ini_nm_data['map_items']; + + $nm_name = $map_data['name']; + $nm_group = $map_data['group']; + $nm_description = $map_data['description']; + $nm_node_radius = $map_data['node_radius']; + + $nm_id_group = get_group_or_create_demo_group($nm_group); + + if ($nm_id_group === false) { + // Network map could not be created. Skip network map creation. + continue; + } + + $values = []; + $new_map_filter = []; + $new_map_filter['dont_show_subgroups'] = 0; + $new_map_filter['node_radius'] = $nm_node_radius; + $new_map_filter['x_offs'] = 0; + $new_map_filter['y_offs'] = 0; + $new_map_filter['z_dash'] = '0.5'; + $new_map_filter['node_sep'] = '0.25'; + $new_map_filter['rank_sep'] = '0.25'; + $new_map_filter['mindist'] = 1; + $new_map_filter['kval'] = '0.3'; + $values['filter'] = json_encode($new_map_filter); + $values['description'] = $nm_description; + $values['id_group'] = $nm_id_group; + $values['name'] = $nm_name; + + $id_map = db_process_sql_insert('tmap', $values); + + if ($id_map > 0) { + // Register created map in tdemo_data. + $values = [ + 'item_id' => $id_map, + 'table_name' => 'tmap', + ]; + $result = (bool) db_process_sql_insert('tdemo_data', $values); + + if ($result === false) { + // Rollback demo item creation if could not be registered in tdemo_data. + db_process_sql_delete('tmap', ['id' => $id_map]); + continue; + } + } else { + // Network map group could not be created. Skip creation of map. + continue; + } + + if (count($map_items) > 0) { + $item_access_idx = 1; + + while (1) { + $items_array = []; + foreach ($map_items as $key => $value) { + $items_array[$key] = ($value[$item_access_idx] ?? null); + } + + $item_access_idx++; + + $test_empty_array = array_filter($items_array); + + if (empty($test_empty_array) === true) { + break; + } + + $item_values = []; + + $item_values['id_map'] = $id_map; + + if (isset($items_array['agent_name']) === true || is_string($items_array['agent_name']) === false) { + $matched_agents = agents_get_agents(['nombre' => $items_array['agent_name']], ['id_agente', 'id_os', 'alias']); + + $matched_agent = $matched_agents[0]['id_agente']; + $alias = $matched_agents[0]['alias']; + if (isset($matched_agent) === true && $matched_agent > 0) { + $item_values['source_data'] = $matched_agent; + if (isset($matched_agents[0]['id_agente']) === true && $matched_agents[0]['id_os']) { + $agent_os_id = $matched_agents[0]['id_os']; + $icon_name = db_get_value('icon_name', 'tconfig_os', 'id_os', $agent_os_id); + } + } else { + // Skip report item creation if agent does not exist. + continue; + } + } else { + continue; + } + + $style_values = [ + 'shape' => 'circle', + 'image' => 'images/networkmap/'.$icon_name, + 'width' => null, + 'height' => null, + 'label' => $alias, + ]; + + $item_values['style'] = json_encode($style_values); + $item_values['x'] = (isset($items_array['x']) === true) ? $items_array['x'] : '0'; + $item_values['y'] = (isset($items_array['y']) === true) ? $items_array['y'] : '0'; + + $created_nm_item_id = db_process_sql_insert('titem', $item_values); + + if ($created_nm_item_id > 0) { + // Register created demo item in tdemo_data. + $values = [ + 'item_id' => $created_nm_item_id, + 'table_name' => 'titem', + ]; + $result = (bool) db_process_sql_insert('tdemo_data', $values); + + if ($result === false) { + // Rollback demo item if could not be registered in tdemo_data. + db_process_sql_delete('titem', ['id' => $created_nm_item_id]); + continue; + } + } + } + } + + // Calculate progress. + $percentage_inc = (100 / count($parsed_ini)); + $current_progress_val = db_get_value_filter( + 'value', + 'tconfig', + ['token' => 'demo_data_load_progress'], + 'AND', + false, + false + ); + + if ($current_progress_val === false) { + $current_progress_val = 0; + } + + config_update_value('demo_data_load_progress', ($current_progress_val + $percentage_inc)); + } + + // Create graphs. + foreach ($parsed_ini['graphs'] as $ini_graph_data) { + // Constant graph types. + $graph_types = [ + 'line' => 2, + 'area' => 0, + 's_line' => 3, + 's_area' => 1, + 'h_bars' => 6, + 'v_bars' => 7, + 'gauge' => 5, + 'pie' => 8, + ]; + + $graph_data = $ini_graph_data['graph_data']; + $graph_items = $ini_graph_data['graph_items']; + + $graph_name = $graph_data['name']; + $graph_group = $graph_data['group']; + $graph_description = $graph_data['description']; + $graph_type = (isset($graph_types[$graph_data['type']]) === true) ? $graph_types[$graph_data['type']] : 0; + $graph_periodicity = $graph_data['periodicity']; + + $graph_id_group = get_group_or_create_demo_group($graph_group); + + if ($graph_id_group === false) { + // Group could not be created. Skip graph creation. + continue; + } + + $values = []; + $values['description'] = $graph_description; + $values['id_group'] = $graph_id_group; + $values['name'] = $graph_name; + $values['period'] = $graph_periodicity; + $values['stacked'] = $graph_type; + + $id_graph = db_process_sql_insert('tgraph', $values); + + if ($id_graph > 0) { + // Register created graph in tdemo_data. + $values = [ + 'item_id' => $id_graph, + 'table_name' => 'tgraph', + ]; + $result = (bool) db_process_sql_insert('tdemo_data', $values); + + if ($result === false) { + // Rollback graph creation if could not be registered in tdemo_data. + db_process_sql_delete('tgraph', ['id_graph' => $id_graph]); + continue; + } + } else { + // Graph could not be created. Skip creation of graph. + continue; + } + + if (count($graph_items) > 0) { + $item_access_idx = 1; + + while (1) { + $items_array = []; + foreach ($graph_items as $key => $value) { + $items_array[$key] = ($value[$item_access_idx] ?? null); + } + + $item_access_idx++; + + $test_empty_array = array_filter($items_array); + + if (empty($test_empty_array) === true) { + break; + } + + $item_values = []; + + if (isset($items_array['agent_name']) === false || is_string($items_array['agent_name']) === false) { + // Agent must be defined. Skip graph item creation. + continue; + } + + if (isset($items_array['module']) === false || is_string($items_array['module']) === false) { + // Module must be defined. Skip graph item creation. + continue; + } + + $matched_agents = agents_get_agents(['nombre' => $items_array['agent_name']], ['id_agente']); + $agent_id = $matched_agents[0]['id_agente']; + + $module_row = modules_get_agentmodule_id(io_safe_input($items_array['module']), $agent_id); + + $module_id = $module_row['id_agente_modulo']; + + if (!($module_id > 0)) { + continue; + } + + $item_values = [ + 'id_graph' => $id_graph, + 'id_agent_module' => $module_id, + ]; + + $created_graph_item_id = db_process_sql_insert('tgraph_source', $item_values); + + if ($created_graph_item_id > 0) { + // Register created demo item in tdemo_data. + $values = [ + 'item_id' => $created_graph_item_id, + 'table_name' => 'tgraph_source', + ]; + $result = (bool) db_process_sql_insert('tdemo_data', $values); + + if ($result === false) { + // Rollback demo item if could not be registered in tdemo_data. + db_process_sql_delete('tgraph_source', ['id_gs' => $created_graph_item_id]); + continue; + } + } + } + } + + // Calculate progress. + $percentage_inc = (100 / count($parsed_ini)); + $current_progress_val = db_get_value_filter( + 'value', + 'tconfig', + ['token' => 'demo_data_load_progress'], + 'AND', + false, + false + ); + + if ($current_progress_val === false) { + $current_progress_val = 0; + } + + config_update_value('demo_data_load_progress', ($current_progress_val + $percentage_inc)); + } + + // Create reports. + foreach ($parsed_ini['reports'] as $ini_report_data) { + $report_data = $ini_report_data['report_data']; + $report_items = $ini_report_data['report_items']; + + $group_id = get_group_or_create_demo_group($report_data['group']); + + if ($group_id === false) { + // Could not create group. Skip report creation. + continue; + } + + $report_values = []; + $report_values['id_group'] = $group_id; + $report_values['name'] = $report_data['name']; + $report_values['description'] = $report_data['description']; + + $created_report_id = db_process_sql_insert('treport', $report_values); + + if ($created_report_id > 0) { + // Register created graph in tdemo_data. + $values = [ + 'item_id' => $created_report_id, + 'table_name' => 'treport', + ]; + $result = (bool) db_process_sql_insert('tdemo_data', $values); + + if ($result === false) { + // Rollback report creation if could not be registered in tdemo_data. + db_process_sql_delete('treport', ['id_report' => $created_report_id]); + continue; + } + } else { + // Report could not be created. Skip creation of map. + continue; + } + + if (count($report_items) > 0) { + $item_access_idx = 1; + + while (1) { + $items_array = []; + foreach ($report_items as $key => $value) { + $items_array[$key] = ($value[$item_access_idx] ?? null); + } + + $item_access_idx++; + + $test_empty_array = array_filter($items_array); + + if (empty($test_empty_array) === true) { + break; + } + + $item_values = []; + + $item_values['id_report'] = $created_report_id; + + if (isset($items_array['agent_name']) === true) { + if (is_string($items_array['module']) === false) { + continue; + } + + $matched_agents = agents_get_agents(['nombre' => $items_array['agent_name']], ['id_agente']); + + $matched_agent = $matched_agents[0]['id_agente']; + if (isset($matched_agent) === true && $matched_agent > 0) { + $item_values['id_agent'] = $matched_agent; + } else { + // Skip report item creation if agent does not exist. + continue; + } + } + + if (isset($items_array['module']) === true) { + if (is_string($items_array['module']) === false) { + // Module wrong data type read. Skip. + continue; + } + + if ($item_values['id_agent'] > 0) { + $module_id = db_get_value_sql('SELECT id_agente_modulo FROM tagente_modulo WHERE nombre = "'.io_safe_input($items_array['module']).'" AND id_agente = '.$item_values['id_agent']); + + if ($module_id > 0) { + $item_values['id_agent_module'] = $module_id; + } else { + // Skip report item creation if agent module does not exist. + continue; + } + } else { + continue; + } + } + + if (isset($items_array['graph_name']) === true && is_string($items_array['graph_name']) === true) { + $id_custom_graph = reset(custom_graphs_search('', $items_array['graph_name']))['id_graph']; + + if ($id_custom_graph > 0) { + $item_values['id_gs'] = $id_custom_graph; + } else { + // Skip report item creation if specified custom graph does not exist. + continue; + } + } + + $created_report_item_id = db_process_sql_insert('treport_content', $item_values); + + if ($created_report_item_id > 0) { + // Register created demo item in tdemo_data. + $values = [ + 'item_id' => $created_report_item_id, + 'table_name' => 'treport_content', + ]; + $result = (bool) db_process_sql_insert('tdemo_data', $values); + + if ($result === false) { + // Rollback report item if could not be registered in tdemo_data. + db_process_sql_delete('treport_content', ['id_rc' => $created_report_item_id]); + continue; + } + } + } + } + + // Calculate progress. + $percentage_inc = (100 / count($parsed_ini)); + $current_progress_val = db_get_value_filter( + 'value', + 'tconfig', + ['token' => 'demo_data_load_progress'], + 'AND', + false, + false + ); + + if ($current_progress_val === false) { + $current_progress_val = 0; + } + + config_update_value('demo_data_load_progress', ($current_progress_val + $percentage_inc)); + } + + // Create services. + foreach ($parsed_ini['services'] as $ini_service_data) { + $service_data = $ini_service_data['service_data']; + $service_items = $ini_service_data['service_items']; + + // Check for mandatory fields. + if (isset($service_data['name']) === false + || isset($service_data['group']) === false + ) { + continue; + } + + $id_group = get_group_or_create_demo_group($service_data['group']); + + if ($id_group === false) { + // Group could not be created. Skip graph creation. + continue; + } + + $service_values = []; + + $service_values['name'] = $service_data['name']; + $service_values['description'] = $service_data['description']; + $service_values['id_group'] = $id_group; + $service_values['critical'] = $service_data['critical']; + $service_values['warning'] = $service_data['warning']; + $service_values['auto_calculate'] = (isset($service_data['mode']) === true && (string) $service_data['mode'] === 'smart') ? 1 : 0; + + $created_service_id = db_process_sql_insert('tservice', $service_values); + + if ($created_service_id > 0) { + // Register created service in tdemo_data. + $values = [ + 'item_id' => $created_service_id, + 'table_name' => 'tservice', + ]; + $result = (bool) db_process_sql_insert('tdemo_data', $values); + + if ($result === false) { + // Rollback service creation if could not be registered in tdemo_data. + db_process_sql_delete('tservice', ['id' => $created_service_id]); + continue; + } + } else { + // Service could not be created. Skip creation of map. + continue; + } + + if (count($service_items) > 0) { + $item_access_idx = 1; + while (1) { + $items_array = []; + foreach ($service_items as $key => $value) { + $items_array[$key] = ($value[$item_access_idx] ?? null); + } + + $item_access_idx++; + + $test_empty_array = array_filter($items_array); + + if (empty($test_empty_array) === true) { + break; + } + + $element_values = []; + + $element_values = ['id_service' => $created_service_id]; + + $element_type = (string) $items_array['type']; + + if (in_array($element_type, ['agent', 'module', 'dynamic', 'service']) === false) { + // Skip element creation if type not valid. + continue; + } + + if (in_array($element_type, ['agent', 'module', 'dynamic']) === true) { + // Get agent ID and module ID. + $matched_agents = agents_get_agents(['nombre' => $items_array['agent_name']], ['id_agente']); + $matched_agent = $matched_agents[0]['id_agente']; + + if (isset($matched_agent) === true && $matched_agent > 0) { + $element_values['id_agent'] = $matched_agent; + } else { + // Skip element creation if agent does not exist. + continue; + } + } + + if (in_array($element_type, ['module', 'dynamic']) === true) { + if ($element_values['id_agent'] > 0) { + $module_id = db_get_value_sql('SELECT id_agente_modulo FROM tagente_modulo WHERE nombre = "'.io_safe_input($items_array['module']).'" AND id_agente = '.$element_values['id_agent']); + + if ($module_id > 0) { + $element_values['id_agente_modulo'] = $module_id; + } else { + // Skip element creation if agent module does not exist. + continue; + } + } else { + continue; + } + } + + if ($element_type === 'dynamic') { + if ($service_values['auto_calculate'] === 1) { + if (isset($items_array['match']) === false + || ($items_array['match'] !== 'agent' && $items_array['match'] !== 'module') + ) { + // If failed to provide match value, 'agent' is assigned by default. + $match_value = 'agent'; + } else { + $match_value = $items_array['match']; + } + + if (isset($items_array['group']) === true) { + $group_id_value = get_group_or_create_demo_group($items_array['group']); + + if ($group_id_value === false) { + $group_id_value = -1; + } + } else { + $group_id_value = -1; + } + + $element_values['id_agent'] = 0; + $element_values['id_agente_modulo'] = 0; + + $rules_arr = [ + 'dynamic_type' => $match_value, + 'group' => $group_id_value, + 'agent_name' => (isset($items_array['agent_name']) === true) ? $items_array['agent_name'] : '', + 'module_name' => (isset($items_array['module']) === true) ? $items_array['module'] : '', + 'regex_mode' => (isset($items_array['regex']) === true) ? $items_array['regex'] : false, + 'custom_fields' => [], + ]; + + $element_values['rules'] = base64_encode(json_encode($rules_arr)); + } + } + + if ($element_type === 'service') { + if (isset($items_array['service_name']) === true + && is_string($items_array['service_name']) === true + ) { + $services = services_get_services(['name' => $items_array['service_name']]); + + $service_id = $services[0]['id']; + + if ($service_id > 0) { + $element_values['id_service_child'] = $service_id; + } else { + // Skip element creation if specified service does not exist. + continue; + } + } else { + // Skip element creation if service name was not provided. + continue; + } + } + + $id = db_process_sql_insert('tservice_element', $element_values); + + if ($id > 0) { + // Register created demo item in tdemo_data. + $values = [ + 'item_id' => $id, + 'table_name' => 'tservice_element', + ]; + $result = (bool) db_process_sql_insert('tdemo_data', $values); + + if ($result === false) { + // Rollback service element if could not be registered in tdemo_data. + db_process_sql_delete('tservice_element', ['id' => $id]); + continue; + } + } + } + } + + // Calculate progress. + $percentage_inc = (100 / count($parsed_ini)); + $current_progress_val = db_get_value_filter( + 'value', + 'tconfig', + ['token' => 'demo_data_load_progress'], + 'AND', + false, + false + ); + + if ($current_progress_val === false) { + $current_progress_val = 0; + } + + config_update_value('demo_data_load_progress', ($current_progress_val + $percentage_inc)); + } + + $demo_agents_count = db_get_value('count(*)', 'tdemo_data', 'table_name', 'tagente'); + echo json_encode(['agents_count' => $demo_agents_count]); return; @@ -421,6 +1193,16 @@ if ($action === 'cleanup_demo_data') { 'tmodule_inventory' => 'id_module_inventory', 'tagent_module_inventory' => 'id_agent_module_inventory', 'tagente_datos_inventory' => 'id_agent_module_inventory', + 'tgraph' => 'id_graph', + 'tmap' => 'id', + 'treport' => 'id_report', + 'treport_content' => 'id_rc', + 'tservice' => 'id', + 'tservice_element' => 'id', + 'ttrap' => 'id_trap', + 'tagente_datos' => 'id_agente_modulo', + 'titem' => 'id', + 'tgraph_source' => 'id_gs', ]; $table_id_field = $table_id_field_dict[$item['table_name']]; @@ -461,7 +1243,8 @@ if ($action === 'get_progress_bar') { return; } -function calculateNextHostAddress($ip) { +function calculateNextHostAddress($ip) +{ list($network, $subnet) = explode('/', $ip); // Convert the network address to an array of octets. @@ -478,3 +1261,53 @@ function calculateNextHostAddress($ip) { return $nextHost.'/'.$subnet; } + +function get_group_or_create_demo_group($name) +{ + if (is_string($name) === false) { + return false; + } + + $id_group = db_get_value('id_grupo', 'tgrupo', 'nombre', $name); + + if ($id_group > 0) { + return $id_group; + } else { + $id_group = groups_create_group($group, []); + + if ($id_group > 0) { + // Register created group in tdemo_data. + $values = [ + 'item_id' => $id_group, + 'table_name' => 'tgrupo', + ]; + $result = (bool) db_process_sql_insert('tdemo_data', $values); + + if ($result === false) { + // Rollback demo group creation if could not be registered in tdemo_data. + db_process_sql_delete('tgrupo', ['id_grupo' => $id_group]); + return false; + } + + return $id_group; + } else { + // Network map group could not be created. Skip creation of map. + return false; + } + } +} + +function generateRandomMacAddress() +{ + $macAddress = []; + + // Generate the remaining five octets. + for ($i = 0; $i < 6; $i++) { + $macAddress[] = str_pad(dechex(mt_rand(0, 255)), 2, '0', STR_PAD_LEFT); + } + + // Join the octets with colons to form the MAC address. + $randomMacAddress = implode(':', $macAddress); + + return $randomMacAddress; +} diff --git a/pandora_console/include/class/WelcomeWindow.class.php b/pandora_console/include/class/WelcomeWindow.class.php index cd057414d0..c0800e8b4c 100644 --- a/pandora_console/include/class/WelcomeWindow.class.php +++ b/pandora_console/include/class/WelcomeWindow.class.php @@ -1158,7 +1158,7 @@ class WelcomeWindow extends Wizard // Task to do actions. function loadDemoDataPage() { - window.location = ''; + window.location = ''; } function openCreateModulesDialog() { diff --git a/pandora_console/include/db/mysql.php b/pandora_console/include/db/mysql.php index e8e7a6b020..048ec8719f 100644 --- a/pandora_console/include/db/mysql.php +++ b/pandora_console/include/db/mysql.php @@ -655,7 +655,7 @@ function mysql_encapsule_fields_with_same_name_to_instructions($field) * * @return mixed Value of first column of the first row. False if there were no row. */ -function mysql_db_get_value_filter($field, $table, $filter, $where_join='AND', $search_history_db=false) +function mysql_db_get_value_filter($field, $table, $filter, $where_join='AND', $search_history_db=false, $cache=true) { if (!is_array($filter) || empty($filter)) { return false; @@ -672,7 +672,7 @@ function mysql_db_get_value_filter($field, $table, $filter, $where_join='AND', $ db_format_array_where_clause_sql($filter, $where_join) ); - $result = db_get_all_rows_sql($sql, $search_history_db); + $result = db_get_all_rows_sql($sql, $search_history_db, $cache); if ($result === false) { return false; @@ -1022,7 +1022,11 @@ function mysql_db_get_row_filter($table, $filter, $fields=false, $where_join='AN } $sql = sprintf('SELECT %s FROM %s %s', $fields, $table, $filter); - +if ($table==='tagente_modulo') { + hd("QUERYYYYYY", true); + hd($sql, true); +} + return db_get_row_sql($sql, $historydb, $cache); } diff --git a/pandora_console/include/db/oracle.php b/pandora_console/include/db/oracle.php index 3ec2b558a4..c712e6a008 100644 --- a/pandora_console/include/db/oracle.php +++ b/pandora_console/include/db/oracle.php @@ -574,7 +574,7 @@ function oracle_encapsule_fields_with_same_name_to_instructions($field) * * @return mixed Value of first column of the first row. False if there were no row. */ -function oracle_db_get_value_filter($field, $table, $filter, $where_join='AND', $search_history_db=false) +function oracle_db_get_value_filter($field, $table, $filter, $where_join='AND', $search_history_db=false, $cache=true) { if (! is_array($filter) || empty($filter)) { return false; @@ -590,7 +590,7 @@ function oracle_db_get_value_filter($field, $table, $filter, $where_join='AND', $table, db_format_array_where_clause_sql($filter, $where_join) ); - $result = db_get_all_rows_sql($sql, $search_history_db); + $result = db_get_all_rows_sql($sql, $search_history_db, $cache); if ($result === false) { return false; diff --git a/pandora_console/include/db/postgresql.php b/pandora_console/include/db/postgresql.php index a664bd45c7..8c1394a97d 100644 --- a/pandora_console/include/db/postgresql.php +++ b/pandora_console/include/db/postgresql.php @@ -474,7 +474,7 @@ function postgresql_encapsule_fields_with_same_name_to_instructions($field) * * @return mixed Value of first column of the first row. False if there were no row. */ -function postgresql_db_get_value_filter($field, $table, $filter, $where_join='AND', $search_history_db=false) +function postgresql_db_get_value_filter($field, $table, $filter, $where_join='AND', $search_history_db=false, $cache=true) { if (! is_array($filter) || empty($filter)) { return false; @@ -496,7 +496,7 @@ function postgresql_db_get_value_filter($field, $table, $filter, $where_join='AN db_format_array_where_clause_sql($filter, $where_join) ); - $result = db_get_all_rows_sql($sql, $search_history_db); + $result = db_get_all_rows_sql($sql, $search_history_db, $cache); $row = array_shift($result); $value = array_shift($row); diff --git a/pandora_console/include/functions_db.php b/pandora_console/include/functions_db.php index 637257e764..3872b405a0 100644 --- a/pandora_console/include/functions_db.php +++ b/pandora_console/include/functions_db.php @@ -380,21 +380,21 @@ function db_get_value( * * @return mixed Value of first column of the first row. False if there were no row. */ -function db_get_value_filter($field, $table, $filter, $where_join='AND', $search_history_db=false) +function db_get_value_filter($field, $table, $filter, $where_join='AND', $search_history_db=false, $cache=true) { global $config; switch ($config['dbtype']) { case 'mysql': - return mysql_db_get_value_filter($field, $table, $filter, $where_join, $search_history_db); + return mysql_db_get_value_filter($field, $table, $filter, $where_join, $search_history_db, $cache); break; case 'postgresql': - return postgresql_db_get_value_filter($field, $table, $filter, $where_join, $search_history_db); + return postgresql_db_get_value_filter($field, $table, $filter, $where_join, $search_history_db, $cache); break; case 'oracle': - return oracle_db_get_value_filter($field, $table, $filter, $where_join, $search_history_db); + return oracle_db_get_value_filter($field, $table, $filter, $where_join, $search_history_db, $cache); break; }