Merge branch 'ent-8648-Improvement-for-SNMP-interface-wizard' into 'develop'

Added default definition for SNMP Interface Wizard

See merge request artica/pandorafms!5168
This commit is contained in:
Diego Muñoz-Reja 2022-10-18 09:25:17 +00:00
commit dfb5776f68
3 changed files with 98 additions and 27 deletions

View File

@ -701,6 +701,28 @@ if (enterprise_installed() === true) {
);
}
// Agent Wizard defaults.
$defaultAgentWizardOptions = json_decode(io_safe_output($config['agent_wizard_defaults']));
$tableSnmpWizard = new stdClass();
$tableSnmpWizard->width = '100%';
$tableSnmpWizard->class = 'databox filters';
$tableSnmpWizard->data = [];
$tableSnmpWizard->style[0] = 'font-weight: bold';
$tableSnmpWizard->style[2] = 'font-weight: bold';
$tableSnmpWizard->size[0] = '30%';
$tableSnmpWizard->size[2] = '30%';
$i = 0;
$j = 0;
foreach ($defaultAgentWizardOptions as $key => $value) {
$tableSnmpWizard->data[$i][$j++] = $key;
$tableSnmpWizard->data[$i][$j++] = html_print_checkbox_switch('agent_wizard_defaults_'.$key, 1, $value, true);
if ($j >= 3) {
$j = 0;
$i++;
}
}
echo '<form id="form_setup" method="post">';
echo '<fieldset class="full-column">';
@ -725,6 +747,11 @@ echo '<fieldset>';
html_print_table($table_other);
echo '</fieldset>';
echo '<fieldset>';
echo '<legend>'.__('Agent SNMP Interface Wizard defaults').' '.ui_print_help_icon('agent_snmp_wizard_options_tab', true).'</legend>';
html_print_table($tableSnmpWizard);
echo '</fieldset>';
echo '<div class="action-buttons" style="width: '.$table->width.'">';
html_print_input_hidden('update_config', 1);
html_print_submit_button(

View File

@ -14,7 +14,7 @@
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
*
* ============================================================================
* Copyright (c) 2005-2021 Artica Soluciones Tecnologicas
* Copyright (c) 2005-2022 Artica Soluciones Tecnologicas
* Please see http://pandorafms.org for full contribution list
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -285,6 +285,13 @@ class AgentWizard extends HTML
*/
private $wmiBinary = '';
/**
* Default values for SNMP Interfaces.
*
* @var string
*/
private $defaultSNMPValues = [];
/**
* Constructor
@ -319,6 +326,7 @@ class AgentWizard extends HTML
$this->idPolicy = get_parameter('id', '');
$this->targetIp = get_parameter('targetIp', '');
$this->wmiBinary = $config['wmiBinary'];
$this->defaultSNMPValues = (array) json_decode(io_safe_output($config['agent_wizard_defaults']));
if (empty($this->idAgent) === false) {
$array_aux = db_get_all_rows_sql(
@ -330,7 +338,7 @@ class AgentWizard extends HTML
)
);
if (!empty($array_aux)) {
if (empty($array_aux) === false) {
$this->datalist = [];
foreach ($array_aux as $key => $value) {
$this->datalist[] = $value['ip'];
@ -547,7 +555,7 @@ class AgentWizard extends HTML
// Fill with servers to perform the discover.
$fieldsServers = [];
$fieldsServers[0] = __('Local console');
if (enterprise_installed()) {
if (enterprise_installed() === true) {
enterprise_include_once('include/functions_satellite.php');
// Get the servers.
$rows = get_proxy_servers();
@ -607,7 +615,7 @@ class AgentWizard extends HTML
],
];
if (!empty($this->datalist)) {
if (empty($this->datalist) === false) {
$inputs[] = [
'id' => 'li_address_list',
'arguments' => [
@ -4719,7 +4727,7 @@ class AgentWizard extends HTML
'execution_type' => 'network',
'value' => '1.3.6.1.2.1.2.2.1.8.'.$value,
'module_unit' => '',
'default_enabled' => true,
'default_enabled' => (bool) $this->defaultSNMPValues['ifOperStatus'],
'module_enabled' => false,
'module_thresholds' => [
'min_warning' => $min_warning,
@ -4776,7 +4784,7 @@ class AgentWizard extends HTML
'execution_type' => 'network',
'value' => '1.3.6.1.4.1.9.2.2.1.1.12.'.$value,
'module_unit' => 'packets/s',
'default_enabled' => true,
'default_enabled' => (bool) $this->defaultSNMPValues['locIfInCRC'],
'module_enabled' => false,
'module_thresholds' => [
'min_warning' => '0',
@ -4830,7 +4838,7 @@ class AgentWizard extends HTML
'module_info' => 'Indicates whether the port is operating in half-duplex, full-duplex, disagree or auto negotiation mode. If the port could not agree with the far end on port duplex, the port will be in disagree(3) mode.',
'execution_type' => 'network',
'value' => $duplexMismatchOID,
'default_enabled' => true,
'default_enabled' => (bool) $this->defaultSNMPValues['DuplexMismatch'],
'module_enabled' => false,
'module_thresholds' => [
'min_warning' => '0',
@ -4919,7 +4927,7 @@ class AgentWizard extends HTML
'id_plugin' => $plugin_id,
'id_modulo' => MODULE_PLUGIN,
'macros' => json_encode($macros),
'default_enabled' => true,
'default_enabled' => (bool) $this->defaultSNMPValues['Bandwidth'],
'module_enabled' => false,
'module_unit' => '%',
'module_thresholds' => [
@ -4958,7 +4966,7 @@ class AgentWizard extends HTML
'id_plugin' => $plugin_id,
'id_modulo' => MODULE_PLUGIN,
'macros' => json_encode($macros),
'default_enabled' => true,
'default_enabled' => (bool) $this->defaultSNMPValues['inUsage'],
'module_enabled' => false,
'module_unit' => '%',
'module_thresholds' => [
@ -4997,7 +5005,7 @@ class AgentWizard extends HTML
'id_plugin' => $plugin_id,
'id_modulo' => MODULE_PLUGIN,
'macros' => json_encode($macros),
'default_enabled' => true,
'default_enabled' => (bool) $this->defaultSNMPValues['outUsage'],
'module_enabled' => false,
'module_unit' => '%',
'module_thresholds' => [
@ -5029,7 +5037,7 @@ class AgentWizard extends HTML
'execution_type' => 'network',
'value' => '1.3.6.1.2.1.2.2.1.7.'.$value,
'module_unit' => '',
'default_enabled' => false,
'default_enabled' => (bool) $this->defaultSNMPValues['ifAdminStatus'],
'module_enabled' => false,
'module_thresholds' => [
'min_warning' => '0',
@ -5056,7 +5064,7 @@ class AgentWizard extends HTML
'execution_type' => 'network',
'value' => '1.3.6.1.2.1.2.2.1.13.'.$value,
'module_unit' => 'packets/s',
'default_enabled' => false,
'default_enabled' => (bool) $this->defaultSNMPValues['ifInDiscards'],
'module_enabled' => false,
'module_thresholds' => [
'min_warning' => '0',
@ -5083,7 +5091,7 @@ class AgentWizard extends HTML
'execution_type' => 'network',
'value' => '1.3.6.1.2.1.2.2.1.19.'.$value,
'module_unit' => 'packets/s',
'default_enabled' => false,
'default_enabled' => (bool) $this->defaultSNMPValues['ifOutDiscards'],
'module_enabled' => false,
'module_thresholds' => [
'min_warning' => '0',
@ -5110,7 +5118,7 @@ class AgentWizard extends HTML
'execution_type' => 'network',
'value' => '1.3.6.1.2.1.2.2.1.14.'.$value,
'module_unit' => 'packets/s',
'default_enabled' => false,
'default_enabled' => (bool) $this->defaultSNMPValues['ifInErrors'],
'module_enabled' => false,
'module_thresholds' => [
'min_warning' => '0',
@ -5137,7 +5145,7 @@ class AgentWizard extends HTML
'execution_type' => 'network',
'value' => '1.3.6.1.2.1.2.2.1.20.'.$value,
'module_unit' => 'packets/s',
'default_enabled' => false,
'default_enabled' => (bool) $this->defaultSNMPValues['ifOutErrors'],
'module_enabled' => false,
'module_thresholds' => [
'min_warning' => '0',
@ -5207,7 +5215,7 @@ class AgentWizard extends HTML
'execution_type' => 'network',
'value' => '1.3.6.1.2.1.2.2.1.10.'.$value,
'module_unit' => 'bytes/s',
'default_enabled' => true,
'default_enabled' => (bool) $this->defaultSNMPValues['ifInOctets'],
'module_enabled' => false,
'module_thresholds' => [
'min_warning' => '0',
@ -5235,7 +5243,7 @@ class AgentWizard extends HTML
'execution_type' => 'network',
'value' => '1.3.6.1.2.1.2.2.1.16.'.$value,
'module_unit' => 'bytes/s',
'default_enabled' => true,
'default_enabled' => (bool) $this->defaultSNMPValues['ifOutOctets'],
'module_enabled' => false,
'module_thresholds' => [
'min_warning' => '0',
@ -5263,7 +5271,7 @@ class AgentWizard extends HTML
'execution_type' => 'network',
'value' => '1.3.6.1.2.1.2.2.1.11.'.$value,
'module_unit' => 'packets/s',
'default_enabled' => false,
'default_enabled' => (bool) $this->defaultSNMPValues['ifInUcastPkts'],
'module_enabled' => false,
'module_thresholds' => [
'min_warning' => '0',
@ -5290,7 +5298,7 @@ class AgentWizard extends HTML
'execution_type' => 'network',
'value' => '1.3.6.1.2.1.2.2.1.17.'.$value,
'module_unit' => 'packets/s',
'default_enabled' => false,
'default_enabled' => (bool) $this->defaultSNMPValues['ifOutUcastPkts'],
'module_enabled' => false,
'module_thresholds' => [
'min_warning' => '0',
@ -5317,7 +5325,7 @@ class AgentWizard extends HTML
'execution_type' => 'network',
'value' => '1.3.6.1.2.1.2.2.1.12.'.$value,
'module_unit' => 'packets/s',
'default_enabled' => false,
'default_enabled' => (bool) $this->defaultSNMPValues['ifInNUcastPkts'],
'module_enabled' => false,
'module_thresholds' => [
'min_warning' => '0',
@ -5344,7 +5352,7 @@ class AgentWizard extends HTML
'execution_type' => 'network',
'value' => '1.3.6.1.2.1.2.2.1.18.'.$value,
'module_unit' => 'packets/s',
'default_enabled' => false,
'default_enabled' => (bool) $this->defaultSNMPValues['ifOutNUcastPkts'],
'module_enabled' => false,
'module_thresholds' => [
'min_warning' => '0',
@ -5414,7 +5422,7 @@ class AgentWizard extends HTML
'execution_type' => 'network',
'value' => '1.3.6.1.2.1.31.1.1.1.6.'.$value,
'module_unit' => 'bytes/s',
'default_enabled' => true,
'default_enabled' => (bool) $this->defaultSNMPValues['ifHCInOctets'],
'module_enabled' => false,
'module_thresholds' => [
'min_warning' => '0',
@ -5442,7 +5450,7 @@ class AgentWizard extends HTML
'execution_type' => 'network',
'value' => '1.3.6.1.2.1.31.1.1.1.10.'.$value,
'module_unit' => 'bytes/s',
'default_enabled' => true,
'default_enabled' => (bool) $this->defaultSNMPValues['ifHCOutOctets'],
'module_enabled' => false,
'module_thresholds' => [
'min_warning' => '0',
@ -5470,7 +5478,7 @@ class AgentWizard extends HTML
'execution_type' => 'network',
'value' => '1.3.6.1.2.1.31.1.1.1.7.'.$value,
'module_unit' => 'packets/s',
'default_enabled' => false,
'default_enabled' => (bool) $this->defaultSNMPValues['ifHCInUcastPkts'],
'module_enabled' => false,
'module_thresholds' => [
'min_warning' => '0',
@ -5498,7 +5506,7 @@ class AgentWizard extends HTML
'execution_type' => 'network',
'value' => '1.3.6.1.2.1.31.1.1.1.11.'.$value,
'module_unit' => 'packets/s',
'default_enabled' => false,
'default_enabled' => (bool) $this->defaultSNMPValues['ifHCOutUcastPkts'],
'module_enabled' => false,
'module_thresholds' => [
'min_warning' => '0',
@ -5525,7 +5533,7 @@ class AgentWizard extends HTML
'execution_type' => 'network',
'value' => '1.3.6.1.2.1.31.1.1.1.7.'.$value,
'module_unit' => 'packets/s',
'default_enabled' => false,
'default_enabled' => (bool) $this->defaultSNMPValues['ifHCInNUcastPkts'],
'module_enabled' => false,
'module_thresholds' => [
'min_warning' => '0',
@ -5552,7 +5560,7 @@ class AgentWizard extends HTML
'execution_type' => 'network',
'value' => '1.3.6.1.2.1.31.1.1.1.11.'.$value,
'module_unit' => 'packets/s',
'default_enabled' => false,
'default_enabled' => (bool) $this->defaultSNMPValues['ifHCOutNUcastPkts'],
'module_enabled' => false,
'module_thresholds' => [
'min_warning' => '0',

View File

@ -909,6 +909,16 @@ function config_update_config()
$error_update[] = __('Default WMI Binary');
}
// Walk the array with defaults.
$defaultAgentWizardOptions = json_decode(io_safe_output($config['agent_wizard_defaults']));
foreach ($defaultAgentWizardOptions as $key => $value) {
$selectedAgentWizardOptions[$key] = get_parameter_switch('agent_wizard_defaults_'.$key);
}
if (config_update_value('agent_wizard_defaults', json_encode($selectedAgentWizardOptions), true) === false) {
$error_update[] = __('SNMP Interface Agent Wizard');
}
$pjs = get_parameter('phantomjs_cache_interval');
switch ($pjs) {
case $config['phantomjs_cache_interval']:
@ -2244,6 +2254,32 @@ function config_process_config()
config_update_value('2Fa_auth', '');
}
if (isset($config['agent_wizard_defaults']) === false) {
config_update_value(
'agent_wizard_defaults',
json_encode(
[
'ifOperStatus' => 1,
'ifInOctets' => 1,
'ifOutOctets' => 1,
'ifInUcastPkts' => 0,
'ifOutUcastPkts' => 0,
'ifInNUcastPkts' => 0,
'ifOutNUcastPkts' => 0,
'locIfInCRC' => 1,
'Bandwidth' => 1,
'inUsage' => 1,
'outUsage' => 1,
'ifAdminStatus' => 0,
'ifInDiscards' => 0,
'ifOutDiscards' => 0,
'ifInErrors' => 0,
'ifOutErrors' => 0,
],
)
);
}
/*
* Parse the ACL IP list for access API
*/