| 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::alcatel::oxe::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 |
|
| 29 |
sub custom_status_output { |
| 30 |
my ($self, %options) = @_; |
| 31 |
|
| 32 |
return 'status: ' . $self->{result_values}->{trunkstatus}; |
| 33 |
} |
| 34 |
|
| 35 |
sub custom_usage_perfdata { |
| 36 |
my ($self, %options) = @_; |
| 37 |
|
| 38 |
$self->{output}->perfdata_add( |
| 39 |
nlabel => $self->{nlabel}, |
| 40 |
instances => $self->{result_values}->{name}, |
| 41 |
value => $self->{result_values}->{used}, |
| 42 |
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}, total => $self->{result_values}->{total}, cast_int => 1), |
| 43 |
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}, total => $self->{result_values}->{total}, cast_int => 1), |
| 44 |
min => 0, max => $self->{result_values}->{total} |
| 45 |
); |
| 46 |
} |
| 47 |
|
| 48 |
sub custom_usage_threshold { |
| 49 |
my ($self, %options) = @_; |
| 50 |
|
| 51 |
my $exit = $self->{perfdata}->threshold_check( |
| 52 |
value => $self->{result_values}->{prct_used}, |
| 53 |
threshold => [ |
| 54 |
{ label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, |
| 55 |
{ label => 'warning-' . $self->{thlabel}, exit_litteral => 'warning' } |
| 56 |
] |
| 57 |
); |
| 58 |
return $exit; |
| 59 |
} |
| 60 |
|
| 61 |
sub custom_usage_output { |
| 62 |
my ($self, %options) = @_; |
| 63 |
|
| 64 |
return sprintf( |
| 65 |
"channels usage total: %s used: %s (%.2f%%) free: %s (%.2f%%)", |
| 66 |
$self->{result_values}->{total}, |
| 67 |
$self->{result_values}->{used}, $self->{result_values}->{prct_used}, |
| 68 |
$self->{result_values}->{free}, $self->{result_values}->{prct_free} |
| 69 |
); |
| 70 |
} |
| 71 |
|
| 72 |
sub custom_trunk_usage_calc { |
| 73 |
my ($self, %options) = @_; |
| 74 |
|
| 75 |
$self->{result_values}->{name} = $options{new_datas}->{$self->{instance} . '_name'}; |
| 76 |
$self->{result_values}->{free} = $options{new_datas}->{$self->{instance} . '_freechan'}; |
| 77 |
$self->{result_values}->{used} = $options{new_datas}->{$self->{instance} . '_busychan'}; |
| 78 |
$self->{result_values}->{total} = $self->{result_values}->{free} + $self->{result_values}->{used}; |
| 79 |
|
| 80 |
return -10 if ($self->{result_values}->{total} <= 0); |
| 81 |
|
| 82 |
$self->{result_values}->{prct_free} = $self->{result_values}->{free} * 100 / $self->{result_values}->{total}; |
| 83 |
$self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total}; |
| 84 |
return 0; |
| 85 |
} |
| 86 |
|
| 87 |
sub prefix_trunk_output { |
| 88 |
my ($self, %options) = @_; |
| 89 |
|
| 90 |
return "Trunk '" . $options{instance_value}->{name} . "' "; |
| 91 |
} |
| 92 |
|
| 93 |
sub set_counters { |
| 94 |
my ($self, %options) = @_; |
| 95 |
|
| 96 |
$self->{maps_counters_type} = [ |
| 97 |
{ name => 'trunk', type => 1, cb_prefix_output => 'prefix_trunk_output', message_multiple => 'All trunks are ok', skipped_code => { -2 => 1, -10 => 1 } } |
| 98 |
]; |
| 99 |
|
| 100 |
$self->{maps_counters}->{trunk} = [ |
| 101 |
{ label => 'trunk-status', type => 2, critical_default => '%{trunkstatus} =~ /oos/i', set => { |
| 102 |
key_values => [ { name => 'trunkstatus' } ], |
| 103 |
closure_custom_output => $self->can('custom_status_output'), |
| 104 |
closure_custom_perfdata => sub { return 0; }, |
| 105 |
closure_custom_threshold_check => \&catalog_status_threshold_ng |
| 106 |
} |
| 107 |
}, |
| 108 |
{ label => 'channel-usage', nlabel => 'trunk.channels.usage.count', set => { |
| 109 |
key_values => [ { name => 'busychan' }, { name => 'freechan' }, { name => 'name' } ], |
| 110 |
closure_custom_calc => $self->can('custom_trunk_usage_calc'), |
| 111 |
closure_custom_output => $self->can('custom_usage_output'), |
| 112 |
closure_custom_perfdata => $self->can('custom_usage_perfdata'), |
| 113 |
closure_custom_threshold_check => $self->can('custom_usage_threshold') |
| 114 |
} |
| 115 |
}, |
| 116 |
{ label => 'channel-outofservice', nlabel => 'trunk.channels.outofservice.count', set => { |
| 117 |
key_values => [ { name => 'ooschan' } ], |
| 118 |
output_template => 'channels out of service %s', |
| 119 |
perfdatas => [ |
| 120 |
{ template => '%s', min => 0, label_extra_instance => 1 } |
| 121 |
] |
| 122 |
} |
| 123 |
} |
| 124 |
]; |
| 125 |
} |
| 126 |
|
| 127 |
sub new { |
| 128 |
my ($class, %options) = @_; |
| 129 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); |
| 130 |
bless $self, $class; |
| 131 |
|
| 132 |
$options{options}->add_options(arguments => { |
| 133 |
"filter-trunk:s" => { name => 'filter_trunk' }, |
| 134 |
}); |
| 135 |
|
| 136 |
return $self; |
| 137 |
} |
| 138 |
|
| 139 |
my $map_trunk_status = { 0 => 'OOS', 1 => 'INS' }; |
| 140 |
|
| 141 |
my $mapping = { |
| 142 |
trunkname => { oid => '.1.3.6.1.4.1.637.64.4400.1.9.1.2' }, |
| 143 |
crystalno => { oid => '.1.3.6.1.4.1.637.64.4400.1.9.1.3' }, # not used |
| 144 |
couplerno => { oid => '.1.3.6.1.4.1.637.64.4400.1.9.1.4' }, # not used |
| 145 |
trunktype => { oid => '.1.3.6.1.4.1.637.64.4400.1.9.1.5' }, # not used |
| 146 |
nodepbx => { oid => '.1.3.6.1.4.1.637.64.4400.1.9.1.6' }, # not used |
| 147 |
freechan => { oid => '.1.3.6.1.4.1.637.64.4400.1.9.1.7' }, |
| 148 |
busychan => { oid => '.1.3.6.1.4.1.637.64.4400.1.9.1.8' }, |
| 149 |
ooschan => { oid => '.1.3.6.1.4.1.637.64.4400.1.9.1.9' }, |
| 150 |
trunkstatus => { oid => '.1.3.6.1.4.1.637.64.4400.1.9.1.10', map => $map_trunk_status }, |
| 151 |
cumuloos => { oid => '.1.3.6.1.4.1.637.64.4400.1.9.1.11' }, # not used |
| 152 |
cumuloverrun => { oid => '.1.3.6.1.4.1.637.64.4400.1.9.1.12' } # not used |
| 153 |
}; |
| 154 |
|
| 155 |
sub manage_selection { |
| 156 |
my ($self, %options) = @_; |
| 157 |
|
| 158 |
my $oid_trunkEntry = '.1.3.6.1.4.1.637.64.4400.1.9.1'; |
| 159 |
my $snmp_result = $options{snmp}->get_table( |
| 160 |
oid => $oid_trunkEntry, |
| 161 |
nothing_quit => 1 |
| 162 |
); |
| 163 |
|
| 164 |
$self->{trunk} = {}; |
| 165 |
foreach my $oid (keys %$snmp_result) { |
| 166 |
next if ($oid !~ /^$mapping->{trunkname}->{oid}\.(\d+)/); |
| 167 |
my $instance = $1; |
| 168 |
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); |
| 169 |
|
| 170 |
next if (defined($self->{option_results}->{filter_trunk}) && $self->{option_results}->{filter_trunk} ne '' && |
| 171 |
$result->{trunkname} !~ /$self->{option_results}->{filter_trunk}/); |
| 172 |
|
| 173 |
$self->{trunk}->{ $result->{trunkname} } = { |
| 174 |
name => $result->{trunkname}, |
| 175 |
%{$result} |
| 176 |
}; |
| 177 |
} |
| 178 |
|
| 179 |
if (scalar(keys %{$self->{trunk}}) <= 0) { |
| 180 |
$self->{output}->add_option_msg(short_msg => "No trunk found."); |
| 181 |
$self->{output}->option_exit(); |
| 182 |
} |
| 183 |
} |
| 184 |
|
| 185 |
1; |
| 186 |
|
| 187 |
__END__ |
| 188 |
|
| 189 |
=head1 MODE |
| 190 |
|
| 191 |
Check Trunk usages. |
| 192 |
|
| 193 |
=over 8 |
| 194 |
|
| 195 |
=item B<--filter-trunk> |
| 196 |
|
| 197 |
Filter by trunk name (regexp can be used). |
| 198 |
|
| 199 |
=item B<--warning-trunk-status> |
| 200 |
|
| 201 |
Define the conditions to match for the status to be WARNING |
| 202 |
You can use the following variables: %{trunkstatus} |
| 203 |
|
| 204 |
=item B<--critical-trunk-status> |
| 205 |
|
| 206 |
Define the conditions to match for the status to be CRITICAL (default: '%{trunkstatus} =~ /oos/i'). |
| 207 |
You can use the following variables: %{trunkstatus} |
| 208 |
|
| 209 |
=item B<--warning-*> |
| 210 |
|
| 211 |
Warning threshold. |
| 212 |
Can be: 'channel-usage' (%), 'channel-outofservice' (absolute) |
| 213 |
|
| 214 |
=item B<--critical-*> |
| 215 |
|
| 216 |
Critical threshold. |
| 217 |
Can be: 'channel-usage' (%), 'channel-outofservice' (absolute) |
| 218 |
|
| 219 |
=back |
| 220 |
|
| 221 |
=cut |