From be6cd928ebe76554a606f4449bd934f926e8d408 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Mon, 17 Aug 2015 16:43:12 +0200 Subject: [PATCH] + Add list-connections mode for atrica --- network/atrica/snmp/mode/connections.pm | 2 +- network/atrica/snmp/mode/listconnections.pm | 148 ++++++++++++++++++++ network/atrica/snmp/plugin.pm | 3 +- snmp_standard/mode/listinterfaces.pm | 29 ++-- 4 files changed, 172 insertions(+), 10 deletions(-) create mode 100644 network/atrica/snmp/mode/listconnections.pm diff --git a/network/atrica/snmp/mode/connections.pm b/network/atrica/snmp/mode/connections.pm index 1907071a0..5b0697bd3 100644 --- a/network/atrica/snmp/mode/connections.pm +++ b/network/atrica/snmp/mode/connections.pm @@ -367,7 +367,7 @@ __END__ =head1 MODE -Check connections. +Check connections (A-Series.mib). =over 8 diff --git a/network/atrica/snmp/mode/listconnections.pm b/network/atrica/snmp/mode/listconnections.pm new file mode 100644 index 000000000..3798d233d --- /dev/null +++ b/network/atrica/snmp/mode/listconnections.pm @@ -0,0 +1,148 @@ +# +# Copyright 2015 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package network::atrica::snmp::mode::listconnections; + +use base qw(snmp_standard::mode::listinterfaces); + +use strict; +use warnings; + +sub set_oids_status { + my ($self, %options) = @_; + + if ($self->{option_results}->{oid_filter} eq 'atrconncepgendescr') { + $self->{oid_adminstatus} = '.1.3.6.1.4.1.6110.2.7.5.1.7'; + $self->{oid_adminstatus_mapping} = { + 1 => 'up', 2 => 'down', + }; + $self->{oid_opstatus} = '.1.3.6.1.4.1.6110.2.7.5.1.8'; + $self->{oid_opstatus_mapping} = { + 1 => 'up', 2 => 'down', 3 => 'oneWay', 4 => 'twoWay', 5 => 'fastProtected', + }; + } else { + $self->{oid_adminstatus} = '.1.3.6.1.4.1.6110.2.2.1.1.3'; + $self->{oid_adminstatus_mapping} = { + 2 => 'off', # off + 3 => 'on', # on + }; + $self->{oid_opstatus} = '.1.3.6.1.4.1.6110.2.2.1.1.4'; + $self->{oid_opstatus_mapping} = { + 2 => 'off', 3 => 'systemBusy', 4 => 'dependencyBusy', 5 => 'inService', 6 => 'alterInService', 7 => 'failed', + 8 => 'mainInServiceViaCoreLinkProtec', 9 => 'alterInServiceViaCoreLinkProtec', + 10 => 'mainAndAltDownConnUpSendingToMain', 11 => 'mainAndAltDownConnUpSendingToAlt', + }; + } +} + +sub is_admin_status_down { + my ($self, %options) = @_; + + if (defined($self->{option_results}->{use_adminstatus}) && defined($options{admin_status}) && + $self->{oid_adminstatus_mapping}->{$options{admin_status}} !~ /^up|on$/) { + return 1; + } + return 0; +} + +sub set_oids_label { + my ($self, %options) = @_; + + $self->{oids_label} = { + 'atrconncepgendescr' => '.1.3.6.1.4.1.6110.2.7.5.1.1', + 'atrconningdescr' => '.1.3.6.1.4.1.6110.2.2.1.1.2', + }; +} + +sub default_oid_filter_name { + my ($self, %options) = @_; + + return 'atrConnCepGenDescr'; +} + +sub default_oid_display_name { + my ($self, %options) = @_; + + return 'atrConnCepGenDescr'; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, + no_speed => 1); + bless $self, $class; + return $self; +} + +1; + +__END__ + +=head1 MODE + +=over 8 + +=item B<--interface> + +Set the interface (number expected) ex: 1,2,... (empty means 'check all interface'). + +=item B<--name> + +Allows to use interface name with option --interface instead of interface oid index (Can be a regexp) + +=item B<--speed> + +Set interface speed (in Mb). + +=item B<--skip-speed0> + +Don't display interface with speed 0. + +=item B<--filter-status> + +Display interfaces matching the filter (example: 'up'). + +=item B<--use-adminstatus> + +Display interfaces with AdminStatus 'up'. + +=item B<--oid-filter> + +Choose OID used to filter interface (default: atrConnCepGenDescr) (values: atrConnIngDescr, atrConnCepGenDescr). + +=item B<--oid-display> + +Choose OID used to display interface (default: atrConnCepGenDescr) (values: atrConnIngDescr, atrConnCepGenDescr). + +=item B<--display-transform-src> + +Regexp src to transform display value. (security risk!!!) + +=item B<--display-transform-dst> + +Regexp dst to transform display value. (security risk!!!) + +=item B<--add-extra-oid> + +Display an OID. Example: --add-extra-oid='alias,.1.3.6.1.2.1.31.1.1.1.18' + +=back + +=cut diff --git a/network/atrica/snmp/plugin.pm b/network/atrica/snmp/plugin.pm index fa4737402..ffdf9064f 100644 --- a/network/atrica/snmp/plugin.pm +++ b/network/atrica/snmp/plugin.pm @@ -32,7 +32,8 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'connections' => 'network::atrica::snmp::mode::connections', + 'connections' => 'network::atrica::snmp::mode::connections', + 'list-connections' => 'network::atrica::snmp::mode::listconnections', ); return $self; diff --git a/snmp_standard/mode/listinterfaces.pm b/snmp_standard/mode/listinterfaces.pm index 829935d5e..8c7d84f26 100644 --- a/snmp_standard/mode/listinterfaces.pm +++ b/snmp_standard/mode/listinterfaces.pm @@ -77,11 +77,22 @@ sub default_oid_display_name { return 'ifname'; } +sub is_admin_status_down { + my ($self, %options) = @_; + + if (defined($self->{option_results}->{use_adminstatus}) && defined($options{admin_status}) && + $self->{oid_adminstatus_mapping}->{$options{admin_status}} ne 'up') { + return 1; + } + return 0; +} + sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => defined($options{package}) ? $options{package} : __PACKAGE__, %options); bless $self, $class; + $self->{no_speed} = defined($options{no_speed}) && $options{no_speed} =~ /^[01]$/ ? $options{no_speed} : 0; $self->{version} = '1.0'; $options{options}->add_options(arguments => { @@ -133,8 +144,11 @@ sub run { foreach (sort @{$self->{interface_id_selected}}) { my $display_value = $self->get_display_value(id => $_); - my $interface_speed = (defined($result->{$oid_speed64 . "." . $_}) && $result->{$oid_speed64 . "." . $_} ne '' && $result->{$oid_speed64 . "." . $_} != 0 ? - ($result->{$oid_speed64 . "." . $_}) : (sprintf("%g", $result->{$oid_speed32 . "." . $_} / 1000 / 1000))); + my $interface_speed = 0; + if ($self->{no_speed} == 0) { + $interface_speed = (defined($result->{$oid_speed64 . "." . $_}) && $result->{$oid_speed64 . "." . $_} ne '' && $result->{$oid_speed64 . "." . $_} != 0 ? + ($result->{$oid_speed64 . "." . $_}) : (sprintf("%g", $result->{$oid_speed32 . "." . $_} / 1000 / 1000))); + } if (defined($self->{option_results}->{speed}) && $self->{option_results}->{speed} ne '') { $interface_speed = $self->{option_results}->{speed}; } @@ -148,8 +162,7 @@ sub run { $self->{output}->output_add(long_msg => "Skipping interface '" . $display_value . "': no matching filter status"); next; } - if (defined($self->{option_results}->{use_adminstatus}) && defined($result->{$self->{oid_adminstatus} . "." . $_}) && - $self->{oid_adminstatus_mapping}->{$result->{$self->{oid_adminstatus} . "." . $_}} ne 'up') { + if ($self->is_admin_status_down(admin_status => $result->{$self->{oid_adminstatus} . "." . $_})) { $self->{output}->output_add(long_msg => "Skipping interface '" . $display_value . "': adminstatus is not 'up' and option --use-adminstatus is set"); next; } @@ -172,10 +185,11 @@ sub run { sub get_additional_information { my ($self, %options) = @_; - my $oids = [$oid_speed32]; + my $oids = []; push @$oids, $self->{oid_adminstatus} if (defined($self->{oid_adminstatus})); push @$oids, $self->{oid_opstatus} if (defined($self->{oid_opstatus})); - push @$oids, $oid_speed64 if (!$self->{snmp}->is_snmpv1()); + push @$oids, $oid_speed32 if ($self->{no_speed} == 0); + push @$oids, $oid_speed64 if (!$self->{snmp}->is_snmpv1() && $self->{no_speed} == 0); if (scalar(keys %{$self->{extra_oids}}) > 0) { push @$oids, values %{$self->{extra_oids}}; } @@ -275,8 +289,7 @@ sub disco_show { next if (defined($self->{option_results}->{skip_speed0}) && $interface_speed == 0); next if (defined($self->{option_results}->{filter_status}) && defined($result->{$self->{oid_opstatus} . "." . $_}) && $self->{oid_opstatus_mapping}->{$result->{$self->{oid_opstatus} . "." . $_}} !~ /$self->{option_results}->{filter_status}/i); - next if (defined($self->{option_results}->{use_adminstatus}) && defined($result->{$self->{oid_adminstatus} . "." . $_}) && - $self->{oid_adminstatus_mapping}->{$result->{$self->{oid_adminstatus} . "." . $_}} ne 'up'); + next if ($self->is_admin_status_down(admin_status => $result->{$self->{oid_adminstatus} . "." . $_})); my %extra_values = (); foreach my $name (keys %{$self->{extra_oids}}) {