From 1363072405212cc9a5bd9beac752f8add519d7a5 Mon Sep 17 00:00:00 2001 From: "alejandro.campos@artica.es" Date: Tue, 27 Feb 2024 18:38:37 +0100 Subject: [PATCH 1/3] implemented agent module custom selectors --- .../godmode/agentes/agent_manager.php | 2 +- .../godmode/agentes/configurar_agente.php | 7 +- .../agentes/module_manager_editor_common.php | 14 +- .../godmode/massive/massive_edit_agents.php | 4 +- .../godmode/massive/massive_edit_modules.php | 2 +- .../modules/manage_network_components.php | 5 + .../manage_network_components_form_common.php | 2 +- pandora_console/include/functions_clippy.php | 7 +- pandora_console/include/functions_html.php | 179 +++++++++++++++++- .../help/clippy/agent_module_interval.php | 49 +++++ .../help/clippy/data_configuration_module.php | 2 +- pandora_console/include/styles/pandora.css | 4 + 12 files changed, 266 insertions(+), 11 deletions(-) create mode 100644 pandora_console/include/help/clippy/agent_module_interval.php diff --git a/pandora_console/godmode/agentes/agent_manager.php b/pandora_console/godmode/agentes/agent_manager.php index 36d2458be7..4decf2e75d 100644 --- a/pandora_console/godmode/agentes/agent_manager.php +++ b/pandora_console/godmode/agentes/agent_manager.php @@ -558,7 +558,7 @@ if ($broker === false) { $tableAgent->data['caption_interval'][0] = __('Interval'); // $tableAgent->rowstyle['interval'] = 'width: 260px'; $tableAgent->rowclass['interval'] = 'w540px'; - $tableAgent->data['interval'][0] = html_print_extended_select_for_time( + $tableAgent->data['interval'][0] = html_print_select_agentmodule_interval( 'intervalo', $intervalo, '', diff --git a/pandora_console/godmode/agentes/configurar_agente.php b/pandora_console/godmode/agentes/configurar_agente.php index 6a1084e605..68e0a068f5 100644 --- a/pandora_console/godmode/agentes/configurar_agente.php +++ b/pandora_console/godmode/agentes/configurar_agente.php @@ -878,7 +878,7 @@ if ($id_agente) { ], ], [], - $dots + $dots ?? '' ); } @@ -1472,6 +1472,11 @@ if ($update_module === true || $create_module === true) { $min = (int) get_parameter('min'); $max = (int) get_parameter('max'); $interval = (int) get_parameter('module_interval', $intervalo); + // Limit module interval to at least 60 secs. + if ($interval > 0) { + $interval = max($interval, 60); + } + $ff_interval = (int) get_parameter('module_ff_interval'); $quiet_module = (int) get_parameter('quiet_module'); $cps_module = (int) get_parameter('cps_module'); diff --git a/pandora_console/godmode/agentes/module_manager_editor_common.php b/pandora_console/godmode/agentes/module_manager_editor_common.php index a9d809d29f..be4391f54f 100644 --- a/pandora_console/godmode/agentes/module_manager_editor_common.php +++ b/pandora_console/godmode/agentes/module_manager_editor_common.php @@ -701,7 +701,19 @@ if ((int) $moduletype === MODULE_DATA) { // be taken the agent interval (this code is at configurar_agente.php). } else { $interval = ($interval === '') ? '300' : $interval; - $outputExecutionInterval = html_print_extended_select_for_time('module_interval', $interval, '', '', '0', false, true, false, false, $classdisabledBecauseInPolicy, $disabledBecauseInPolicy); + $outputExecutionInterval = html_print_select_agentmodule_interval( + 'module_interval', + $interval, + '', + '', + '0', + false, + true, + false, + false, + $classdisabledBecauseInPolicy, + $disabledBecauseInPolicy + ); } $module_id_policy_module = 0; diff --git a/pandora_console/godmode/massive/massive_edit_agents.php b/pandora_console/godmode/massive/massive_edit_agents.php index 26ab73603c..740bb5b93b 100755 --- a/pandora_console/godmode/massive/massive_edit_agents.php +++ b/pandora_console/godmode/massive/massive_edit_agents.php @@ -744,7 +744,7 @@ $table->data[1][1] .= ''; $table->data[2][0] = __('Interval'); -$table->data[2][1] = html_print_extended_select_for_time( +$table->data[2][1] = html_print_select_agentmodule_interval( 'interval', -2, '', @@ -1155,7 +1155,7 @@ $table->data[6][1] = html_print_select( true ); -$table->data[7][0] = __('Safe operation mode').': '.ui_print_help_tip( +$table->data[7][0] = __('Safe operation mode').ui_print_help_tip( __( 'This mode allow %s to disable all modules of this agent while the selected module is on CRITICAL status', get_product_name() diff --git a/pandora_console/godmode/massive/massive_edit_modules.php b/pandora_console/godmode/massive/massive_edit_modules.php index 672c59276c..960437b039 100755 --- a/pandora_console/godmode/massive/massive_edit_modules.php +++ b/pandora_console/godmode/massive/massive_edit_modules.php @@ -865,7 +865,7 @@ $table->data[15][0] = html_print_label_input_block( $table->data[16][0] = html_print_label_input_block( __('Interval'), - html_print_extended_select_for_time( + html_print_select_agentmodule_interval( 'module_interval', 0, '', diff --git a/pandora_console/godmode/modules/manage_network_components.php b/pandora_console/godmode/modules/manage_network_components.php index c04a66b549..7e72262bdf 100644 --- a/pandora_console/godmode/modules/manage_network_components.php +++ b/pandora_console/godmode/modules/manage_network_components.php @@ -82,6 +82,11 @@ $snmp_oid = (string) get_parameter('snmp_oid'); $snmp_community = (string) get_parameter('snmp_community'); $id_module_group = (int) get_parameter('id_module_group'); $module_interval = (int) get_parameter('module_interval'); +// Limit module interval to at least 60 secs. +if ($module_interval > 0) { + $module_interval = max($module_interval, 60); +} + $id_group = (int) get_parameter('id_group'); $plugin_user = (string) get_parameter('plugin_user'); $plugin_pass = io_input_password((string) get_parameter('plugin_pass')); diff --git a/pandora_console/godmode/modules/manage_network_components_form_common.php b/pandora_console/godmode/modules/manage_network_components_form_common.php index 3f573ec2c8..7a016d7a91 100644 --- a/pandora_console/godmode/modules/manage_network_components_form_common.php +++ b/pandora_console/godmode/modules/manage_network_components_form_common.php @@ -154,7 +154,7 @@ $table->data[2][0] = html_print_label_input_block( $table->data[2][1] = html_print_label_input_block( __('Interval'), - html_print_extended_select_for_time('module_interval', $module_interval, '', '', '0', false, true) + html_print_select_agentmodule_interval('module_interval', $module_interval, '', '', '0', false, true) ); $dynamic_interval_img = ''.html_print_image( diff --git a/pandora_console/include/functions_clippy.php b/pandora_console/include/functions_clippy.php index 8505e0bf09..1da6d46285 100644 --- a/pandora_console/include/functions_clippy.php +++ b/pandora_console/include/functions_clippy.php @@ -317,6 +317,11 @@ function clippy_context_help($help=null) $title = $clippy_data_configuration_module['tours']['data_configuration_module']['steps'][0]['title']; $intro = $clippy_data_configuration_module['tours']['data_configuration_module']['steps'][0]['intro']; $img = $clippy_data_configuration_module['tours']['data_configuration_module']['steps'][0]['img']; + } else if ($help === 'agent_module_interval') { + $clippy_agent_module_interval = clippy_agent_module_interval(); + $title = $clippy_agent_module_interval['tours']['agent_module_interval']['steps'][0]['title']; + $intro = $clippy_agent_module_interval['tours']['agent_module_interval']['steps'][0]['intro']; + $img = $clippy_agent_module_interval['tours']['agent_module_interval']['steps'][0]['img']; } else { $img = html_print_image( 'images/info-warning.svg', @@ -351,6 +356,6 @@ function clippy_context_help($help=null) }); '; - +hd($return, true); return $return; } diff --git a/pandora_console/include/functions_html.php b/pandora_console/include/functions_html.php index 7f4033ab53..4d27a3388e 100644 --- a/pandora_console/include/functions_html.php +++ b/pandora_console/include/functions_html.php @@ -2286,7 +2286,7 @@ function html_print_extended_select_for_time( echo ''; - echo '
'; + echo '
'; html_print_input_text($uniq_name.'_text', $selected, '', $size, 255, false, $readonly, false, '', $class, $script_input); html_print_input_hidden($name, $selected, false, $uniq_name); @@ -2313,7 +2313,7 @@ function html_print_extended_select_for_time( false, false ); - echo ' '.html_print_image( + echo '  '.html_print_image( 'images/logs@svg.svg', true, [ @@ -2354,6 +2354,181 @@ function html_print_extended_select_for_time( } +/** + * Render agent/module interval-specific time selection set of inputs + * from html_print_extended_select_for_time with additional structure and + * behavior associated (establishes a limit of at least 60 seconds to be + * selected and displays notice when this limit is actively selected). + * + * @param string $name Select form name. + * @param mixed $selected Current selected value. Can be a single value or an array of selected values (in combination with multiple). + * @param string $script Javascript onChange (select) code. + * @param string $nothing Label when nothing is selected. + * @param mixed $nothing_value Value when nothing is selected. + * @param integer $size Size of the input. + * @param boolean $return Whether to return an output string or echo now (optional, echo by default). + * @param boolean $select_style Wherter to assign to combo a unique name (to have more than one on same page, like dashboard). + * @param boolean $unique_name Uunique name value. + * @param string $class Class value. + * @param boolean $readonly Readonly value. + * @param string $custom_fields Custom fields value. + * @param string $style_icon Style icon value. + * @param boolean $no_change No change value. + * @param boolean $allow_zero Allow the use of the value zero. + + * @return string HTML code if return parameter is true. + */ +function html_print_select_agentmodule_interval( + $name, + $selected='', + $script='', + $nothing='', + $nothing_value='0', + $size=false, + $return=false, + $select_style=false, + $unique_name=true, + $class='', + $readonly=false, + $custom_fields=false, + $style_icon='', + $no_change=false, + $allow_zero=0, + $units=null, + $script_input='' +) { + global $config; + + include_once $config['homedir'].'/include/functions_clippy.php'; + + $output = '
'; + $output .= html_print_extended_select_for_time( + $name, + $selected, + $script, + $nothing, + $nothing_value, + $size, + $return, + $select_style, + $unique_name, + $class, + $readonly + ); + + $unique_id = ''; + + if ($unique_name === true) { + $pattern = '/'.$name.'([a-fA-F0-9]+)_default/'; + + if (preg_match($pattern, $output, $matches)) { + // Obtain the unique ID of the generated input. + $unique_id = $matches[1]; + $name .= $unique_id; + } + } + + $output .= html_print_div( + [ + 'id' => 'agent_module_interval_clippy'.$unique_id, + 'class' => 'invisible flex align-self-center', + 'content' => clippy_context_help('agent_module_interval'), + ], + true + ); + + $output .= ""; + $output .= '
'; + return $output; +} + + /** * Print selects to configure the cron of a module. * diff --git a/pandora_console/include/help/clippy/agent_module_interval.php b/pandora_console/include/help/clippy/agent_module_interval.php new file mode 100644 index 0000000000..c7914ca4ca --- /dev/null +++ b/pandora_console/include/help/clippy/agent_module_interval.php @@ -0,0 +1,49 @@ + true, + 'intro' => __('Pandora FMS is designed to monitor thousands of elements. It is possible to use very low sampling intervals using specific elements for it (Satellite Server) but doing it in a centralized way can have a severe impact in the performance, that\'s why we limit it to intervals of at least 60 seconds. Even then, you should only do 60 second sampling on very specific modules. The impact on your infrastructure can be severe, leading to event storms and delays in other monitoring. If you are going to use 60-second intervals, we recommend that you disable unknown detection to avoid unwanted events and use FlipFlop\'s protection settings.'), + 'title' => __('Data Configuration Module.'), + 'img' => html_print_image( + 'images/info-warning.svg', + true, + [ + 'class' => 'main_menu_icon invert_filter', + 'style' => 'margin-left: 5px;', + ] + ), + ]; + $return_tours['tours']['agent_module_interval']['conf'] = []; + $return_tours['tours']['agent_module_interval']['conf']['autostart'] = false; + $return_tours['tours']['agent_module_interval']['conf']['show_bullets'] = 0; + $return_tours['tours']['agent_module_interval']['conf']['show_step_numbers'] = 0; + + return $return_tours; +} diff --git a/pandora_console/include/help/clippy/data_configuration_module.php b/pandora_console/include/help/clippy/data_configuration_module.php index 4e5d33efaa..fd28262da4 100644 --- a/pandora_console/include/help/clippy/data_configuration_module.php +++ b/pandora_console/include/help/clippy/data_configuration_module.php @@ -32,7 +32,7 @@ function clippy_data_configuration_module() $return_tours['tours']['data_configuration_module']['steps'] = []; $return_tours['tours']['data_configuration_module']['steps'][] = [ 'init_step_context' => true, - 'intro' => __('Please note that information provided here affects how the agent collect information and generate the data XML. Any data/configuration reported by the agent, different from data or description is discarded, and the configuration shown in the console prevails over any configuration coming from the agent, this applies for example for crit/warn thresholds, interval, module group, min/max value, tags, etc.').__('Information imported FIRST time from the XML will fill the information you can see in the console, but after the first import, system will ignore any update coming from the XML/Agent.'), + 'intro' => __('Please note that information provided here affects how the agent collects information and generate the data XML. Any data/configuration reported by the agent, different from data or description is discarded, and the configuration shown in the console prevails over any configuration coming from the agent, this applies for example to crit/warn thresholds, interval, module group, min/max value, tags, etc.').' '.__('Information imported FIRST time from the XML will fill the information you can see in the console, but after the first import, system will ignore any update coming from the XML/Agent.'), 'title' => __('Data Configuration Module.'), 'img' => html_print_image( 'images/info-warning.svg', diff --git a/pandora_console/include/styles/pandora.css b/pandora_console/include/styles/pandora.css index 61c91f9370..64b215c2a5 100644 --- a/pandora_console/include/styles/pandora.css +++ b/pandora_console/include/styles/pandora.css @@ -995,6 +995,10 @@ select:-internal-list-box { display: flex; } +.align-self-center { + align-self: center; +} + .flex_important { display: flex !important; } From 8ff51b3679935d40c65c56907de72e9344a11ede Mon Sep 17 00:00:00 2001 From: "alejandro.campos@artica.es" Date: Tue, 27 Feb 2024 18:46:34 +0100 Subject: [PATCH 2/3] implemented agent module custom selectors --- pandora_console/godmode/agentes/configurar_agente.php | 2 +- pandora_console/include/functions_clippy.php | 2 +- pandora_console/include/functions_html.php | 9 +-------- 3 files changed, 3 insertions(+), 10 deletions(-) diff --git a/pandora_console/godmode/agentes/configurar_agente.php b/pandora_console/godmode/agentes/configurar_agente.php index 68e0a068f5..d7c308f008 100644 --- a/pandora_console/godmode/agentes/configurar_agente.php +++ b/pandora_console/godmode/agentes/configurar_agente.php @@ -878,7 +878,7 @@ if ($id_agente) { ], ], [], - $dots ?? '' + ($dots ?? '') ); } diff --git a/pandora_console/include/functions_clippy.php b/pandora_console/include/functions_clippy.php index 1da6d46285..1ccb9724a0 100644 --- a/pandora_console/include/functions_clippy.php +++ b/pandora_console/include/functions_clippy.php @@ -356,6 +356,6 @@ function clippy_context_help($help=null) }); '; -hd($return, true); + return $return; } diff --git a/pandora_console/include/functions_html.php b/pandora_console/include/functions_html.php index 4d27a3388e..46ba526e80 100644 --- a/pandora_console/include/functions_html.php +++ b/pandora_console/include/functions_html.php @@ -2439,13 +2439,10 @@ function html_print_select_agentmodule_interval( $output .= "