enhance indent
This commit is contained in:
parent
75ba86eda9
commit
12df0f4486
|
@ -45,26 +45,26 @@ sub new {
|
|||
|
||||
if (!defined($options{noptions})) {
|
||||
$options{options}->add_options(arguments => {
|
||||
"hostname|host:s" => { name => 'host' },
|
||||
"snmp-community:s" => { name => 'snmp_community', default => 'public' },
|
||||
"snmp-version:s" => { name => 'snmp_version', default => 1 },
|
||||
"snmp-port:s" => { name => 'snmp_port', default => 161 },
|
||||
"snmp-timeout:s" => { name => 'snmp_timeout', default => 1 },
|
||||
"snmp-retries:s" => { name => 'snmp_retries', default => 5 },
|
||||
"maxrepetitions:s" => { name => 'maxrepetitions', default => 50 },
|
||||
"subsetleef:s" => { name => 'subsetleef', default => 50 },
|
||||
"subsettable:s" => { name => 'subsettable', default => 100 },
|
||||
"snmp-autoreduce:s" => { name => 'snmp_autoreduce' },
|
||||
"snmp-force-getnext" => { name => 'snmp_force_getnext' },
|
||||
"snmp-username:s" => { name => 'snmp_security_name' },
|
||||
"authpassphrase:s" => { name => 'snmp_auth_passphrase' },
|
||||
"authprotocol:s" => { name => 'snmp_auth_protocol' },
|
||||
"privpassphrase:s" => { name => 'snmp_priv_passphrase' },
|
||||
"privprotocol:s" => { name => 'snmp_priv_protocol' },
|
||||
"contextname:s" => { name => 'snmp_context_name' },
|
||||
"contextengineid:s" => { name => 'snmp_context_engine_id' },
|
||||
"securityengineid:s" => { name => 'snmp_security_engine_id' },
|
||||
"snmp-errors-exit:s" => { name => 'snmp_errors_exit', default => 'unknown' },
|
||||
'hostname|host:s' => { name => 'host' },
|
||||
'snmp-community:s' => { name => 'snmp_community', default => 'public' },
|
||||
'snmp-version:s' => { name => 'snmp_version', default => 1 },
|
||||
'snmp-port:s' => { name => 'snmp_port', default => 161 },
|
||||
'snmp-timeout:s' => { name => 'snmp_timeout', default => 1 },
|
||||
'snmp-retries:s' => { name => 'snmp_retries', default => 5 },
|
||||
'maxrepetitions:s' => { name => 'maxrepetitions', default => 50 },
|
||||
'subsetleef:s' => { name => 'subsetleef', default => 50 },
|
||||
'subsettable:s' => { name => 'subsettable', default => 100 },
|
||||
'snmp-autoreduce:s' => { name => 'snmp_autoreduce' },
|
||||
'snmp-force-getnext' => { name => 'snmp_force_getnext' },
|
||||
'snmp-username:s' => { name => 'snmp_security_name' },
|
||||
'authpassphrase:s' => { name => 'snmp_auth_passphrase' },
|
||||
'authprotocol:s' => { name => 'snmp_auth_protocol' },
|
||||
'privpassphrase:s' => { name => 'snmp_priv_passphrase' },
|
||||
'privprotocol:s' => { name => 'snmp_priv_protocol' },
|
||||
'contextname:s' => { name => 'snmp_context_name' },
|
||||
'contextengineid:s' => { name => 'snmp_context_engine_id' },
|
||||
'securityengineid:s' => { name => 'snmp_security_engine_id' },
|
||||
'snmp-errors-exit:s' => { name => 'snmp_errors_exit', default => 'unknown' },
|
||||
});
|
||||
}
|
||||
$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()) {
|
||||
next if ($self->{snmp_autoreduce} == 1 && $self->autoreduce_leef(current => $entry) == 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->set_error(error_status => -1, error_msg => "SNMP partial response");
|
||||
$self->set_error(error_status => -1, error_msg => 'SNMP partial response');
|
||||
return undef;
|
||||
}
|
||||
|
||||
|
@ -358,7 +358,7 @@ sub get_leef {
|
|||
}
|
||||
|
||||
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});
|
||||
}
|
||||
|
||||
|
@ -517,7 +517,7 @@ sub get_multiple_table {
|
|||
|
||||
# infinite loop. Some equipments it returns nothing!!??
|
||||
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});
|
||||
}
|
||||
}
|
||||
|
@ -533,7 +533,7 @@ sub get_multiple_table {
|
|||
}
|
||||
|
||||
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});
|
||||
}
|
||||
}
|
||||
|
@ -648,7 +648,7 @@ sub get_table {
|
|||
}
|
||||
|
||||
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});
|
||||
}
|
||||
|
||||
|
@ -733,13 +733,13 @@ sub check_options {
|
|||
# $options{option_results} = ref to options result
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
$options{option_results}->{snmp_version} =~ s/^v//;
|
||||
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();
|
||||
}
|
||||
|
||||
|
@ -755,11 +755,13 @@ sub check_options {
|
|||
$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},
|
||||
Version => $options{option_results}->{snmp_version},
|
||||
RemotePort => $options{option_results}->{snmp_port},
|
||||
Retries => 5);
|
||||
Retries => 5
|
||||
);
|
||||
|
||||
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);
|
||||
|
@ -769,7 +771,7 @@ sub check_options {
|
|||
$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}->{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 ;
|
||||
}
|
||||
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
|
@ -798,12 +799,12 @@ sub check_options {
|
|||
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_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();
|
||||
}
|
||||
$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") {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong authentication protocol. Must be MD5 or 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}->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_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();
|
||||
}
|
||||
|
||||
$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') {
|
||||
$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();
|
||||
}
|
||||
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->{snmp_params}->{SecLevel} = 'authPriv';
|
||||
|
@ -924,8 +925,7 @@ sub oid_lex_sort {
|
|||
|
||||
return map { $_->[0] }
|
||||
sort { $a->[1] cmp $b->[1] }
|
||||
map
|
||||
{
|
||||
map {
|
||||
my $oid = $_;
|
||||
$oid =~ s/^\.//;
|
||||
$oid =~ s/ /\.0/g;
|
||||
|
|
Loading…
Reference in New Issue