Debian Codegraph @

src/network/brocade/snmp/mode/listinterfaces.pm

raw
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::brocade::snmp::mode::listinterfaces;
22
23 use base qw(snmp_standard::mode::listinterfaces);
24
25 use strict;
26 use warnings;
27
28 sub set_oids_label {
29 my ($self, %options) = @_;
30
31 $self->SUPER::set_oids_label(%options);
32 $self->{oids_label}->{fcportname} = '.1.3.6.1.4.1.1588.2.1.1.1.6.2.1.36';
33 }
34
35 sub new {
36 my ($class, %options) = @_;
37 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
38 bless $self, $class;
39 return $self;
40 }
41
42 sub manage_selection {
43 my ($self, %options) = @_;
44
45 my $oids = [{ oid => $self->{oids_label}->{$self->{option_results}->{oid_filter}} }];
46 if ($self->{option_results}->{oid_filter} ne $self->{option_results}->{oid_display}) {
47 push @$oids, { oid => $self->{oids_label}->{$self->{option_results}->{oid_display}} };
48 }
49 if (scalar(keys %{$self->{extra_oids}}) > 0) {
50 foreach (keys %{$self->{extra_oids}}) {
51 push @$oids, { oid => $self->{extra_oids}->{$_}->{oid} };
52 }
53 }
54
55 # ifName mandatory with fcPortName
56 if (($self->{option_results}->{oid_filter} eq 'fcportname' || $self->{option_results}->{oid_display} eq 'fcportname') &&
57 ($self->{option_results}->{oid_filter} ne 'ifname' && $self->{option_results}->{oid_display} ne 'ifname')) {
58 push @$oids, { oid => $self->{oids_label}->{ifname} };
59 }
60
61 $self->{datas} = {};
62 $self->{results} = $self->{snmp}->get_multiple_table(oids => $oids);
63 $self->{datas}->{all_ids} = [];
64
65 my $oid_filter = $self->{option_results}->{oid_filter} eq 'fcportname' ? 'ifname' : $self->{option_results}->{oid_filter};
66 foreach ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{ $self->{oids_label}->{$oid_filter} }})) {
67 next if (! /^$self->{oids_label}->{$oid_filter}\.(.*)$/);
68
69 my $ifIndex = $1;
70 if ($self->{option_results}->{oid_filter} eq 'fcportname' && $self->{results}->{ $self->{oids_label}->{ifname} }->{$_} =~ /\d+\/(\d+)$/) {
71 $self->{datas}->{ $self->{option_results}->{oid_filter} . '_' . $ifIndex } = $self->{output}->decode($self->{results}->{ $self->{oids_label}->{fcportname} }->{ $self->{oids_label}->{fcportname} . '.' . ($1 + 1) });
72 } else {
73 $self->{datas}->{ $self->{option_results}->{oid_filter} . '_' . $ifIndex } = $self->{output}->decode($self->{results}->{ $self->{oids_label}->{$oid_filter} }->{$_});
74 }
75
76 push @{$self->{datas}->{all_ids}}, $ifIndex;
77 }
78
79 if (scalar(@{$self->{datas}->{all_ids}}) <= 0) {
80 $self->{output}->add_option_msg(short_msg => "Can't get interfaces...");
81 $self->{output}->option_exit();
82 }
83
84 if ($self->{option_results}->{oid_filter} ne $self->{option_results}->{oid_display}) {
85 my $oid_display = $self->{option_results}->{oid_display} eq 'fcportname' ? 'ifname' : $self->{option_results}->{oid_display};
86 foreach ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{ $self->{oids_label}->{$oid_display} }})) {
87 next if (! /^$self->{oids_label}->{$oid_display}\.(.*)$/);
88
89 my $ifIndex = $1;
90 if ($self->{option_results}->{oid_display} eq 'fcportname' && $self->{results}->{ $self->{oids_label}->{ifname} }->{$_} =~ /\d+\/(\d+)$/) {
91 $self->{datas}->{ $self->{option_results}->{oid_display} . '_' . $ifIndex } = $self->{output}->decode($self->{results}->{ $self->{oids_label}->{fcportname} }->{ $self->{oids_label}->{fcportname} . '.' . ($1 + 1) });
92 } else {
93 $self->{datas}->{ $self->{option_results}->{oid_display} . '_' . $ifIndex } = $self->{output}->decode($self->{results}->{ $self->{oids_label}->{$oid_display} }->{$_});
94 }
95 }
96 }
97
98 if (!defined($self->{option_results}->{use_name}) && defined($self->{option_results}->{interface})) {
99 foreach (@{$self->{datas}->{all_ids}}) {
100 if ($self->{option_results}->{interface} =~ /(^|\s|,)$_(\s*,|$)/) {
101 push @{$self->{interface_id_selected}}, $_;
102 }
103 }
104 } else {
105 foreach (@{$self->{datas}->{all_ids}}) {
106 my $filter_name = $self->{datas}->{$self->{option_results}->{oid_filter} . "_" . $_};
107 next if (!defined($filter_name));
108
109 if (!defined($self->{option_results}->{interface})) {
110 push @{$self->{interface_id_selected}}, $_;
111 next;
112 }
113 if ($filter_name =~ /$self->{option_results}->{interface}/) {
114 push @{$self->{interface_id_selected}}, $_;
115 }
116 }
117 }
118
119 if (scalar(@{$self->{interface_id_selected}}) <= 0 && !defined($options{disco})) {
120 $self->{output}->add_option_msg(short_msg => 'No entry found');
121 $self->{output}->option_exit();
122 }
123 }
124
125 1;
126
127 __END__
128
129 =head1 MODE
130
131 =over 8
132
133 =item B<--interface>
134
135 Set the interface (number expected) example: 1,2,... (empty means 'check all interfaces').
136
137 =item B<--name>
138
139 Allows you to define the interface (in option --interface) by name instead of OID index. The name matching mode supports regular expressions.
140
141 =item B<--speed>
142
143 Set interface speed (in Mb).
144
145 =item B<--skip-speed0>
146
147 Don't display interface with speed 0.
148
149 =item B<--filter-status>
150
151 Display interfaces matching the filter (example: 'up').
152
153 =item B<--use-adminstatus>
154
155 Display interfaces with AdminStatus 'up'.
156
157 =item B<--oid-filter>
158
159 Define the OID to be used to filter interfaces (default: ifName) (values: fcPortName, ifDesc, ifAlias, ifName).
160
161 =item B<--oid-display>
162
163 Define the OID that will be used to name the interfaces (default: ifName) (values: fcPortName, ifDesc, ifAlias, ifName).
164
165 =item B<--display-transform-src> B<--display-transform-dst>
166
167 Modify the interface name displayed by using a regular expression.
168
169 Example: adding --display-transform-src='eth' --display-transform-dst='ens' will replace all occurrences of 'eth' with 'ens'
170
171 =item B<--add-extra-oid>
172
173 Display an OID.
174 Example: --add-extra-oid='alias,.1.3.6.1.2.1.31.1.1.1.18'
175 or --add-extra-oid='vlan,.1.3.6.1.2.1.31.19,%{instance}\..*'
176
177 =item B<--add-mac-address>
178
179 Display interface mac address.
180
181 =back
182
183 =cut