| 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::f5::bigip::snmp::mode::trunks; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::templates::counter); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); |
| 28 |
use Digest::MD5 qw(md5_hex); |
| 29 |
|
| 30 |
sub custom_traffic_perfdata { |
| 31 |
my ($self, %options) = @_; |
| 32 |
|
| 33 |
my ($warning, $critical); |
| 34 |
if ($self->{instance_mode}->{option_results}->{units_traffic} eq '%' && defined($self->{result_values}->{speed}) && $self->{result_values}->{speed} > 0) { |
| 35 |
$warning = $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}, total => $self->{result_values}->{speed}, cast_int => 1); |
| 36 |
$critical = $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}, total => $self->{result_values}->{speed}, cast_int => 1); |
| 37 |
} elsif ($self->{instance_mode}->{option_results}->{units_traffic} eq 'b/s') { |
| 38 |
$warning = $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}); |
| 39 |
$critical = $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}); |
| 40 |
} |
| 41 |
|
| 42 |
my $speed = $self->{result_values}->{speed} > 0 ? $self->{result_values}->{speed} : undef; |
| 43 |
|
| 44 |
$self->{output}->perfdata_add( |
| 45 |
label => 'traffic_' . $self->{result_values}->{label}, unit => 'b/s', |
| 46 |
instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display} : undef, |
| 47 |
value => sprintf("%.2f", $self->{result_values}->{traffic_per_seconds}), |
| 48 |
warning => $warning, |
| 49 |
critical => $critical, |
| 50 |
min => 0, max => $speed |
| 51 |
); |
| 52 |
} |
| 53 |
|
| 54 |
sub custom_traffic_threshold { |
| 55 |
my ($self, %options) = @_; |
| 56 |
|
| 57 |
my $exit = 'ok'; |
| 58 |
if ($self->{instance_mode}->{option_results}->{units_traffic} eq '%' && defined($self->{result_values}->{speed}) && $self->{result_values}->{speed} > 0) { |
| 59 |
$exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{traffic_prct}, threshold => [ { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{thlabel}, exit_litteral => 'warning' } ]); |
| 60 |
} elsif ($self->{instance_mode}->{option_results}->{units_traffic} eq 'b/s') { |
| 61 |
$exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{traffic_per_seconds}, threshold => [ { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{thlabel}, exit_litteral => 'warning' } ]); |
| 62 |
} |
| 63 |
return $exit; |
| 64 |
} |
| 65 |
|
| 66 |
sub custom_traffic_output { |
| 67 |
my ($self, %options) = @_; |
| 68 |
|
| 69 |
my ($traffic_value, $traffic_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{traffic_per_seconds}, network => 1); |
| 70 |
return sprintf( |
| 71 |
"traffic %s: %s/s (%s)", |
| 72 |
$self->{result_values}->{label}, |
| 73 |
$traffic_value . $traffic_unit, |
| 74 |
defined($self->{result_values}->{traffic_prct}) ? sprintf("%.2f%%", $self->{result_values}->{traffic_prct}) : '-' |
| 75 |
); |
| 76 |
} |
| 77 |
|
| 78 |
sub custom_traffic_calc { |
| 79 |
my ($self, %options) = @_; |
| 80 |
|
| 81 |
if (!defined($options{old_datas}->{$self->{instance} . '_' . $options{extra_options}->{label_ref}})) { |
| 82 |
$self->{error_msg} = "buffer creation"; |
| 83 |
return -2; |
| 84 |
} |
| 85 |
|
| 86 |
my $diff_traffic = ($options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{label_ref}} - $options{old_datas}->{$self->{instance} . '_' . $options{extra_options}->{label_ref}}); |
| 87 |
|
| 88 |
$self->{result_values}->{speed} = defined($self->{instance_mode}->{option_results}->{speed}) && $self->{instance_mode}->{option_results}->{speed} ne '' ? $self->{instance_mode}->{option_results}->{speed} : $options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{speed}}; |
| 89 |
$self->{result_values}->{speed} = $self->{result_values}->{speed} * 1000 * 1000; # bits |
| 90 |
$self->{result_values}->{traffic_per_seconds} = $diff_traffic * 8 / $options{delta_time}; |
| 91 |
$self->{result_values}->{traffic_prct} = $self->{result_values}->{traffic_per_seconds} * 100 / $self->{result_values}->{speed} if ($self->{result_values}->{speed} > 0); |
| 92 |
$self->{result_values}->{label} = $options{extra_options}->{label}; |
| 93 |
$self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; |
| 94 |
return 0; |
| 95 |
} |
| 96 |
|
| 97 |
sub custom_errors_perfdata { |
| 98 |
my ($self, %options) = @_; |
| 99 |
|
| 100 |
my $warning = $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}); |
| 101 |
my $critical = $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}); |
| 102 |
|
| 103 |
$self->{output}->perfdata_add( |
| 104 |
label => 'packets_error_' . $self->{result_values}->{label}, unit => '%', |
| 105 |
instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display} : undef, |
| 106 |
value => sprintf("%.2f", $self->{result_values}->{errors_prct}), |
| 107 |
warning => $warning, |
| 108 |
critical => $critical, |
| 109 |
min => 0, max => 100 |
| 110 |
); |
| 111 |
} |
| 112 |
|
| 113 |
sub custom_errors_threshold { |
| 114 |
my ($self, %options) = @_; |
| 115 |
|
| 116 |
return $self->{perfdata}->threshold_check(value => $self->{result_values}->{errors_prct}, threshold => [ { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{thlabel}, exit_litteral => 'warning' } ]); |
| 117 |
} |
| 118 |
|
| 119 |
sub custom_errors_output { |
| 120 |
my ($self, %options) = @_; |
| 121 |
|
| 122 |
return sprintf( |
| 123 |
"packets %s error: %s", |
| 124 |
$self->{result_values}->{label}, |
| 125 |
defined($self->{result_values}->{errors_prct}) ? sprintf("%.2f%%", $self->{result_values}->{errors_prct}) : '-' |
| 126 |
); |
| 127 |
} |
| 128 |
|
| 129 |
sub custom_errors_calc { |
| 130 |
my ($self, %options) = @_; |
| 131 |
|
| 132 |
if (!defined($options{old_datas}->{$self->{instance} . '_' . $options{extra_options}->{errors}})) { |
| 133 |
$self->{error_msg} = "buffer creation"; |
| 134 |
return -2; |
| 135 |
} |
| 136 |
|
| 137 |
my $diff_errors = ($options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{errors}} - $options{old_datas}->{$self->{instance} . '_' . $options{extra_options}->{errors}}); |
| 138 |
my $diff_packets = ($options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{packets}} - $options{old_datas}->{$self->{instance} . '_' . $options{extra_options}->{packets}}); |
| 139 |
|
| 140 |
$self->{result_values}->{errors_prct} = ($diff_packets != 0) ? $diff_errors * 100 / $diff_packets : 0; |
| 141 |
$self->{result_values}->{label} = $options{extra_options}->{label}; |
| 142 |
$self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; |
| 143 |
return 0; |
| 144 |
} |
| 145 |
|
| 146 |
sub custom_drops_perfdata { |
| 147 |
my ($self, %options) = @_; |
| 148 |
|
| 149 |
my $warning = $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}); |
| 150 |
my $critical = $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}); |
| 151 |
|
| 152 |
$self->{output}->perfdata_add( |
| 153 |
label => 'packets_drop_' . $self->{result_values}->{label}, unit => '%', |
| 154 |
instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display} : undef, |
| 155 |
value => sprintf("%.2f", $self->{result_values}->{drops_prct}), |
| 156 |
warning => $warning, |
| 157 |
critical => $critical, |
| 158 |
min => 0, max => 100 |
| 159 |
); |
| 160 |
} |
| 161 |
|
| 162 |
sub custom_drops_threshold { |
| 163 |
my ($self, %options) = @_; |
| 164 |
|
| 165 |
return $self->{perfdata}->threshold_check(value => $self->{result_values}->{drops_prct}, threshold => [ { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{thlabel}, exit_litteral => 'warning' } ]); |
| 166 |
} |
| 167 |
|
| 168 |
sub custom_drops_output { |
| 169 |
my ($self, %options) = @_; |
| 170 |
|
| 171 |
return sprintf( |
| 172 |
"packets %s drop: %s", |
| 173 |
$self->{result_values}->{label}, |
| 174 |
defined($self->{result_values}->{drops_prct}) ? sprintf("%.2f%%", $self->{result_values}->{drops_prct}) : '-' |
| 175 |
); |
| 176 |
} |
| 177 |
|
| 178 |
sub custom_drops_calc { |
| 179 |
my ($self, %options) = @_; |
| 180 |
|
| 181 |
if (!defined($options{old_datas}->{$self->{instance} . '_' . $options{extra_options}->{drops}})) { |
| 182 |
$self->{error_msg} = "buffer creation"; |
| 183 |
return -2; |
| 184 |
} |
| 185 |
|
| 186 |
my $diff_drops = ($options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{drops}} - $options{old_datas}->{$self->{instance} . '_' . $options{extra_options}->{drops}}); |
| 187 |
my $diff_packets = ($options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{packets}} - $options{old_datas}->{$self->{instance} . '_' . $options{extra_options}->{packets}}); |
| 188 |
|
| 189 |
$self->{result_values}->{drops_prct} = ($diff_packets != 0) ? $diff_drops * 100 / $diff_packets : 0; |
| 190 |
$self->{result_values}->{label} = $options{extra_options}->{label}; |
| 191 |
$self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; |
| 192 |
return 0; |
| 193 |
} |
| 194 |
|
| 195 |
sub port_trunk_output { |
| 196 |
my ($self, %options) = @_; |
| 197 |
|
| 198 |
return "checking trunk '" . $options{instance_value}->{display} . "'"; |
| 199 |
} |
| 200 |
|
| 201 |
sub prefix_trunk_output { |
| 202 |
my ($self, %options) = @_; |
| 203 |
|
| 204 |
return "Trunk '" . $options{instance_value}->{display} . "' "; |
| 205 |
} |
| 206 |
|
| 207 |
sub prefix_interface_output { |
| 208 |
my ($self, %options) = @_; |
| 209 |
|
| 210 |
return "interface '" . $options{instance_value}->{display} . "' "; |
| 211 |
} |
| 212 |
|
| 213 |
sub set_counters { |
| 214 |
my ($self, %options) = @_; |
| 215 |
|
| 216 |
$self->{maps_counters_type} = [ |
| 217 |
{ |
| 218 |
name => 'trunks', type => 3, cb_prefix_output => 'prefix_trunk_output', cb_long_output => 'port_trunk_output', indent_long_output => ' ', message_multiple => 'All trunks are ok', |
| 219 |
group => [ |
| 220 |
{ name => 'trunk_global', type => 0, skipped_code => { -10 => 1 } }, |
| 221 |
{ name => 'interfaces', display_long => 1, cb_prefix_output => 'prefix_interface_output', message_multiple => 'All interfaces are ok', type => 1, skipped_code => { -10 => 1 } } |
| 222 |
] |
| 223 |
} |
| 224 |
]; |
| 225 |
|
| 226 |
$self->{maps_counters}->{trunk_global} = [ |
| 227 |
{ |
| 228 |
label => 'status', type => 2, critical_default => '%{status} =~ /uninitialized|down/', |
| 229 |
set => { |
| 230 |
key_values => [ { name => 'status' }, { name => 'display' } ], |
| 231 |
output_template => "status is '%s'", output_error_template => 'status: %s', |
| 232 |
closure_custom_perfdata => sub { return 0; }, |
| 233 |
closure_custom_threshold_check => \&catalog_status_threshold_ng |
| 234 |
} |
| 235 |
}, |
| 236 |
{ label => 'traffic-in', set => { |
| 237 |
key_values => [ { name => 'sysTrunkStatBytesIn', diff => 1 }, { name => 'sysTrunkOperBw', diff => 1 }, { name => 'display' } ], |
| 238 |
closure_custom_calc => $self->can('custom_traffic_calc'), |
| 239 |
closure_custom_calc_extra_options => { label_ref => 'sysTrunkStatBytesIn', speed => 'sysTrunkOperBw', label => 'in' }, |
| 240 |
closure_custom_output => $self->can('custom_traffic_output'), output_error_template => 'traffic in: %s', |
| 241 |
closure_custom_perfdata => $self->can('custom_traffic_perfdata'), |
| 242 |
closure_custom_threshold_check => $self->can('custom_traffic_threshold') |
| 243 |
} |
| 244 |
}, |
| 245 |
{ label => 'traffic-out', set => { |
| 246 |
key_values => [ { name => 'sysTrunkStatBytesOut', diff => 1 }, { name => 'sysTrunkOperBw', diff => 1 }, { name => 'display' } ], |
| 247 |
closure_custom_calc => $self->can('custom_traffic_calc'), |
| 248 |
closure_custom_calc_extra_options => { label_ref => 'sysTrunkStatBytesOut', speed => 'sysTrunkOperBw', label => 'out' }, |
| 249 |
closure_custom_output => $self->can('custom_traffic_output'), output_error_template => 'traffic out: %s', |
| 250 |
closure_custom_perfdata => $self->can('custom_traffic_perfdata'), |
| 251 |
closure_custom_threshold_check => $self->can('custom_traffic_threshold') |
| 252 |
} |
| 253 |
}, |
| 254 |
{ label => 'packets-error-in', set => { |
| 255 |
key_values => [ { name => 'sysTrunkStatErrorsIn', diff => 1 }, { name => 'sysTrunkStatPktsIn', diff => 1 }, { name => 'display' } ], |
| 256 |
closure_custom_calc => $self->can('custom_errors_calc'), |
| 257 |
closure_custom_calc_extra_options => { errors => 'sysTrunkStatErrorsIn', packets => 'sysTrunkStatPktsIn', label => 'in' }, |
| 258 |
closure_custom_output => $self->can('custom_errors_output'), output_error_template => 'packets in error: %s', |
| 259 |
closure_custom_perfdata => $self->can('custom_errors_perfdata'), |
| 260 |
closure_custom_threshold_check => $self->can('custom_errors_threshold') |
| 261 |
} |
| 262 |
}, |
| 263 |
{ label => 'packets-error-out', set => { |
| 264 |
key_values => [ { name => 'sysTrunkStatErrorsOut', diff => 1 }, { name => 'sysTrunkStatPktsOut', diff => 1 }, { name => 'display' } ], |
| 265 |
closure_custom_calc => $self->can('custom_errors_calc'), |
| 266 |
closure_custom_calc_extra_options => { errors => 'sysTrunkStatErrorsOut', packets => 'sysTrunkStatPktsOut', label => 'out' }, |
| 267 |
closure_custom_output => $self->can('custom_errors_output'), output_error_template => 'packets out error: %s', |
| 268 |
closure_custom_perfdata => $self->can('custom_errors_perfdata'), |
| 269 |
closure_custom_threshold_check => $self->can('custom_errors_threshold') |
| 270 |
} |
| 271 |
}, |
| 272 |
{ label => 'packets-drop-in', set => { |
| 273 |
key_values => [ { name => 'sysTrunkStatDropsIn', diff => 1 }, { name => 'sysTrunkStatPktsIn', diff => 1 }, { name => 'display' } ], |
| 274 |
closure_custom_calc => $self->can('custom_drops_calc'), |
| 275 |
closure_custom_calc_extra_options => { drops => 'sysTrunkStatDropsIn', packets => 'sysTrunkStatPktsIn', label => 'in' }, |
| 276 |
closure_custom_output => $self->can('custom_drops_output'), output_error_template => 'packets in drop: %s', |
| 277 |
closure_custom_perfdata => $self->can('custom_drops_perfdata'), |
| 278 |
closure_custom_threshold_check => $self->can('custom_drops_threshold') |
| 279 |
} |
| 280 |
}, |
| 281 |
{ label => 'packets-drop-out', set => { |
| 282 |
key_values => [ { name => 'sysTrunkStatDropsOut', diff => 1 }, { name => 'sysTrunkStatPktsOut', diff => 1 }, { name => 'display' } ], |
| 283 |
closure_custom_calc => $self->can('custom_drops_calc'), |
| 284 |
closure_custom_calc_extra_options => { drops => 'sysTrunkStatDropsOut', packets => 'sysTrunkStatPktsOut', label => 'out' }, |
| 285 |
closure_custom_output => $self->can('custom_drops_output'), output_error_template => 'packets out drop: %s', |
| 286 |
closure_custom_perfdata => $self->can('custom_drops_perfdata'), |
| 287 |
closure_custom_threshold_check => $self->can('custom_drops_threshold') |
| 288 |
} |
| 289 |
}, |
| 290 |
{ label => 'interfaces-total', nlabel => 'trunk.interfaces.total.count', display_ok => 0, set => { |
| 291 |
key_values => [ { name => 'total_interfaces' }, { name => 'display' } ], |
| 292 |
output_template => 'total interfaces: %s', |
| 293 |
perfdatas => [ |
| 294 |
{ label => 'total_interfaces', template => '%d', min => 0, label_extra_instance => 1 } |
| 295 |
] |
| 296 |
} |
| 297 |
} |
| 298 |
]; |
| 299 |
|
| 300 |
$self->{maps_counters}->{interfaces} = [ |
| 301 |
{ label => 'interface-status', type => 2, set => { |
| 302 |
key_values => [ { name => 'status' }, { name => 'display' } ], |
| 303 |
output_template => "status is '%s'", |
| 304 |
closure_custom_perfdata => sub { return 0; }, |
| 305 |
closure_custom_threshold_check => \&catalog_status_threshold_ng |
| 306 |
} |
| 307 |
} |
| 308 |
]; |
| 309 |
} |
| 310 |
|
| 311 |
sub new { |
| 312 |
my ($class, %options) = @_; |
| 313 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); |
| 314 |
bless $self, $class; |
| 315 |
|
| 316 |
$options{options}->add_options(arguments => { |
| 317 |
'filter-name:s' => { name => 'filter_name' }, |
| 318 |
'units-traffic:s' => { name => 'units_traffic', default => '%' }, |
| 319 |
'speed:s' => { name => 'speed' }, |
| 320 |
'add-interfaces' => { name => 'add_interfaces' } |
| 321 |
}); |
| 322 |
|
| 323 |
return $self; |
| 324 |
} |
| 325 |
|
| 326 |
my $map_trunk_status = { |
| 327 |
0 => 'up', |
| 328 |
1 => 'down', |
| 329 |
2 => 'disable', |
| 330 |
3 => 'uninitialized', |
| 331 |
4 => 'loopback', |
| 332 |
5 => 'unpopulated' |
| 333 |
}; |
| 334 |
my $map_interface_status = { |
| 335 |
1 => 'up', |
| 336 |
2 => 'down', |
| 337 |
3 => 'testing', |
| 338 |
4 => 'unknown', |
| 339 |
5 => 'dormant', |
| 340 |
6 => 'notPresent', |
| 341 |
7 => 'lowerLayerDown' |
| 342 |
}; |
| 343 |
my $mapping_interface = { |
| 344 |
display => { oid => '.1.3.6.1.2.1.2.2.1.2' }, # ifDescr |
| 345 |
status => { oid => '.1.3.6.1.2.1.2.2.1.8', map => $map_interface_status } # ifOperStatus |
| 346 |
}; |
| 347 |
|
| 348 |
my $mapping = { |
| 349 |
status => { oid => '.1.3.6.1.4.1.3375.2.1.2.12.1.2.1.2', map => $map_trunk_status }, # sysTrunkStatus |
| 350 |
sysTrunkOperBw => { oid => '.1.3.6.1.4.1.3375.2.1.2.12.1.2.1.5' }, |
| 351 |
sysTrunkStatPktsIn => { oid => '.1.3.6.1.4.1.3375.2.1.2.12.2.3.1.2' }, |
| 352 |
sysTrunkStatBytesIn => { oid => '.1.3.6.1.4.1.3375.2.1.2.12.2.3.1.3' }, # Bytes |
| 353 |
sysTrunkStatPktsOut => { oid => '.1.3.6.1.4.1.3375.2.1.2.12.2.3.1.4' }, |
| 354 |
sysTrunkStatBytesOut => { oid => '.1.3.6.1.4.1.3375.2.1.2.12.2.3.1.5' }, # Bytes |
| 355 |
sysTrunkStatErrorsIn => { oid => '.1.3.6.1.4.1.3375.2.1.2.12.2.3.1.8' }, |
| 356 |
sysTrunkStatErrorsOut => { oid => '.1.3.6.1.4.1.3375.2.1.2.12.2.3.1.9' }, |
| 357 |
sysTrunkStatDropsIn => { oid => '.1.3.6.1.4.1.3375.2.1.2.12.2.3.1.10' }, |
| 358 |
sysTrunkStatDropsOut => { oid => '.1.3.6.1.4.1.3375.2.1.2.12.2.3.1.11' } |
| 359 |
}; |
| 360 |
|
| 361 |
sub add_interfaces { |
| 362 |
my ($self, %options) = @_; |
| 363 |
|
| 364 |
my $interfaces = $options{snmp}->get_multiple_table( |
| 365 |
oids => [ { oid => $mapping_interface->{display}->{oid} }, { oid => $mapping_interface->{status}->{oid} } ], |
| 366 |
return_type => 1 |
| 367 |
); |
| 368 |
|
| 369 |
my $oid_sysTrunkCfgMemberName = '.1.3.6.1.4.1.3375.2.1.2.12.3.2.1.2'; |
| 370 |
my $snmp_result = $options{snmp}->get_table(oid => $oid_sysTrunkCfgMemberName); |
| 371 |
foreach my $trunk_name (keys %{$self->{trunks}}) { |
| 372 |
$self->{trunks}->{$trunk_name}->{trunk_global}->{total_interfaces} = 0; |
| 373 |
foreach (keys %$snmp_result) { |
| 374 |
next if (! /^$oid_sysTrunkCfgMemberName\.$self->{trunks}->{$trunk_name}->{instance}\./); |
| 375 |
my $interface_name = $snmp_result->{$_}; |
| 376 |
foreach my $oid_int (keys %$interfaces) { |
| 377 |
next if ($oid_int !~ /^$mapping_interface->{display}->{oid}\.(.*)/); |
| 378 |
my $instance = $1; |
| 379 |
next if ($interfaces->{$oid_int} ne $snmp_result->{$_}); |
| 380 |
my $result = $options{snmp}->map_instance(mapping => $mapping_interface, results => $interfaces, instance => $instance); |
| 381 |
|
| 382 |
$self->{trunks}->{$trunk_name}->{interfaces}->{ $result->{display} } = { |
| 383 |
%$result |
| 384 |
}; |
| 385 |
$self->{trunks}->{$trunk_name}->{trunk_global}->{total_interfaces}++; |
| 386 |
} |
| 387 |
} |
| 388 |
} |
| 389 |
} |
| 390 |
|
| 391 |
sub manage_selection { |
| 392 |
my ($self, %options) = @_; |
| 393 |
|
| 394 |
if ($options{snmp}->is_snmpv1()) { |
| 395 |
$self->{output}->add_option_msg(short_msg => 'Need to use SNMP v2c or v3.'); |
| 396 |
$self->{output}->option_exit(); |
| 397 |
} |
| 398 |
|
| 399 |
my $oid_sysTrunkName = '.1.3.6.1.4.1.3375.2.1.2.12.1.2.1.1'; |
| 400 |
my $snmp_result = $options{snmp}->get_table(oid => $oid_sysTrunkName, nothing_quit => 1); |
| 401 |
|
| 402 |
$self->{trunks} = {}; |
| 403 |
foreach (keys %$snmp_result) { |
| 404 |
/^$oid_sysTrunkName\.(.*)$/; |
| 405 |
my $instance = $1; |
| 406 |
|
| 407 |
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && |
| 408 |
$snmp_result->{$_} !~ /$self->{option_results}->{filter_name}/) { |
| 409 |
$self->{output}->output_add(long_msg => "skipping trunk '" . $snmp_result->{$_} . "'.", debug => 1); |
| 410 |
next; |
| 411 |
} |
| 412 |
|
| 413 |
$self->{trunks}->{ $snmp_result->{$_} } = { |
| 414 |
display => $snmp_result->{$_}, |
| 415 |
instance => $instance, |
| 416 |
interfaces => {} |
| 417 |
}; |
| 418 |
} |
| 419 |
|
| 420 |
if (scalar(keys %{$self->{trunks}}) <= 0) { |
| 421 |
$self->{output}->add_option_msg(short_msg => 'No trunk found.'); |
| 422 |
$self->{output}->option_exit(); |
| 423 |
} |
| 424 |
|
| 425 |
$options{snmp}->load(oids => [ |
| 426 |
map($_->{oid}, values(%$mapping)) |
| 427 |
], |
| 428 |
instances => [map($_->{instance}, values(%{$self->{trunks}}))], |
| 429 |
instance_regexp => '^(.*)$' |
| 430 |
); |
| 431 |
$snmp_result = $options{snmp}->get_leef(nothing_quit => 1); |
| 432 |
|
| 433 |
foreach (keys %{$self->{trunks}}) { |
| 434 |
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $self->{trunks}->{$_}->{instance}); |
| 435 |
$self->{trunks}->{$_}->{trunk_global} = { |
| 436 |
display => $_, |
| 437 |
%$result |
| 438 |
}; |
| 439 |
} |
| 440 |
|
| 441 |
$self->add_interfaces(snmp => $options{snmp}) if (defined($self->{option_results}->{add_interfaces})); |
| 442 |
|
| 443 |
$self->{cache_name} = 'f5_bipgip_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' . |
| 444 |
(defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all')) . '_' . |
| 445 |
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); |
| 446 |
} |
| 447 |
|
| 448 |
1; |
| 449 |
|
| 450 |
__END__ |
| 451 |
|
| 452 |
=head1 MODE |
| 453 |
|
| 454 |
Check Trunks usage. |
| 455 |
|
| 456 |
=over 8 |
| 457 |
|
| 458 |
=item B<--filter-name> |
| 459 |
|
| 460 |
Filter by trunks name (regexp can be used). |
| 461 |
|
| 462 |
=item B<--units-traffic> |
| 463 |
|
| 464 |
Units of thresholds for the traffic (default: '%') ('%', 'b/s'). |
| 465 |
|
| 466 |
=item B<--speed> |
| 467 |
|
| 468 |
Set trunk speed in Mbps (default: sysTrunkOperBw). |
| 469 |
If not set and sysTrunkOperBw OID value is 0, |
| 470 |
percentage thresholds will not be applied on traffic metrics. |
| 471 |
|
| 472 |
=item B<--add-interfaces> |
| 473 |
|
| 474 |
Monitor trunk interfaces. |
| 475 |
|
| 476 |
=item B<--unknown-status> |
| 477 |
|
| 478 |
Define the conditions to match for the status to be UNKNOWN. |
| 479 |
You can use the following variables: %{status}, %{display} |
| 480 |
|
| 481 |
=item B<--warning-status> |
| 482 |
|
| 483 |
Define the conditions to match for the status to be WARNING. |
| 484 |
You can use the following variables: %{status}, %{display} |
| 485 |
|
| 486 |
=item B<--critical-status> |
| 487 |
|
| 488 |
Define the conditions to match for the status to be CRITICAL (default: '%{status} =~ /uninitialized|down/'). |
| 489 |
You can use the following variables: %{status}, %{display} |
| 490 |
|
| 491 |
=item B<--unknown-interface-status> |
| 492 |
|
| 493 |
Define the conditions to match for the status to be UNKNOWN. |
| 494 |
You can use the following variables: %{status}, %{display} |
| 495 |
|
| 496 |
=item B<--warning-interface-status> |
| 497 |
|
| 498 |
Define the conditions to match for the status to be WARNING. |
| 499 |
You can use the following variables: %{status}, %{display} |
| 500 |
|
| 501 |
=item B<--critical-interface-status> |
| 502 |
|
| 503 |
Define the conditions to match for the status to be CRITICAL. |
| 504 |
You can use the following variables: %{status}, %{display} |
| 505 |
|
| 506 |
=item B<--warning-*> B<--critical-*> |
| 507 |
|
| 508 |
Thresholds. |
| 509 |
Can be: 'traffic-in', 'traffic-out', 'packets-error-in' (%), |
| 510 |
'packets-error-out' (%), 'packets-drop-in' (%), 'packets-drop-out' (%), |
| 511 |
'total-interfaces'. |
| 512 |
|
| 513 |
=back |
| 514 |
|
| 515 |
=cut |