harden list-interfaces mode (#2711)

This commit is contained in:
qgarnier 2021-04-15 17:12:40 +02:00 committed by GitHub
parent e0513b1608
commit 7954eed685
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 10 deletions

View File

@ -177,7 +177,12 @@ sub run {
$extra_display .= '[' . $name . ' = ' . $extra_values->{$name} . ']';
}
if (defined($self->{oid_iftype})) {
$extra_display .= '[type = ' . $map_iftype->{ $result->{ $self->{oid_iftype} . '.' . $_ } } . ']';
$extra_display .= sprintf(
'[type = %s]',
defined($result->{ $self->{oid_iftype} . '.' . $_}) && defined($map_iftype->{ $result->{ $self->{oid_iftype} . '.' . $_ } }) ?
$map_iftype->{ $result->{ $self->{oid_iftype} . '.' . $_ } } :
'unknown'
);
}
$self->{output}->output_add(
@ -217,8 +222,8 @@ sub get_additional_information {
sub get_display_value {
my ($self, %options) = @_;
my $value = $self->{datas}->{$self->{option_results}->{oid_display} . "_" . $options{id}};
my $value = $self->{datas}->{$self->{option_results}->{oid_display} . '_' . $options{id}};
if (defined($self->{option_results}->{display_transform_src})) {
$self->{option_results}->{display_transform_dst} = '' if (!defined($self->{option_results}->{display_transform_dst}));
eval "\$value =~ s{$self->{option_results}->{display_transform_src}}{$self->{option_results}->{display_transform_dst}}";
@ -332,8 +337,8 @@ sub disco_format {
sub disco_show {
my ($self, %options) = @_;
$self->{snmp} = $options{snmp};
$self->{snmp} = $options{snmp};
$self->manage_selection(disco => 1);
return if (scalar(@{$self->{interface_id_selected}}) == 0);
my $result = $self->get_additional_information();
@ -357,7 +362,8 @@ sub disco_show {
my $extra_values = $self->get_extra_values_by_instance(result => $result, instance => $_);
if (defined($self->{oid_iftype})) {
$extra_values->{type} = $map_iftype->{ $result->{ $self->{oid_iftype} . '.' . $_ } };
$extra_values->{type} = defined($result->{ $self->{oid_iftype} . '.' . $_ }) && defined($map_iftype->{ $result->{ $self->{oid_iftype} . '.' . $_ } }) ?
$map_iftype->{ $result->{ $self->{oid_iftype} . '.' . $_ } } : 'unknown';
}
$self->{output}->add_disco_entry(
name => $display_value,