| 1 |
# |
| 2 |
# Copyright 2024 Centreon (http://www.centreon.com/) |
| 3 |
# |
| 4 |
# Centreon is a full-fledged industry-strength solution that meets |
| 5 |
# the needs in IT infrastructure and application monitoring for |
| 6 |
# service performance. |
| 7 |
# |
| 8 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
| 9 |
# you may not use this file except in compliance with the License. |
| 10 |
# You may obtain a copy of the License at |
| 11 |
# |
| 12 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 13 |
# |
| 14 |
# Unless required by applicable law or agreed to in writing, software |
| 15 |
# distributed under the License is distributed on an "AS IS" BASIS, |
| 16 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 |
# See the License for the specific language governing permissions and |
| 18 |
# limitations under the License. |
| 19 |
# |
| 20 |
|
| 21 |
package network::nokia::isam::snmp::mode::listhubsap; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::mode); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
|
| 28 |
sub new { |
| 29 |
my ($class, %options) = @_; |
| 30 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options); |
| 31 |
bless $self, $class; |
| 32 |
|
| 33 |
$options{options}->add_options(arguments => |
| 34 |
{ |
| 35 |
}); |
| 36 |
|
| 37 |
return $self; |
| 38 |
} |
| 39 |
|
| 40 |
sub check_options { |
| 41 |
my ($self, %options) = @_; |
| 42 |
$self->SUPER::init(%options); |
| 43 |
} |
| 44 |
|
| 45 |
my %map_admin = (1 => 'up', 2 => 'down'); |
| 46 |
my %map_oper = (1 => 'up', 2 => 'down', 3 => 'ingressQosMismatch', |
| 47 |
4 => 'egressQosMismatch', 5 => 'portMtuTooSmall', 6 => 'svcAdminDown', |
| 48 |
7 => 'iesIfAdminDown' |
| 49 |
); |
| 50 |
my $mapping = { |
| 51 |
sapAdminStatus => { oid => '.1.3.6.1.4.1.6527.3.1.2.4.3.2.1.6', map => \%map_admin }, |
| 52 |
sapOperStatus => { oid => '.1.3.6.1.4.1.6527.3.1.2.4.3.2.1.7', map => \%map_oper }, |
| 53 |
}; |
| 54 |
my $oid_sapDescription = '.1.3.6.1.4.1.6527.3.1.2.4.3.2.1.5'; |
| 55 |
my $oid_svcDescription = '.1.3.6.1.4.1.6527.3.1.2.4.2.2.1.6'; |
| 56 |
my $oid_sapBaseInfoEntry = '.1.3.6.1.4.1.6527.3.1.2.4.3.2.1'; |
| 57 |
my $oid_ifName = '.1.3.6.1.2.1.31.1.1.1.1'; |
| 58 |
|
| 59 |
sub manage_selection { |
| 60 |
my ($self, %options) = @_; |
| 61 |
|
| 62 |
$self->{sap} = {}; |
| 63 |
my $snmp_result = $self->{snmp}->get_multiple_table(oids => [ |
| 64 |
{ oid => $oid_sapDescription }, |
| 65 |
{ oid => $oid_svcDescription }, |
| 66 |
{ oid => $oid_ifName }, |
| 67 |
{ oid => $oid_sapBaseInfoEntry, start => $mapping->{sapAdminStatus}->{oid}, end => $mapping->{sapOperStatus}->{oid} }, |
| 68 |
], nothing_quit => 1); |
| 69 |
foreach my $oid (keys %{$snmp_result->{$oid_sapDescription}}) { |
| 70 |
next if ($oid !~ /^$oid_sapDescription\.(.*?)\.(.*?)\.(.*?)$/); |
| 71 |
my ($SvcId, $SapPortId, $SapEncapValue) = ($1, $2, $3); |
| 72 |
|
| 73 |
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $snmp_result->{ $oid_sapBaseInfoEntry }, instance => $SvcId . '.' . $SapPortId . '.' . $SapEncapValue); |
| 74 |
$self->{sap}->{$SvcId . '.' . $SapPortId . '.' . $SapEncapValue} = { |
| 75 |
SvcId => $SvcId, |
| 76 |
SapPortId => $SapPortId, |
| 77 |
SapEncapValue => $SapEncapValue, |
| 78 |
IfName => defined($snmp_result->{$oid_ifName}->{$oid_ifName . '.' . $SapPortId}) && $snmp_result->{$oid_ifName}->{$oid_ifName . '.' . $SapPortId} ne '' ? |
| 79 |
$snmp_result->{$oid_ifName}->{$oid_ifName . '.' . $SapPortId} : $SapPortId, |
| 80 |
SapDescription => $snmp_result->{$oid_sapDescription}->{$oid} ne '' ? $snmp_result->{$oid_sapDescription}->{$oid} : 'unknown', |
| 81 |
SvcDescription => defined($snmp_result->{$oid_svcDescription}->{$oid_svcDescription . '.' . $SvcId}) && $snmp_result->{$oid_svcDescription}->{$oid_svcDescription . '.' . $SvcId} ne '' ? |
| 82 |
$snmp_result->{$oid_svcDescription}->{$oid_svcDescription . '.' . $SvcId} : $SvcId, |
| 83 |
SapEncapName => defined($snmp_result->{$oid_svcDescription}->{$oid_svcDescription . '.' . $SapEncapValue}) && $snmp_result->{$oid_svcDescription}->{$oid_svcDescription . '.' . $SapEncapValue} ne '' ? |
| 84 |
$snmp_result->{$oid_svcDescription}->{$oid_svcDescription . '.' . $SapEncapValue} : $SapEncapValue, |
| 85 |
SapAdminStatus => $result->{sapAdminStatus}, |
| 86 |
SapOperStatus => $result->{sapOperStatus}, |
| 87 |
}; |
| 88 |
} |
| 89 |
} |
| 90 |
|
| 91 |
sub run { |
| 92 |
my ($self, %options) = @_; |
| 93 |
|
| 94 |
$self->{snmp} = $options{snmp}; |
| 95 |
$self->manage_selection(); |
| 96 |
foreach my $instance (sort keys %{$self->{sap}}) { |
| 97 |
my $msg = ''; |
| 98 |
$self->{output}->output_add(long_msg => |
| 99 |
"[SvcId = " . $self->{sap}->{$instance}->{SvcId} . "]" . |
| 100 |
"[SapPortId = " . $self->{sap}->{$instance}->{SapPortId} . "]" . |
| 101 |
"[SapEncapValue = " . $self->{sap}->{$instance}->{SapEncapValue} . "]" . |
| 102 |
"[SapDescription = " . $self->{sap}->{$instance}->{SapDescription} . "]" . |
| 103 |
"[SvcDescription = " . $self->{sap}->{$instance}->{SvcDescription} . "]" . |
| 104 |
"[SapEncapName = " . $self->{sap}->{$instance}->{SapEncapName} . "]" . |
| 105 |
"[SapAdminStatus = " . $self->{sap}->{$instance}->{SapAdminStatus} . "]" . |
| 106 |
"[SapOperStatus = " . $self->{sap}->{$instance}->{SapOperStatus} . "]" . |
| 107 |
"[IfName = " . $self->{sap}->{$instance}->{IfName} |
| 108 |
); |
| 109 |
} |
| 110 |
|
| 111 |
$self->{output}->output_add(severity => 'OK', |
| 112 |
short_msg => 'List SAP:'); |
| 113 |
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); |
| 114 |
$self->{output}->exit(); |
| 115 |
} |
| 116 |
|
| 117 |
sub disco_format { |
| 118 |
my ($self, %options) = @_; |
| 119 |
|
| 120 |
$self->{output}->add_disco_format(elements => ['SvcId', 'SapPortId', 'SapEncapValue', 'SapDescription', |
| 121 |
'SvcDescription', 'SapEncapName', 'SapAdminStatus', 'SapOperStatus', 'IfName']); |
| 122 |
} |
| 123 |
|
| 124 |
sub disco_show { |
| 125 |
my ($self, %options) = @_; |
| 126 |
$self->{snmp} = $options{snmp}; |
| 127 |
|
| 128 |
$self->manage_selection(disco => 1); |
| 129 |
foreach my $instance (sort keys %{$self->{sap}}) { |
| 130 |
$self->{output}->add_disco_entry(%{$self->{sap}->{$instance}}); |
| 131 |
} |
| 132 |
} |
| 133 |
|
| 134 |
1; |
| 135 |
|
| 136 |
__END__ |
| 137 |
|
| 138 |
=head1 MODE |
| 139 |
|
| 140 |
List Service Access Points (SAP) for service discovery. |
| 141 |
|
| 142 |
=over 8 |
| 143 |
|
| 144 |
=back |
| 145 |
|
| 146 |
=cut |
| 147 |
|