| 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::mitel::3300icp::snmp::mode::zapbandwidth; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::templates::counter); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
use Digest::MD5 qw(md5_hex); |
| 28 |
|
| 29 |
sub custom_usage_calc { |
| 30 |
my ($self, %options) = @_; |
| 31 |
|
| 32 |
$self->{result_values}->{used} = $options{new_datas}->{$self->{instance} . '_mitelBWMCurrentBandwidthInUse'} * 1000; |
| 33 |
$self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_mitelBWMCurrentBandwidthLimit'} * 1000; |
| 34 |
$self->{result_values}->{used_prct} = $self->{result_values}->{used} / $self->{result_values}->{total} * 100; |
| 35 |
$self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; |
| 36 |
return 0; |
| 37 |
} |
| 38 |
|
| 39 |
sub custom_usage_perfdata { |
| 40 |
my ($self, %options) = @_; |
| 41 |
|
| 42 |
my $extra_label = ''; |
| 43 |
$extra_label = '_' . $self->{result_values}->{display} if (!defined($options{extra_instance}) || $options{extra_instance} != 0); |
| 44 |
|
| 45 |
$self->{output}->perfdata_add( |
| 46 |
label => 'usage' . $extra_label, unit => 'b/s', |
| 47 |
value => $self->{result_values}->{used}, |
| 48 |
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, total => $self->{result_values}->{total}, cast_int => 1), |
| 49 |
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, total => $self->{result_values}->{total}, cast_int => 1), |
| 50 |
min => 0, max => $self->{result_values}->{total} |
| 51 |
); |
| 52 |
} |
| 53 |
|
| 54 |
sub custom_usage_output { |
| 55 |
my ($self, %options) = @_; |
| 56 |
|
| 57 |
my ($used_value, $used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used}, network => 1); |
| 58 |
return sprintf("Bandwidth usage: %s/s (%.2f %%)", $used_value . ' ' . $used_unit, $self->{result_values}->{used_prct}); |
| 59 |
} |
| 60 |
|
| 61 |
sub set_counters { |
| 62 |
my ($self, %options) = @_; |
| 63 |
|
| 64 |
$self->{maps_counters_type} = [ |
| 65 |
{ name => 'zap', type => 1, cb_prefix_output => 'prefix_zap_output', |
| 66 |
message_multiple => 'All zone access points are ok' }, |
| 67 |
]; |
| 68 |
|
| 69 |
$self->{maps_counters}->{zap} = [ |
| 70 |
{ label => 'usage', set => { |
| 71 |
key_values => [ { name => 'mitelBWMCurrentBandwidthInUse' }, |
| 72 |
{ name => 'mitelBWMCurrentBandwidthLimit' }, |
| 73 |
{ name => 'display' } ], |
| 74 |
closure_custom_calc => $self->can('custom_usage_calc'), |
| 75 |
closure_custom_output => $self->can('custom_usage_output'), |
| 76 |
threshold_use => 'used_prct', |
| 77 |
closure_custom_perfdata => $self->can('custom_usage_perfdata'), |
| 78 |
} |
| 79 |
}, |
| 80 |
]; |
| 81 |
} |
| 82 |
|
| 83 |
sub prefix_zap_output { |
| 84 |
my ($self, %options) = @_; |
| 85 |
|
| 86 |
return "Zone access point '" . $options{instance_value}->{display} . "' "; |
| 87 |
} |
| 88 |
|
| 89 |
sub new { |
| 90 |
my ($class, %options) = @_; |
| 91 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options); |
| 92 |
bless $self, $class; |
| 93 |
|
| 94 |
$options{options}->add_options(arguments => { |
| 95 |
"filter-name:s" => { name => 'filter_name' }, |
| 96 |
}); |
| 97 |
|
| 98 |
return $self; |
| 99 |
} |
| 100 |
|
| 101 |
sub check_options { |
| 102 |
my ($self, %options) = @_; |
| 103 |
$self->SUPER::check_options(%options); |
| 104 |
} |
| 105 |
|
| 106 |
my $oid_mitelBWMCurrentZAPLabel = '.1.3.6.1.4.1.1027.4.1.1.2.5.1.1.1.1.4', |
| 107 |
my $mapping = { |
| 108 |
mitelBWMCurrentBandwidthInUse => { oid => '.1.3.6.1.4.1.1027.4.1.1.2.5.1.1.1.1.5' }, |
| 109 |
mitelBWMCurrentBandwidthLimit => { oid => '.1.3.6.1.4.1.1027.4.1.1.2.5.1.1.1.1.6' }, |
| 110 |
}; |
| 111 |
|
| 112 |
sub manage_selection { |
| 113 |
my ($self, %options) = @_; |
| 114 |
|
| 115 |
$self->{zap} = {}; |
| 116 |
my $snmp_result = $options{snmp}->get_table(oid => $oid_mitelBWMCurrentZAPLabel, nothing_quit => 1); |
| 117 |
foreach my $oid (keys %{$snmp_result}) { |
| 118 |
$oid =~ /^$oid_mitelBWMCurrentZAPLabel\.(.*)$/; |
| 119 |
my $instance = $1; |
| 120 |
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && |
| 121 |
$snmp_result->{$oid} !~ /$self->{option_results}->{filter_name}/) { |
| 122 |
$self->{output}->output_add(long_msg => "skipping '" . $snmp_result->{$oid} . "'.", debug => 1); |
| 123 |
next; |
| 124 |
} |
| 125 |
|
| 126 |
$self->{zap}->{$instance} = { display => $snmp_result->{$oid} }; |
| 127 |
} |
| 128 |
|
| 129 |
$options{snmp}->load(oids => [ $mapping->{mitelBWMCurrentBandwidthInUse}->{oid}, |
| 130 |
$mapping->{mitelBWMCurrentBandwidthLimit}->{oid} ], |
| 131 |
instances => [ keys %{$self->{zap}} ], |
| 132 |
instance_regexp => '^(.*)$'); |
| 133 |
$snmp_result = $options{snmp}->get_leef(nothing_quit => 1); |
| 134 |
|
| 135 |
foreach (keys %{$self->{zap}}) { |
| 136 |
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $_); |
| 137 |
foreach my $name (keys %{$mapping}) { |
| 138 |
$self->{zap}->{$_}->{$name} = $result->{$name}; |
| 139 |
} |
| 140 |
} |
| 141 |
|
| 142 |
if (scalar(keys %{$self->{zap}}) <= 0) { |
| 143 |
$self->{output}->add_option_msg(short_msg => "No zone access points found."); |
| 144 |
$self->{output}->option_exit(); |
| 145 |
} |
| 146 |
} |
| 147 |
|
| 148 |
1; |
| 149 |
|
| 150 |
__END__ |
| 151 |
|
| 152 |
=head1 MODE |
| 153 |
|
| 154 |
Check zone access points bandwidth usage. |
| 155 |
|
| 156 |
=over 8 |
| 157 |
|
| 158 |
=item B<--filter-name> |
| 159 |
|
| 160 |
Filter by zone access points name (can be a regexp). |
| 161 |
|
| 162 |
=item B<--warning-usage> |
| 163 |
|
| 164 |
Warning threshold in percentage of bandwidth limit. |
| 165 |
|
| 166 |
=item B<--critical-usage> |
| 167 |
|
| 168 |
Critical threshold in percentage of bandwidth limit. |
| 169 |
|
| 170 |
=back |
| 171 |
|
| 172 |
=cut |
| 173 |
|