| 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 hardware::devices::cisco::ces::restapi::mode::callsrt; |
| 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_traffic_calc { |
| 30 |
my ($self, %options) = @_; |
| 31 |
|
| 32 |
if (!defined($options{delta_time})) { |
| 33 |
$self->{error_msg} = 'Buffer creation'; |
| 34 |
return -1; |
| 35 |
} |
| 36 |
|
| 37 |
my $total_bytes = 0; |
| 38 |
foreach (keys %{$options{new_datas}}) { |
| 39 |
if (/\Q$self->{instance}\E_.*_bytes/) { |
| 40 |
my $new_bytes = $options{new_datas}->{$_}; |
| 41 |
next if (!defined($options{old_datas}->{$_})); |
| 42 |
my $old_bytes = $options{old_datas}->{$_}; |
| 43 |
my $bytes = $new_bytes - $old_bytes; |
| 44 |
$bytes = $new_bytes if ($bytes < 0); |
| 45 |
|
| 46 |
$total_bytes += $bytes; |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
$self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; |
| 51 |
$self->{result_values}->{traffic_per_seconds} = ($total_bytes * 8) / $options{delta_time}; |
| 52 |
return 0; |
| 53 |
} |
| 54 |
|
| 55 |
sub custom_jitter_calc { |
| 56 |
my ($self, %options) = @_; |
| 57 |
|
| 58 |
my $max_jitter = 0; |
| 59 |
foreach (keys %{$options{new_datas}}) { |
| 60 |
if (/\Q$self->{instance}\E_.*_maxjitter/) { |
| 61 |
$max_jitter = $options{new_datas}->{$_} if ($options{new_datas}->{$_} > $max_jitter); |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
$self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; |
| 66 |
$self->{result_values}->{max_jitter} = $max_jitter; |
| 67 |
return 0; |
| 68 |
} |
| 69 |
|
| 70 |
sub custom_loss_calc { |
| 71 |
my ($self, %options) = @_; |
| 72 |
|
| 73 |
my ($total_loss, $total_pkts) = (0, 0); |
| 74 |
foreach (keys %{$options{new_datas}}) { |
| 75 |
if (/\Q$self->{instance}\E_.*_loss/) { |
| 76 |
my $new_loss = $options{new_datas}->{$_}; |
| 77 |
next if (!defined($options{old_datas}->{$_})); |
| 78 |
my $old_loss = $options{old_datas}->{$_}; |
| 79 |
my $loss = $new_loss - $old_loss; |
| 80 |
$loss = $new_loss if ($loss < 0); |
| 81 |
|
| 82 |
$total_loss += $loss; |
| 83 |
} elsif (/\Q$self->{instance}\E_.*_packets/) { |
| 84 |
my $new_pkts = $options{new_datas}->{$_}; |
| 85 |
next if (!defined($options{old_datas}->{$_})); |
| 86 |
my $old_pkts = $options{old_datas}->{$_}; |
| 87 |
my $pkts = $new_pkts - $old_pkts; |
| 88 |
$pkts = $new_pkts if ($pkts < 0); |
| 89 |
|
| 90 |
$total_pkts += $pkts; |
| 91 |
} |
| 92 |
} |
| 93 |
|
| 94 |
$self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; |
| 95 |
$self->{result_values}->{packets_loss} = $total_loss; |
| 96 |
$self->{result_values}->{packets_loss_prct} = 0; |
| 97 |
$self->{result_values}->{packets} = $total_pkts; |
| 98 |
if ($total_pkts > 0) { |
| 99 |
$self->{result_values}->{packets_loss_prct} = ($total_loss * 100) / $total_pkts; |
| 100 |
} |
| 101 |
|
| 102 |
return 0; |
| 103 |
} |
| 104 |
|
| 105 |
sub custom_loss_output { |
| 106 |
my ($self, %options) = @_; |
| 107 |
|
| 108 |
return sprintf( |
| 109 |
"packets loss: %.2f%% (%s on %s)", |
| 110 |
$self->{result_values}->{packets_loss_prct}, |
| 111 |
$self->{result_values}->{packets_loss}, |
| 112 |
$self->{result_values}->{packets} |
| 113 |
); |
| 114 |
} |
| 115 |
|
| 116 |
sub set_counters { |
| 117 |
my ($self, %options) = @_; |
| 118 |
|
| 119 |
$self->{maps_counters_type} = [ |
| 120 |
{ name => 'channels', type => 1, cb_prefix_output => 'prefix_channels_output', message_multiple => 'All call channels are ok', skipped_code => { -10 => 1 } } |
| 121 |
]; |
| 122 |
|
| 123 |
$self->{maps_counters}->{channels} = [ |
| 124 |
{ label => 'channels-traffic', nlabel => 'call.channels.traffic.bytes', set => { |
| 125 |
key_values => [], |
| 126 |
manual_keys => 1, |
| 127 |
closure_custom_calc => $self->can('custom_traffic_calc'), |
| 128 |
output_template => 'traffic: %s %s/s', |
| 129 |
output_change_bytes => 1, |
| 130 |
output_use => 'traffic_per_seconds', threshold_use => 'traffic_per_seconds', |
| 131 |
perfdatas => [ |
| 132 |
{ value => 'traffic_per_seconds', template => '%d', |
| 133 |
unit => 'B/s', min => 0, label_extra_instance => 1, instance_use => 'display' } |
| 134 |
] |
| 135 |
} |
| 136 |
}, |
| 137 |
{ label => 'channels-maxjitter', nlabel => 'call.channels.maxjitter.milliseconds', set => { |
| 138 |
key_values => [], |
| 139 |
manual_keys => 1, |
| 140 |
closure_custom_calc => $self->can('custom_jitter_calc'), |
| 141 |
output_template => 'max jitter: %s ms', |
| 142 |
output_use => 'max_jitter', threshold_use => 'max_jitter', |
| 143 |
perfdatas => [ |
| 144 |
{ value => 'max_jitter', template => '%d', |
| 145 |
unit => 'ms', min => 0, label_extra_instance => 1, instance_use => 'display' } |
| 146 |
] |
| 147 |
} |
| 148 |
}, |
| 149 |
{ label => 'channels-packetloss', nlabel => 'call.channels.packetloss.count', set => { |
| 150 |
key_values => [], |
| 151 |
manual_keys => 1, |
| 152 |
closure_custom_calc => $self->can('custom_loss_calc'), |
| 153 |
closure_custom_output => $self->can('custom_loss_output'), |
| 154 |
threshold_use => 'packets_loss', |
| 155 |
perfdatas => [ |
| 156 |
{ value => 'packets_loss', template => '%d', |
| 157 |
min => 0, label_extra_instance => 1, instance_use => 'display' } |
| 158 |
] |
| 159 |
} |
| 160 |
}, |
| 161 |
{ label => 'channels-packetloss-prct', nlabel => 'call.channels.packetloss.percentage', display_ok => 0, set => { |
| 162 |
key_values => [], |
| 163 |
manual_keys => 1, |
| 164 |
closure_custom_calc => $self->can('custom_loss_calc'), |
| 165 |
closure_custom_output => $self->can('custom_loss_output'), |
| 166 |
threshold_use => 'packets_loss_prct', |
| 167 |
perfdatas => [ |
| 168 |
{ value => 'packets_loss_prct', template => '%.2f', |
| 169 |
unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' } |
| 170 |
] |
| 171 |
} |
| 172 |
} |
| 173 |
]; |
| 174 |
} |
| 175 |
|
| 176 |
sub prefix_channels_output { |
| 177 |
my ($self, %options) = @_; |
| 178 |
|
| 179 |
return "Channel '" . $options{instance_value}->{display} ."' "; |
| 180 |
} |
| 181 |
|
| 182 |
sub new { |
| 183 |
my ($class, %options) = @_; |
| 184 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1, statefile => 1); |
| 185 |
bless $self, $class; |
| 186 |
|
| 187 |
$self->{version} = '1.0'; |
| 188 |
$options{options}->add_options(arguments => { |
| 189 |
}); |
| 190 |
|
| 191 |
return $self; |
| 192 |
} |
| 193 |
|
| 194 |
sub manage_selection { |
| 195 |
my ($self, %options) = @_; |
| 196 |
|
| 197 |
$self->{cache_name} = 'cces_' . $options{custom}->{hostname} . '_' . $self->{mode} . '_' . |
| 198 |
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); |
| 199 |
|
| 200 |
my $result = $options{custom}->request_api(url_path => '/status.xml', ForceArray => ['Call']); |
| 201 |
foreach (('data~incoming', 'video~incoming~main', 'video~outgoing~main', |
| 202 |
'video~outgoing~presentation', 'video~incoming~presentation', |
| 203 |
'audio~incoming~main', 'audio~outgoing~main')) { |
| 204 |
$self->{channels}->{$_} = { display => $_ }; |
| 205 |
} |
| 206 |
|
| 207 |
if (!defined($result->{version}) || $result->{version} !~ /^(?:CE|TC)(\d+\.\d+)/i) { |
| 208 |
$self->{output}->add_option_msg(short_msg => 'cannot find firmware version'); |
| 209 |
$self->{output}->option_exit(); |
| 210 |
} |
| 211 |
my ($version_major, $version_minor) = split(/\./, $1); |
| 212 |
if (($version_major < 8) || ($version_major == 8 && $version_minor < 3)) { |
| 213 |
$self->{output}->add_option_msg(short_msg => 'firmware version is too old (' . $version_major . '.' . $version_minor . ')'); |
| 214 |
$self->{output}->option_exit(); |
| 215 |
} |
| 216 |
|
| 217 |
return if (!defined($result->{MediaChannels}->{Call})); |
| 218 |
|
| 219 |
foreach my $call (@{$result->{MediaChannels}->{Call}}) { |
| 220 |
foreach (@{$call->{Channel}}) { |
| 221 |
my $instance = lc($_->{Type}) . '~' . lc($_->{Direction}); |
| 222 |
$instance .= '~' . lc($_->{Audio}->{ChannelRole}) if (defined($_->{Audio})); |
| 223 |
$instance .= '~' . lc($_->{Video}->{ChannelRole}) if (defined($_->{Video})); |
| 224 |
|
| 225 |
$self->{channels}->{$instance}->{$_->{item} . '_bytes'} = defined($_->{Netstat}->{Bytes}) ? $_->{Netstat}->{Bytes} : 0; |
| 226 |
$self->{channels}->{$instance}->{$_->{item} . '_maxjitter'} = $_->{Netstat}->{MaxJitter} if (defined($_->{Netstat}->{MaxJitter})); |
| 227 |
$self->{channels}->{$instance}->{$_->{item} . '_loss'} = defined($_->{Netstat}->{Loss}) ? $_->{Netstat}->{Loss} : 0; |
| 228 |
$self->{channels}->{$instance}->{$_->{item} . '_packets'} = defined($_->{Netstat}->{Packets}) ? $_->{Netstat}->{Packets} : 0; |
| 229 |
} |
| 230 |
} |
| 231 |
} |
| 232 |
|
| 233 |
1; |
| 234 |
|
| 235 |
__END__ |
| 236 |
|
| 237 |
=head1 MODE |
| 238 |
|
| 239 |
Check call channels in real-time (since CE 8.3) |
| 240 |
|
| 241 |
=over 8 |
| 242 |
|
| 243 |
=item B<--warning-*> B<--critical-*> |
| 244 |
|
| 245 |
Thresholds. |
| 246 |
Can be: 'channels-traffic', 'channels-maxjitter' |
| 247 |
'channels-packetloss', 'channels-packetloss-prct'. |
| 248 |
|
| 249 |
=back |
| 250 |
|
| 251 |
=cut |