enhance list-trunks f5
This commit is contained in:
parent
69817df147
commit
7cdbfca446
|
@ -30,12 +30,9 @@ sub new {
|
||||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||||
bless $self, $class;
|
bless $self, $class;
|
||||||
|
|
||||||
$options{options}->add_options(arguments =>
|
$options{options}->add_options(arguments => {
|
||||||
{
|
'filter-name:s' => { name => 'name' }
|
||||||
"name:s" => { name => 'name' },
|
});
|
||||||
"regexp" => { name => 'use_regexp' },
|
|
||||||
});
|
|
||||||
$self->{trunks_selected} = [];
|
|
||||||
|
|
||||||
return $self;
|
return $self;
|
||||||
}
|
}
|
||||||
|
@ -45,62 +42,67 @@ sub check_options {
|
||||||
$self->SUPER::init(%options);
|
$self->SUPER::init(%options);
|
||||||
}
|
}
|
||||||
|
|
||||||
my %map_trunk_status = (
|
my $map_trunk_status = {
|
||||||
0 => 'up',
|
0 => 'up',
|
||||||
1 => 'down',
|
1 => 'down',
|
||||||
2 => 'disable',
|
2 => 'disable',
|
||||||
3 => 'uninitialized',
|
3 => 'uninitialized',
|
||||||
4 => 'loopback',
|
4 => 'loopback',
|
||||||
5 => 'unpopulated',
|
5 => 'unpopulated'
|
||||||
);
|
};
|
||||||
|
|
||||||
my $sysTrunkTable = '.1.3.6.1.4.1.3375.2.1.2.12.1.2';
|
my $mapping = {
|
||||||
my $sysTrunkName = '.1.3.6.1.4.1.3375.2.1.2.12.1.2.1.1';
|
sysTrunkName => { oid => '.1.3.6.1.4.1.3375.2.1.2.12.1.2.1.1' },
|
||||||
my $sysTrunkStatus = '.1.3.6.1.4.1.3375.2.1.2.12.1.2.1.2';
|
sysTrunkStatus => { oid => '.1.3.6.1.4.1.3375.2.1.2.12.1.2.1.2', map => $map_trunk_status },
|
||||||
my $sysTrunkOperBw = '.1.3.6.1.4.1.3375.2.1.2.12.1.2.1.5';
|
sysTrunkOperBw => { oid => '.1.3.6.1.4.1.3375.2.1.2.12.1.2.1.5' }
|
||||||
|
};
|
||||||
|
my $oid_sysTrunkTable = '.1.3.6.1.4.1.3375.2.1.2.12.1.2';
|
||||||
|
|
||||||
sub manage_selection {
|
sub manage_selection {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
$self->{result} = $self->{snmp}->get_table(oid => $sysTrunkTable, nothing_quit => 1);
|
my $snmp_result = $options{snmp}->get_table(
|
||||||
|
oid => $oid_sysTrunkTable,
|
||||||
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{result}})) {
|
end => $mapping->{sysTrunkOperBw}->{oid},
|
||||||
next if ($oid !~ /^$sysTrunkName\.(.*)$/);
|
nothing_quit => 1
|
||||||
|
);
|
||||||
|
my $trunks = {};
|
||||||
|
foreach my $oid (keys %$snmp_result) {
|
||||||
|
next if ($oid !~ /^$mapping->{sysTrunkName}->{oid}\.(.*)$/);
|
||||||
my $instance = $1;
|
my $instance = $1;
|
||||||
|
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance);
|
||||||
|
|
||||||
# Get all without a name
|
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
|
||||||
if (!defined($self->{option_results}->{name})) {
|
$result->{sysTrunkName} !~ /$self->{option_results}->{filter_name}/) {
|
||||||
push @{$self->{trunks_selected}}, $instance;
|
$self->{output}->output_add(long_msg => "skipping trunk '" . $result->{sysTrunkName} . "': no matching filter name.", debug => 1);
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!defined($self->{option_results}->{use_regexp}) && $self->{result}->{$sysTrunkName . '.' . $instance} eq $self->{option_results}->{name}) {
|
$trunks->{$result->{sysTrunkName}} = $result;
|
||||||
push @{$self->{trunks_selected}}, $instance;
|
|
||||||
next;
|
|
||||||
}
|
|
||||||
if (defined($self->{option_results}->{use_regexp}) && $self->{result}->{$sysTrunkName . '.' . $instance} =~ /$self->{option_results}->{name}/) {
|
|
||||||
push @{$self->{trunks_selected}}, $instance;
|
|
||||||
next;
|
|
||||||
}
|
|
||||||
|
|
||||||
$self->{output}->output_add(long_msg => "Skipping pool '" . $self->{result}->{$sysTrunkName . '.' . $instance} . "': no matching filter name", debug => 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $trunks;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub run {
|
sub run {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
$self->{snmp} = $options{snmp};
|
|
||||||
|
|
||||||
$self->manage_selection();
|
my $trunks = $self->manage_selection(snmp => $options{snmp});
|
||||||
foreach my $instance (sort @{$self->{trunks_selected}}) {
|
foreach (sort keys %$trunks) {
|
||||||
$self->{output}->output_add(long_msg => sprintf("'%s' [status: %s] [speed: %s]",
|
$self->{output}->output_add(
|
||||||
$self->{result}->{$sysTrunkName . '.' . $instance},
|
long_msg => sprintf(
|
||||||
$map_trunk_status{$self->{result}->{$sysTrunkStatus . '.' . $instance}},
|
"'%s' [status: %s] [speed: %s]",
|
||||||
$self->{result}->{$sysTrunkOperBw . '.' . $instance}));
|
$_,
|
||||||
|
$trunks->{$_}->{sysTrunkStatus},
|
||||||
|
$trunks->{$_}->{sysTrunkOperBw}
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$self->{output}->output_add(severity => 'OK',
|
$self->{output}->output_add(
|
||||||
short_msg => 'List Trunks:');
|
severity => 'OK',
|
||||||
|
short_msg => 'List trunks:'
|
||||||
|
);
|
||||||
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
|
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
|
||||||
$self->{output}->exit();
|
$self->{output}->exit();
|
||||||
}
|
}
|
||||||
|
@ -113,15 +115,14 @@ sub disco_format {
|
||||||
|
|
||||||
sub disco_show {
|
sub disco_show {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
$self->{snmp} = $options{snmp};
|
|
||||||
|
|
||||||
$self->manage_selection(disco => 1);
|
my $trunks = $self->manage_selection(snmp => $options{snmp});
|
||||||
foreach my $instance (sort @{$self->{trunks_selected}}) {
|
foreach (sort keys %$trunks) {
|
||||||
my $name = $self->{result}->{$sysTrunkName . '.' . $instance};
|
$self->{output}->add_disco_entry(
|
||||||
my $status = $map_trunk_status{$self->{result}->{$sysTrunkStatus . '.' . $instance}};
|
name => $_,
|
||||||
my $speed = $self->{result}->{$sysTrunkOperBw . '.' . $instance};
|
status => $trunks->{$_}->{sysTrunkStatus},
|
||||||
|
speed => $trunks->{$_}->{sysTrunkOperBw}
|
||||||
$self->{output}->add_disco_entry(name => $name, status => $status, speed => $speed);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,13 +136,9 @@ List Trunks.
|
||||||
|
|
||||||
=over 8
|
=over 8
|
||||||
|
|
||||||
=item B<--name>
|
=item B<--filter-name>
|
||||||
|
|
||||||
Set the trunk name.
|
Filter by trunk name (regexp can be used).
|
||||||
|
|
||||||
=item B<--regexp>
|
|
||||||
|
|
||||||
Allows to use regexp to filter trunk name (with option --name).
|
|
||||||
|
|
||||||
=back
|
=back
|
||||||
|
|
||||||
|
|
|
@ -390,8 +390,8 @@ sub manage_selection {
|
||||||
|
|
||||||
my $results = $options{snmp}->get_multiple_table(
|
my $results = $options{snmp}->get_multiple_table(
|
||||||
oids => [
|
oids => [
|
||||||
{ oid => $oid_sysTrunkTable },
|
{ oid => $oid_sysTrunkTable, end => $mapping_sysTrunk->{sysTrunkOperBw}->{oid} },
|
||||||
{ oid => $oid_sysTrunkStatTable },
|
{ oid => $oid_sysTrunkStatTable }
|
||||||
],
|
],
|
||||||
nothing_quit => 1
|
nothing_quit => 1
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue