| 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::mikrotik::snmp::mode::interfaces; |
| 22 |
|
| 23 |
use base qw(snmp_standard::mode::interfaces); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
|
| 28 |
sub set_oids_errors { |
| 29 |
my ($self, %options) = @_; |
| 30 |
|
| 31 |
$self->{oids_errors}->{oid_ifInDiscard} = '.1.3.6.1.2.1.2.2.1.13'; |
| 32 |
$self->{oids_errors}->{oid_ifInError} = '.1.3.6.1.2.1.2.2.1.14'; |
| 33 |
$self->{oids_errors}->{oid_ifOutDiscard} = '.1.3.6.1.2.1.2.2.1.19'; |
| 34 |
$self->{oids_errors}->{oid_ifOutError} = '.1.3.6.1.2.1.2.2.1.20'; |
| 35 |
$self->{oids_errors}->{oid_ifInTooShort} = '.1.3.6.1.4.1.14988.1.1.14.1.1.33'; |
| 36 |
$self->{oids_errors}->{oid_ifInTooLong} = '.1.3.6.1.4.1.14988.1.1.14.1.1.41'; |
| 37 |
$self->{oids_errors}->{oid_ifInFCSError} = '.1.3.6.1.4.1.14988.1.1.14.1.1.45'; |
| 38 |
$self->{oids_errors}->{oid_ifInAlignError} = '.1.3.6.1.4.1.14988.1.1.14.1.1.46'; |
| 39 |
$self->{oids_errors}->{oid_ifInFragment} = '.1.3.6.1.4.1.14988.1.1.14.1.1.47'; |
| 40 |
$self->{oids_errors}->{oid_ifInOverflow} = '.1.3.6.1.4.1.14988.1.1.14.1.1.48'; |
| 41 |
$self->{oids_errors}->{oid_ifInUnknownOp} = '.1.3.6.1.4.1.14988.1.1.14.1.1.50'; |
| 42 |
$self->{oids_errors}->{oid_ifInLengthError} = '.1.3.6.1.4.1.14988.1.1.14.1.1.51'; |
| 43 |
$self->{oids_errors}->{oid_ifInCodeError} = '.1.3.6.1.4.1.14988.1.1.14.1.1.52'; |
| 44 |
$self->{oids_errors}->{oid_ifInCarrierError} = '.1.3.6.1.4.1.14988.1.1.14.1.1.53'; |
| 45 |
$self->{oids_errors}->{oid_ifInJabber} = '.1.3.6.1.4.1.14988.1.1.14.1.1.54'; |
| 46 |
$self->{oids_errors}->{oid_ifInDrop} = '.1.3.6.1.4.1.14988.1.1.14.1.1.55'; |
| 47 |
$self->{oids_errors}->{oid_ifOutTooShort} = '.1.3.6.1.4.1.14988.1.1.14.1.1.63'; |
| 48 |
$self->{oids_errors}->{oid_ifOutTooLong} = '.1.3.6.1.4.1.14988.1.1.14.1.1.71'; |
| 49 |
$self->{oids_errors}->{oid_ifOutUnderrun} = '.1.3.6.1.4.1.14988.1.1.14.1.1.75'; |
| 50 |
$self->{oids_errors}->{oid_ifOutCollision} = '.1.3.6.1.4.1.14988.1.1.14.1.1.76'; |
| 51 |
$self->{oids_errors}->{oid_ifOutExcessiveCollision} = '.1.3.6.1.4.1.14988.1.1.14.1.1.77'; |
| 52 |
$self->{oids_errors}->{oid_ifOutMultipleCollision} = '.1.3.6.1.4.1.14988.1.1.14.1.1.78'; |
| 53 |
$self->{oids_errors}->{oid_ifOutSingleCollision} = '.1.3.6.1.4.1.14988.1.1.14.1.1.79'; |
| 54 |
$self->{oids_errors}->{oid_ifOutExcessiveDeferred} = '.1.3.6.1.4.1.14988.1.1.14.1.1.80'; |
| 55 |
$self->{oids_errors}->{oid_ifOutDeferred} = '.1.3.6.1.4.1.14988.1.1.14.1.1.81'; |
| 56 |
$self->{oids_errors}->{oid_ifOutLateCollision} = '.1.3.6.1.4.1.14988.1.1.14.1.1.82'; |
| 57 |
$self->{oids_errors}->{oid_ifOutTotalCollision} = '.1.3.6.1.4.1.14988.1.1.14.1.1.83'; |
| 58 |
$self->{oids_errors}->{oid_ifOutDrop} = '.1.3.6.1.4.1.14988.1.1.14.1.1.85'; |
| 59 |
$self->{oids_errors}->{oid_ifOutJabber} = '.1.3.6.1.4.1.14988.1.1.14.1.1.86'; |
| 60 |
$self->{oids_errors}->{oid_ifOutFCSError} = '.1.3.6.1.4.1.14988.1.1.14.1.1.87'; |
| 61 |
$self->{oids_errors}->{oid_ifOutFragment} = '.1.3.6.1.4.1.14988.1.1.14.1.1.89'; |
| 62 |
} |
| 63 |
|
| 64 |
sub set_counters_errors { |
| 65 |
my ($self, %options) = @_; |
| 66 |
|
| 67 |
$self->set_oids_errors(); |
| 68 |
|
| 69 |
foreach my $oid (keys %{$self->{oids_errors}}) { |
| 70 |
$oid =~ /^oid_if(In|Out)(.*)$/; |
| 71 |
push @{$self->{maps_counters}->{int}}, |
| 72 |
{ label => lc($1) . '-' . lc($2), filter => 'add_errors', nlabel => 'interface.packets.' . lc($1) . '.' . lc($2) . '.count', set => { |
| 73 |
key_values => [ { name => lc($1.$2), diff => 1 }, { name => 'total_' . lc($1) . '_packets', diff => 1 }, { name => 'display' }, { name => 'mode_cast' } ], |
| 74 |
closure_custom_calc => $self->can('custom_errors_calc'), closure_custom_calc_extra_options => { label => $1 . ' ' . $2, label_ref1 => lc($1), label_ref2 => lc($2) }, |
| 75 |
closure_custom_output => $self->can('custom_errors_output'), output_error_template => 'Packets ' . $1 . ' ' . $2 . ' : %s', |
| 76 |
closure_custom_perfdata => $self->can('custom_errors_perfdata'), |
| 77 |
closure_custom_threshold_check => $self->can('custom_errors_threshold') |
| 78 |
} |
| 79 |
} |
| 80 |
; |
| 81 |
} |
| 82 |
} |
| 83 |
|
| 84 |
sub new { |
| 85 |
my ($class, %options) = @_; |
| 86 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options); |
| 87 |
bless $self, $class; |
| 88 |
|
| 89 |
$options{options}->add_options(arguments => { |
| 90 |
'warning-errors:s' => { name => 'warning_errors' }, |
| 91 |
'critical-errors:s' => { name => 'critical_errors' } |
| 92 |
}); |
| 93 |
|
| 94 |
return $self; |
| 95 |
} |
| 96 |
|
| 97 |
sub check_options { |
| 98 |
my ($self, %options) = @_; |
| 99 |
|
| 100 |
foreach ('warning', 'critical') { |
| 101 |
next if (!defined($options{option_results}->{$_ . '_errors'}) || $options{option_results}->{$_ . '_errors'} eq ''); |
| 102 |
foreach my $oid (keys %{$self->{oids_errors}}) { |
| 103 |
$oid =~ /^oid_if(In|Out)(.*)$/; |
| 104 |
if (!defined($options{option_results}->{$_ . '-instance-interface-packets-' . lc($1) . '-' . lc($2) . '-count'})) { |
| 105 |
$options{option_results}->{$_ . '-instance-interface-packets-' . lc($1) . '-' . lc($2) . '-count'} = $options{option_results}->{$_ . '_errors'}; |
| 106 |
} |
| 107 |
if (!defined($options{option_results}->{$_ . '-' . lc($1) . '-' . lc($2)})) { |
| 108 |
$options{option_results}->{$_ . '-' . lc($1) . '-' . lc($2)} = $options{option_results}->{$_ . '_errors'}; |
| 109 |
} |
| 110 |
} |
| 111 |
} |
| 112 |
|
| 113 |
$self->SUPER::check_options(%options); |
| 114 |
} |
| 115 |
|
| 116 |
sub load_errors { |
| 117 |
my ($self, %options) = @_; |
| 118 |
|
| 119 |
$self->{snmp}->load( |
| 120 |
oids => [ values %{$self->{oids_errors}} ], |
| 121 |
instances => $self->{array_interface_selected} |
| 122 |
); |
| 123 |
} |
| 124 |
|
| 125 |
sub add_result_errors { |
| 126 |
my ($self, %options) = @_; |
| 127 |
|
| 128 |
foreach my $oid (keys %{$self->{oids_errors}}) { |
| 129 |
$oid =~ /^oid_if(In|Out)(.*)$/; |
| 130 |
$self->{int}->{$options{instance}}->{lc($1.$2)} = $self->{results}->{$self->{oids_errors}->{$oid} . '.' . $options{instance}}; |
| 131 |
} |
| 132 |
} |
| 133 |
|
| 134 |
1; |
| 135 |
|
| 136 |
__END__ |
| 137 |
|
| 138 |
=head1 MODE |
| 139 |
|
| 140 |
Check interfaces. |
| 141 |
|
| 142 |
=over 8 |
| 143 |
|
| 144 |
=item B<--add-global> |
| 145 |
|
| 146 |
Check global port statistics (by default if no --add-* option is set). |
| 147 |
|
| 148 |
=item B<--add-status> |
| 149 |
|
| 150 |
Check interface status. |
| 151 |
|
| 152 |
=item B<--add-duplex-status> |
| 153 |
|
| 154 |
Check duplex status (with --warning-status and --critical-status). |
| 155 |
|
| 156 |
=item B<--add-traffic> |
| 157 |
|
| 158 |
Check interface traffic. |
| 159 |
|
| 160 |
=item B<--add-errors> |
| 161 |
|
| 162 |
Check interface errors. |
| 163 |
|
| 164 |
=item B<--add-cast> |
| 165 |
|
| 166 |
Check interface cast. |
| 167 |
|
| 168 |
=item B<--add-speed> |
| 169 |
|
| 170 |
Check interface speed. |
| 171 |
|
| 172 |
=item B<--add-volume> |
| 173 |
|
| 174 |
Check interface data volume between two checks (not supposed to be graphed, useful for BI reporting). |
| 175 |
|
| 176 |
=item B<--check-metrics> |
| 177 |
|
| 178 |
If the expression is true, metrics are checked (default: '%{opstatus} eq "up"'). |
| 179 |
|
| 180 |
=item B<--warning-status> |
| 181 |
|
| 182 |
Define the conditions to match for the status to be WARNING. |
| 183 |
You can use the following variables: %{admstatus}, %{opstatus}, %{duplexstatus}, %{display} |
| 184 |
|
| 185 |
=item B<--critical-status> |
| 186 |
|
| 187 |
Define the conditions to match for the status to be CRITICAL (default: '%{admstatus} eq "up" and %{opstatus} ne "up"'). |
| 188 |
You can use the following variables: %{admstatus}, %{opstatus}, %{duplexstatus}, %{display} |
| 189 |
|
| 190 |
=item B<--warning-errors> |
| 191 |
|
| 192 |
Set warning threshold for all error counters. |
| 193 |
|
| 194 |
=item B<--critical-errors> |
| 195 |
|
| 196 |
Set critical threshold for all error counters. |
| 197 |
|
| 198 |
=item B<--warning-*> B<--critical-*> |
| 199 |
|
| 200 |
Thresholds (will superseed --[warning|critical]-errors). |
| 201 |
Can be: 'total-port', 'total-admin-up', 'total-admin-down', 'total-oper-up', 'total-oper-down', |
| 202 |
'in-traffic', 'out-traffic', 'in-error', 'in-discard', 'out-error', 'out-discard', |
| 203 |
'in-ucast', 'in-bcast', 'in-mcast', 'out-ucast', 'out-bcast', 'out-mcast', |
| 204 |
'speed' (b/s). |
| 205 |
|
| 206 |
And also: 'in-tooshort' (%), 'in-toolong' (%), 'in-fcserror' (%), 'in-alignerror' (%), 'in-fragment' (%), |
| 207 |
'in-overflow' (%), 'in-unknownop' (%), 'in-lengtherror' (%), 'in-codeerror' (%), 'in-carriererror' (%), |
| 208 |
'in-jabber' (%), 'in-drop' (%), 'out-tooshort' (%), 'out-toolong' (%), 'out-underrun' (%), |
| 209 |
'out-collision' (%), 'out-excessivecollision' (%), 'out-multiplecollision' (%), 'out-singlecollision' (%), |
| 210 |
'out-excessivedeferred' (%),'out-deferred' (%), 'out-latecollision' (%), 'out-totalcollision' (%), |
| 211 |
'out-drop' (%), 'out-jabber' (%), 'out-fcserror' (%), 'out-fragment' (%). |
| 212 |
|
| 213 |
=item B<--units-traffic> |
| 214 |
|
| 215 |
Units of thresholds for the traffic (default: 'percent_delta') ('percent_delta', 'bps', 'counter'). |
| 216 |
|
| 217 |
=item B<--units-errors> |
| 218 |
|
| 219 |
Units of thresholds for errors/discards (default: 'percent_delta') ('percent_delta', 'percent', 'delta', 'deltaps', 'counter'). |
| 220 |
|
| 221 |
=item B<--units-cast> |
| 222 |
|
| 223 |
Units of thresholds for communication types (default: 'percent_delta') ('percent_delta', 'percent', 'delta', 'deltaps', 'counter'). |
| 224 |
|
| 225 |
=item B<--nagvis-perfdata> |
| 226 |
|
| 227 |
Display traffic perfdata to be compatible with nagvis widget. |
| 228 |
|
| 229 |
=item B<--interface> |
| 230 |
|
| 231 |
Set the interface (number expected) example: 1,2,... (empty means 'check all interfaces'). |
| 232 |
|
| 233 |
=item B<--name> |
| 234 |
|
| 235 |
Allows you to define the interface (in option --interface) by name instead of OID index. The name matching mode supports regular expressions. |
| 236 |
|
| 237 |
=item B<--speed> |
| 238 |
|
| 239 |
Set interface speed for incoming/outgoing traffic (in Mb). |
| 240 |
|
| 241 |
=item B<--speed-in> |
| 242 |
|
| 243 |
Set interface speed for incoming traffic (in Mb). |
| 244 |
|
| 245 |
=item B<--speed-out> |
| 246 |
|
| 247 |
Set interface speed for outgoing traffic (in Mb). |
| 248 |
|
| 249 |
=item B<--force-counters32> |
| 250 |
|
| 251 |
Force to use 32 bits counters (even in snmp v2c and v3). Should be used when 64 bits counters are buggy. |
| 252 |
|
| 253 |
=item B<--reload-cache-time> |
| 254 |
|
| 255 |
Time in minutes before reloading cache file (default: 180). |
| 256 |
|
| 257 |
=item B<--oid-filter> |
| 258 |
|
| 259 |
Define the OID to be used to filter interfaces (default: ifName) (values: ifDesc, ifAlias, ifName, IpAddr). |
| 260 |
|
| 261 |
=item B<--oid-display> |
| 262 |
|
| 263 |
Define the OID that will be used to name the interfaces (default: ifName) (values: ifDesc, ifAlias, ifName, IpAddr). |
| 264 |
|
| 265 |
=item B<--oid-extra-display> |
| 266 |
|
| 267 |
Add an OID to display. |
| 268 |
|
| 269 |
=item B<--display-transform-src> B<--display-transform-dst> |
| 270 |
|
| 271 |
Modify the interface name displayed by using a regular expression. |
| 272 |
|
| 273 |
Example: adding --display-transform-src='eth' --display-transform-dst='ens' will replace all occurrences of 'eth' with 'ens' |
| 274 |
|
| 275 |
=item B<--show-cache> |
| 276 |
|
| 277 |
Display cache interface data. |
| 278 |
|
| 279 |
=back |
| 280 |
|
| 281 |
=cut |