From 4fb7e1719b1d8cc53d5c8e61c90bd76a37eb747f Mon Sep 17 00:00:00 2001 From: daniel Date: Wed, 18 Oct 2023 12:49:47 +0200 Subject: [PATCH 001/125] add periodicity graph pandora_enterprise#9640 --- pandora_console/extensions/agents_modules.php | 2 +- pandora_console/include/ajax/module.php | 17 +- pandora_console/include/functions_graph.php | 537 ++++++++++++++++ pandora_console/include/graphs/fgraph.php | 67 +- pandora_console/include/styles/pandora.css | 33 +- .../operation/agentes/stat_win.php | 572 +++++++----------- pandora_console/operation/search_modules.php | 2 +- 7 files changed, 845 insertions(+), 385 deletions(-) diff --git a/pandora_console/extensions/agents_modules.php b/pandora_console/extensions/agents_modules.php index d6c4f3bb32..f372f45812 100644 --- a/pandora_console/extensions/agents_modules.php +++ b/pandora_console/extensions/agents_modules.php @@ -1007,7 +1007,7 @@ function mainAgentsModules() echo ""; $win_handle = dechex(crc32($module_id.$module['name'])); $graph_type = return_graphtype(modules_get_agentmodule_type($module_id)); - $link = "winopeng_var('".'operation/agentes/stat_win.php?'."type=$graph_type&".'period='.SECONDS_1DAY.'&'.'id='.$module_id.'&'.'refresh='.SECONDS_10MINUTES."', 'day_".$win_handle."', 800, 480)"; + $link = "winopeng_var('".'operation/agentes/stat_win.php?'."type=$graph_type&".'period='.SECONDS_1DAY.'&id='.$module_id.'&period_graph=0&refresh='.SECONDS_10MINUTES."', 'day_".$win_handle."', 800, 480)"; echo ''; diff --git a/pandora_console/include/ajax/module.php b/pandora_console/include/ajax/module.php index 78daacb0a0..2951ad495a 100755 --- a/pandora_console/include/ajax/module.php +++ b/pandora_console/include/ajax/module.php @@ -1283,7 +1283,7 @@ if (check_login()) { } if (is_snapshot_data($module['datos']) === false) { - $link = 'winopeng_var(\'operation/agentes/stat_win.php?type='.$graph_type.'&period='.SECONDS_1DAY.'&id='.$module['id_agente_modulo'].'&refresh='.SECONDS_10MINUTES.'&draw_events='.$draw_events.'\', \'day_'.$win_handle.'\', 800, 480)'; + $link = 'winopeng_var(\'operation/agentes/stat_win.php?type='.$graph_type.'&period='.SECONDS_1DAY.'&id='.$module['id_agente_modulo'].'&refresh='.SECONDS_10MINUTES.'&period_graph=0&draw_events='.$draw_events.'\', \'day_'.$win_handle.'\', 800, 480)'; $graphButtons[] = html_print_anchor( [ 'href' => 'javascript:'.$link, @@ -1499,9 +1499,14 @@ if (check_login()) { $output = ''; $graph_data = get_parameter('graph_data', ''); $params = json_decode(base64_decode($graph_data), true); + $form_data = json_decode(base64_decode(get_parameter('form_data', [])), true); $server_id = (int) get_parameter('server_id', 0); include_once $config['homedir'].'/include/functions_graph.php'; + $tab_active = get_parameter('active', 'tabs-chart-module-graph'); + + $output .= draw_form_stat_win($form_data, $tab_active); + // Metaconsole connection to the node. if (is_metaconsole() === true && empty($server_id) === false) { $server = metaconsole_get_connection_by_id($server_id); @@ -1553,7 +1558,15 @@ if (check_login()) { $output .= $graph['chart']; $output .= ''; } else { - $output .= grafico_modulo_sparse($params); + if ($tab_active === 'tabs-chart-module-graph') { + $output .= grafico_modulo_sparse($params); + } else { + $output .= graphic_periodicity_module($params); + if ($params['compare'] === 'separated') { + $params['date'] = ($params['date'] - $params['period']); + $output .= graphic_periodicity_module($params); + } + } } } diff --git a/pandora_console/include/functions_graph.php b/pandora_console/include/functions_graph.php index e6605a488b..006870757e 100644 --- a/pandora_console/include/functions_graph.php +++ b/pandora_console/include/functions_graph.php @@ -2422,6 +2422,147 @@ function graphic_combined_module( } +/** + * Draw periodicity graph + * + * @param array $params Params for draw chart. + * + * @return string Html output. + */ +function graphic_periodicity_module(array $params): string +{ + $date_array = []; + $date_array['period'] = $params['period']; + $date_array['final_date'] = $params['date']; + $date_array['start_date'] = ($params['date'] - $params['period']); + + $array_data = fullscale_data( + $params['agent_module_id'], + $date_array, + false, + false, + 1, + false, + $params['period_slice_chart'], + 0 + ); + + if (empty($array_data) === false) { + $graph_labels = []; + $multiple_labels = []; + foreach ($array_data['sum1']['slice_data'] as $time => $array_data) { + $graph_labels[] = date('H:i', ($time / 1000)); + + $avg = [ + 'y' => $array_data['avg'], + 'x' => $time, + ]; + + $max = [ + 'y' => $array_data['max'], + 'x' => $time, + ]; + + $min = [ + 'y' => $array_data['min'], + 'x' => $time, + ]; + + $sum = [ + 'y' => $array_data['sum'], + 'x' => $time, + ]; + if ((int) $params['period_mode'] === CUSTOM_GRAPH_HBARS) { + $avg = [ + 'x' => $array_data['avg'], + 'y' => $time, + ]; + + $max = [ + 'x' => $array_data['max'], + 'y' => $time, + ]; + + $min = [ + 'x' => $array_data['min'], + 'y' => $time, + ]; + + $sum = [ + 'x' => $array_data['sum'], + 'y' => $time, + ]; + } + + $graph_values_avg[] = $avg; + $graph_values_max[] = $max; + $graph_values_min[] = $min; + $graph_values_sum[] = $sum; + } + + if ((bool) $params['period_average'] === true) { + $graph_values['avg'] = $graph_values_avg; + $multiple_labels['avg'] = [ + 'label' => __('Average'), + 'fill' => ((int) $params['period_mode'] === CUSTOM_GRAPH_AREA) ? true : false, + ]; + } + + if ((bool) $params['period_maximum'] === true) { + $graph_values['max'] = $graph_values_max; + $multiple_labels['max'] = [ + 'label' => __('Maximun'), + 'fill' => ((int) $params['period_mode'] === CUSTOM_GRAPH_AREA) ? true : false, + ]; + } + + if ((bool) $params['period_minimum'] === true) { + $graph_values['min'] = $graph_values_min; + $multiple_labels['min'] = [ + 'label' => __('Minimum'), + 'fill' => ((int) $params['period_mode'] === CUSTOM_GRAPH_AREA) ? true : false, + ]; + } + + if ((bool) $params['period_summatory'] === true) { + $graph_values['sum'] = $graph_values_sum; + $multiple_labels['sum'] = [ + 'label' => __('Summatory'), + 'fill' => ((int) $params['period_mode'] === CUSTOM_GRAPH_AREA) ? true : false, + ]; + } + } + + $options = [ + 'height' => 200, + 'waterMark' => true, + 'legend' => ['display' => true], + 'labels' => $graph_labels, + 'multiple' => $multiple_labels, + ]; + + $output = '
'; + $output .= '
'; + if ((int) $params['period_mode'] === CUSTOM_GRAPH_HBARS + || (int) $params['period_mode'] === CUSTOM_GRAPH_VBARS + ) { + if ((int) $params['period_mode'] === CUSTOM_GRAPH_HBARS) { + $options['axis'] = 'y'; + } + + $output .= vbar_graph($graph_values, $options); + } else { + $output .= line_graph($graph_values, $options); + } + + $output .= '
'; + $output .= '
'; + + return $output; + +} + + /** * Function for convert data summatory. * @@ -3909,6 +4050,7 @@ function fullscale_data( } $data['sum'.$series_suffix]['slice_data'][$real_date]['avg'] = ($sum_data / $count_data); + $data['sum'.$series_suffix]['slice_data'][$real_date]['sum'] = $sum_data; if ($max_value != (-PHP_INT_MAX)) { $data['sum'.$series_suffix]['slice_data'][$real_date]['max'] = $max_value; @@ -4174,6 +4316,7 @@ function fullscale_data( $data['sum'.$series_suffix]['slice_data'][($date_array['final_date'] * 1000)]['avg'] = 0; if (isset($count_data) === true) { $data['sum'.$series_suffix]['slice_data'][($date_array['final_date'] * 1000)]['avg'] = ($sum_data / $count_data); + $data['sum'.$series_suffix]['slice_data'][($date_array['final_date'] * 1000)]['sum'] = $sum_data; } $data['sum'.$series_suffix]['slice_data'][($date_array['final_date'] * 1000)]['max'] = $max_value; @@ -5351,3 +5494,397 @@ function graph_analytics_filter_select() return $result; } + + +function draw_form_stat_win(array $form_data, string $tab_active) +{ + $table = html_get_predefined_table('transparent', 2); + $table->width = '100%'; + $table->id = 'stat_win_form_div'; + $table->style[0] = 'text-align:left;font-weight: bold;font-size:8.5pt;line-height:30pt;'; + $table->style[1] = 'text-align:left;font-weight: bold;line-height:30pt;'; + $table->style[2] = 'text-align:left;font-weight: bold;line-height:30pt;'; + $table->style[3] = 'text-align:left;font-weight: bold;line-height:30pt;'; + $table->class = 'table_modal_alternate'; + $table->data = []; + + if ((bool) $form_data['histogram'] === true || $tab_active === 'tabs-chart-period-graph') { + $table->data[0][0] = __('Refresh time'); + $table->data[0][1] = '
'.html_print_extended_select_for_time( + 'refresh', + $form_data['refresh'], + '', + '', + 0, + 7, + true + ).'
'; + + $table->data[0][2] = ''; + $table->data[0][3] = ''; + + $table->data[1][0] = __('Begin date'); + $table->data[1][1] = html_print_input_text( + 'start_date', + $form_data['start_date'], + '', + 10, + 20, + true, + false, + false, + '', + 'small-input' + ); + + $table->data[1][2] = __('Begin time'); + $table->data[1][3] = html_print_input_text( + 'start_time', + $form_data['start_time'], + '', + 10, + 10, + true, + false, + false, + '', + 'small-input' + ); + + $table->data[2][0] = __('Time range'); + $table->data[2][1] = '
'.html_print_extended_select_for_time( + 'period', + $form_data['period'], + '', + '', + 0, + 7, + true + ).'
'; + + $table->data[3][0] = __('Time compare (Separated)'); + $table->data[3][1] = html_print_checkbox_switch( + 'time_compare_separated', + 1, + (bool) $form_data['time_compare_separated'], + true + ); + + $table->data[3][2] = ''; + $table->data[3][3] = ''; + + if ($tab_active === 'tabs-chart-period-graph') { + $table->data[4][0] = __('Maximum'); + $table->data[4][1] = html_print_checkbox_switch( + 'period_maximum', + 1, + (bool) $form_data['period_maximum'], + true + ); + + $table->data[4][2] = __('Minimum'); + $table->data[4][3] = html_print_checkbox_switch( + 'period_minimum', + 1, + (bool) $form_data['period_minimum'], + true + ); + + $table->data[5][0] = __('Average'); + $table->data[5][1] = html_print_checkbox_switch( + 'period_average', + 1, + (bool) $form_data['period_average'], + true + ); + + $table->data[5][2] = __('Summatory'); + $table->data[5][3] = html_print_checkbox_switch( + 'period_summatory', + 1, + (bool) $form_data['period_summatory'], + true + ); + + $table->data[6][0] = __('Slice'); + $table->data[6][1] = '
'.html_print_extended_select_for_time( + 'period_slice_chart', + (string) $form_data['period_slice_chart'], + '', + '', + 0, + 7, + true, + false, + true, + '', + false, + [ + SECONDS_1HOUR => __('1 hour'), + SECONDS_1DAY => __('1 day'), + SECONDS_1WEEK => __('1 week'), + SECONDS_1MONTH => __('1 month'), + ] + ).'
'; + + $table->data[6][2] = __('Mode'); + $options_period_mode = [ + CUSTOM_GRAPH_AREA => __('Area'), + CUSTOM_GRAPH_LINE => __('Line'), + // CUSTOM_GRAPH_HBARS => __('Horizontal bars'), + CUSTOM_GRAPH_VBARS => __('Vertical bars'), + ]; + + $table->data[6][3] = '
'.html_print_select( + $options_period_mode, + 'period_mode', + $form_data['period_mode'], + '', + '', + 0, + true, + false, + false + ).'
'; + } + } else { + $table->data[0][0] = __('Refresh time'); + $table->data[0][1] = '
'.html_print_extended_select_for_time( + 'refresh', + $form_data['refresh'], + '', + '', + 0, + 7, + true + ).'
'; + + $table->data[0][2] = __('Show events'); + $disabled = false; + + $table->data[0][3] = html_print_checkbox_switch( + 'draw_events', + 1, + (bool) $form_data['draw_events'], + true, + $disabled + ); + + $table->data[1][0] = __('Begin date'); + $table->data[1][1] = html_print_input_text( + 'start_date', + $form_data['start_date'], + '', + 10, + 20, + true, + false, + false, + '', + 'small-input' + ); + + $table->data[1][2] = __('Show alerts'); + $table->data[1][3] = html_print_checkbox_switch( + 'draw_alerts', + 1, + (bool) $form_data['draw_alerts'], + true + ); + + $table->data[2][0] = __('Begin time'); + $table->data[2][1] = html_print_input_text( + 'start_time', + $form_data['start_time'], + '', + 10, + 10, + true, + false, + false, + '', + 'small-input' + ); + + $table->data[2][2] = __('Show unknown graph'); + $table->data[2][3] = html_print_checkbox_switch( + 'unknown_graph', + 1, + (bool) $form_data['unknown_graph'], + true + ); + + $table->data[3][0] = __('Time range'); + $table->data[3][1] = '
'.html_print_extended_select_for_time( + 'period', + $form_data['period'], + '', + '', + 0, + 7, + true + ).'
'; + + $table->data[3][2] = ''; + $table->data[3][3] = ''; + + if (!modules_is_boolean($form_data['id'])) { + $table->data[4][0] = __('Zoom'); + $options = []; + $options[$form_data['zoom']] = 'x'.$form_data['zoom']; + $options[1] = 'x1'; + $options[2] = 'x2'; + $options[3] = 'x3'; + $options[4] = 'x4'; + $options[5] = 'x5'; + $table->data[4][1] = '
'.html_print_select( + $options, + 'zoom', + $form_data['zoom'], + '', + '', + 0, + true, + false, + false + ).'
'; + + $table->data[4][2] = __('Show percentil'); + $table->data[4][3] = html_print_checkbox_switch( + 'show_percentil', + 1, + (bool) $form_data['show_percentil'], + true + ); + } + + $table->data[5][0] = __('Time compare (Overlapped)'); + $table->data[5][1] = html_print_checkbox_switch( + 'time_compare_overlapped', + 1, + (bool) $form_data['time_compare_overlapped'], + true + ); + + $table->data[5][2] = __('Time compare (Separated)'); + $table->data[5][3] = html_print_checkbox_switch( + 'time_compare_separated', + 1, + (bool) $form_data['time_compare_separated'], + true + ); + + $table->data[6][0] = __('Show AVG/MAX/MIN data series in graph'); + $table->data[6][1] = html_print_checkbox_switch( + 'type_mode_graph', + 1, + (bool) $form_data['type_mode_graph'], + true, + false + ); + + $table->data[6][2] = __('Show full scale graph (TIP)'); + $table->data[6][2] .= ui_print_help_tip( + __('TIP mode charts do not support average - maximum - minimum series, you can only enable TIP or average, maximum or minimum series'), + true + ); + $table->data[6][3] = html_print_checkbox_switch( + 'fullscale', + 1, + (bool) $form_data['fullscale'], + true, + false + ); + + $table->data[7][0] = __('Projection graph'); + $table->data[7][0] .= ui_print_help_tip( + __('Projection graph take as begin date the current time'), + true + ); + $table->data[7][1] = html_print_checkbox_switch( + 'enable_projected_period', + 1, + (bool) $form_data['enable_projected_period'], + true + ); + + $table->data[7][2] = __('Projection period'); + $table->data[7][3] = '
'.html_print_extended_select_for_time( + 'period_projected', + $form_data['period_projected'], + '', + '', + 0, + 7, + true + ).'
'; + } + + $form_table = html_print_table($table, true); + $form_table .= html_print_div( + [ + 'class' => 'action-buttons-right-forced margin-top-10', + 'content' => html_print_submit_button( + __('Reload'), + 'submit', + false, + [ + 'icon' => 'search', + 'mode' => 'secondary mini', + 'class' => 'float-right', + ], + true + ), + ], + true + ); + + $output = '
'; + $output .= html_print_input_hidden('id', $form_data['id'], true); + $output .= html_print_input_hidden('label', $form_data['label'], true); + + if (empty($server_id) === false) { + $output .= html_print_input_hidden('server', $form_data['server_id'], true); + } + + $output .= html_print_input_hidden('histogram', $form_data['histogram'], true); + $output .= html_print_input_hidden('period_graph', $form_data['period_graph'], true); + $output .= html_print_input_hidden('type', $form_data['type'], true); + + $output .= ui_toggle( + $form_table, + ''.__('Graph configuration menu').''.ui_print_help_tip( + __('In Pandora FMS, data is stored compressed. The data visualization in database, charts or CSV exported data won\'t match, because is interpreted at runtime. Please check \'Pandora FMS Engineering\' chapter from documentation.'), + true + ), + '', + '', + true, + true, + '', + 'white-box-content', + 'box-flat pdd_10px', + 'images/arrow@svg.svg', + 'images/arrow@svg.svg', + true + ); + $output .= '
'; + + return $output; +} + + +function draw_container_chart_stat_win(?string $name='stat-win-module-graph') +{ + $output = '
'; + $output .= '
'; + $output .= html_print_image('images/spinner_charts.gif', true); + $output .= '
'; + + $output .= '
'; + $output .= '
'; + + $output .= '
'; + + return $output; +} diff --git a/pandora_console/include/graphs/fgraph.php b/pandora_console/include/graphs/fgraph.php index 494ec9c010..9cf7b5621d 100644 --- a/pandora_console/include/graphs/fgraph.php +++ b/pandora_console/include/graphs/fgraph.php @@ -1220,11 +1220,24 @@ function get_build_setup_charts($type, $options, $data) break; case 'BAR': - $setData->setLabel('data')->setBackgroundColor($colors); - $setData->setLabel('data')->setBorderColor($borders); - $setData->setLabel('data')->setBorderWidth(2); - - $setData->setLabel('data')->data()->exchangeArray(array_values($data)); + if (isset($options['multiple']) === true && empty($options['multiple']) === false) { + $i = 0; + foreach ($options['multiple'] as $key_label => $info) { + $dataSet = $chart->createDataSet(); + $dataSet->setLabel(($info['label'] ?? '--')); + $dataSet->setBackgroundColor(($info['backgroundColor'] ?? $colors[$i])); + $dataSet->setBorderColor(($info['borderColor'] ?? $borders[$i])); + $dataSet->setBorderWidth(($info['borderWidth'] ?? 2)); + $dataSet->data()->exchangeArray(array_values($data[$key_label])); + $chart->addDataSet($dataSet); + $i++; + } + } else { + $setData->setLabel('data')->setBackgroundColor($colors); + $setData->setLabel('data')->setBorderColor($borders); + $setData->setLabel('data')->setBorderWidth(2); + $setData->setLabel('data')->data()->exchangeArray(array_values($data)); + } // Para las horizontales. if (isset($options['axis']) === true @@ -1250,19 +1263,32 @@ function get_build_setup_charts($type, $options, $data) break; case 'LINE': - $chart->labels()->exchangeArray($options['labels']); - - foreach ($data as $key => $dataset) { - $dataSet1 = $chart->createDataSet(); - $dataSet1->setLabel($dataset['label']); - $dataSet1->setBackgroundColor($dataset['backgroundColor']); - $dataSet1->setBorderColor($dataset['borderColor']); - $dataSet1->setPointBackgroundColor($dataset['pointBackgroundColor']); - $dataSet1->setPointBorderColor($dataset['pointBorderColor']); - $dataSet1->setPointHoverBackgroundColor($dataset['pointHoverBackgroundColor']); - $dataSet1->setPointHoverBorderColor($dataset['pointHoverBorderColor']); - $dataSet1->data()->exchangeArray($dataset['data']); - $chart->addDataSet($dataSet1); + if (isset($options['multiple']) === true && empty($options['multiple']) === false) { + $i = 0; + foreach ($options['multiple'] as $key_label => $info) { + $dataSet = $chart->createDataSet(); + $dataSet->setLabel(($info['label'] ?? '--')); + $dataSet->setBackgroundColor(($info['backgroundColor'] ?? $colors[$i])); + $dataSet->setBorderColor(($info['borderColorColor'] ?? $borders[$i])); + $dataSet->setFill(($info['fill'] ?? false)); + $dataSet->data()->exchangeArray(array_values($data[$key_label])); + $chart->addDataSet($dataSet); + $i++; + } + } else { + $chart->labels()->exchangeArray($options['labels']); + foreach ($data as $key => $dataset) { + $dataSet = $chart->createDataSet(); + $dataSet->setLabel($dataset['label']); + $dataSet->setBackgroundColor($dataset['backgroundColor']); + $dataSet->setBorderColor($dataset['borderColor']); + $dataSet->setPointBackgroundColor($dataset['pointBackgroundColor']); + $dataSet->setPointBorderColor($dataset['pointBorderColor']); + $dataSet->setPointHoverBackgroundColor($dataset['pointHoverBackgroundColor']); + $dataSet->setPointHoverBorderColor($dataset['pointHoverBorderColor']); + $dataSet->data()->exchangeArray($dataset['data']); + $chart->addDataSet($dataSet); + } } break; @@ -1271,7 +1297,10 @@ function get_build_setup_charts($type, $options, $data) break; } - if ($type !== 'RADAR' && $type !== 'LINE') { + if ($type !== 'RADAR' + && $type !== 'LINE' + && ((isset($options['multiple']) === false || empty($options['multiple']) === true)) + ) { $chart->addDataSet($setData); } diff --git a/pandora_console/include/styles/pandora.css b/pandora_console/include/styles/pandora.css index 1e89e83243..87b2c9d89e 100644 --- a/pandora_console/include/styles/pandora.css +++ b/pandora_console/include/styles/pandora.css @@ -9572,9 +9572,19 @@ div.stat-win-spinner img { } .stat_win_histogram { - width: 95%; margin: 0 auto; - margin-top: 18%; +} + +.bg_general { + background-color: #ffffff; +} + +#tabs-chart-modal { + border: 0px; +} + +#tabs-chart-ul-graphs li a img { + margin-left: 20px; } #stat-win-module-graph .stat_win_histogram div.nodata_container { @@ -12787,3 +12797,22 @@ tr.shown td.details-control { position: relative; top: -92px; } + +.container-periodicity-graph { + display: flex; + flex-direction: row; + justify-content: center; + align-items: center; + align-content: center; + border: 1px solid #e5e9ed; + border-radius: 10px; + margin-top: 25px; + padding: 10px; +} + +.container-periodicity-graph > div { + flex: 0 0 auto; + width: 100%; + height: 300px; + background-color: transparent; +} diff --git a/pandora_console/operation/agentes/stat_win.php b/pandora_console/operation/agentes/stat_win.php index a16d4c6e65..0f8b7e707b 100644 --- a/pandora_console/operation/agentes/stat_win.php +++ b/pandora_console/operation/agentes/stat_win.php @@ -127,6 +127,7 @@ ui_print_message_dialog( + '; +echo '
'; +echo ''.__('Configure demo data').''; +html_print_input_hidden('update_config', 1); +html_print_table($table_aux); +echo '
'; + +$actionButtons = []; + +$actionButtons[] = html_print_submit_button( + __('Create demo data'), + 'update_button', + false, + [ 'icon' => 'update' ], + true +); + +$actionButtons[] = html_print_button( + __('Delete demo data'), + 'delete_session_users', + false, + '', + [ + 'icon' => 'delete', + 'mode' => 'secondary', + ], + true +); + +html_print_action_buttons( + implode('', $actionButtons) +); + +echo ''; + +?> + + \ No newline at end of file diff --git a/pandora_console/include/ajax/demo_data.ajax.php b/pandora_console/include/ajax/demo_data.ajax.php new file mode 100644 index 0000000000..1016903e57 --- /dev/null +++ b/pandora_console/include/ajax/demo_data.ajax.php @@ -0,0 +1,386 @@ + 0) { + // Read all ini files. + $parsed_ini[] = parse_ini_file($config['homedir'].'/extras/demodata/agents/linux.ini', true, INI_SCANNER_TYPED); +hd($parsed_ini, true); + $ag_groups_num = ($agents_num / 10); + + // 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' + ); + + if ($group_name === false) { + $group_last_id = 0; + } else { + $group_last_id = (int) explode(' ', $group_name)[2]; + } + + if (!($group_last_id > -1)) { + echo json_encode(['msg' => 'Demo group ID not valid']); + return; + } + + $demo_group_name = 'Demo group '.($i + $group_last_id + 1); + + $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; + } + } + + $agents_created_count = 0; + $group_idx = 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 ($agent_alias === false) { + $agent_last_id = 0; + } else { + $agent_last_id = (int) explode(' ', $agent_alias)[1]; + } + + 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; + } + } + + // Define agents to be created per group of 10. + $agents_per_os = [ + 'Linux' => 5, + 'Windows' => 2, + 'MAC OS' => 1, + 'BSD' => 1, + 'Cisco' => 1, + ]; + + $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++; + + 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) { + break; + } + + $id_tipo = db_get_value_filter('id_tipo', 'ttipo_modulo', ['nombre' => $modules_array['type']]); + + $values = [ + 'unit' => $modules_array['unit'], + 'descripcion' => $modules_array['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']); + + if ((string) $parsed[0] === 'RANDOM') { + $data = rand($parsed[1], $parsed[2]); + } else if ((string) $parsed[0] === 'PROC') { + $probability = (int) $parsed[1]; + + $data = 0; + + if ($probability > 0) { + $randomNumber = rand(1, 100); + + if ($randomNumber <= $probability) { + $data = 1; + } + } + } + + $agent_data_values = [ + 'id_agente_modulo' => $created_mod_id, + 'datos' => $data, + 'utimestamp' => time(), + ]; + + db_process_sql_insert('tagente_datos', $agent_data_values); + } + + $module_access_idx++; + }; + + // 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) { + $modules_array = []; + foreach ($inventory as $key => $value) { + $modules_array[$key] = ($value[$module_access_idx] ?? null); + } + + $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' => 1, + ]; + + // STEP 1: tmodule_inventory. + $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; + } + } + + $module_access_idx++; + + // STEP 2: tagent_module_inventory. + $values = [ + 'id_agente' => $created_agent_id, + 'id_module_inventory' => $created_inventory_mod_id, + 'interval' => 300, + 'utimestamp' => time(), + 'timestamp' => $current_date_time, + ]; + + + + // STEP 3: Create inventory values (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 + ); + + hd("INV VALUES", true); + hd($selected_inventory_values, true); + + $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); + + hd("DATA STR",true); + hd($data_str, true); + + $inventory_data_values = [ + 'data' => $data_str, + 'utimestamp' => time(), + 'timestamp' => $current_date_time, + ]; + + $created_inventory_data = db_process_sql_insert('tagente_datos_inventory', $inventory_data_values); + hd("CID",true); + hd($inventory_data_values, true); + hd($created_inventory_data, true); + + 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; + } + } + }; + } + } + } + + return; +} + + +function calculateNextHostAddress($ip) { + list($network, $subnet) = explode('/', $ip); + + // Convert the network address to an array of octets. + $octets = explode('.', $network); + + // Convert the last octet to an integer. + $lastOctet = (int)$octets[3]; + + // Increment the last octet, and wrap around if it exceeds 255. + $lastOctet = ($lastOctet + 1) % 256; + + // Assemble the next host address. + $nextHost = implode('.', array($octets[0], $octets[1], $octets[2], $lastOctet)); + + return $nextHost . '/' . $subnet; +} \ No newline at end of file diff --git a/pandora_console/include/class/WelcomeWindow.class.php b/pandora_console/include/class/WelcomeWindow.class.php index 5e66268403..cd057414d0 100644 --- a/pandora_console/include/class/WelcomeWindow.class.php +++ b/pandora_console/include/class/WelcomeWindow.class.php @@ -581,6 +581,7 @@ class WelcomeWindow extends Wizard ], ]; + $fields['load_demo_data'] = __('Load demo data'); $fields['wizard_agent'] = __('Agent installation wizard'); $fields['check_web'] = __('Create WEB monitoring'); $fields['check_connectivity'] = __('Create network monitoring'); @@ -1112,6 +1113,9 @@ class WelcomeWindow extends Wizard alert(""); } else { switch($('#task_to_perform :selected').val()) { + case 'load_demo_data': + loadDemoDataPage(); + break; case 'wizard_agent': deployAgent(); break; @@ -1152,6 +1156,11 @@ class WelcomeWindow extends Wizard window.location = ''; } + // Task to do actions. + function loadDemoDataPage() { + window.location = ''; + } + function openCreateModulesDialog() { $('#dialog_goliat').dialog({ title: '', diff --git a/pandora_console/include/functions_agents.php b/pandora_console/include/functions_agents.php index 720b0e6e55..04174569a1 100644 --- a/pandora_console/include/functions_agents.php +++ b/pandora_console/include/functions_agents.php @@ -207,6 +207,8 @@ function agents_get_next_contact_time_left(int $id_agente) * @param string $ip_address Agent IP. * @param mixed $values Other tagente fields. * @param boolean $alias_as_name True to not assign an alias as name. + * @param mixed $os OS ID. + * @param mixed $os_version OS version. * * @return integer New agent id if created. False if it could not be created. */ @@ -216,7 +218,9 @@ function agents_create_agent( $interval, $ip_address, $values=false, - $alias_as_name=false + $alias_as_name=false, + $os=false, + $os_version=false ) { global $config; @@ -250,6 +254,14 @@ function agents_create_agent( $values['direccion'] = $ip_address; } + if (empty($os) === false) { + $values['id_os'] = $os; + } + + if (empty($os_version) === false) { + $values['os_version'] = $os_version; + } + // Check if group has limit or overrides the agent limit. if (group_allow_more_agents($id_group, true, 'create') === false) { return false; diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index 141ab4344d..86533ed028 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -4516,4 +4516,15 @@ CREATE TABLE IF NOT EXISTS `tgraph_analytics_filter` ( `graph_modules` TEXT NULL, `interval` INT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4; \ No newline at end of file +) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4; + +-- --------------------------------------------------------------------- +-- Table `tdemo_data` +-- --------------------------------------------------------------------- +CREATE TABLE IF NOT EXISTS `tdemo_data` ( + `id` INT UNSIGNED NOT NULL AUTO_INCREMENT, + `item_id` INT UNSIGNED NULL DEFAULT NULL, + `table_name` VARCHAR(64) NULL DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4; + From fc82a04a58ffbddf38fdf8521b2e0e60d979f553 Mon Sep 17 00:00:00 2001 From: "alejandro.campos@artica.es" Date: Fri, 27 Oct 2023 08:42:07 +0200 Subject: [PATCH 009/125] change location of file --- .../{update_manager_client => }/required_um_versions.php | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename pandora_console/{update_manager_client => }/required_um_versions.php (100%) diff --git a/pandora_console/update_manager_client/required_um_versions.php b/pandora_console/required_um_versions.php similarity index 100% rename from pandora_console/update_manager_client/required_um_versions.php rename to pandora_console/required_um_versions.php From 1fcc263046aa69d254b81f3707c91d95f866734c Mon Sep 17 00:00:00 2001 From: "alejandro.campos@artica.es" Date: Fri, 10 Nov 2023 11:24:34 +0100 Subject: [PATCH 010/125] implemented demo data load --- pandora_console/godmode/setup/demo.php | 221 +++++++++++++++--- .../include/ajax/demo_data.ajax.php | 158 ++++++++++--- 2 files changed, 315 insertions(+), 64 deletions(-) diff --git a/pandora_console/godmode/setup/demo.php b/pandora_console/godmode/setup/demo.php index 9af7e2721e..d0d65c748f 100644 --- a/pandora_console/godmode/setup/demo.php +++ b/pandora_console/godmode/setup/demo.php @@ -34,6 +34,14 @@ if (! check_acl($config['id_user'], 0, 'PM') && ! is_user_admin($config['id_user return; } +config_update_value('demo_data_load_progress', 0); + +html_print_input_hidden('demo_items_count', 0); + +$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'); + // Basic/Advanced mode. $mode = (string) get_parameter('mode', 'basic'); @@ -85,7 +93,7 @@ ui_print_standard_header( ); $table_aux = new stdClass(); -$table_aux->id = 'table-password-policy'; +$table_aux->id = 'table-demo'; $table_aux->class = 'filter-table-adv'; $table_aux->width = '100%'; $table_aux->data = []; @@ -124,20 +132,34 @@ $table_aux->data['row1'][] = html_print_label_input_block( 'agents_num', $config['gis_default_icon'], '', - '', - '', + '30', + 30, true, false, true, 'w80px' - ).'  '.__('(%d demo agents currently in the system)').'', + ).'  '.__('(%d demo agents currently in the system)', $demo_agents_count).'', ], true ) ); +$table_aux->data['row2'][] = progress_bar( + 0, + 100, + 20, + '', + 0, + false, + ((int) 0 !== -1) ? false : '#f3b200', + [ + 'class' => 'progress_bar', + 'id' => 'progress_bar', + ] +).html_print_input_hidden('js_timer_'.$operation['id'], 0, true); + if ($mode === 'advanced') { - $table_aux->data['row2'][] = html_print_label_input_block( + $table_aux->data['row3'][] = html_print_label_input_block( __('Generate historical data for all agents (15 days by default)'), html_print_checkbox_switch( 'enable_pass_policy_admin', @@ -147,7 +169,7 @@ if ($mode === 'advanced') { ) ); - $table_aux->data['row3'][] = html_print_label_input_block( + $table_aux->data['row4'][] = html_print_label_input_block( __('Create services, visual console, dashboard, reports, clusters and network maps'), html_print_checkbox_switch( 'enable_pass_policy_admin', @@ -157,7 +179,7 @@ if ($mode === 'advanced') { ) ); - $table_aux->data['row4'][] = html_print_label_input_block( + $table_aux->data['row5'][] = html_print_label_input_block( __('Generate custom/combined graphs'), html_print_checkbox_switch( 'enable_pass_policy_admin', @@ -167,7 +189,7 @@ if ($mode === 'advanced') { ) ); - $table_aux->data['row5'][] = html_print_label_input_block( + $table_aux->data['row6'][] = html_print_label_input_block( __('Generate netflow demo data'), html_print_checkbox_switch( 'enable_pass_policy_admin', @@ -177,7 +199,7 @@ if ($mode === 'advanced') { ) ); - $table_aux->data['row6'][] = html_print_label_input_block( + $table_aux->data['row7'][] = html_print_label_input_block( __('Generate logs for each agent'), html_print_checkbox_switch( 'enable_pass_policy_admin', @@ -187,7 +209,7 @@ if ($mode === 'advanced') { ) ); - $table_aux->data['row7'][] = html_print_label_input_block( + $table_aux->data['row8'][] = html_print_label_input_block( __('Generate inventory data for each agent'), html_print_checkbox_switch( 'enable_pass_policy_admin', @@ -197,7 +219,7 @@ if ($mode === 'advanced') { ) ); - $table_aux->data['row8'][] = html_print_label_input_block( + $table_aux->data['row9'][] = html_print_label_input_block( __('Generate SNMP traps for each agent'), html_print_checkbox_switch( 'enable_pass_policy_admin', @@ -207,7 +229,7 @@ if ($mode === 'advanced') { ) ); - $table_aux->data['row9'][] = html_print_label_input_block( + $table_aux->data['row10'][] = html_print_label_input_block( __('Days of historical data to insert in the agent data'), html_print_input_text( 'days_hist_data', @@ -250,18 +272,21 @@ $actionButtons[] = html_print_submit_button( __('Create demo data'), 'update_button', false, - [ 'icon' => 'update' ], + [ + 'icon' => 'update', + 'fixed_id' => 'btn-create-demo-data', + ], true ); -$actionButtons[] = html_print_button( +$actionButtons[] = html_print_submit_button( __('Delete demo data'), - 'delete_session_users', + 'update_button', false, - '', [ - 'icon' => 'delete', - 'mode' => 'secondary', + 'icon' => 'delete', + 'mode' => 'secondary', + 'fixed_id' => 'btn-delete-demo-data', ], true ); @@ -271,29 +296,161 @@ html_print_action_buttons( ); echo ''; - ?> \ No newline at end of file diff --git a/pandora_console/include/ajax/demo_data.ajax.php b/pandora_console/include/ajax/demo_data.ajax.php index 1016903e57..c2d163054a 100644 --- a/pandora_console/include/ajax/demo_data.ajax.php +++ b/pandora_console/include/ajax/demo_data.ajax.php @@ -20,17 +20,23 @@ * ============================================================================ */ +global $config; + +// Login check. +check_login(); + include $config['homedir'].'/include/functions_inventory.php'; $action = (string) get_parameter('action', null); if ($action === 'create_demo_data') { + config_update_value('demo_data_load_progress', 0); $agents_num = (int) get_parameter('agents_num', 0); - hd("qqqq ".$agents_num, true); + if ($agents_num > 0) { // Read all ini files. $parsed_ini[] = parse_ini_file($config['homedir'].'/extras/demodata/agents/linux.ini', true, INI_SCANNER_TYPED); -hd($parsed_ini, true); + $ag_groups_num = ($agents_num / 10); // Create new group per group of ten agents that are to be created. @@ -88,6 +94,7 @@ hd($parsed_ini, true); $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']; @@ -109,6 +116,21 @@ hd($parsed_ini, true); 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]); + continue; + } + } } // Define agents to be created per group of 10. @@ -122,7 +144,7 @@ hd($parsed_ini, true); $agents_to_create = ($ag_groups_num * $agents_per_os[$os_name]); - for ($i=0; $i < $agents_to_create; $i++) { + for ($i = 0; $i < $agents_to_create; $i++) { $next_ip_address = calculateNextHostAddress($address_network); $os_version = current($os_versions); @@ -163,6 +185,15 @@ hd($parsed_ini, true); $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++; } @@ -249,6 +280,7 @@ hd($parsed_ini, true); $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); @@ -266,7 +298,6 @@ hd($parsed_ini, true); 'id_os' => 1, ]; - // STEP 1: tmodule_inventory. $created_inventory_mod_id = inventory_create_inventory_module($values); if ($created_inventory_mod_id > 0) { @@ -286,18 +317,7 @@ hd($parsed_ini, true); $module_access_idx++; - // STEP 2: tagent_module_inventory. - $values = [ - 'id_agente' => $created_agent_id, - 'id_module_inventory' => $created_inventory_mod_id, - 'interval' => 300, - 'utimestamp' => time(), - 'timestamp' => $current_date_time, - ]; - - - - // STEP 3: Create inventory values (tagente_datos_inventory). + // Insert in tagent_module_inventory and tagente_datos_inventory. $field_idx = 1; $values_array = explode(';', $modules_array['values']); @@ -309,9 +329,6 @@ hd($parsed_ini, true); ARRAY_FILTER_USE_KEY ); - hd("INV VALUES", true); - hd($selected_inventory_values, true); - $data_lines = []; while (1) { $line_values = array_column($selected_inventory_values, $field_idx); @@ -326,19 +343,40 @@ hd($parsed_ini, true); $data_str = implode('\n', $data_lines); - hd("DATA STR",true); - hd($data_str, true); + $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 = [ - 'data' => $data_str, - 'utimestamp' => time(), - 'timestamp' => $current_date_time, + '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); - hd("CID",true); - hd($inventory_data_values, true); - hd($created_inventory_data, true); if ($created_inventory_data > 0) { // Register created inventory data element in tdemo_data. @@ -363,9 +401,65 @@ hd($parsed_ini, true); } } + $demo_agents_count = db_get_value('count(*)', 'tdemo_data', 'table_name', 'tagente'); + echo json_encode(['agents_count' => $demo_agents_count]); + return; } +if ($action === 'cleanup_demo_data') { + config_update_value('demo_data_load_progress', 0); + + $demo_items = db_get_all_rows_in_table('tdemo_data'); + + foreach ($demo_items as $item) { + $table_id_field_dict = [ + 'tconfig_os' => 'id_os', + 'tagente' => 'id_agente', + 'tgrupo' => 'id_grupo', + 'tagente_modulo' => 'id_agente_modulo', + 'tmodule_inventory' => 'id_module_inventory', + 'tagent_module_inventory' => 'id_agent_module_inventory', + 'tagente_datos_inventory' => 'id_agent_module_inventory', + ]; + + $table_id_field = $table_id_field_dict[$item['table_name']]; + + $result = db_process_sql_delete( + $item['table_name'], + [$table_id_field => $item['item_id']] + ); + + if ($result !== false) { + db_process_sql_delete( + 'tdemo_data', + ['item_id' => $item['item_id']] + ); + } + } + + echo 1; +} + +if ($action === 'get_progress_bar') { + $operation = (string) get_parameter('operation'); + + if ($operation === 'create') { + $current_progress_val = db_get_value_filter('value', 'tconfig', ['token' => 'demo_data_load_progress']); + + if ($current_progress_val === false) { + $current_progress_val = 0; + } + } else if ($operation === 'cleanup') { + $demo_items_to_cleanup = (int) get_parameter('demo_items_to_cleanup'); + $count_current_demo_items = db_get_value('count(*)', 'tdemo_data'); + $current_progress_val = ((($demo_items_to_cleanup - $count_current_demo_items) * 100) / $demo_items_to_cleanup); + } + + echo $current_progress_val; + + return; +} function calculateNextHostAddress($ip) { list($network, $subnet) = explode('/', $ip); @@ -374,13 +468,13 @@ function calculateNextHostAddress($ip) { $octets = explode('.', $network); // Convert the last octet to an integer. - $lastOctet = (int)$octets[3]; + $lastOctet = (int) $octets[3]; // Increment the last octet, and wrap around if it exceeds 255. - $lastOctet = ($lastOctet + 1) % 256; + $lastOctet = (($lastOctet + 1) % 256); // Assemble the next host address. - $nextHost = implode('.', array($octets[0], $octets[1], $octets[2], $lastOctet)); + $nextHost = implode('.', [$octets[0], $octets[1], $octets[2], $lastOctet]); - return $nextHost . '/' . $subnet; -} \ No newline at end of file + return $nextHost.'/'.$subnet; +} From 06f9b2e0935413d72861ab74aafdbf4cb1342fd7 Mon Sep 17 00:00:00 2001 From: Calvo Date: Fri, 10 Nov 2023 16:20:04 +0100 Subject: [PATCH 011/125] Policy capacity planning modules. JS errors --- .../godmode/agentes/module_manager_editor.php | 13 +++++++++++++ .../agentes/module_manager_editor_common.php | 2 +- .../agentes/module_manager_editor_prediction.php | 3 ++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/pandora_console/godmode/agentes/module_manager_editor.php b/pandora_console/godmode/agentes/module_manager_editor.php index a52813fbf3..29d5cb43e1 100644 --- a/pandora_console/godmode/agentes/module_manager_editor.php +++ b/pandora_console/godmode/agentes/module_manager_editor.php @@ -680,6 +680,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; @@ -862,6 +864,17 @@ ui_require_javascript_file('pandora_modules'); ?> From 863561781567df6bb90a1ec18fe476a1ceba42d9 Mon Sep 17 00:00:00 2001 From: Jorge Rincon Date: Thu, 16 Nov 2023 10:24:03 +0100 Subject: [PATCH 014/125] #12200 The Christmas effect is added after 25 clicks on the about image --- pandora_console/include/functions_menu.php | 3 ++- .../include/javascript/pandora_events.js | 12 ++++++++++++ pandora_console/index.php | 15 +++++++++++---- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/pandora_console/include/functions_menu.php b/pandora_console/include/functions_menu.php index 346dee04b5..ac76541162 100644 --- a/pandora_console/include/functions_menu.php +++ b/pandora_console/include/functions_menu.php @@ -1328,8 +1328,9 @@ if (is_ajax()) { -
+ logo + diff --git a/pandora_console/include/javascript/pandora_events.js b/pandora_console/include/javascript/pandora_events.js index 86b84376c5..4c1364c54c 100644 --- a/pandora_console/include/javascript/pandora_events.js +++ b/pandora_console/include/javascript/pandora_events.js @@ -1483,6 +1483,18 @@ function show_dialog(dialog) { }, 50); } +function christmas_click() { + let counter = $("#count_click").val(); + counter++; + $("#count_click").val(counter); + if (counter == 25) { + $("#container-snow").removeClass("invisible"); + setTimeout(() => { + $("#container-snow").addClass("invisible"); + }, 30000); + } +} + /* ############################################################################# ## diff --git a/pandora_console/index.php b/pandora_console/index.php index ff6f27b152..63f063c02d 100755 --- a/pandora_console/index.php +++ b/pandora_console/index.php @@ -1199,7 +1199,7 @@ if ($config['pure'] == 0) { $menuCollapsed = (isset($_SESSION['menu_type']) === true && $_SESSION['menu_type'] !== 'classic'); $menuTypeClass = ($menuCollapsed === true) ? 'collapsed' : 'classic'; // Snow. - $string = '
+ $string = '