Merge remote-tracking branch 'origin/develop' into ent-9500-cli-en-la-metaconsola-no-se-sicnroniza-con-los-nodos

This commit is contained in:
Daniel Barbero 2022-10-18 13:41:25 +02:00
commit 4b3376057c
4 changed files with 144 additions and 30 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
*/

View File

@ -251,6 +251,11 @@ sub help_screen{
print "\nEVENTS\n\n" unless $param ne '';
help_screen_line('--event_in_progress', '<id_event> ', 'Set event in progress');
print "\nGIS\n\n" unless $param ne '';
help_screen_line('--get_gis_agent', '<agent_id> ', 'Gets agent GIS information');
help_screen_line('--insert_gis_data', '<agent_id> [<latitude>] [<longitude>] [<altitude>]', 'Sets new GIS data for specified agent');
print "\n";
exit;
}
@ -261,7 +266,7 @@ sub help_screen{
sub api_call($$$;$$$$) {
my ($pa_config, $op, $op2, $id, $id2, $other, $return_type) = @_;
my $content = undef;
eval {
# Set the parameters for the POST request.
my $params = {};
@ -275,10 +280,11 @@ sub api_call($$$;$$$$) {
$params->{"other"} = $other;
$params->{"return_type"} = $return_type;
$params->{"other_mode"} = "url_encode_separator_|";
# Call the API.
my $ua = new LWP::UserAgent;
my $url = $pa_config->{"console_api_url"};
my $response = $ua->post($url, $params);
if ($response->is_success) {
@ -288,7 +294,7 @@ sub api_call($$$;$$$$) {
$content = $response->decoded_content();
}
};
return $content;
}
@ -8194,6 +8200,14 @@ sub pandora_manage_main ($$$) {
param_check($ltotal, 4, 5);
cli_agent_update_custom_fields();
}
elsif ($param eq '--get_gis_agent') {
param_check($ltotal, 1, 0);
cli_get_gis_agent();
}
elsif ($param eq '--insert_gis_data'){
param_check($ltotal, 4, 0);
cli_insert_gis_data();
}
else {
print_log "[ERROR] Invalid option '$param'.\n\n";
$param = '';
@ -8914,3 +8928,32 @@ sub pandora_validate_alert_id($$$$) {
return 1;
}
##############################################################################
# Get GIS data from agent
##############################################################################
sub cli_get_gis_agent(){
my $agent_id = @ARGV[2];
my $result = api_call(\%conf,'get', 'gis_agent', $agent_id);
print "$result \n\n ";
}
##############################################################################
# Set GIS data for specified agent
##############################################################################
sub cli_insert_gis_data(){
my ($agent_id, $latitude, $longitude, $altitude) = @ARGV[2..5];
my $agent_id = @ARGV[2];
my @position = @ARGV[3..5];
my $other = join('|', @position);
my $result = api_call(\%conf,'set', 'gis_agent_only_position', $agent_id, undef, "$other");
print "$result \n\n ";
}