From 5b1ea802ac2afc2a4fdc3a62a30c01bb6ee1a558 Mon Sep 17 00:00:00 2001 From: qgarnier Date: Fri, 22 Oct 2021 10:49:47 +0200 Subject: [PATCH] enh(polycom/trio): add modes paired and registration (#3213) --- .../polycom/trio/restapi/mode/callsrt.pm | 29 ++-- .../polycom/trio/restapi/mode/callssummary.pm | 21 ++- .../polycom/trio/restapi/mode/device.pm | 51 +++---- .../polycom/trio/restapi/mode/network.pm | 1 - .../polycom/trio/restapi/mode/paired.pm | 143 ++++++++++++++++++ .../polycom/trio/restapi/mode/registration.pm | 103 +++++++++++++ .../devices/polycom/trio/restapi/plugin.pm | 10 +- 7 files changed, 296 insertions(+), 62 deletions(-) create mode 100644 centreon-plugins/hardware/devices/polycom/trio/restapi/mode/paired.pm create mode 100644 centreon-plugins/hardware/devices/polycom/trio/restapi/mode/registration.pm diff --git a/centreon-plugins/hardware/devices/polycom/trio/restapi/mode/callsrt.pm b/centreon-plugins/hardware/devices/polycom/trio/restapi/mode/callsrt.pm index 84b579e78..fbcdc5fdc 100644 --- a/centreon-plugins/hardware/devices/polycom/trio/restapi/mode/callsrt.pm +++ b/centreon-plugins/hardware/devices/polycom/trio/restapi/mode/callsrt.pm @@ -54,6 +54,12 @@ sub custom_loss_output { ); } +sub prefix_channels_output { + my ($self, %options) = @_; + + return "Channel '" . $options{instance_value}->{display} ."' "; +} + sub set_counters { my ($self, %options) = @_; @@ -67,8 +73,8 @@ sub set_counters { output_change_bytes => 1, output_template => 'traffic in: %s %s/s', perfdatas => [ - { template => '%d', unit => 'B/s', min => 0, label_extra_instance => 1 }, - ], + { template => '%d', unit => 'B/s', min => 0, label_extra_instance => 1 } + ] } }, { label => 'channel-traffic-out', nlabel => 'call.channel.traffic.out.bytes', set => { @@ -76,16 +82,16 @@ sub set_counters { output_change_bytes => 1, output_template => 'traffic out: %s %s/s', perfdatas => [ - { template => '%d', unit => 'B/s', min => 0, label_extra_instance => 1 }, - ], + { template => '%d', unit => 'B/s', min => 0, label_extra_instance => 1 } + ] } }, { label => 'channel-maxjitter', nlabel => 'call.channel.maxjitter.milliseconds', set => { key_values => [ { name => 'max_jitter' }, { name => 'display' } ], output_template => 'max jitter: %s ms', perfdatas => [ - { template => '%d', unit => 'ms', min => 0, label_extra_instance => 1 }, - ], + { template => '%d', unit => 'ms', min => 0, label_extra_instance => 1 } + ] } }, { label => 'channel-packetloss', nlabel => 'call.channel.packetloss.count', set => { @@ -94,8 +100,8 @@ sub set_counters { closure_custom_output => $self->can('custom_loss_output'), threshold_use => 'packets_loss', perfdatas => [ - { value => 'packets_loss', template => '%d', min => 0, label_extra_instance => 1 } - ], + { value => 'packets_loss', template => '%d', min => 0, label_extra_instance => 1 + ] } }, { label => 'channel-packetloss-prct', nlabel => 'call.channel.packetloss.percentage', display_ok => 0, set => { @@ -111,18 +117,11 @@ sub set_counters { ]; } -sub prefix_channels_output { - my ($self, %options) = @_; - - return "Channel '" . $options{instance_value}->{display} ."' "; -} - sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1, statefile => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/hardware/devices/polycom/trio/restapi/mode/callssummary.pm b/centreon-plugins/hardware/devices/polycom/trio/restapi/mode/callssummary.pm index 3936093d3..37814ca19 100644 --- a/centreon-plugins/hardware/devices/polycom/trio/restapi/mode/callssummary.pm +++ b/centreon-plugins/hardware/devices/polycom/trio/restapi/mode/callssummary.pm @@ -37,7 +37,7 @@ sub set_counters { my ($self, %options) = @_; $self->{maps_counters_type} = [ - { name => 'global', type => 0, cb_prefix_output => 'prefix_global_output', skipped_code => { -10 => 1 } }, + { name => 'global', type => 0, cb_prefix_output => 'prefix_global_output', skipped_code => { -10 => 1 } } ]; $self->{maps_counters}->{global} = [ @@ -45,34 +45,34 @@ sub set_counters { key_values => [ { name => 'total' } ], output_template => 'total: d', perfdatas => [ - { value => 'total', template => '%d', min => 0 }, - ], + { template => '%d', min => 0 } + ] } }, { label => 'placed', nlabel => 'calls.placed.count', set => { key_values => [ { name => 'placed' } ], output_template => 'placed: %d', perfdatas => [ - { value => 'placed', template => '%d', min => 0 }, - ], + { template => '%d', min => 0 } + ] } }, { label => 'missed', nlabel => 'calls.missed.count', set => { key_values => [ { name => 'missed' } ], output_template => 'missed: %d', perfdatas => [ - { value => 'missed', template => '%d', min => 0 }, - ], + { template => '%d', min => 0 } + ] } }, { label => 'received', nlabel => 'calls.received.count', set => { key_values => [ { name => 'received' } ], output_template => 'received: %d', perfdatas => [ - { value => 'received', template => '%d', min => 0 }, - ], + { template => '%d', min => 0 } + ] } - }, + } ]; } @@ -81,7 +81,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - $self->{version} = '1.0'; $options{options}->add_options(arguments => { }); diff --git a/centreon-plugins/hardware/devices/polycom/trio/restapi/mode/device.pm b/centreon-plugins/hardware/devices/polycom/trio/restapi/mode/device.pm index 56593372e..a77a515e5 100644 --- a/centreon-plugins/hardware/devices/polycom/trio/restapi/mode/device.pm +++ b/centreon-plugins/hardware/devices/polycom/trio/restapi/mode/device.pm @@ -24,7 +24,7 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); sub custom_status_output { my ($self, %options) = @_; @@ -53,50 +53,49 @@ sub set_counters { ]; $self->{maps_counters}->{global} = [ - { label => 'status', threshold => 0, set => { + { label => 'status', type => 2, critical_default => '%{status} =~ /error/i', 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, + closure_custom_threshold_check => \&catalog_status_threshold_ng } }, { 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', template => '%.2f', - min => 0, max => 100, unit => '%' }, - ], + { 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' } ], + 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', template => '%d', min => 0, max => 'total', - unit => 'B', cast_int => 1 }, - ], + { template => '%d', min => 0, max => 'total', 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' } ], + 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', template => '%d', min => 0, max => 'total', - unit => 'B', cast_int => 1 }, - ], + { template => '%d', min => 0, max => 'total', 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', template => '%.2f', min => 0, max => 100, - unit => '%' }, - ], + { template => '%.2f', min => 0, max => 100, unit => '%' } + ] } } ]; @@ -106,22 +105,12 @@ 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) = @_; @@ -143,7 +132,7 @@ sub manage_selection { $result = $options{custom}->request_api(url_path => '/api/v1/mgmt/pollForStatus'); return if (!defined($result->{data}->{State})); - + $self->{global}->{status} = $result->{data}->{State}; } diff --git a/centreon-plugins/hardware/devices/polycom/trio/restapi/mode/network.pm b/centreon-plugins/hardware/devices/polycom/trio/restapi/mode/network.pm index 80d6d11ef..8775c47ef 100644 --- a/centreon-plugins/hardware/devices/polycom/trio/restapi/mode/network.pm +++ b/centreon-plugins/hardware/devices/polycom/trio/restapi/mode/network.pm @@ -57,7 +57,6 @@ 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 => { }); diff --git a/centreon-plugins/hardware/devices/polycom/trio/restapi/mode/paired.pm b/centreon-plugins/hardware/devices/polycom/trio/restapi/mode/paired.pm new file mode 100644 index 000000000..d66e9cffd --- /dev/null +++ b/centreon-plugins/hardware/devices/polycom/trio/restapi/mode/paired.pm @@ -0,0 +1,143 @@ +# +# Copyright 2021 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::paired; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +sub prefix_global_output { + my ($self, %options) = @_; + + return 'Devices paired '; +} + +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 => 'camera-paired', nlabel => 'devices.camera.paired.count', set => { + key_values => [ { name => 'cameraSrc' } ], + output_template => 'camera: %d', + perfdatas => [ + { template => '%d', min => 0 } + ] + } + }, + { label => 'audio-paired', nlabel => 'devices.audio.paired.count', set => { + key_values => [ { name => 'audioSrcSink' } ], + output_template => 'audio: %d', + perfdatas => [ + { template => '%d', min => 0 } + ] + } + }, + { label => 'displayui-paired', nlabel => 'devices.display_ui.paired.count', set => { + key_values => [ { name => 'displayUI' } ], + output_template => 'display ui: %d', + perfdatas => [ + { template => '%d', min => 0 } + ] + } + } + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + + $options{options}->add_options(arguments => { + 'filter-device-name:s' => { name => 'filter_device_name' }, + 'filter-device-type:s' => { name => 'filter_device_type' } + }); + + return $self; +} + +sub manage_selection { + my ($self, %options) = @_; + + my $result = $options{custom}->request_api(url_path => '/api/v1/mgmt/mrpair/info'); + + $self->{global} = { cameraSrc => 0, displayUI => 0, audioSrcSink => 0 }; + foreach my $ConnectedDeviceList (@{$result->{data}->{ConnectedDeviceList}}) { + foreach my $component (@{$ConnectedDeviceList->{ComponentList}}) { + next if ($component->{componentType} !~ /^(?:cameraSrc|audioSrcSink|displayUI)$/); + + if (defined($self->{option_results}->{filter_device_name}) && $self->{option_results}->{filter_device_name} ne '' && + $component->{componentName} !~ /$self->{option_results}->{filter_device_name}/) { + $self->{output}->output_add(long_msg => "skipping device '" . $component->{componentName} . "': no matching filter.", debug => 1); + next; + } + if (defined($self->{option_results}->{filter_device_type}) && $self->{option_results}->{filter_device_type} ne '' && + $component->{componentType} !~ /$self->{option_results}->{filter_device_type}/) { + $self->{output}->output_add(long_msg => "skipping device '" . $component->{componentName} . "': no matching filter.", debug => 1); + next; + } + + $self->{global}->{ $component->{componentType} }++; + $self->{output}->output_add( + long_msg => sprintf( + 'componentType: %s [name: %s] [details: %s] [SerialNumer: %s] [componentUri: %s]', + $component->{componentType}, + $component->{componentName}, + $component->{componentDetail}, + $component->{componentSerialNumber}, + $component->{componentUri} + ) + ); + } + } +} + +1; + +__END__ + +=head1 MODE + +Check paired devices. + +=over 8 + +=item B<--filter-device-name> + +Filter devices by name. + +=item B<--filter-device-type> + +Filter devices by type. + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'camera-paired', 'audio-paired', 'displayui-paired'. + +=back + +=cut + diff --git a/centreon-plugins/hardware/devices/polycom/trio/restapi/mode/registration.pm b/centreon-plugins/hardware/devices/polycom/trio/restapi/mode/registration.pm new file mode 100644 index 000000000..2b7c2bb2f --- /dev/null +++ b/centreon-plugins/hardware/devices/polycom/trio/restapi/mode/registration.pm @@ -0,0 +1,103 @@ +# +# Copyright 2021 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::registration; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); + +sub custom_status_output { + my ($self, %options) = @_; + + return "SIP status is '" . $self->{result_values}->{status} . "'"; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0, skipped_code => { -10 => 1 } } + ]; + + $self->{maps_counters}->{global} = [ + { label => 'status', type => 2, critical_default => '%{status} !~ /registered/i', set => { + key_values => [ { name => 'status' } ], + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold_ng + } + } + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + + $options{options}->add_options(arguments => { + }); + + return $self; +} + +sub manage_selection { + my ($self, %options) = @_; + + my $result = $options{custom}->request_api(url_path => '/api/v1/webCallControl/sipStatus'); + + $self->{global} = {}; + foreach my $user (@{$result->{data}->{User}}) { + foreach my $events (@{$user->{Events}}) { + next if ($events->{Type} !~ /register/i); + $self->{global}->{status} = $events->{RegistrationState}; + } + } + if (!defined($self->{global}->{status})) { + $self->{output}->add_option_msg(short_msg => 'Cannot find registration event'); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check SIP registration. + +=over 8 + +=item B<--warning-status> + +Set warning threshold for status. +Can used special variables like: %{status} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{status} !~ /registred/i'). +Can used special variables like: %{status} + +=back + +=cut diff --git a/centreon-plugins/hardware/devices/polycom/trio/restapi/plugin.pm b/centreon-plugins/hardware/devices/polycom/trio/restapi/plugin.pm index 84179202b..b9e7df4eb 100644 --- a/centreon-plugins/hardware/devices/polycom/trio/restapi/plugin.pm +++ b/centreon-plugins/hardware/devices/polycom/trio/restapi/plugin.pm @@ -30,14 +30,16 @@ sub new { bless $self, $class; $self->{version} = '1.0'; - %{$self->{modes}} = ( + $self->{modes} = { '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' - ); + 'network' => 'hardware::devices::polycom::trio::restapi::mode::network', + 'paired' => 'hardware::devices::polycom::trio::restapi::mode::paired', + 'registration' => 'hardware::devices::polycom::trio::restapi::mode::registration' + }; - $self->{custom_modes}{api} = 'hardware::devices::polycom::trio::restapi::custom::api'; + $self->{custom_modes}->{api} = 'hardware::devices::polycom::trio::restapi::custom::api'; return $self; }