enhance indent

This commit is contained in:
garnier-quentin 2020-01-10 14:26:44 +01:00
parent 75ba86eda9
commit 12df0f4486
1 changed files with 133 additions and 133 deletions

View File

@ -45,26 +45,26 @@ sub new {
if (!defined($options{noptions})) { if (!defined($options{noptions})) {
$options{options}->add_options(arguments => { $options{options}->add_options(arguments => {
"hostname|host:s" => { name => 'host' }, 'hostname|host:s' => { name => 'host' },
"snmp-community:s" => { name => 'snmp_community', default => 'public' }, 'snmp-community:s' => { name => 'snmp_community', default => 'public' },
"snmp-version:s" => { name => 'snmp_version', default => 1 }, 'snmp-version:s' => { name => 'snmp_version', default => 1 },
"snmp-port:s" => { name => 'snmp_port', default => 161 }, 'snmp-port:s' => { name => 'snmp_port', default => 161 },
"snmp-timeout:s" => { name => 'snmp_timeout', default => 1 }, 'snmp-timeout:s' => { name => 'snmp_timeout', default => 1 },
"snmp-retries:s" => { name => 'snmp_retries', default => 5 }, 'snmp-retries:s' => { name => 'snmp_retries', default => 5 },
"maxrepetitions:s" => { name => 'maxrepetitions', default => 50 }, 'maxrepetitions:s' => { name => 'maxrepetitions', default => 50 },
"subsetleef:s" => { name => 'subsetleef', default => 50 }, 'subsetleef:s' => { name => 'subsetleef', default => 50 },
"subsettable:s" => { name => 'subsettable', default => 100 }, 'subsettable:s' => { name => 'subsettable', default => 100 },
"snmp-autoreduce:s" => { name => 'snmp_autoreduce' }, 'snmp-autoreduce:s' => { name => 'snmp_autoreduce' },
"snmp-force-getnext" => { name => 'snmp_force_getnext' }, 'snmp-force-getnext' => { name => 'snmp_force_getnext' },
"snmp-username:s" => { name => 'snmp_security_name' }, 'snmp-username:s' => { name => 'snmp_security_name' },
"authpassphrase:s" => { name => 'snmp_auth_passphrase' }, 'authpassphrase:s' => { name => 'snmp_auth_passphrase' },
"authprotocol:s" => { name => 'snmp_auth_protocol' }, 'authprotocol:s' => { name => 'snmp_auth_protocol' },
"privpassphrase:s" => { name => 'snmp_priv_passphrase' }, 'privpassphrase:s' => { name => 'snmp_priv_passphrase' },
"privprotocol:s" => { name => 'snmp_priv_protocol' }, 'privprotocol:s' => { name => 'snmp_priv_protocol' },
"contextname:s" => { name => 'snmp_context_name' }, 'contextname:s' => { name => 'snmp_context_name' },
"contextengineid:s" => { name => 'snmp_context_engine_id' }, 'contextengineid:s' => { name => 'snmp_context_engine_id' },
"securityengineid:s" => { name => 'snmp_security_engine_id' }, 'securityengineid:s' => { name => 'snmp_security_engine_id' },
"snmp-errors-exit:s" => { name => 'snmp_errors_exit', default => 'unknown' }, 'snmp-errors-exit:s' => { name => 'snmp_errors_exit', default => 'unknown' },
}); });
} }
$options{options}->add_help(package => __PACKAGE__, sections => 'SNMP OPTIONS'); $options{options}->add_help(package => __PACKAGE__, sections => 'SNMP OPTIONS');
@ -334,11 +334,11 @@ sub get_leef {
if (((scalar(@$vb) != scalar(@{$entry})) || (scalar(@{@$vb[-1]}) < 3)) && !$self->is_snmpv1()) { if (((scalar(@$vb) != scalar(@{$entry})) || (scalar(@{@$vb[-1]}) < 3)) && !$self->is_snmpv1()) {
next if ($self->{snmp_autoreduce} == 1 && $self->autoreduce_leef(current => $entry) == 0); next if ($self->{snmp_autoreduce} == 1 && $self->autoreduce_leef(current => $entry) == 0);
if ($dont_quit == 0) { if ($dont_quit == 0) {
$self->{output}->add_option_msg(short_msg => "SNMP partial response. Please try --snmp-autoreduce option"); $self->{output}->add_option_msg(short_msg => 'SNMP partial response. Please try --snmp-autoreduce option');
$self->{output}->option_exit(exit_litteral => $self->{snmp_errors_exit}); $self->{output}->option_exit(exit_litteral => $self->{snmp_errors_exit});
} }
$self->set_error(error_status => -1, error_msg => "SNMP partial response"); $self->set_error(error_status => -1, error_msg => 'SNMP partial response');
return undef; return undef;
} }
@ -358,7 +358,7 @@ sub get_leef {
} }
if ($nothing_quit == 1 && $total == 0) { if ($nothing_quit == 1 && $total == 0) {
$self->{output}->add_option_msg(short_msg => "SNMP GET Request : Cant get a single value."); $self->{output}->add_option_msg(short_msg => 'SNMP GET Request : Cant get a single value.');
$self->{output}->option_exit(exit_litteral => $self->{snmp_errors_exit}); $self->{output}->option_exit(exit_litteral => $self->{snmp_errors_exit});
} }
@ -517,7 +517,7 @@ sub get_multiple_table {
# infinite loop. Some equipments it returns nothing!!?? # infinite loop. Some equipments it returns nothing!!??
if ($pos == -1) { if ($pos == -1) {
$self->{output}->add_option_msg(short_msg => "SNMP Table Request: problem to get values (try --snmp-force-getnext option)"); $self->{output}->add_option_msg(short_msg => 'SNMP Table Request: problem to get values (try --snmp-force-getnext option)');
$self->{output}->option_exit(exit_litteral => $self->{snmp_errors_exit}); $self->{output}->option_exit(exit_litteral => $self->{snmp_errors_exit});
} }
} }
@ -533,7 +533,7 @@ sub get_multiple_table {
} }
if ($total == 0) { if ($total == 0) {
$self->{output}->add_option_msg(short_msg => "SNMP Table Request: Cant get a single value."); $self->{output}->add_option_msg(short_msg => 'SNMP Table Request: Cant get a single value.');
$self->{output}->option_exit(exit_litteral => $self->{snmp_errors_exit}); $self->{output}->option_exit(exit_litteral => $self->{snmp_errors_exit});
} }
} }
@ -648,7 +648,7 @@ sub get_table {
} }
if ($nothing_quit == 1 && scalar(keys %$results) == 0) { if ($nothing_quit == 1 && scalar(keys %$results) == 0) {
$self->{output}->add_option_msg(short_msg => "SNMP Table Request: Cant get a single value."); $self->{output}->add_option_msg(short_msg => 'SNMP Table Request: Cant get a single value.');
$self->{output}->option_exit(exit_litteral => $self->{snmp_errors_exit}); $self->{output}->option_exit(exit_litteral => $self->{snmp_errors_exit});
} }
@ -733,13 +733,13 @@ sub check_options {
# $options{option_results} = ref to options result # $options{option_results} = ref to options result
if (!defined($options{option_results}->{host})) { if (!defined($options{option_results}->{host})) {
$self->{output}->add_option_msg(short_msg => "Missing parameter --hostname."); $self->{output}->add_option_msg(short_msg => 'Missing parameter --hostname.');
$self->{output}->option_exit(); $self->{output}->option_exit();
} }
$options{option_results}->{snmp_version} =~ s/^v//; $options{option_results}->{snmp_version} =~ s/^v//;
if ($options{option_results}->{snmp_version} !~ /1|2c|2|3/) { if ($options{option_results}->{snmp_version} !~ /1|2c|2|3/) {
$self->{output}->add_option_msg(short_msg => "Unknown snmp version."); $self->{output}->add_option_msg(short_msg => 'Unknown snmp version.');
$self->{output}->option_exit(); $self->{output}->option_exit();
} }
@ -755,11 +755,13 @@ sub check_options {
$self->{snmp_autoreduce_divisor} = $1 if ($options{option_results}->{snmp_autoreduce} =~ /(\d+(\.\d+)?)/ && $1 > 1); $self->{snmp_autoreduce_divisor} = $1 if ($options{option_results}->{snmp_autoreduce} =~ /(\d+(\.\d+)?)/ && $1 > 1);
} }
%{$self->{snmp_params}} = (DestHost => $options{option_results}->{host}, %{$self->{snmp_params}} = (
DestHost => $options{option_results}->{host},
Community => $options{option_results}->{snmp_community}, Community => $options{option_results}->{snmp_community},
Version => $options{option_results}->{snmp_version}, Version => $options{option_results}->{snmp_version},
RemotePort => $options{option_results}->{snmp_port}, RemotePort => $options{option_results}->{snmp_port},
Retries => 5); Retries => 5
);
if (defined($options{option_results}->{snmp_timeout}) && $options{option_results}->{snmp_timeout} =~ /^[0-9]+$/) { if (defined($options{option_results}->{snmp_timeout}) && $options{option_results}->{snmp_timeout} =~ /^[0-9]+$/) {
$self->{snmp_params}->{Timeout} = $options{option_results}->{snmp_timeout} * (10**6); $self->{snmp_params}->{Timeout} = $options{option_results}->{snmp_timeout} * (10**6);
@ -769,7 +771,7 @@ sub check_options {
$self->{snmp_params}->{Retries} = $options{option_results}->{snmp_retries}; $self->{snmp_params}->{Retries} = $options{option_results}->{snmp_retries};
} }
if ($options{option_results}->{snmp_version} eq "3") { if ($options{option_results}->{snmp_version} eq '3') {
$self->{snmp_params}->{Context} = $options{option_results}->{snmp_context_name} if (defined($options{option_results}->{snmp_context_name})); $self->{snmp_params}->{Context} = $options{option_results}->{snmp_context_name} if (defined($options{option_results}->{snmp_context_name}));
$self->{snmp_params}->{ContextEngineId} = $options{option_results}->{snmp_context_engine_id} if (defined($options{option_results}->{snmp_context_engine_id})); $self->{snmp_params}->{ContextEngineId} = $options{option_results}->{snmp_context_engine_id} if (defined($options{option_results}->{snmp_context_engine_id}));
@ -786,9 +788,8 @@ sub check_options {
return ; return ;
} }
if (!defined($options{option_results}->{snmp_security_name}) || $options{option_results}->{snmp_security_name} eq '') { if (!defined($options{option_results}->{snmp_security_name}) || $options{option_results}->{snmp_security_name} eq '') {
$self->{output}->add_option_msg(short_msg => "Missing parameter Security Name."); $self->{output}->add_option_msg(short_msg => 'Missing parameter Security Name.');
$self->{output}->option_exit(); $self->{output}->option_exit();
} }
@ -798,12 +799,12 @@ sub check_options {
my $user_activate = 0; my $user_activate = 0;
if (defined($options{option_results}->{snmp_auth_passphrase}) && $options{option_results}->{snmp_auth_passphrase} ne '') { if (defined($options{option_results}->{snmp_auth_passphrase}) && $options{option_results}->{snmp_auth_passphrase} ne '') {
if (!defined($options{option_results}->{snmp_auth_protocol})) { if (!defined($options{option_results}->{snmp_auth_protocol})) {
$self->{output}->add_option_msg(short_msg => "Missing parameter authenticate protocol."); $self->{output}->add_option_msg(short_msg => 'Missing parameter authenticate protocol.');
$self->{output}->option_exit(); $self->{output}->option_exit();
} }
$options{option_results}->{snmp_auth_protocol} = uc($options{option_results}->{snmp_auth_protocol}); $options{option_results}->{snmp_auth_protocol} = uc($options{option_results}->{snmp_auth_protocol});
if ($options{option_results}->{snmp_auth_protocol} ne "MD5" && $options{option_results}->{snmp_auth_protocol} ne "SHA") { if ($options{option_results}->{snmp_auth_protocol} ne 'MD5' && $options{option_results}->{snmp_auth_protocol} ne 'SHA') {
$self->{output}->add_option_msg(short_msg => "Wrong authentication protocol. Must be MD5 or SHA."); $self->{output}->add_option_msg(short_msg => 'Wrong authentication protocol. Must be MD5 or SHA.');
$self->{output}->option_exit(); $self->{output}->option_exit();
} }
@ -815,17 +816,17 @@ sub check_options {
if (defined($options{option_results}->{snmp_priv_passphrase}) && $options{option_results}->{snmp_priv_passphrase} ne '') { if (defined($options{option_results}->{snmp_priv_passphrase}) && $options{option_results}->{snmp_priv_passphrase} ne '') {
if (!defined($options{option_results}->{snmp_priv_protocol})) { if (!defined($options{option_results}->{snmp_priv_protocol})) {
$self->{output}->add_option_msg(short_msg => "Missing parameter privacy protocol."); $self->{output}->add_option_msg(short_msg => 'Missing parameter privacy protocol.');
$self->{output}->option_exit(); $self->{output}->option_exit();
} }
$options{option_results}->{snmp_priv_protocol} = uc($options{option_results}->{snmp_priv_protocol}); $options{option_results}->{snmp_priv_protocol} = uc($options{option_results}->{snmp_priv_protocol});
if ($options{option_results}->{snmp_priv_protocol} ne 'DES' && $options{option_results}->{snmp_priv_protocol} ne 'AES') { if ($options{option_results}->{snmp_priv_protocol} ne 'DES' && $options{option_results}->{snmp_priv_protocol} ne 'AES') {
$self->{output}->add_option_msg(short_msg => "Wrong privacy protocol. Must be DES or AES."); $self->{output}->add_option_msg(short_msg => 'Wrong privacy protocol. Must be DES or AES.');
$self->{output}->option_exit(); $self->{output}->option_exit();
} }
if ($user_activate == 0) { if ($user_activate == 0) {
$self->{output}->add_option_msg(short_msg => "Cannot use snmp v3 privacy option without snmp v3 authentification options."); $self->{output}->add_option_msg(short_msg => 'Cannot use snmp v3 privacy option without snmp v3 authentification options.');
$self->{output}->option_exit(); $self->{output}->option_exit();
} }
$self->{snmp_params}->{SecLevel} = 'authPriv'; $self->{snmp_params}->{SecLevel} = 'authPriv';
@ -924,8 +925,7 @@ sub oid_lex_sort {
return map { $_->[0] } return map { $_->[0] }
sort { $a->[1] cmp $b->[1] } sort { $a->[1] cmp $b->[1] }
map map {
{
my $oid = $_; my $oid = $_;
$oid =~ s/^\.//; $oid =~ s/^\.//;
$oid =~ s/ /\.0/g; $oid =~ s/ /\.0/g;