zyxel plugin add list vpn

This commit is contained in:
qgarnier 2017-11-23 16:20:31 +01:00
parent bf21d1d289
commit a3a5ad17d4
2 changed files with 38 additions and 39 deletions

View File

@ -18,7 +18,7 @@
# limitations under the License. # limitations under the License.
# #
package network::kemp::snmp::mode::listvs; package network::zyxel::snmp::mode::listvpn;
use base qw(centreon::plugins::mode); use base qw(centreon::plugins::mode);
@ -35,8 +35,7 @@ sub new {
{ {
"filter-name:s" => { name => 'filter_name' }, "filter-name:s" => { name => 'filter_name' },
}); });
$self->{vs_id_selected} = []; $self->{vpn} = {};
return $self; return $self;
} }
@ -45,52 +44,53 @@ sub check_options {
$self->SUPER::init(%options); $self->SUPER::init(%options);
} }
my %map_state = ( my %map_active_status = (0 => 'inactive', 1 => 'active');
1 => 'inService', my %map_connect_status = (0 => 'disconnected', 1 => 'connected');
2 => 'outOfService',
4 => 'disabled',
5 => 'sorry',
6 => 'redirect',
7 => 'errormsg',
);
my $mapping = { my $mapping = {
vSname => { oid => '.1.3.6.1.4.1.12196.13.1.1.13' }, vpnStatusConnectionName => { oid => '.1.3.6.1.4.1.890.1.6.22.2.4.1.2' },
vSstate => { oid => '.1.3.6.1.4.1.12196.13.1.1.14', map => \%map_state }, vpnStatusActiveStatus => { oid => '.1.3.6.1.4.1.890.1.6.22.2.4.1.5', map => \%map_active_status },
vpnStatusConnectStatus => { oid => '.1.3.6.1.4.1.890.1.6.22.2.4.1.6', map => \%map_connect_status },
}; };
my $oid_vpnStatusEntry = '.1.3.6.1.4.1.890.1.6.22.2.4.1';
sub manage_selection { sub manage_selection {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{results} = $self->{snmp}->get_multiple_table(oids => [ { oid => $mapping->{vSname}->{oid} }, { oid => $mapping->{vSstate}->{oid} } ], my $snmp_result = $options{snmp}->get_table(oid => $oid_vpnStatusEntry, nothing_quit => 1);
nothing_quit => 1, return_type => 1); foreach my $oid (keys %{$snmp_result}) {
foreach my $oid (keys %{$self->{results}}) { next if ($oid !~ /^$mapping->{vpnStatusConnectionName}->{oid}\.(.*)$/);
next if ($oid !~ /^$mapping->{vSname}->{oid}\.(.*)$/);
my $instance = $1; my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}, instance => $instance); my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance);
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
$result->{vSname} !~ /$self->{option_results}->{filter_name}/) { $result->{vpnStatusConnectionName} !~ /$self->{option_results}->{filter_name}/) {
$self->{output}->output_add(long_msg => "skipping '" . $result->{vSname} . "': no matching filter.", debug => 1); $self->{output}->output_add(long_msg => "skipping '" . $result->{vpnStatusConnectionName} . "': no matching filter.", debug => 1);
next; next;
} }
push @{$self->{vs_id_selected}}, $instance; $self->{vpn}->{$result->{vpnStatusConnectionName}} = {
name => $result->{vpnStatusConnectionName},
active_status => $result->{vpnStatusActiveStatus},
connect_status => $result->{vpnStatusConnectStatus},
};
} }
} }
sub run { sub run {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{snmp} = $options{snmp}; $self->manage_selection(%options);
$self->manage_selection(); foreach my $instance (sort keys %{$self->{vpn}}) {
foreach my $instance (sort @{$self->{vs_id_selected}}) { $self->{output}->output_add(long_msg => '[name = ' . $self->{vpn}->{$instance}->{name} . "]" .
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}, instance => $instance); " [active status = '" . $self->{vpn}->{$instance}->{active_status} . "']" .
" [connect status = '" . $self->{vpn}->{$instance}->{connect_status} . "']"
$self->{output}->output_add(long_msg => "'" . $result->{vSname} . "' [state = " . $result->{vSstate} . "]"); );
} }
$self->{output}->output_add(severity => 'OK', $self->{output}->output_add(severity => 'OK',
short_msg => 'List Virtual Servers:'); short_msg => 'List VPNs:');
$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();
} }
@ -98,18 +98,17 @@ sub run {
sub disco_format { sub disco_format {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{output}->add_disco_format(elements => ['name', 'state']); $self->{output}->add_disco_format(elements => ['name', 'active_status', 'connect_status']);
} }
sub disco_show { sub disco_show {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{snmp} = $options{snmp};
$self->manage_selection(disco => 1); $self->manage_selection(%options);
foreach my $instance (sort @{$self->{vs_id_selected}}) { foreach my $instance (sort keys %{$self->{vpn}}) {
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}, instance => $instance); $self->{output}->add_disco_entry(
%{$self->{vpn}->{$instance}}
$self->{output}->add_disco_entry(name => $result->{vSname}, state => $result->{vSstate}); );
} }
} }
@ -119,15 +118,15 @@ __END__
=head1 MODE =head1 MODE
List virtual servers. List VPNs.
=over 8 =over 8
=item B<--filter-name> =item B<--filter-name>
Set the virtual server name. Filter by VPN name.
=back =back
=cut =cut

View File

@ -34,7 +34,7 @@ sub new {
'cpu' => 'network::zyxel::snmp::mode::cpu', 'cpu' => 'network::zyxel::snmp::mode::cpu',
'interfaces' => 'snmp_standard::mode::interfaces', 'interfaces' => 'snmp_standard::mode::interfaces',
'list-interfaces' => 'snmp_standard::mode::listinterfaces', 'list-interfaces' => 'snmp_standard::mode::listinterfaces',
'list-vpn' => 'snmp_standard::mode::listvpn', 'list-vpn' => 'network::zyxel::snmp::mode::listvpn',
'memory' => 'network::zyxel::snmp::mode::memory', 'memory' => 'network::zyxel::snmp::mode::memory',
'vpn-status' => 'network::zyxel::snmp::mode::vpnstatus', 'vpn-status' => 'network::zyxel::snmp::mode::vpnstatus',
); );