polycom trio done + some fixes

This commit is contained in:
garnier-quentin 2020-01-29 11:01:00 +01:00
parent 4b98474a79
commit 55b457332c
15 changed files with 463 additions and 15 deletions

View File

@ -246,7 +246,7 @@ sub manage_selection {
foreach (keys %{$response->{data}->{$datacenter_id}->{alarms}}) {
my $create_time = Date::Parse::str2time($response->{data}->{$datacenter_id}->{alarms}->{$_}->{time});
if (!defined($create_time)) {
$self->{manager}->{output}->output_add(severity => 'UNKNOWN',
$self->{output}->output_add(severity => 'UNKNOWN',
short_msg => "Can't Parse date '" . $response->{data}->{$datacenter_id}->{alarms}->{$_}->{time} . "'");
next;
}

View File

@ -247,7 +247,7 @@ sub manage_selection {
foreach (keys %{$response->{data}->{$esxhost_id}->{alarms}}) {
my $create_time = Date::Parse::str2time($response->{data}->{$esxhost_id}->{alarms}->{$_}->{time});
if (!defined($create_time)) {
$self->{manager}->{output}->output_add(severity => 'UNKNOWN',
$self->{output}->output_add(severity => 'UNKNOWN',
short_msg => "Can't Parse date '" . $response->{data}->{$esxhost_id}->{alarms}->{$_}->{time} . "'");
next;
}

View File

@ -121,7 +121,7 @@ sub manage_selection {
foreach my $alarm (@{$alarm_results}) {
my $create_time = Date::Parse::str2time($alarm->{StateUpdatedTimestamp});
if (!defined($create_time)) {
$self->{manager}->{output}->output_add(
$self->{output}->output_add(
severity => 'UNKNOWN',
short_msg => "Can't Parse date '" . $alarm->{StateUpdatedTimestamp} . "'"
);

View File

@ -152,7 +152,7 @@ sub manage_selection {
foreach (@{$result->{CallHistoryGetResult}->{Entry}}) {
my $end_time = Date::Parse::str2time($_->{EndTimeUTC});
if (!defined($end_time)) {
$self->{manager}->{output}->output_add(
$self->{output}->output_add(
severity => 'UNKNOWN',
short_msg => "can't parse date '" . $_->{EndTimeUTC} . "'"
);

View File

@ -148,7 +148,6 @@ sub settings {
sub request_api {
my ($self, %options) = @_;
=for comment
my $tutu = do {
local $/ = undef;
if (!open my $fh, "<", '/tmp/plop.txt') {
@ -166,7 +165,6 @@ sub request_api {
$self->{output}->option_exit();
}
return $tutu2;
=cut
$self->settings();
my ($fh, $content);

View File

@ -142,6 +142,10 @@ sub manage_selection {
my $result = $options{custom}->request_api(url_path => '/api/v1/mgmt/media/sessionStats');
$self->{channels} = {};
if (!defined($result->{data}) || ref($result->{data}) ne 'ARRAY') {
$self->{output}->add_option_msg(short_msg => "cannot find session information.");
$self->{output}->option_exit();
}
if (!defined($result->{data}->[0]->{Streams})) {
$self->{output}->output_add(
severity => 'OK',

View File

@ -0,0 +1,161 @@
#
# Copyright 2020 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package hardware::devices::polycom::trio::restapi::mode::callssummary;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::statefile;
use Digest::MD5 qw(md5_hex);
sub prefix_global_output {
my ($self, %options) = @_;
return 'total calls ';
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', type => 0, cb_prefix_output => 'prefix_global_output', skipped_code => { -10 => 1 } },
];
$self->{maps_counters}->{global} = [
{ label => 'total', nlabel => 'calls.total.count', display_ok => 0, set => {
key_values => [ { name => 'total' } ],
output_template => 'total: d',
perfdatas => [
{ value => 'total_absolute', template => '%d', min => 0 },
],
}
},
{ label => 'placed', nlabel => 'calls.placed.count', set => {
key_values => [ { name => 'placed' } ],
output_template => 'placed: %d',
perfdatas => [
{ value => 'placed_absolute', template => '%d', min => 0 },
],
}
},
{ label => 'missed', nlabel => 'calls.missed.count', set => {
key_values => [ { name => 'missed' } ],
output_template => 'missed: %d',
perfdatas => [
{ value => 'missed_absolute', template => '%d', min => 0 },
],
}
},
{ label => 'received', nlabel => 'calls.received.count', set => {
key_values => [ { name => 'received' } ],
output_template => 'received: %d',
perfdatas => [
{ value => 'received_absolute', template => '%d', min => 0 },
],
}
},
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments => {
});
centreon::plugins::misc::mymodule_load(
output => $self->{output},
module => 'Date::Parse',
error_msg => "Cannot load module 'Date::Parse'."
);
$self->{statefile_cache} = centreon::plugins::statefile->new(%options);
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$self->{statefile_cache}->check_options(%options);
}
sub manage_selection {
my ($self, %options) = @_;
$self->{statefile_cache}->read(
statefile => 'polycom_trio_' . $options{custom}->{hostname} . '_' . $self->{mode} . '_' .
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'))
);
my $last_times = $self->{statefile_cache}->get(name => 'last_times');
$last_times = { placed => 0, missed => 0, received => 0 } if (!defined($last_times));
my $result = $options{custom}->request_api(url_path => '/api/v1/mgmt/callLogs');
if (!defined($result->{data}->{Placed})) {
$self->{output}->add_option_msg(short_msg => "cannot find callLogs information.");
$self->{output}->option_exit();
}
$self->{global} = { total => 0, placed => 0, missed => 0, received => 0 };
my $new_last_times = { placed => 0, missed => 0, received => 0 };
foreach (('placed', 'missed', 'received')) {
foreach my $entry (@{$result->{data}->{ucfirst($_)}}) {
my $start_time = Date::Parse::str2time($entry->{StartTime});
if (!defined($start_time)) {
$self->{output}->output_add(
severity => 'UNKNOWN',
short_msg => "can't parse date '" . $entry->{StartTime} . "'"
);
next;
}
$new_last_times->{$_} = $start_time if ($new_last_times->{$_} < $start_time);
next if ($start_time <= $last_times->{$_});
$self->{global}->{total}++;
$self->{global}->{$_}++;
}
}
$self->{statefile_cache}->write(data => { last_times => $new_last_times });
}
1;
__END__
=head1 MODE
Check call history.
=over 8
=item B<--warning-*> B<--critical-*>
Thresholds.
Can be: 'total', 'placed', 'missed', 'received'.
=back
=cut

View File

@ -0,0 +1,178 @@
#
# Copyright 2020 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package hardware::devices::polycom::trio::restapi::mode::device;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc);
sub custom_status_output {
my ($self, %options) = @_;
return "status is '" . $self->{result_values}->{status} . "'";
}
sub custom_memory_output {
my ($self, %options) = @_;
return sprintf(
"memory total: %s %s used: %s %s (%.2f%%) free: %s %s (%.2f%%)",
$self->{perfdata}->change_bytes(value => $self->{result_values}->{total_absolute}),
$self->{perfdata}->change_bytes(value => $self->{result_values}->{used_absolute}),
$self->{result_values}->{prct_used_absolute},
$self->{perfdata}->change_bytes(value => $self->{result_values}->{free_absolute}),
$self->{result_values}->{prct_free_absolute}
);
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', type => 0, skipped_code => { -10 => 1 } },
];
$self->{maps_counters}->{global} = [
{ label => 'status', threshold => 0, set => {
key_values => [ { name => 'status' } ],
closure_custom_calc => \&catalog_status_calc,
closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold,
}
},
{ label => 'cpu-utilization-average', nlabel => 'device.cpu.utilization.average.percentage', set => {
key_values => [ { name => 'cpu_average' } ],
output_template => 'cpu average: %.2f%%',
perfdatas => [
{ value => 'cpu_average_absolute', template => '%.2f',
min => 0, max => 100, unit => '%' },
],
}
},
{ label => 'memory-usage', nlabel => 'device.memory.usage.bytes', set => {
key_values => [ { name => 'used' }, { name => 'free' }, { name => 'prct_used' },
{ name => 'prct_free' }, { name => 'total' } ],
closure_custom_output => $self->can('custom_memory_output'),
perfdatas => [
{ value => 'used_absolute', template => '%d', min => 0, max => 'total_absolute',
unit => 'B', cast_int => 1 },
],
}
},
{ label => 'memory-usage-free', display_ok => 0, nlabel => 'device.memory.free.bytes', set => {
key_values => [ { name => 'free' }, { name => 'used' }, { name => 'prct_used' },
{ name => 'prct_free' }, { name => 'total' } ],
closure_custom_output => $self->can('custom_memory_output'),
perfdatas => [
{ value => 'free_absolute', template => '%d', min => 0, max => 'total_absolute',
unit => 'B', cast_int => 1 },
],
}
},
{ label => 'memory-usage-prct', display_ok => 0, nlabel => 'device.memory.usage.percentage', set => {
key_values => [ { name => 'prct_used' } ],
output_template => 'Memory Used: %.2f %%',
perfdatas => [
{ value => 'prct_used_absolute', template => '%.2f', min => 0, max => 100,
unit => '%' },
],
}
}
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
$self->{version} = '1.0';
$options{options}->add_options(arguments => {
'warning-status:s' => { name => 'warning_status', default => '' },
'critical-status:s' => { name => 'critical_status', default => '%{status} =~ /error/i' },
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$self->change_macros(macros => ['warning_status', 'critical_status']);
}
sub manage_selection {
my ($self, %options) = @_;
my $result = $options{custom}->request_api(url_path => '/api/v1/mgmt/device/stats');
if (!defined($result->{data}->{CPU})) {
$self->{output}->add_option_msg(short_msg => "cannot find device information.");
$self->{output}->option_exit();
}
my $used = $result->{data}->{Memory}->{Used} - $result->{data}->{Memory}->{SReclaim};
$self->{global} = {
cpu_average => $result->{data}->{CPU}->{Average},
total => $result->{data}->{Memory}->{Total},
free => $result->{data}->{Memory}->{Total} - $used,
used => $used,
prct_free => ($result->{data}->{Memory}->{Total} - $used) * 100 / $result->{data}->{Memory}->{Total},
prct_used => $used * 100 / $result->{data}->{Memory}->{Total}
};
$result = $options{custom}->request_api(url_path => '/api/v1/mgmt/pollForStatus');
return if (!defined($result->{data}->{State}));
$self->{global}->{status} = $result->{data}->{State};
}
1;
__END__
=head1 MODE
Check device cpu, memory and state.
=over 8
=item B<--warning-status>
Set warning threshold for status (Default: '').
Can used special variables like: %{status}
=item B<--critical-status>
Set critical threshold for status (Default: '%{status} =~ /error/i').
Can used special variables like: %{status}
=item B<--warning-*> B<--critical-*>
Thresholds.
Can be: 'cpu-utilization-average', 'memory-usage',
'memory-usage-free', 'memory-usage-prct'.
=back
=cut

View File

@ -0,0 +1,104 @@
#
# Copyright 2020 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package hardware::devices::polycom::trio::restapi::mode::network;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use Digest::MD5 qw(md5_hex);
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', type => 0 },
];
$self->{maps_counters}->{global} = [
{ label => 'packets-in', nlabel => 'network.packets.in.persecond', set => {
key_values => [ { name => 'packets_in', diff => 1 } ],
output_template => 'packets in: %.2f/s',
per_second => 1,
perfdatas => [
{ value => 'packets_in_per_second', template => '%.2f', min => 0, unit => '/s' },
],
}
},
{ label => 'packets-out', nlabel => 'network.packets.out.persecond', set => {
key_values => [ { name => 'packets_out', diff => 1 } ],
output_template => 'packets out: %.2f/s',
per_second => 1,
perfdatas => [
{ value => 'packets_out_per_second', template => '%.2f', min => 0, unit => '/s' },
],
}
}
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1, statefile => 1);
$self->{version} = '1.0';
$options{options}->add_options(arguments => {
});
return $self;
}
sub manage_selection {
my ($self, %options) = @_;
my $result = $options{custom}->request_api(url_path => '/api/v1/mgmt/network/stats');
if (!defined($result->{data}->{TxPackets})) {
$self->{output}->add_option_msg(short_msg => "cannot find network information.");
$self->{output}->option_exit();
}
$self->{global} = {
packets_in => $result->{data}->{RxPackets},
packets_out => $result->{data}->{TxPackets}
};
$self->{cache_name} = 'polycom_trio_' . $options{custom}->{hostname} . '_' . $self->{mode} . '_' .
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
}
1;
__END__
=head1 MODE
Check network traffic.
=over 8
=item B<--warning-*> B<--critical-*>
Thresholds.
Can be: 'packets-in', 'packets-out'.
=back
=cut

View File

@ -31,7 +31,10 @@ sub new {
$self->{version} = '1.0';
%{$self->{modes}} = (
'calls-rt' => 'hardware::devices::polycom::trio::restapi::mode::callsrt',
'calls-summary' => 'hardware::devices::polycom::trio::restapi::mode::callssummary',
'calls-rt' => 'hardware::devices::polycom::trio::restapi::mode::callsrt',
'device' => 'hardware::devices::polycom::trio::restapi::mode::device',
'network' => 'hardware::devices::polycom::trio::restapi::mode::network'
);
$self->{custom_modes}{api} = 'hardware::devices::polycom::trio::restapi::custom::api';

View File

@ -133,7 +133,7 @@ sub manage_selection {
my $create_time = Date::Parse::str2time($result->{msgGenerationTime});
if (!defined($create_time)) {
$self->{manager}->{output}->output_add(severity => 'UNKNOWN',
$self->{output}->output_add(severity => 'UNKNOWN',
short_msg => "Can't Parse date '" . $result->{msgGenerationTime} . "'");
next;
}

View File

@ -136,7 +136,7 @@ sub manage_selection {
my $create_time = $result->{perleEntityAlarmTimeStamp};
$result->{perleEntityAlarmTimeStamp} = strftime("%d/%m/%Y %H:%M:%S", localtime($result->{perleEntityAlarmTimeStamp}));
if (!defined($create_time)) {
$self->{manager}->{output}->output_add(
$self->{output}->output_add(
severity => 'UNKNOWN',
short_msg => "Can't get date '" . $create_time . "'"
);

View File

@ -132,8 +132,8 @@ sub manage_selection {
my $create_time = $result->{radwllMilOduAgnLastEventsTimeT};
$result->{radwllMilOduAgnLastEventsTimeT} = strftime("%d/%m/%Y %H:%M:%S", localtime($result->{radwllMilOduAgnLastEventsTimeT}));
if (!defined($create_time)) {
$self->{manager}->{output}->output_add(severity => 'UNKNOWN',
short_msg => "Can't get date '" . $result->{radwllMilOduAgnLastEventsTimeT} . "'");
$self->{output}->output_add(severity => 'UNKNOWN',
short_msg => "Can't get date '" . $result->{radwllMilOduAgnLastEventsTimeT} . "'");
next;
}

View File

@ -134,8 +134,8 @@ sub manage_selection {
my $create_time = $result->{spsActiveAlarmLogTime};
if (!defined($create_time)) {
$self->{manager}->{output}->output_add(severity => 'UNKNOWN',
short_msg => "Can't get date '" . $result->{spsActiveAlarmLogTime} . "'");
$self->{output}->output_add(severity => 'UNKNOWN',
short_msg => "Can't get date '" . $result->{spsActiveAlarmLogTime} . "'");
next;
}

View File

@ -122,8 +122,8 @@ sub manage_selection {
foreach my $alarm (@{$alarm_results}) {
my $create_time = Date::Parse::str2time($alarm->{opened});
if (!defined($create_time)) {
$self->{manager}->{output}->output_add(severity => 'UNKNOWN',
short_msg => "Can't Parse date '" . $alarm->{opened} . "'");
$self->{output}->output_add(severity => 'UNKNOWN',
short_msg => "Can't Parse date '" . $alarm->{opened} . "'");
next;
}