Merge branch 'ent-12236-varios-bugs-en-modulos-predictivos-de-politica' into 'develop'

Policy capacity planning modules. JS errors

See merge request artica/pandorafms!6650
This commit is contained in:
Diego Muñoz-Reja 2023-12-21 10:57:42 +00:00
commit 6114c6a37a
11 changed files with 184 additions and 80 deletions

View File

@ -1,3 +1,4 @@
-- Active: 1696349857571@@172.16.0.2@3306
START TRANSACTION;
CREATE TABLE IF NOT EXISTS `tdemo_data` (
@ -1501,6 +1502,18 @@ ALTER TABLE `tevent_filter` ADD COLUMN `regex` TEXT NULL AFTER `private_filter_u
-- Update macros for plugin oracle
UPDATE `tdiscovery_apps` SET `version` = '1.1' WHERE `short_name` = 'pandorafms.oracle';
CREATE TABLE IF NOT EXISTS `tpolicy_modules_synth` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`id_agent_module_source` INT UNSIGNED NOT NULL DEFAULT 0,
`id_agent_module_target` INT UNSIGNED NOT NULL DEFAULT 0,
`fixed_value` DOUBLE NOT NULL DEFAULT 0,
`operation` enum ('ADD', 'SUB', 'DIV', 'MUL', 'AVG', 'NOP') NOT NULL DEFAULT 'NOP',
`order` INT NOT NULL DEFAULT 0,
FOREIGN KEY (`id_agent_module_target`) REFERENCES tpolicy_modules(`id`)
ON DELETE CASCADE ON UPDATE CASCADE,
PRIMARY KEY (id)
);
SET @id_app := (SELECT `id_app` FROM `tdiscovery_apps` WHERE `short_name` = 'pandorafms.oracle');
UPDATE `tdiscovery_apps_tasks_macros` SET `value` = 'agents_group_id=__taskGroupID__ interval=__taskInterval__ user=_dbuser_ password=_dbpass_ thick_mode=_thickMode_ client_path=_clientPath_ threads=_threads_ modules_prefix=_prefixModuleName_ execute_custom_queries=_executeCustomQueries_ analyze_connections=_checkConnections_ engine_uptime=_checkUptime_ query_stats=_queryStats_ cache_stats=_checkCache_ fragmentation_ratio=_checkFragmentation_ check_tablescpaces=_checkTablespaces_' WHERE `macro` = '_tempfileConf_' AND `id_task` IN (SELECT `id_rt` FROM `trecon_task` WHERE `id_app` = @id_app);

View File

@ -682,6 +682,8 @@ switch ($moduletype) {
1,
];
include 'module_manager_editor_common.php';
ui_require_jquery_file('validate');
ui_require_javascript_file_enterprise('pandora_synthetic');
include 'module_manager_editor_prediction.php';
break;
@ -864,6 +866,20 @@ ui_require_javascript_file('pandora_modules');
?>
<script language="javascript">
/* <![CDATA[ */
var textsToTranslate = {
"None": "<?php __('None'); ?>",
};
var url = 'include/ajax/module';
var id_source = '<?php echo $id_agente; ?>';
var icons = {
'load_icon': '<?php html_print_image('images/spinner.gif', false); ?>',
'error_icon': '<?php html_print_image('images/error_red.png', false); ?>',
};
var no_name_lang =`
<?php
echo ui_print_info_message(

View File

@ -28,8 +28,8 @@
enterprise_include_once('include/functions_policies.php');
enterprise_include_once('godmode/agentes/module_manager_editor_prediction.php');
enterprise_include_once('include/functions_modules.php');
require_once 'include/functions_agents.php';
ui_require_jquery_file('validate');
$disabledBecauseInPolicy = false;
$disabledTextBecauseInPolicy = '';
@ -38,9 +38,21 @@ $id_agente = get_parameter('id_agente', '');
$agent_name = get_parameter('agent_name', agents_get_alias($id_agente));
$id_agente_modulo = get_parameter('id_agent_module', 0);
$custom_integer_2 = get_parameter('custom_integer_2', 0);
$sql = 'SELECT *
FROM tagente_modulo
WHERE id_agente_modulo = '.$id_agente_modulo;
$id_policy_module = get_parameter('id_policy_module', 0);
$policy = false;
if (strstr($page, 'policy_modules') !== false) {
$sql = 'SELECT *
FROM tpolicy_modules
WHERE id = '.$id_policy_module;
$policy = true;
$id_agente_modulo = $id_policy_module;
} else {
$sql = 'SELECT *
FROM tagente_modulo
WHERE id_agente_modulo = '.$id_agente_modulo;
}
$row = db_get_row_sql($sql);
$is_service = false;
$is_synthetic = false;
@ -48,9 +60,10 @@ $is_synthetic_avg = false;
$ops = false;
if ($row !== false && is_array($row) === true) {
$prediction_module = $row['prediction_module'];
$custom_integer_2 = $row['custom_integer_2'];
// Services are an Enterprise feature.
$custom_integer_1 = $row['custom_integer_1'];
$custom_integer_2 = $row['custom_integer_2'];
$custom_string_1 = $row['custom_string_1'];
$custom_integer_2 = $row['custom_integer_2'];
switch ((int) $prediction_module) {
case MODULE_PREDICTION_SERVICE:
@ -61,7 +74,10 @@ if ($row !== false && is_array($row) === true) {
case MODULE_PREDICTION_SYNTHETIC:
$ops_json = enterprise_hook(
'modules_get_synthetic_operations',
[$id_agente_modulo]
[
$id_agente_modulo,
$policy,
]
);
$ops = json_decode($ops_json, true);
@ -84,6 +100,7 @@ if ($row !== false && is_array($row) === true) {
case MODULE_PREDICTION_TRENDING:
$selected = 'trending_selected';
$prediction_module = $custom_integer_1;
break;
case MODULE_PREDICTION_PLANNING:
@ -223,7 +240,31 @@ if (strstr($page, 'policy_modules') === false) {
}
$data[0] = $predictionModuleInput;
$data[1] = html_print_select([__('Weekly'), __('Monthly'), __('Daily')], 'custom_integer_2', $custom_integer_2, '', '', 0, true, false, true, '', false, 'width: 100%;');
$data[1] = html_print_select(
[
'0' => __('Weekly'),
'1' => __('Monthly'),
'2' => __('Daily'),
],
'custom_integer_2',
$module['custom_integer_2'],
'',
'',
0,
true,
false,
true,
'',
false,
false,
false,
false,
false,
'',
false,
false,
true
);
$data[1] .= html_print_input_hidden('id_agente_module_prediction', $id_agente, true);
$table_simple->cellclass['prediction_module'][0] = 'w33p';
@ -328,6 +369,7 @@ if ($netflow_module_form !== ENTERPRISE_NOT_HOOK) {
// Removed common useless parameter.
unset($table_advanced->data[3]);
?>
<script type="text/javascript">
$(document).ready(function() {
@ -338,6 +380,7 @@ unset($table_advanced->data[3]);
$selected,
$is_netflow,
$ops,
false,
]
);
?>

View File

@ -204,9 +204,7 @@ if ($display_loading === true || $running_create === true || $running_delete) {
$btn_span,
'redirect_button',
false,
[
'icon' => $icon,
],
['icon' => $icon],
true
),
[],
@ -345,7 +343,7 @@ if ($display_loading === true || $running_create === true || $running_delete) {
/*
$table_adv->data['row4'][] = html_print_label_input_block(
$table_adv->data['row4'][] = html_print_label_input_block(
__('Services agent name').ui_print_help_tip(__('If not set, %s will be used as the default agent', 'demo-global-agent-1'), true),
html_print_input_text(
'service_agent_name',
@ -359,7 +357,7 @@ if ($display_loading === true || $running_create === true || $running_delete) {
'',
'w300px'
)
);
);
*/
}
@ -424,7 +422,7 @@ if ($display_loading === true || $running_create === true || $running_delete) {
);
/*
$table_adv->data['row11'][] = html_print_label_input_block(
$table_adv->data['row11'][] = html_print_label_input_block(
__('Demo data plugin agent'),
html_print_input_text(
'plugin_agent',
@ -438,7 +436,7 @@ if ($display_loading === true || $running_create === true || $running_delete) {
'',
'w300px'
)
);
);
*/
$table_adv->data['row12'][] = html_print_label_input_block(
@ -550,13 +548,11 @@ if ($display_loading === true || $running_create === true || $running_delete) {
);
// echo '<div id="btn-set" style="display:none;">';
html_print_action_buttons(
implode('', $actionButtons)
);
// echo '</div>';
echo '</form>';
} else {
// Summary data.

View File

@ -107,7 +107,7 @@ if ($action === 'create_demo_data') {
foreach ($files as $file) {
$current_parsed_ini = parse_ini_file($directory_path.'/'.$file, true, INI_SCANNER_TYPED);
if($current_parsed_ini !== false) {
if ($current_parsed_ini !== false) {
$parsed_ini[$directory][] = array_merge(['filename' => $file], $current_parsed_ini);
}
}
@ -139,8 +139,7 @@ if ($action === 'create_demo_data') {
$agent_created_total = 0;
$agent_data_values_buffer = [];
// TRAPS HISTORY: Removed due to performance issues
//$agent_traps_values_buffer = [];
// $agent_traps_values_buffer = [];
if ($total_agents_to_create > 0 && $agents_to_create > 0) {
while ($agent_created_total < ($total_agents_to_create - 1)) {
if (count($parsed_ini['agents']) === 0) {
@ -748,7 +747,8 @@ if ($action === 'create_demo_data') {
$utimestamp = time();
// TRAPS HISTORY: Removed due to performance issues
/*for ($p = 0; $p < $back_periods; $p++) {
/*
for ($p = 0; $p < $back_periods; $p++) {
$trap_access_idx = 1;
while (1) {
@ -820,7 +820,7 @@ if ($action === 'create_demo_data') {
$current_date_time = $date_time->format('Y-m-d H:i:s');
$utimestamp -= $interval;
}
}
}
*/
}
@ -837,8 +837,7 @@ if ($action === 'create_demo_data') {
$agent_data_values_buffer_chunks = array_chunk($agent_data_values_buffer, 100000);
// TRAPS HISTORY: Removed due to performance issues
//$agent_traps_values_buffer_chunks = array_chunk($agent_traps_values_buffer, 100000);
// $agent_traps_values_buffer_chunks = array_chunk($agent_traps_values_buffer, 100000);
foreach ($agent_data_values_buffer_chunks as $chunk) {
// Bulk inserts (insert batches of up to 100,000 as a performance limit).
mysql_db_process_sql_insert_multiple(
@ -849,56 +848,57 @@ if ($action === 'create_demo_data') {
}
// Get last trap in database.
/*$id_trap_begin = db_get_value(
/*
$id_trap_begin = db_get_value(
'MAX(id_trap)',
'ttrap',
1,
1,
false,
false
);
);
if ($id_trap_begin === false) {
if ($id_trap_begin === false) {
$id_trap_begin = 0;
}
}
// TRAPS HISTORY: Removed due to performance issues
/*
foreach ($agent_traps_values_buffer_chunks as $chunk) {
// TRAPS HISTORY: Removed due to performance issues
/*
foreach ($agent_traps_values_buffer_chunks as $chunk) {
// Bulk inserts (insert batches of up to 100,000 as a performance limit).
mysql_db_process_sql_insert_multiple(
'ttrap',
$chunk,
false
);
}
}
// Get last trap in database after insertion.
$id_trap_end = db_get_value(
// Get last trap in database after insertion.
$id_trap_end = db_get_value(
'MAX(id_trap)',
'ttrap',
1,
1,
false,
false
);
);
if ($id_trap_end === false) {
if ($id_trap_end === false) {
$id_trap_end = 0;
}
}
$agent_traps_demo_registry_buffer = [];
for ($i = ($id_trap_begin + 1); $i <= $id_trap_end; $i++) {
$agent_traps_demo_registry_buffer = [];
for ($i = ($id_trap_begin + 1); $i <= $id_trap_end; $i++) {
// Get batches to be stored in tdemo_data.
$agent_traps_demo_registry_buffer[] = [
'item_id' => $i,
'table_name' => 'ttrap',
];
}
}
$agent_traps_demo_registry_buffer_chunks = array_chunk($agent_traps_demo_registry_buffer, 100000);
$agent_traps_demo_registry_buffer_chunks = array_chunk($agent_traps_demo_registry_buffer, 100000);
foreach ($agent_traps_demo_registry_buffer_chunks as $chunk) {
foreach ($agent_traps_demo_registry_buffer_chunks as $chunk) {
// Bulk inserts (insert batches of up to 100,000 as a performance limit).
mysql_db_process_sql_insert_multiple(
'tdemo_data',
@ -911,7 +911,7 @@ if ($action === 'create_demo_data') {
}
}
$services_count = count($parsed_ini['services'] ?? []);
$services_count = count(($parsed_ini['services'] ?? []));
if ($services_count > 0) {
// Create services.
foreach ($parsed_ini['services'] as $ini_service_data) {
@ -1333,7 +1333,7 @@ if ($action === 'create_demo_data') {
register_error(DEMO_SERVICE, __('No configuration files found or failed to parse files'));
}
$nm_count = count($parsed_ini['network_maps'] ?? []);
$nm_count = count(($parsed_ini['network_maps'] ?? []));
if ($nm_count > 0) {
// Create network maps.
foreach ($parsed_ini['network_maps'] as $ini_nm_data) {
@ -1354,7 +1354,7 @@ if ($action === 'create_demo_data') {
}
$map_types = [
'circular' => 0,
'circular' => 0,
'radial_dynamic' => 6,
];
@ -1580,7 +1580,7 @@ if ($action === 'create_demo_data') {
register_error(DEMO_NETWORK_MAP, __('No configuration files found or failed to parse files'));
}
$gis_count = count($parsed_ini['gis_maps'] ?? []);
$gis_count = count(($parsed_ini['gis_maps'] ?? []));
if ($gis_count > 0) {
// Enable GIS features
$token = 'activate_gis';
@ -1696,13 +1696,13 @@ if ($action === 'create_demo_data') {
$item_values = [];
$layer_order = $item_access_idx - 2;
$layer_order = ($item_access_idx - 2);
$item_values['tgis_map_id_tgis_map'] = $id_map;
$item_values['layer_stack_order'] = $layer_order;
$item_values['tgrupo_id_grupo'] = -1;
$item_values['view_layer'] = 1;
$item_values['layer_name'] = io_safe_input((isset($items_array['name']) === true) ? $items_array['name'] : 'layer-'-$layer_order);
$item_values['layer_name'] = io_safe_input((isset($items_array['name']) === true) ? $items_array['name'] : ('layer-' - $layer_order));
if (isset($items_array['group']) === true) {
$layer_id_group = get_group_or_create_demo_group($items_array['group']);
@ -1748,7 +1748,7 @@ if ($action === 'create_demo_data') {
register_error(DEMO_GIS_MAP, __('No configuration files found or failed to parse files'));
}
$cg_count = count($parsed_ini['graphs'] ?? []);
$cg_count = count(($parsed_ini['graphs'] ?? []));
if ($cg_count > 0) {
// Create graphs.
foreach ($parsed_ini['graphs'] as $ini_graph_data) {
@ -1934,7 +1934,7 @@ if ($action === 'create_demo_data') {
register_error(DEMO_CUSTOM_GRAPH, __('No configuration files found or failed to parse files'));
}
$rep_count = count($parsed_ini['reports'] ?? []);
$rep_count = count(($parsed_ini['reports'] ?? []));
if ($rep_count > 0) {
// Create reports.
foreach ($parsed_ini['reports'] as $ini_report_data) {
@ -2195,7 +2195,7 @@ if ($action === 'create_demo_data') {
register_error(DEMO_REPORT, __('No configuration files found or failed to parse files'));
}
$vc_count = count($parsed_ini['visual_consoles'] ?? []);
$vc_count = count(($parsed_ini['visual_consoles'] ?? []));
if ($vc_count > 0) {
// Create visual consoles.
foreach ($parsed_ini['visual_consoles'] as $ini_data) {
@ -2451,7 +2451,6 @@ if ($action === 'create_demo_data') {
}
if ($items_array['type'] === 'custom_graph') {
if (isset($items_array['graph_name']) === true
&& is_string($items_array['graph_name']) === true
) {
@ -2820,7 +2819,7 @@ if ($action === 'create_demo_data') {
register_error(DEMO_VISUAL_CONSOLE, __('No configuration files found or failed to parse files'));
}
$dashboards_count = count($parsed_ini['dashboards'] ?? []);
$dashboards_count = count(($parsed_ini['dashboards'] ?? []));
if ($dashboards_count > 0) {
// Create dashboards.
foreach ($parsed_ini['dashboards'] as $ini_data) {
@ -3068,8 +3067,8 @@ if ($action === 'create_demo_data') {
$options_data = [
'title' => $title,
'background' => '#ffffff',
'groupId' => ["0"],
'status' => ["4,1,0,2"],
'groupId' => ['0'],
'status' => ['4,1,0,2'],
'sunburst' => false,
];
@ -3113,13 +3112,13 @@ if ($action === 'create_demo_data') {
}
$options_data = [
'title' => $title,
'background' => '#ffffff',
'agentId' => "$agent_id",
'metaconsoleId' => 0,
'moduleId' => "$module_id",
'period' => (isset($items_array['interval']) === true) ? $items_array['interval'] : '86400',
'sizeLabel' => 30
'title' => $title,
'background' => '#ffffff',
'agentId' => "$agent_id",
'metaconsoleId' => 0,
'moduleId' => "$module_id",
'period' => (isset($items_array['interval']) === true) ? $items_array['interval'] : '86400',
'sizeLabel' => 30,
];
$order++;
@ -3134,11 +3133,14 @@ if ($action === 'create_demo_data') {
'limit' => 20,
'eventStatus' => -1,
'severity' => -1,
'groupId' => [""],
'tagsId' => [""],
'groupId' => [''],
'tagsId' => [''],
'groupRecursion' => 0,
'customFilter' => -1,
'columns_events_widget' => ["mini_severity,evento,estado,agent_name,timestamp", ""]
'columns_events_widget' => [
'mini_severity,evento,estado,agent_name,timestamp',
'',
],
];
$order++;
@ -3150,9 +3152,9 @@ if ($action === 'create_demo_data') {
'background' => '#ffffff',
'amountShow' => 10,
'maxHours' => 8,
'groupId' => ["0"],
'legendPosition' => "bottom",
'show_total_data' => 0
'groupId' => ['0'],
'legendPosition' => 'bottom',
'show_total_data' => 0,
];
$order++;
@ -3169,7 +3171,7 @@ if ($action === 'create_demo_data') {
'order' => '2',
'display' => '0',
'type_graph' => 'bar_vertical',
'legend' => 'agent_module'
'legend' => 'agent_module',
];
$order++;
@ -3181,10 +3183,10 @@ if ($action === 'create_demo_data') {
$item_height = $items_array['height'];
$position_data = [
'x' => (isset($items_array['x']) === true) ? "$item_x" : "0",
'y' => (isset($items_array['y']) === true) ? "$item_y" : "0",
'width' => (isset($items_array['width']) === true) ? "$item_width" : "4",
'height' => (isset($items_array['height']) === true) ? "$item_height" : "4",
'x' => (isset($items_array['x']) === true) ? "$item_x" : '0',
'y' => (isset($items_array['y']) === true) ? "$item_y" : '0',
'width' => (isset($items_array['width']) === true) ? "$item_width" : '4',
'height' => (isset($items_array['height']) === true) ? "$item_height" : '4',
];
$element_values = [
@ -3608,7 +3610,8 @@ function update_progress($total_items_count, $total_type_items_count, $created_n
*
* @return void
*/
function update_item_checked($item_id) {
function update_item_checked($item_id)
{
$current_load_status_data = db_get_value_filter(
'value',
'tconfig',

View File

@ -27,6 +27,7 @@
*/
use PandoraFMS\Enterprise\Metaconsole\Node;
use PandoraFMS\Agent;
// Begin.
if (check_login()) {
@ -82,6 +83,7 @@ if (check_login()) {
$update_monitor_filter = get_parameter('update_monitor_filter', 0);
$delete_monitor_filter = get_parameter('delete_monitor_filter', 0);
$get_cluster_module_detail = (bool) get_parameter('get_cluster_module_detail', 0);
$get_combo_modules = (bool) get_parameter('get_combo_modules', false);
if ($get_agent_modules_json_by_name === true) {
$agent_name = get_parameter('agent_name');
@ -2864,4 +2866,19 @@ if (check_login()) {
<?php
return;
}
if ($get_combo_modules === true) {
$id_agent = get_parameter('id_source');
$modules = db_get_all_rows_filter(
'tagente_modulo',
['id_agente' => $id_agent],
[
'id_agente_modulo as id',
'nombre as name',
]
);
echo json_encode($modules);
return;
}
}

View File

@ -715,7 +715,7 @@ class WelcomeWindow extends Wizard
echo html_print_div(
[
'class' => '',
'content' => 'This wizard will create a complete data set, with history, reports, visual consoles, dashboard and network maps so you can explore the power of Pandora FMS. You will be able to configure it and delete the demo data in the setup.<br><br>'
'content' => 'This wizard will create a complete data set, with history, reports, visual consoles, dashboard and network maps so you can explore the power of Pandora FMS. You will be able to configure it and delete the demo data in the setup.<br><br>',
],
true
);

View File

@ -1022,7 +1022,7 @@ function mysql_db_get_row_filter($table, $filter, $fields=false, $where_join='AN
}
$sql = sprintf('SELECT %s FROM %s %s', $fields, $table, $filter);
return db_get_row_sql($sql, $historydb, $cache);
}

View File

@ -1435,8 +1435,7 @@ class Manager implements PublicLogin
{
global $config;
//Widget::dashboardInstallWidgets($this->cellId);
// Widget::dashboardInstallWidgets($this->cellId);
$search = \io_safe_output(\get_parameter('search', ''));
// The limit is fixed here.

View File

@ -250,8 +250,9 @@ class Widget
*
* @return void
*/
/*public static function dashboardInstallWidgets(int $cellId)
{
/*
public static function dashboardInstallWidgets(int $cellId)
{
global $config;
$dir = $config['homedir'].'/include/lib/Dashboard/Widgets/';

View File

@ -4595,3 +4595,19 @@ CREATE TABLE IF NOT EXISTS `tfiles_repo_group` (
PRIMARY KEY (`id`),
FOREIGN KEY (`id_file`) REFERENCES tfiles_repo(`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- -----------------------------------------------------
-- Table `tmodule_synth`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `tpolicy_modules_synth` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`id_agent_module_source` INT UNSIGNED NOT NULL DEFAULT 0,
`id_agent_module_target` INT UNSIGNED NOT NULL DEFAULT 0,
`fixed_value` DOUBLE NOT NULL DEFAULT 0,
`operation` enum ('ADD', 'SUB', 'DIV', 'MUL', 'AVG', 'NOP') NOT NULL DEFAULT 'NOP',
`order` INT NOT NULL DEFAULT 0,
FOREIGN KEY (`id_agent_module_target`) REFERENCES tpolicy_modules(`id`)
ON DELETE CASCADE ON UPDATE CASCADE,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4;