| 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::cts::snmp::mode::calls; |
| 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_$options{extra_options}->{label_ref}/) { |
| 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_$options{extra_options}->{label_ref}/) { |
| 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}->{label} = $options{extra_options}->{label_ref}; |
| 95 |
$self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; |
| 96 |
$self->{result_values}->{packets_loss} = $total_loss; |
| 97 |
$self->{result_values}->{packets_loss_prct} = 0; |
| 98 |
$self->{result_values}->{packets} = $total_pkts; |
| 99 |
if ($total_pkts > 0) { |
| 100 |
$self->{result_values}->{packets_loss_prct} = ($total_loss * 100) / $total_pkts; |
| 101 |
} |
| 102 |
|
| 103 |
return 0; |
| 104 |
} |
| 105 |
|
| 106 |
sub custom_loss_output { |
| 107 |
my ($self, %options) = @_; |
| 108 |
|
| 109 |
return sprintf( |
| 110 |
"packets %s loss: %.2f%% (%s on %s)", |
| 111 |
$self->{result_values}->{label}, |
| 112 |
$self->{result_values}->{packets_loss_prct}, |
| 113 |
$self->{result_values}->{packets_loss}, |
| 114 |
$self->{result_values}->{packets} |
| 115 |
); |
| 116 |
} |
| 117 |
|
| 118 |
sub prefix_global_output { |
| 119 |
my ($self, %options) = @_; |
| 120 |
|
| 121 |
return 'Calls '; |
| 122 |
} |
| 123 |
|
| 124 |
sub set_counters { |
| 125 |
my ($self, %options) = @_; |
| 126 |
|
| 127 |
$self->{maps_counters_type} = [ |
| 128 |
{ name => 'global', type => 0, cb_prefix_output => 'prefix_global_output' }, |
| 129 |
{ name => 'streams_active', type => 1, cb_prefix_output => 'prefix_stream_active_output', message_multiple => 'All active call streams are ok', skipped_code => { -10 => 1 } } |
| 130 |
]; |
| 131 |
|
| 132 |
$self->{maps_counters}->{global} = [ |
| 133 |
{ label => 'dummy', threshold => 0, display_ok => 0, set => { |
| 134 |
key_values => [ { name => 'calls_instance_finished' } ], |
| 135 |
output_template => 'none', |
| 136 |
perfdatas => [] |
| 137 |
} |
| 138 |
}, |
| 139 |
{ label => 'active', nlabel => 'calls.active.count', set => { |
| 140 |
key_values => [ { name => 'active' } ], |
| 141 |
output_template => 'active: %s', |
| 142 |
perfdatas => [ |
| 143 |
{ template => '%s', min => 0 } |
| 144 |
] |
| 145 |
} |
| 146 |
}, |
| 147 |
{ label => 'total', nlabel => 'calls.total.count', display_ok => 0, set => { |
| 148 |
key_values => [ { name => 'total' } ], |
| 149 |
output_template => 'total: %s', |
| 150 |
perfdatas => [ |
| 151 |
{ template => '%s', min => 0 } |
| 152 |
] |
| 153 |
} |
| 154 |
} |
| 155 |
]; |
| 156 |
|
| 157 |
my @map = ( |
| 158 |
['total-unknown', 'unknown: %s', 'unknown'], |
| 159 |
['total-other', 'other: %s', 'other'], |
| 160 |
['total-internal-error', 'internal error: %s', 'internal.error'], |
| 161 |
['total-local-disconnected', 'local disconnected: %s', 'local.disconnected'], |
| 162 |
['total-remote-disconnected', 'remote disconnected: %s', 'remote.disconnected'], |
| 163 |
['total-network-congestion', 'network congestion: %s', 'network.congestion'], |
| 164 |
['total-media-negotiation-failure', 'media negotiation failure: %s', 'media.negotiation.failure'], |
| 165 |
['total-security-config-mismatched', 'security config mismatched: %s', 'security.config.mismatched'], |
| 166 |
['total-incompatible-remote-endpoint', 'incompatible remote endpoint: %s', 'incompatible.remote.endpoint'], |
| 167 |
['total-service-unavailable', 'service unaivalable: %s', 'service.unavailable'], |
| 168 |
['total-remote-terminated-error', 'remote terminated with error: %s', 'remote.terminated.error'] |
| 169 |
); |
| 170 |
foreach (@map) { |
| 171 |
push @{$self->{maps_counters}->{global}}, { label => $_->[0], nlabel => 'calls.total.' . $_->[2] . '.count', display_ok => 0, set => { |
| 172 |
key_values => [ { name => $_->[2] } ], |
| 173 |
output_template => $_->[1], |
| 174 |
perfdatas => [ |
| 175 |
{ template => '%s', min => 0 } |
| 176 |
] |
| 177 |
} |
| 178 |
}; |
| 179 |
} |
| 180 |
|
| 181 |
$self->{maps_counters}->{streams_active} = [ |
| 182 |
{ label => 'streams-active-maxjitter', nlabel => 'calls.streams.active.maxjitter.milliseconds', set => { |
| 183 |
key_values => [], |
| 184 |
manual_keys => 1, |
| 185 |
closure_custom_calc => $self->can('custom_jitter_calc'), |
| 186 |
output_template => 'max jitter: %s ms', |
| 187 |
output_use => 'max_jitter', threshold_use => 'max_jitter', |
| 188 |
perfdatas => [ |
| 189 |
{ value => 'max_jitter', template => '%d', |
| 190 |
unit => 'ms', min => 0, label_extra_instance => 1, instance_use => 'display' } |
| 191 |
] |
| 192 |
} |
| 193 |
} |
| 194 |
]; |
| 195 |
|
| 196 |
foreach (('in', 'out')) { |
| 197 |
push @{$self->{maps_counters}->{streams_active}}, |
| 198 |
{ label => 'streams-active-traffic-' . $_, nlabel => 'calls.streams.active.traffic.' . $_ . '.bytes', set => { |
| 199 |
key_values => [], |
| 200 |
manual_keys => 1, |
| 201 |
closure_custom_calc => $self->can('custom_traffic_calc'), closure_custom_calc_extra_options => { label_ref => $_ }, |
| 202 |
output_template => 'traffic ' . $_ . ': %s %s/s', |
| 203 |
output_change_bytes => 1, |
| 204 |
output_use => 'traffic_per_seconds', threshold_use => 'traffic_per_seconds', |
| 205 |
perfdatas => [ |
| 206 |
{ value => 'traffic_per_seconds', template => '%d', |
| 207 |
unit => 'B/s', min => 0, label_extra_instance => 1, instance_use => 'display' } |
| 208 |
] |
| 209 |
} |
| 210 |
}, |
| 211 |
{ label => 'streams-active-packetloss-' . $_, nlabel => 'calls.streams.active.packetloss.' . $_ . '.count', set => { |
| 212 |
key_values => [], |
| 213 |
manual_keys => 1, |
| 214 |
closure_custom_calc => $self->can('custom_loss_calc'), closure_custom_calc_extra_options => { label_ref => $_ }, |
| 215 |
closure_custom_output => $self->can('custom_loss_output'), |
| 216 |
threshold_use => 'packets_loss', |
| 217 |
perfdatas => [ |
| 218 |
{ value => 'packets_loss', template => '%d', |
| 219 |
min => 0, label_extra_instance => 1, instance_use => 'display' } |
| 220 |
] |
| 221 |
} |
| 222 |
}, |
| 223 |
{ label => 'streams-active-packetloss-' . $_ . '-prct', nlabel => 'calls.streams.active.packetloss.' . $_ . '.percentage', display_ok => 0, set => { |
| 224 |
key_values => [], |
| 225 |
manual_keys => 1, |
| 226 |
closure_custom_calc => $self->can('custom_loss_calc'), closure_custom_calc_extra_options => { label_ref => $_ }, |
| 227 |
closure_custom_output => $self->can('custom_loss_output'), |
| 228 |
threshold_use => 'packets_loss_prct', |
| 229 |
perfdatas => [ |
| 230 |
{ value => 'packets_loss_prct', template => '%.2f', |
| 231 |
unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' } |
| 232 |
] |
| 233 |
} |
| 234 |
}; |
| 235 |
} |
| 236 |
} |
| 237 |
|
| 238 |
sub prefix_stream_active_output { |
| 239 |
my ($self, %options) = @_; |
| 240 |
|
| 241 |
return "Stream '" . $options{instance_value}->{display} . "' "; |
| 242 |
} |
| 243 |
|
| 244 |
sub new { |
| 245 |
my ($class, %options) = @_; |
| 246 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1, statefile => 1); |
| 247 |
bless $self, $class; |
| 248 |
|
| 249 |
$self->{version} = '1.0'; |
| 250 |
$options{options}->add_options(arguments => { |
| 251 |
}); |
| 252 |
|
| 253 |
return $self; |
| 254 |
} |
| 255 |
|
| 256 |
my $map_term_reason = { |
| 257 |
1 => 'unknown', 2 => 'other', 3 => 'internal.error', |
| 258 |
4 => 'local.disconnected', 5 => 'remote.disconnected', |
| 259 |
6 => 'network.congestion', 7 => 'media.negotiation.failure', |
| 260 |
8 => 'security.config.mismatched', 9 => 'incompatible.remote.endpoint', |
| 261 |
10 => 'service.unavailable', 11 => 'remote.terminated.error', |
| 262 |
12 => 'incall' |
| 263 |
}; |
| 264 |
my $map_stream_type = { |
| 265 |
1 => 'video', 2 => 'audio', 3 => 'content' |
| 266 |
}; |
| 267 |
my $oid_ctpcCallTermReason = '.1.3.6.1.4.1.9.9.644.1.4.8.1.17'; |
| 268 |
|
| 269 |
my $mapping = { |
| 270 |
traffic_out => { oid => '.1.3.6.1.4.1.9.9.644.1.4.10.1.3' }, # ctpcTxTotalBytes |
| 271 |
packets_out => { oid => '.1.3.6.1.4.1.9.9.644.1.4.10.1.4' }, # ctpcTxTotalPackets |
| 272 |
packets_lost_out => { oid => '.1.3.6.1.4.1.9.9.644.1.4.10.1.5' }, # ctpcTxLostPackets |
| 273 |
traffic_in => { oid => '.1.3.6.1.4.1.9.9.644.1.4.10.1.11' }, # ctpcRxTotalBytes |
| 274 |
packets_in => { oid => '.1.3.6.1.4.1.9.9.644.1.4.10.1.12' }, # ctpcRxTotalPackets |
| 275 |
packets_lost_in => { oid => '.1.3.6.1.4.1.9.9.644.1.4.10.1.13' }, # ctpcRxLostPackets |
| 276 |
maxjitter => { oid => '.1.3.6.1.4.1.9.9.644.1.4.10.1.25' }, # ctpcMaxCallJitter |
| 277 |
}; |
| 278 |
|
| 279 |
sub manage_selection { |
| 280 |
my ($self, %options) = @_; |
| 281 |
|
| 282 |
$self->{cache_name} = 'cisco_cts_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' . |
| 283 |
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); |
| 284 |
my $calls_instance_finished = $self->read_statefile_key(key => 'global_calls_instance_finished'); |
| 285 |
$calls_instance_finished = {} if (!defined($calls_instance_finished)); |
| 286 |
my $calls_instance_finished_new = {}; |
| 287 |
|
| 288 |
my $active_calls = {}; |
| 289 |
$self->{global} = { active => 0, total => 0 }; |
| 290 |
foreach (values %$map_term_reason) { |
| 291 |
$self->{global}->{$_} = 0; |
| 292 |
} |
| 293 |
|
| 294 |
my $snmp_result = $options{snmp}->get_table( |
| 295 |
oid => $oid_ctpcCallTermReason |
| 296 |
); |
| 297 |
foreach (keys %$snmp_result) { |
| 298 |
/^$oid_ctpcCallTermReason\.(\d+)/; |
| 299 |
my $instance = $1; |
| 300 |
if ($map_term_reason->{ $snmp_result->{$_} } eq 'incall') { |
| 301 |
$active_calls->{$instance} = 1; |
| 302 |
$self->{global}->{active}++; |
| 303 |
} else { |
| 304 |
$calls_instance_finished_new->{$instance} = 1; |
| 305 |
next if (defined($calls_instance_finished->{$instance})); |
| 306 |
$self->{global}->{total}++; |
| 307 |
$self->{global}->{ $map_term_reason->{ $snmp_result->{$_} } }++; |
| 308 |
} |
| 309 |
} |
| 310 |
|
| 311 |
$snmp_result = $options{snmp}->get_multiple_table( |
| 312 |
oids => [ |
| 313 |
map({ oid => $_->{oid} }, values(%$mapping)) |
| 314 |
], |
| 315 |
return_type => 1 |
| 316 |
); |
| 317 |
|
| 318 |
$self->{streams_active} = {}; |
| 319 |
foreach (('audio', 'video', 'content')) { |
| 320 |
$self->{streams_active}->{$_} = { display => $_ }; |
| 321 |
} |
| 322 |
|
| 323 |
foreach my $oid (keys %$snmp_result) { |
| 324 |
next if ($oid !~ /^$mapping->{traffic_out}->{oid}\.(\d+)\.(\d+)\.(\d+)/); |
| 325 |
my ($index, $type, $source) = ($1, $2, $3); |
| 326 |
my $instance = $index . '.' . $type . '.' . $source; |
| 327 |
|
| 328 |
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); |
| 329 |
my $stream_type = $map_stream_type->{$type}; |
| 330 |
if (defined($active_calls->{$index})) { |
| 331 |
$self->{streams_active}->{$stream_type}->{$instance . '_traffic_in'} = defined($result->{traffic_in}) ? $result->{traffic_in} : 0; |
| 332 |
$self->{streams_active}->{$stream_type}->{$instance . '_traffic_out'} = defined($result->{traffic_out}) ? $result->{traffic_out} : 0; |
| 333 |
$self->{streams_active}->{$stream_type}->{$instance . '_loss_in'} = defined($result->{packets_lost_in}) ? $result->{packets_lost_in} : 0; |
| 334 |
$self->{streams_active}->{$stream_type}->{$instance . '_packets_in'} = defined($result->{packets_in}) ? $result->{packets_in} : 0; |
| 335 |
$self->{streams_active}->{$stream_type}->{$instance . '_loss_out'} = defined($result->{packets_lost_out}) ? $result->{packets_lost_out} : 0; |
| 336 |
$self->{streams_active}->{$stream_type}->{$instance . '_packets_out'} = defined($result->{packets_out}) ? $result->{packets_out} : 0; |
| 337 |
$self->{streams_active}->{$stream_type}->{$instance . '_maxjitter'} = defined($result->{maxjitter}) ? $result->{maxjitter} : 0; |
| 338 |
} |
| 339 |
} |
| 340 |
|
| 341 |
$self->{global}->{calls_instance_finished} = $calls_instance_finished_new; |
| 342 |
} |
| 343 |
|
| 344 |
1; |
| 345 |
|
| 346 |
__END__ |
| 347 |
|
| 348 |
=head1 MODE |
| 349 |
|
| 350 |
Check call stream (real-time and history) |
| 351 |
|
| 352 |
=over 8 |
| 353 |
|
| 354 |
=item B<--warning-*> B<--critical-*> |
| 355 |
|
| 356 |
Thresholds. |
| 357 |
Can be: 'active', 'total', 'total-unknown', |
| 358 |
'total-other', 'total-internal-error', 'total-local-disconnected', 'total-remote-disconnected', |
| 359 |
'total-network-congestion', 'total-media-negotiation-failure', 'total-security-config-mismatched', |
| 360 |
'total-incompatible-remote-endpoint', 'total-service-unavailable', 'total-remote-terminated-error', |
| 361 |
'streams-active-maxjitter', |
| 362 |
'streams-active-traffic-in', 'streams-active-packetloss-in', 'streams-active-packetloss-in-prct', |
| 363 |
'streams-active-traffic-out', 'streams-active-packetloss-out', 'streams-active-packetloss-out-prct'. |
| 364 |
|
| 365 |
=back |
| 366 |
|
| 367 |
=cut |