Debian Codegraph @

src/network/dlink/standard/snmp/mode/interfaces.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::dlink::standard::snmp::mode::interfaces;
22
23 use base qw(snmp_standard::mode::interfaces);
24
25 use strict;
26 use warnings;
27
28 sub custom_status_output {
29 my ($self, %options) = @_;
30 my $msg = 'Status : ' . $self->{result_values}->{opstatus} . ' (admin: ' . $self->{result_values}->{admstatus} . ')';
31 if (defined($self->{instance_mode}->{option_results}->{add_duplex_status})) {
32 $msg .= ' (duplex: ' . $self->{result_values}->{duplexstatus} . ')';
33 }
34 if (defined($self->{instance_mode}->{option_results}->{add_err_disable})) {
35 $msg .= ' (error disable: ' . $self->{result_values}->{errdisable} . ')';
36 }
37
38 return $msg;
39 }
40
41 sub custom_status_calc {
42 my ($self, %options) = @_;
43
44 $self->SUPER::custom_status_calc(%options);
45 $self->{result_values}->{errdisable} = $options{new_datas}->{$self->{instance} . '_errdisable'};
46 return 0;
47 }
48
49 sub set_key_values_status {
50 my ($self, %options) = @_;
51
52 return [ { name => 'opstatus' }, { name => 'admstatus' }, { name => 'duplexstatus' }, { name => 'errdisable' }, { name => 'display' } ];
53 }
54
55 sub set_oids_status {
56 my ($self, %options) = @_;
57
58 $self->SUPER::set_oids_status(%options);
59 $self->{oid_dErrDisIfStatusTimeLeft} = '.1.3.6.1.4.1.171.14.45.1.3.1.4';
60 $self->{oid_esErrDisIfStatusTimeLeft} = '.1.3.6.1.4.1.171.17.45.1.3.1.4';
61 $self->{oid_errDisIfStatusDisReason_mapping} = {
62 1 => 'loopbackDetect', 2 => 'l2ptGuard',
63 3 => 'psecureViolation', 4 => 'stormControl', 5 => 'bpduProtect',
64 6 => 'arpRateLimit', 7 => 'dhcpRateLimit', 8 => 'ddm',
65 9 => 'scheduledShutdown', 10 => 'scheduledHibernation', 11 => 'duld'
66 };
67 }
68
69 sub new {
70 my ($class, %options) = @_;
71 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
72 bless $self, $class;
73
74 $options{options}->add_options(arguments => {
75 'add-err-disable' => { name => 'add_err_disable' }
76 });
77
78 return $self;
79 }
80
81 sub load_status {
82 my ($self, %options) = @_;
83
84 $self->SUPER::load_status(%options);
85 if (defined($self->{option_results}->{add_err_disable})) {
86 $self->{snmp_errdisable_result}->{ $self->{oid_dErrDisIfStatusTimeLeft} } = $self->{snmp}->get_table(oid => $self->{oid_dErrDisIfStatusTimeLeft});
87 $self->{snmp_errdisable_result}->{ $self->{oid_esErrDisIfStatusTimeLeft} } = $self->{snmp}->get_table(oid => $self->{oid_esErrDisIfStatusTimeLeft});
88 }
89 }
90
91 sub add_result_status {
92 my ($self, %options) = @_;
93
94 $self->SUPER::add_result_status(%options);
95
96 $self->{int}->{ $options{instance} }->{errdisable} = '';
97 if (defined($self->{option_results}->{add_err_disable})) {
98 my $append = '';
99 # ifIndex.vlanIndex (if physical interface, vlanIndex = 0)
100 foreach my $branch (($self->{oid_dErrDisIfStatusTimeLeft}, $self->{oid_esErrDisIfStatusTimeLeft})) {
101 foreach (keys %{$self->{snmp_errdisable_result}->{$branch}}) {
102 next if (! /^$branch\.$options{instance}\.(\d+)\.(\d+)/);
103 my ($vlan, $reason) = ($1, $2);
104 if ($vlan == 0) {
105 $self->{int}->{ $options{instance} }->{errdisable} = $self->{oid_errDisIfStatusDisReason_mapping}->{$reason};
106 last;
107 }
108
109 $self->{int}->{$options{instance}}->{errdisable} .= $append . 'vlan' . $vlan . ':' . $self->{oid_errDisIfStatusDisReason_mapping}->{$reason};
110 $append = ',';
111 }
112 }
113 }
114
115 $self->{int}->{$options{instance}}->{errdisable} = '-'
116 if ($self->{int}->{$options{instance}}->{errdisable} eq '');
117 }
118
119 1;
120
121 __END__
122
123 =head1 MODE
124
125 Check interfaces.
126
127 =over 8
128
129 =item B<--add-global>
130
131 Check global port statistics (by default if no --add-* option is set).
132
133 =item B<--add-status>
134
135 Check interface status.
136
137 =item B<--add-duplex-status>
138
139 Check duplex status (with --warning-status and --critical-status).
140
141 =item B<--add-err-disable>
142
143 Check error disable (with --warning-status and --critical-status).
144
145 =item B<--add-traffic>
146
147 Check interface traffic.
148
149 =item B<--add-errors>
150
151 Check interface errors.
152
153 =item B<--add-cast>
154
155 Check interface cast.
156
157 =item B<--add-speed>
158
159 Check interface speed.
160
161 =item B<--add-volume>
162
163 Check interface data volume between two checks (not supposed to be graphed, useful for BI reporting).
164
165 =item B<--check-metrics>
166
167 If the expression is true, metrics are checked (default: '%{opstatus} eq "up"').
168
169 =item B<--warning-status>
170
171 Define the conditions to match for the status to be WARNING.
172 You can use the following variables: %{admstatus}, %{opstatus}, %{duplexstatus}, %{errdisable}, %{display}
173
174 =item B<--critical-status>
175
176 Define the conditions to match for the status to be CRITICAL (default: '%{admstatus} eq "up" and %{opstatus} ne "up"').
177 You can use the following variables: %{admstatus}, %{opstatus}, %{duplexstatus}, %{errdisable}, %{display}
178
179 =item B<--warning-*> B<--critical-*>
180
181 Thresholds.
182 Can be: 'total-port', 'total-admin-up', 'total-admin-down', 'total-oper-up', 'total-oper-down',
183 'in-traffic', 'out-traffic', 'in-error', 'in-discard', 'out-error', 'out-discard',
184 'in-ucast', 'in-bcast', 'in-mcast', 'out-ucast', 'out-bcast', 'out-mcast',
185 'speed' (b/s).
186
187 =item B<--units-traffic>
188
189 Units of thresholds for the traffic (default: 'percent_delta') ('percent_delta', 'bps', 'counter').
190
191 =item B<--units-errors>
192
193 Units of thresholds for errors/discards (default: 'percent_delta') ('percent_delta', 'percent', 'delta', 'deltaps', 'counter').
194
195 =item B<--units-cast>
196
197 Units of thresholds for communication types (default: 'percent_delta') ('percent_delta', 'percent', 'delta', 'deltaps', 'counter').
198
199 =item B<--nagvis-perfdata>
200
201 Display traffic perfdata to be compatible with nagvis widget.
202
203 =item B<--interface>
204
205 Set the interface (number expected) example: 1,2,... (empty means 'check all interfaces').
206
207 =item B<--name>
208
209 Allows you to define the interface (in option --interface) by name instead of OID index. The name matching mode supports regular expressions.
210
211 =item B<--speed>
212
213 Set interface speed for incoming/outgoing traffic (in Mb).
214
215 =item B<--speed-in>
216
217 Set interface speed for incoming traffic (in Mb).
218
219 =item B<--speed-out>
220
221 Set interface speed for outgoing traffic (in Mb).
222
223 =item B<--force-counters32>
224
225 Force to use 32 bits counters (even in snmp v2c and v3). Should be used when 64 bits counters are buggy.
226
227 =item B<--reload-cache-time>
228
229 Time in minutes before reloading cache file (default: 180).
230
231 =item B<--oid-filter>
232
233 Define the OID to be used to filter interfaces (default: ifName) (values: ifDesc, ifAlias, ifName, IpAddr).
234
235 =item B<--oid-display>
236
237 Define the OID that will be used to name the interfaces (default: ifName) (values: ifDesc, ifAlias, ifName, IpAddr).
238
239 =item B<--oid-extra-display>
240
241 Add an OID to display.
242
243 =item B<--display-transform-src> B<--display-transform-dst>
244
245 Modify the interface name displayed by using a regular expression.
246
247 Example: adding --display-transform-src='eth' --display-transform-dst='ens' will replace all occurrences of 'eth' with 'ens'
248
249 =item B<--show-cache>
250
251 Display cache interface data.
252
253 =back
254
255 =cut