enh(polycom/trio): add modes paired and registration (#3213)

This commit is contained in:
qgarnier 2021-10-22 10:49:47 +02:00 committed by GitHub
parent c1d83ddd2b
commit 5b1ea802ac
7 changed files with 296 additions and 62 deletions

View File

@ -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 => {
});

View File

@ -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 => {
});

View File

@ -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};
}

View File

@ -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 => {
});

View File

@ -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

View File

@ -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

View File

@ -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;
}