implemented agent module custom selectors

This commit is contained in:
alejandro.campos@artica.es 2024-02-27 18:38:37 +01:00
parent 421598df6b
commit 1363072405
12 changed files with 266 additions and 11 deletions

View File

@ -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,
'',

View File

@ -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');

View File

@ -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;

View File

@ -744,7 +744,7 @@ $table->data[1][1] .= '</div>';
$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()

View File

@ -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,
'',

View File

@ -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'));

View File

@ -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 = '<a onclick="advanced_option_dynamic()" class="mrgn_lft_5px mrgn_top_6px">'.html_print_image(

View File

@ -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)
});
</script>
';
hd($return, true);
return $return;
}

View File

@ -2286,7 +2286,7 @@ function html_print_extended_select_for_time(
echo '</div>';
echo '<div id="'.$uniq_name.'_manual" class="w100p inline_flex">';
echo '<div id="'.$uniq_name.'_manual" class="inline_flex">';
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 ' <a href="javascript:">'.html_print_image(
echo '&nbsp&nbsp<a href="javascript:">'.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 = '<div style="display: inline-flex;">';
$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 .= "<script type='text/javascript'>
$(document).ready (function () {
console.log('outputExecutionIntervaloutputExecutionInterval');
console.log('".$unique_id."');
// Trigger first check.
$('#text-".$name."_text').trigger('change');
$('#text-".$name."_text').on('keyup change', function() {
console.log('change1');
var unit_multiplier = parseInt($('#".$name."_units').val());
var numeric_value = parseInt($(this).val());
if (unit_multiplier <= 0 || numeric_value <= 0) {
return;
}
var curr_secs = numeric_value * unit_multiplier;
if (curr_secs === 60) {
$('#agent_module_interval_clippy".$unique_id."').show();
} else {
$('#agent_module_interval_clippy".$unique_id."').hide();
}
});
console.log('.".$name."_toggler');
$('.".$name."_toggler').on('click', function() {
console.log('clickk');
console.log('".$name."_default');
if ($('#".$name."_default').css('display') != 'none') {
$('#agent_module_interval_clippy".$unique_id."').hide();
} else {
console.log('triggggg');
$('#text-".$name."_text').trigger('change');
}
});
$('#".$name."_units').on('input change', function() {
console.log('change2');
var numeric_value = parseInt($('#text-".$name."_text').val());
var unit_multiplier = parseInt($(this).val());
if (unit_multiplier <= 0 || numeric_value <= 0) {
return;
}
var curr_secs = numeric_value * unit_multiplier;
if (curr_secs== 60) {
$('#agent_module_interval_clippy".$unique_id."').show();
} else {
$('#agent_module_interval_clippy".$unique_id."').hide();
}
});
$('#text-".$name."_text').on('change', function() {
checkMinValue($(this));
});
$('#".$name."_units').on('input change', function() {
checkMinValue($('#text-".$name."_text'));
});
});
function checkMinValue(that) {
if (isNaN(that.val()) === true) {
return;
}
var unit_multiplier = parseInt($('#".$name."_units').val());
var numeric_value = parseInt(that.val());
if (unit_multiplier <= 0 || numeric_value <= 0) {
return;
}
var curr_secs = numeric_value * unit_multiplier;
if (curr_secs < 60) {
// Override value to minimum limited seconds (60).
that
.val((60 / unit_multiplier))
.trigger('change');
}
}
</script>";
$output .= '</div>';
return $output;
}
/**
* Print selects to configure the cron of a module.
*

View File

@ -0,0 +1,49 @@
<?php
// Pandora FMS - https://pandorafms.com
// ==================================================
// Copyright (c) 2005-2023 Pandora FMS
// Please see https://pandorafms.com/community/ for full contribution list
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation; version 2
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
/**
* @package Include
* @subpackage Clippy
*/
function clippy_agent_module_interval()
{
$return_tours = [];
$return_tours['first_step_by_default'] = true;
$return_tours['help_context'] = true;
$return_tours['tours'] = [];
$return_tours['tours']['agent_module_interval'] = [];
$return_tours['tours']['agent_module_interval']['steps'] = [];
$return_tours['tours']['agent_module_interval']['steps'][] = [
'init_step_context' => 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;
}

View File

@ -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.').'&nbsp'.__('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',

View File

@ -995,6 +995,10 @@ select:-internal-list-box {
display: flex;
}
.align-self-center {
align-self: center;
}
.flex_important {
display: flex !important;
}