| 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::callssummary; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::templates::counter); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
use centreon::plugins::statefile; |
| 28 |
use Digest::MD5 qw(md5_hex); |
| 29 |
|
| 30 |
sub custom_loss_output { |
| 31 |
my ($self, %options) = @_; |
| 32 |
|
| 33 |
return sprintf( |
| 34 |
"packets loss: %.2f%% (%s on %s)", |
| 35 |
$self->{result_values}->{loss_prct}, |
| 36 |
$self->{result_values}->{loss}, |
| 37 |
$self->{result_values}->{pkts} |
| 38 |
); |
| 39 |
} |
| 40 |
|
| 41 |
sub prefix_global_output { |
| 42 |
my ($self, %options) = @_; |
| 43 |
|
| 44 |
return $options{instance_value}->{label} . ' '; |
| 45 |
} |
| 46 |
|
| 47 |
sub set_counters { |
| 48 |
my ($self, %options) = @_; |
| 49 |
|
| 50 |
$self->{maps_counters_type} = [ |
| 51 |
{ name => 'global', type => 0, skipped_code => { -10 => 1 } }, |
| 52 |
{ name => 'global_roomanalytics', type => 0, skipped_code => { -10 => 1 } }, |
| 53 |
{ name => 'global_video_incoming', cb_prefix_output => 'prefix_global_output', type => 0, skipped_code => { -10 => 1 } }, |
| 54 |
{ name => 'global_video_outgoing', cb_prefix_output => 'prefix_global_output', type => 0, skipped_code => { -10 => 1 } }, |
| 55 |
{ name => 'global_audio_incoming', cb_prefix_output => 'prefix_global_output', type => 0, skipped_code => { -10 => 1 } }, |
| 56 |
{ name => 'global_audio_outgoing', cb_prefix_output => 'prefix_global_output', type => 0, skipped_code => { -10 => 1 } } |
| 57 |
]; |
| 58 |
|
| 59 |
$self->{maps_counters}->{global} = [ |
| 60 |
{ label => 'total-finished', nlabel => 'calls.total.finished.count', set => { |
| 61 |
key_values => [ { name => 'new_calls' } ], |
| 62 |
output_template => 'total calls finished: %d', |
| 63 |
perfdatas => [ |
| 64 |
{ template => '%d', min => 0 } |
| 65 |
] |
| 66 |
} |
| 67 |
} |
| 68 |
]; |
| 69 |
|
| 70 |
$self->{maps_counters}->{'global_roomanalytics'} = [ |
| 71 |
{ label => 'peoplecount', nlabel => 'calls.roomanalytics.people.count', set => { |
| 72 |
key_values => [ { name => 'peoplecount' } ], |
| 73 |
output_template => 'people count: %s', |
| 74 |
perfdatas => [ |
| 75 |
{ template => '%d', min => 0 } |
| 76 |
] |
| 77 |
} |
| 78 |
} |
| 79 |
]; |
| 80 |
|
| 81 |
foreach my $type (('video', 'audio')) { |
| 82 |
foreach my $direction (('incoming', 'outgoing')) { |
| 83 |
$self->{maps_counters}->{'global_' . $type . '_' . $direction} = [ |
| 84 |
{ label => 'packetloss', nlabel => 'calls.' . $type . '.' . $direction . '.packetloss.count', set => { |
| 85 |
key_values => [ { name => 'loss' }, { name => 'pkts' }, { name => 'loss_prct' } ], |
| 86 |
closure_custom_output => $self->can('custom_loss_output'), |
| 87 |
perfdatas => [ |
| 88 |
{ template => '%d', min => 0 } |
| 89 |
] |
| 90 |
} |
| 91 |
}, |
| 92 |
{ label => 'packetloss-prct', nlabel => 'calls.' . $type . '.' . $direction . '.packetloss.percentage', display_ok => 0, set => { |
| 93 |
key_values => [ { name => 'loss_prct' }, { name => 'loss' }, { name => 'pkts' } ], |
| 94 |
closure_custom_output => $self->can('custom_loss_output'), |
| 95 |
perfdatas => [ |
| 96 |
{ template => '%d', unit => '%', min => 0, max => 100 } |
| 97 |
] |
| 98 |
} |
| 99 |
}, |
| 100 |
{ label => 'maxjitter', nlabel => 'calls.' . $type . '.' . $direction . '.maxjitter.count', set => { |
| 101 |
key_values => [ { name => 'maxjitter' } ], |
| 102 |
output_template => 'max jitter: %s ms', |
| 103 |
perfdatas => [ |
| 104 |
{ template => '%d', unit => 'ms', min => 0 } |
| 105 |
] |
| 106 |
} |
| 107 |
} |
| 108 |
]; |
| 109 |
} |
| 110 |
} |
| 111 |
} |
| 112 |
|
| 113 |
sub new { |
| 114 |
my ($class, %options) = @_; |
| 115 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); |
| 116 |
bless $self, $class; |
| 117 |
|
| 118 |
$self->{version} = '1.0'; |
| 119 |
$options{options}->add_options(arguments => { |
| 120 |
}); |
| 121 |
|
| 122 |
centreon::plugins::misc::mymodule_load( |
| 123 |
output => $self->{output}, |
| 124 |
module => 'Date::Parse', |
| 125 |
error_msg => "Cannot load module 'Date::Parse'." |
| 126 |
); |
| 127 |
$self->{statefile_cache} = centreon::plugins::statefile->new(%options); |
| 128 |
return $self; |
| 129 |
} |
| 130 |
|
| 131 |
sub check_options { |
| 132 |
my ($self, %options) = @_; |
| 133 |
$self->SUPER::check_options(%options); |
| 134 |
|
| 135 |
$self->{statefile_cache}->check_options(%options); |
| 136 |
} |
| 137 |
|
| 138 |
sub manage_selection { |
| 139 |
my ($self, %options) = @_; |
| 140 |
|
| 141 |
$self->{statefile_cache}->read( |
| 142 |
statefile => 'cces_' . $options{custom}->{hostname} . '_' . $self->{mode} . '_' . |
| 143 |
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) |
| 144 |
); |
| 145 |
my $last_call_endtime = $self->{statefile_cache}->get(name => 'last_call_endtime'); |
| 146 |
$last_call_endtime = 0 if (!defined($last_call_endtime)); |
| 147 |
|
| 148 |
my $result = $options{custom}->request_api( |
| 149 |
method => 'POST', |
| 150 |
url_path => '/putxml', |
| 151 |
query_form_post => '<Command><CallHistory><Get><DetailLevel>Full</DetailLevel></Get></CallHistory></Command>', |
| 152 |
ForceArray => ['Entry'] |
| 153 |
); |
| 154 |
|
| 155 |
$self->{global} = { new_calls => 0 }; |
| 156 |
$self->{global_video_incoming} = { loss => 0, pkts => 0, loss_prct => 0, maxjitter => 0, label => 'video incoming' }; |
| 157 |
$self->{global_video_outgoing} = { loss => 0, pkts => 0, loss_prct => 0, maxjitter => 0, label => 'video outgoing' }; |
| 158 |
$self->{global_audio_incoming} = { loss => 0, pkts => 0, loss_prct => 0, maxjitter => 0, label => 'audio incoming' }; |
| 159 |
$self->{global_audio_outgoing} = { loss => 0, pkts => 0, loss_prct => 0, maxjitter => 0, label => 'audio outgoing' }; |
| 160 |
$self->{global_roomanalytics} = {}; |
| 161 |
|
| 162 |
return if (!defined($result->{CallHistoryGetResult}->{Entry})); |
| 163 |
|
| 164 |
my $save_last_time = 0; |
| 165 |
foreach (@{$result->{CallHistoryGetResult}->{Entry}}) { |
| 166 |
my $end_time_utc = ref($_->{EndTimeUTC}) eq 'HASH' ? $_->{EndTimeUTC}->{content} : $_->{EndTimeUTC}; |
| 167 |
my $end_time = Date::Parse::str2time($end_time_utc); |
| 168 |
if (!defined($end_time)) { |
| 169 |
$self->{output}->output_add( |
| 170 |
severity => 'UNKNOWN', |
| 171 |
short_msg => "can't parse date '" . $end_time_utc . "'" |
| 172 |
); |
| 173 |
next; |
| 174 |
} |
| 175 |
$save_last_time = $end_time if ($save_last_time < $end_time); |
| 176 |
next if ($end_time <= $last_call_endtime); |
| 177 |
|
| 178 |
$self->{global}->{new_calls}++; |
| 179 |
foreach my $type (('Video', 'Audio')) { |
| 180 |
foreach my $direction (('Incoming', 'Outgoing')) { |
| 181 |
my $max_jitter = ref($_->{$type}->{$direction}->{MaxJitter}) eq 'HASH' ? $_->{$type}->{$direction}->{MaxJitter}->{content} : $_->{$type}->{$direction}->{MaxJitter}; |
| 182 |
my $packet_loss = ref($_->{$type}->{$direction}->{PacketLoss}) eq 'HASH' ? $_->{$type}->{$direction}->{PacketLoss}->{content} : $_->{$type}->{$direction}->{PacketLoss}; |
| 183 |
$self->{'global_' . lc($type) . '_' . lc($direction)}->{maxjitter} = $max_jitter |
| 184 |
if ($self->{'global_' . lc($type) . '_' . lc($direction)}->{maxjitter} < $max_jitter); |
| 185 |
if ($packet_loss =~ /^(\d+)\/(\d+)/) { |
| 186 |
$self->{'global_' . lc($type) . '_' . lc($direction)}->{loss} += $1; |
| 187 |
$self->{'global_' . lc($type) . '_' . lc($direction)}->{pkts} += $2; |
| 188 |
} |
| 189 |
} |
| 190 |
} |
| 191 |
if (defined($_->{RoomAnalytics}->{PeopleCount})) { |
| 192 |
$self->{global_roomanalytics}->{peoplecount} = $_->{RoomAnalytics}->{PeopleCount}; |
| 193 |
if ($_->{RoomAnalytics}->{PeopleCount} =~ /^N\/A$/) { |
| 194 |
$self->{global_roomanalytics}->{peoplecount} = 0; |
| 195 |
} |
| 196 |
} |
| 197 |
} |
| 198 |
|
| 199 |
foreach my $type (('video', 'audio')) { |
| 200 |
foreach my $direction (('incoming', 'outgoing')) { |
| 201 |
$self->{'global_' . $type . '_' . $direction}->{loss_prct} = $self->{'global_' . $type . '_' . $direction}->{loss} * 100 / $self->{'global_' . $type . '_' . $direction}->{pkts} |
| 202 |
if ($self->{'global_' . $type . '_' . $direction}->{pkts} > 0); |
| 203 |
} |
| 204 |
} |
| 205 |
|
| 206 |
$self->{statefile_cache}->write(data => { last_call_endtime => $save_last_time }); |
| 207 |
} |
| 208 |
|
| 209 |
1; |
| 210 |
|
| 211 |
__END__ |
| 212 |
|
| 213 |
=head1 MODE |
| 214 |
|
| 215 |
Check call history (since TC 6.3) |
| 216 |
|
| 217 |
=over 8 |
| 218 |
|
| 219 |
=item B<--warning-*> B<--critical-*> |
| 220 |
|
| 221 |
Thresholds. |
| 222 |
Can be: 'total-finished', 'packetloss' |
| 223 |
'packetloss-prct', 'maxjitter'. |
| 224 |
|
| 225 |
=back |
| 226 |
|
| 227 |
=cut |