From 0501a8d22d2a6ee9d4040c08213e9f19932e89c5 Mon Sep 17 00:00:00 2001 From: Sims24 Date: Wed, 13 Jul 2016 11:47:54 +0200 Subject: [PATCH 1/7] + add plugin.pm Ref https://github.com/centreon/centreon-plugins/issues/20 --- network/sonus/sbc/plugin.pm | 59 +++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 network/sonus/sbc/plugin.pm diff --git a/network/sonus/sbc/plugin.pm b/network/sonus/sbc/plugin.pm new file mode 100644 index 000000000..92020bf61 --- /dev/null +++ b/network/sonus/sbc/plugin.pm @@ -0,0 +1,59 @@ +# +# Copyright 2016 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 network::sonus::sbc::1000::snmp::plugin; + +use strict; +use warnings; +use base qw(centreon::plugins::script_snmp); + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + # $options->{options} = options object + + $self->{version} = '1.0'; + %{$self->{modes}} = ( + 'call-statistics' => 'network::sonus::sbc::1000::snmp::mode::callstats', + 'channels' => 'network::sonus::sbc::1000::snmp::mode::channels', + 'cpu' => 'snmp_standard::mode::cpu', + 'cpu-detailed' => 'snmp_standard::mode::cpudetailed', + 'dsp-stats' => 'network::sonus::sbc::snmp::mode::dspstats', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'load' => 'snmp_standard::mode::loadaverage', + 'memory' => 'snmp_standard::mode::memory', + 'storage' => 'snmp_standard::mode::storage', + 'swap' => 'snmp_standard::mode::swap', + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Sonus Session Border Controllers equipment in SNMP. + +=cut From 0d10cd377e49dcf02a23f94d9014db8b409a6054 Mon Sep 17 00:00:00 2001 From: Sims24 Date: Wed, 13 Jul 2016 11:49:03 +0200 Subject: [PATCH 2/7] + fix indent and paths --- network/sonus/sbc/plugin.pm | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/network/sonus/sbc/plugin.pm b/network/sonus/sbc/plugin.pm index 92020bf61..f058bcfb7 100644 --- a/network/sonus/sbc/plugin.pm +++ b/network/sonus/sbc/plugin.pm @@ -32,15 +32,15 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'call-statistics' => 'network::sonus::sbc::1000::snmp::mode::callstats', - 'channels' => 'network::sonus::sbc::1000::snmp::mode::channels', + 'call-statistics' => 'network::sonus::sbc::snmp::mode::callstats', + 'channels' => 'network::sonus::sbc::snmp::mode::channels', 'cpu' => 'snmp_standard::mode::cpu', 'cpu-detailed' => 'snmp_standard::mode::cpudetailed', - 'dsp-stats' => 'network::sonus::sbc::snmp::mode::dspstats', + 'dsp-stats' => 'network::sonus::sbc::snmp::mode::dspstats', 'interfaces' => 'snmp_standard::mode::interfaces', 'list-interfaces' => 'snmp_standard::mode::listinterfaces', 'load' => 'snmp_standard::mode::loadaverage', - 'memory' => 'snmp_standard::mode::memory', + 'memory' => 'snmp_standard::mode::memory', 'storage' => 'snmp_standard::mode::storage', 'swap' => 'snmp_standard::mode::swap', ); From 0cfa290c4931d0e3d606e9a91ab2e1e17fbb8457 Mon Sep 17 00:00:00 2001 From: Sims24 Date: Wed, 13 Jul 2016 11:58:06 +0200 Subject: [PATCH 3/7] + add call statistics mode https://github.com/centreon/centreon-plugins/issues/20 --- network/sonus/sbc/snmp/callstats.pm | 173 ++++++++++++++++++++++++++++ 1 file changed, 173 insertions(+) create mode 100644 network/sonus/sbc/snmp/callstats.pm diff --git a/network/sonus/sbc/snmp/callstats.pm b/network/sonus/sbc/snmp/callstats.pm new file mode 100644 index 000000000..92c55d54c --- /dev/null +++ b/network/sonus/sbc/snmp/callstats.pm @@ -0,0 +1,173 @@ +# +# Copyright 2016 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 network::sonus::sbc::snmp::mode::callstats; + +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 => 'port', type => 1, cb_prefix_output => 'prefix_port_output', message_multiple => 'All calls stats on ports are OK' }, + ]; + + $self->{maps_counters}->{port} = [ + { label => 'current-calls', set => { + key_values => [ { name => 'current' }, { name => 'display' } ], + output_template => 'Current calls : %s', + perfdatas => [ + { label => 'current', value => 'current_absolute', template => '%d', + min => 0, unit => 'calls', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'total-per-sec', set => { + key_values => [ { name => 'total', diff => 1 }, { name => 'display' } ], + per_second => 1, + output_template => 'total calls: %.2f/s', + perfdatas => [ + { label => 'total', value => 'total_per_second', template => '%.2f', + min => 0, unit => 'calls', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'connected-per-sec', set => { + key_values => [ { name => 'connected', diff => 1 }, { name => 'display' } ], + per_second => 1, + output_template => 'connected calls: %.2f/s', + perfdatas => [ + { label => 'connected', value => 'connected_per_second', template => '%.2f', + min => 0, unit => 'calls', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'refused-per-sec', set => { + key_values => [ { name => 'refused', diff => 1 }, { name => 'display' } ], + per_second => 1, + output_template => 'refused calls: %.2f/s', + perfdatas => [ + { label => 'refused', value => 'refused_per_second', template => '%.2f', + min => 0, unit => 'calls', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'errored-per-sec', set => { + key_values => [ { name => 'errored', diff => 1 }, { name => 'display' } ], + per_second => 1, + output_template => 'errored calls: %.2f/s', + perfdatas => [ + { label => 'errored', value => 'errored_per_second', template => '%.2f', + min => 0, unit => 'calls', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'blocked-per-sec', set => { + key_values => [ { name => 'blocked', diff => 1 }, { name => 'display' } ], + per_second => 1, + output_template => 'blocked calls: %.2f/s', + perfdatas => [ + { label => 'blocked', value => 'blocked_per_second', template => '%.2f', + min => 0, unit => 'calls', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + ]; +} + +sub prefix_dsp_output { + my ($self, %options) = @_; + + return "Port => '" . $options{instance_value}->{display} . "' "; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + }); + return $self; +} + +my $mapping = { + uxPTCurrentCalls => { oid => '.1.3.6.1.4.1.177.15.1.5.1.2.1.5' }, + uxPTTotalCalls => { oid => '.1.3.6.1.4.1.177.15.1.5.1.2.1.6' }, + uxPTConnectedCalls => { oid => '.1.3.6.1.4.1.177.15.1.5.1.2.1.7' }, + uxPTRefusedCalls => { oid => '.1.3.6.1.4.1.177.15.1.5.1.2.1.8' }, + uxPTErroredCalls => { oid => '.1.3.6.1.4.1.177.15.1.5.1.2.1.9' }, + uxPTBlockedCalls => { oid => '.1.3.6.1.4.1.177.15.1.5.1.2.1.18' }, +}; + +my $oid_uxPortTable = '.1.3.6.1.4.1.177.15.1.5.1.2.1'; + +sub manage_selection { + my ($self, %options) = @_; + + $self->{snmp} = $options{snmp}; + $self->{cache_name} = "sonus_" . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' . + (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); + + $self->{results} = $options{snmp}->get_table(oid => $oid_uxPortTable, + nothing_quit => 1); + + foreach my $oid (keys %{$self->{results}}) { + next if $oid !~ /^$mapping->{uxPTCurrentCalls}->{oid}\.(.*)$/; + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}, instance => $instance); + + $self->{port}->{$instance} = { current => $result->{uxPTCurrentCalls}, + total => $result->{uxPTTotalCalls}, + connected => $result->{uxPTConnectedCalls}, + refused => $result->{uxPTRefusedCalls}, + errored => $result->{uxPTErroredCalls}, + blocked => $result->{uxPTBlockedCalls}, + display => $instance }; + } +} + +1; + +__END__ + +=head1 MODE + +Check Call statistics + +=over 8 + +=item B<--warning-*> + +Warning on counters. Can be ('current-calls', 'total-per-sec', 'connected-per-sec', 'refused-per-sec', 'errored-per-sec', 'blocked-per-sec') + +=item B<--critical-*> + +Critical on counters. Can be ('current-calls', 'total-per-sec', 'connected-per-sec', 'refused-per-sec', 'errored-per-sec', 'blocked-per-sec') + +=back + +=cut From 38dfdd61b5ab327da97d205c92e4e64b96ffbca2 Mon Sep 17 00:00:00 2001 From: Sims24 Date: Wed, 13 Jul 2016 12:56:24 +0200 Subject: [PATCH 4/7] + add channels monitoring mode https://github.com/centreon/centreon-plugins/issues/20 --- network/sonus/sbc/snmp/channels.pm | 406 +++++++++++++++++++++++++++++ 1 file changed, 406 insertions(+) create mode 100644 network/sonus/sbc/snmp/channels.pm diff --git a/network/sonus/sbc/snmp/channels.pm b/network/sonus/sbc/snmp/channels.pm new file mode 100644 index 000000000..5c98a74ab --- /dev/null +++ b/network/sonus/sbc/snmp/channels.pm @@ -0,0 +1,406 @@ +# +# Copyright 2016 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 network::sonus::sbc::snmp::mode::channels; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +my $instance_mode; + +sub custom_threshold_output { + my ($self, %options) = @_; + my $status = 'ok'; + my $message; + + eval { + local $SIG{__WARN__} = sub { $message = $_[0]; }; + local $SIG{__DIE__} = sub { $message = $_[0]; }; + + if (defined($instance_mode->{option_results}->{critical_status}) && $instance_mode->{option_results}->{critical_status} ne '' && + eval "$instance_mode->{option_results}->{critical_status}") { + $status = 'critical'; + } elsif (defined($instance_mode->{option_results}->{warning_status}) && $instance_mode->{option_results}->{warning_status} ne '' && + eval "$instance_mode->{option_results}->{warning_status}") { + $status = 'warning'; + } + }; + if (defined($message)) { + $self->{output}->output_add(long_msg => 'filter status issue: ' . $message); + } + + return $status; +} + +sub custom_status_output { + my ($self, %options) = @_; + my $msg; + + if ($self->{result_values}->{admstatus} eq 'disabled') { + $msg = ' is disabled (admin)'; + } else { + $msg = 'Oper Status : ' . $self->{result_values}->{opstatus}; + } + + return $msg; +} + +sub custom_status_calc { + my ($self, %options) = @_; + + $self->{result_values}->{opstatus} = $options{new_datas}->{$self->{instance} . '_opstatus'}; + $self->{result_values}->{admstatus} = $options{new_datas}->{$self->{instance} . '_admstatus'}; + $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; + return 0; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0 }, + { name => 'channels', type => 1, cb_prefix_output => 'prefix_channels_output', message_multiple => 'All channels are ok' } + ]; + $self->{maps_counters}->{global} = [ + { label => 'total', set => { + key_values => [ { name => 'total' } ], + output_template => 'Total channels : %s', + perfdatas => [ + { label => 'total', value => 'total_absolute', template => '%s', + min => 0 }, + ], + } + }, + { label => 'total-outofservice', set => { + key_values => [ { name => 'outofservice' } ], + output_template => 'OutOfService : %s', + perfdatas => [ + { label => 'total_outofservice', value => 'outofservice_absolute', template => '%s', + min => 0 }, + ], + } + }, + { label => 'total-idle', set => { + key_values => [ { name => 'idle' } ], + output_template => 'Idle : %s', + perfdatas => [ + { label => 'total_idle', value => 'idle_absolute', template => '%s', + min => 0 }, + ], + } + }, + { label => 'total-pending', set => { + key_values => [ { name => 'pending' } ], + output_template => 'Pending : %s', + perfdatas => [ + { label => 'total_pending', value => 'pending_absolute', template => '%s', + min => 0 }, + ], + } + }, + { label => 'total-waitingforroute', set => { + key_values => [ { name => 'waitingforroute' } ], + output_template => 'WaitingForRoute : %s', + perfdatas => [ + { label => 'total_waitingforroute', value => 'waitingforroute_absolute_absolute', template => '%s', + min => 0 }, + ], + } + }, + { label => 'total-actionlist', set => { + key_values => [ { name => 'actionlist' } ], + output_template => 'ActionList : %s', + perfdatas => [ + { label => 'total_actionlist', value => 'actionlist_absolute', template => '%s', + min => 0 }, + ], + } + }, + { label => 'total-waitingfordigits', set => { + key_values => [ { name => 'waitingfordigits' } ], + output_template => 'WaitingForDigits : %s', + perfdatas => [ + { label => 'total_waitingfordigits', value => 'waitingfordigits_absolute', template => '%s', + min => 0 }, + ], + } + }, + { label => 'total-remotesetup', set => { + key_values => [ { name => 'remotesetup' } ], + output_template => 'RemoteSetup : %s', + perfdatas => [ + { label => 'total_remotesetup', value => 'remotesetup_absolute', template => '%s', + min => 0 }, + ], + } + }, + { label => 'total-peersetup', set => { + key_values => [ { name => 'peersetup' } ], + output_template => 'PeerSetup : %s', + perfdatas => [ + { label => 'total_peersetup', value => 'peersetup_absolute', template => '%s', + min => 0 }, + ], + } + }, + { label => 'total-alerting', set => { + key_values => [ { name => 'alerting' } ], + output_template => 'Alerting : %s', + perfdatas => [ + { label => 'total_alerting', value => 'alerting_absolute', template => '%s', + min => 0 }, + ], + } + }, + { label => 'total-inbandinfo', set => { + key_values => [ { name => 'inbandinfo' } ], + output_template => 'InBandInfo : %s', + perfdatas => [ + { label => 'total_inbandinfo', value => 'inbandinfo_absolute', template => '%s', + min => 0 }, + ], + } + }, + { label => 'total-connected', set => { + key_values => [ { name => 'connected' } ], + output_template => 'Connected : %s', + perfdatas => [ + { label => 'total_connected', value => 'connected_absolute', template => '%s', + min => 0 }, + ], + } + }, + { label => 'total-tonegeneration', set => { + key_values => [ { name => 'tonegeneration' } ], + output_template => 'ToneGeneration : %s', + perfdatas => [ + { label => 'total_tonegeneration', value => 'tonegeneration_absolute', template => '%s', + min => 0 }, + ], + } + }, + { label => 'total-releasing', set => { + key_values => [ { name => 'releasing' } ], + output_template => 'Releasing : %s', + perfdatas => [ + { label => 'total_releasing', value => 'releasing_absolute', template => '%s', + min => 0 }, + ], + } + }, + { label => 'total-aborting', set => { + key_values => [ { name => 'aborting' } ], + output_template => 'Aborting : %s', + perfdatas => [ + { label => 'total_aborting', value => 'aborting_absolute', template => '%s', + min => 0 }, + ], + } + }, + { label => 'total-resetting', set => { + key_values => [ { name => 'resetting' } ], + output_template => 'Resetting : %s', + perfdatas => [ + { label => 'total_resetting', value => 'resetting_absolute', template => '%s', + min => 0 }, + ], + } + }, + { label => 'total-up', set => { + key_values => [ { name => 'up' } ], + output_template => 'Up : %s', + perfdatas => [ + { label => 'total_up', value => 'up_absolute', template => '%s', + min => 0 }, + ], + } + }, + { label => 'total-down', set => { + key_values => [ { name => 'down' } ], + output_template => 'Down : %s', + perfdatas => [ + { label => 'total_down', value => 'down_absolute', template => '%s', + min => 0 }, + ], + } + }, + ]; + + $self->{maps_counters}->{channels} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'opstatus' }, { name => 'admstatus' }, { name => 'display' } ], + closure_custom_calc => $self->can('custom_status_calc'), + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => $self->can('custom_threshold_output'), + } + }, + { label => 'seconds', set => { + key_values => [ { name => 'seconds' }, { name => 'display' } ], + output_template => 'lifetime : %s seconds', + perfdatas => [ + { label => 'seconds', value => 'seconds_absolute', template => '%s', + min => 0, unit => 's', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + "warning-status:s" => { name => 'warning_status', default => '' }, + "critical-status:s" => { name => 'critical_status', default => '%{admstatus} eq "enable" and %{opstatus} !~ /up|idle|connected/' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $instance_mode = $self; + $self->change_macros(); +} + +sub prefix_channels_output { + my ($self, %options) = @_; + + return "Channels '" . $options{instance_value}->{display} . "' "; +} + +sub change_macros { + my ($self, %options) = @_; + + foreach (('warning_status', 'critical_status')) { + if (defined($self->{option_results}->{$_})) { + $self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g; + } + } +} + +my %map_admin_status = ( + 0 => 'down', + 1 => 'up', +); +my %map_operation_status = ( + 0 => 'outOfService', + 1 => 'idle', + 2 => 'pending', + 3 => 'waitingForRoute', + 4 => 'actionList', + 5 => 'waitingForDigits', + 6 => 'remoteSetUp', + 7 => 'peerSetUp', + 8 => 'alerting', + 9 => 'inBandInfo', + 10 => 'connected', + 11 => 'toneGeneration', + 12 => 'releasing', + 13 => 'aborting', + 14 => 'resetting', + 15 => 'up', + 16 => 'down', +); + +my $mapping = { + uxChAdminState => { oid => '.1.3.6.1.4.1.177.15.1.5.6.1.5', map => \%map_admin_status }, + uxChOperState => { oid => '.1.3.6.1.4.1.177.15.1.5.6.1.6', map => \%map_operation_status }, + uxChInUseSeconds => { oid => '.1.3.6.1.4.1.177.15.1.5.6.1.7' }, +}; + +my $oid_uxChannelStatusEntry = '.1.3.6.1.4.1.177.15.1.5.6.1'; + +sub manage_selection { + my ($self, %options) = @_; + + $self->{channels} = {}; + $self->{global} = { total => 0, outofservice => 0, idle => 0, + pending => 0, waitingforroute => 0, actionlist => 0, + waitingfordigits => 0, remotesetup => 0, peersetup => 0, + alerting => 0, inbandinfo => 0, connected => 0, tonegeneration => 0, + releasing => 0, aborting => 0, resetting => 0, up => 0, down => 0 }; + + $self->{results} = $options{snmp}->get_table(oid => $oid_uxChannelStatusEntry, + nothing_quit => 1); + + foreach my $oid (keys %{$self->{results}}) { + next if($oid !~ /^$mapping->{uxChOperState}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $self->{results}, instance => $instance); + + $self->{global}->{total}++; + my $oper_state = lc($result->{uxChOperState}); + + $self->{global}->{$oper_state}++; + $self->{channels}->{$instance} = {display => $instance, + opstatus => $result->{uxChOperState}, + admstatus => $result->{uxChAdminState}, + seconds => $result->{uxChInUseSeconds}}; + } + +} + +1; + +__END__ + +=head1 MODE + +Check Channels on Sonus + +=over 8 + +=item B<--filter-counters> + +Only display some counters (Can be 'channels' or 'global'). + +=item B<--warning-status> + +Set warning threshold for status. +Can used special variables like: %{admstatus}, %{opstatus}, %{display} + +=item B<--critical-status> + +Set critical threshold for status. +Can used special variables like: %{admstatus}, %{opstatus}, %{display} + +=item B<--warning-*> + +Threshold warning. +Can be: 'total', 'total-outofservice', 'total-disassociating', 'total-idle', 'total-pending', 'total-waitingforroute', 'total-actionlist', 'total-waitingfordigits', 'total-remotesetup', 'total-peersetup', 'total-alerting', 'total-inbandinfo', 'total-connected', 'total-tonegeneration', 'total-releasing', 'total-aborting', 'total-resetting', 'total-up', 'total-down', 'seconds' + +=item B<--critical-*> + +Threshold critical. +Can be: 'total', 'total', 'total-outofservice', 'total-disassociating', 'total-idle', 'total-pending', 'total-waitingforroute', 'total-actionlist', 'total-waitingfordigits', 'total-remotesetup', 'total-peersetup', 'total-alerting', 'total-inbandinfo', 'total-connected', 'total-tonegeneration', 'total-releasing', 'total-aborting', 'total-resetting', 'total-up', 'total-down', 'seconds' + +=back + +=cut From cd26d117e7df6885465f58f1925f815069a8fdb1 Mon Sep 17 00:00:00 2001 From: Sims24 Date: Wed, 13 Jul 2016 12:58:39 +0200 Subject: [PATCH 5/7] + add digital signal processing mode https://github.com/centreon/centreon-plugins/issues/20 --- network/sonus/sbc/snmp/dspstats.pm | 209 +++++++++++++++++++++++++++++ 1 file changed, 209 insertions(+) create mode 100644 network/sonus/sbc/snmp/dspstats.pm diff --git a/network/sonus/sbc/snmp/dspstats.pm b/network/sonus/sbc/snmp/dspstats.pm new file mode 100644 index 000000000..9bb8ba83e --- /dev/null +++ b/network/sonus/sbc/snmp/dspstats.pm @@ -0,0 +1,209 @@ +# +# Copyright 2016 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 network::sonus::sbc::1000::snmp::mode::dspstats; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +my $instance_mode; + +sub custom_threshold_output { + my ($self, %options) = @_; + my $status = 'ok'; + my $message; + + eval { + local $SIG{__WARN__} = sub { $message = $_[0]; }; + local $SIG{__DIE__} = sub { $message = $_[0]; }; + + if (defined($instance_mode->{option_results}->{critical_status}) && $instance_mode->{option_results}->{critical_status} ne '' && + eval "$instance_mode->{option_results}->{critical_status}") { + $status = 'critical'; + } elsif (defined($instance_mode->{option_results}->{warning_status}) && $instance_mode->{option_results}->{warning_status} ne '' && + eval "$instance_mode->{option_results}->{warning_status}") { + $status = 'warning'; + } + }; + if (defined($message)) { + $self->{output}->output_add(long_msg => 'filter status issue: ' . $message); + } + + return $status; +} + +sub custom_state_output { + my ($self, %options) = @_; + + my $msg = sprintf("state is '%s'", $self->{result_values}->{state}); + return $msg; +} + +sub custom_state_calc { + my ($self, %options) = @_; + + $self->{result_values}->{state} = $options{new_datas}->{$self->{instance} . '_state'}; + $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; + return 0; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'dsp', type => 1, cb_prefix_output => 'prefix_dsp_output', message_multiple => 'All DSP stats and states are OK' }, + ]; + $self->{maps_counters}->{dsp} = [ + { label => 'state', threshold => 0, set => { + key_values => [ { name => 'state' }, { name => 'display' } ], + closure_custom_calc => \&custom_state_calc, + closure_custom_output => \&custom_state_output, + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&custom_threshold_output, + } + }, + { label => 'cpu', set => { + key_values => [ { name => 'cpu' }, { name => 'display' } ], + output_template => 'CPU Usage: %s', + perfdatas => [ + { label => 'cpu', value => 'cpu_absolute', template => '%d', + min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'channels', set => { + key_values => [ { name => 'channels' }, { name => 'display' } ], + output_template => 'Active Channels: %s', + perfdatas => [ + { label => 'channels', value => 'channels_absolute', template => '%d', + min => 0, unit => 'channels', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + ]; +} + +sub prefix_dsp_output { + my ($self, %options) = @_; + + return "DSP '" . $options{instance_value}->{display} . "' "; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + "warning-status:s" => { name => 'warning_status', default => '' }, + "critical-status:s" => { name => 'critical_status', default => '%{state} eq "down"' }, + }); + return $self; +} + +sub change_macros { + my ($self, %options) = @_; + + foreach (('warning_status', 'critical_status')) { + if (defined($self->{option_results}->{$_})) { + $self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g; + } + } +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(); + $instance_mode = $self; +} + +my %map_status = ( + 0 => 'down', + 1 => 'up', +); + +my $mapping = { + uxDSPIsPresent => { oid => '.1.3.6.1.4.1.177.15.1.6.1.3' }, + uxDSPCPUUsage => { oid => '.1.3.6.1.4.1.177.15.1.6.1.4' }, + uxDSPChannelsInUse => { oid => '.1.3.6.1.4.1.177.15.1.6.1.5' }, + uxDSPServiceStatus => { oid => '.1.3.6.1.4.1.177.15.1.6.1.6', map => \%map_status }, +}; + +my $oid_uxDSPResourceTable = '.1.3.6.1.4.1.177.15.1.6.1'; + +sub manage_selection { + my ($self, %options) = @_; + + $self->{snmp} = $options{snmp}; + + $self->{results} = $options{snmp}->get_table(oid => $oid_uxDSPResourceTable, + nothing_quit => 1); + + foreach my $oid (keys %{$self->{results}}) { + next if($oid !~ /^$mapping->{uxDSPServiceStatus}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}, instance => $instance); + + next if ($result->{uxDSPIsPresent} eq '0'); + + $self->{dsp}->{$instance} = { state => $result->{uxDSPServiceStatus}, + cpu => $result->{uxDSPCPUUsage}, + channels => $result->{uxDSPChannelsInUse}, + display => $instance }; + } +} + +1; + +__END__ + +=head1 MODE + +Check Digital Signal Processing statistics + +=over 8 + +=item B<--warning-*> + +Warning on counters. Can be ('cpu', 'channels') + +=item B<--critical-*> + +Warning on counters. Can be ('cpu', 'channels') + +=item B<--warning-status> + +Set warning threshold for status. Use "%{state}" as a special variable. +Useful to be notified when tunnel is up "%{state} eq 'up'" + +=item B<--critical-status> + +Set critical threshold for status. Use "%{state}" as a special variable. +Useful to be notified when tunnel is up "%{state} eq 'up'" + +=back + +=cut From 98f6be56ebf6f1dd66ba9703a67b64ee242f804b Mon Sep 17 00:00:00 2001 From: Sims24 Date: Wed, 13 Jul 2016 13:04:01 +0200 Subject: [PATCH 6/7] + fix path to module --- network/sonus/sbc/snmp/dspstats.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/network/sonus/sbc/snmp/dspstats.pm b/network/sonus/sbc/snmp/dspstats.pm index 9bb8ba83e..e59f37440 100644 --- a/network/sonus/sbc/snmp/dspstats.pm +++ b/network/sonus/sbc/snmp/dspstats.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package network::sonus::sbc::1000::snmp::mode::dspstats; +package network::sonus::sbc::snmp::mode::dspstats; use base qw(centreon::plugins::templates::counter); From 1b1ab0be5b5051fea362e751221cb09fb74a0466 Mon Sep 17 00:00:00 2001 From: Sims24 Date: Wed, 13 Jul 2016 13:05:44 +0200 Subject: [PATCH 7/7] + fix path to module --- network/sonus/sbc/plugin.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/network/sonus/sbc/plugin.pm b/network/sonus/sbc/plugin.pm index f058bcfb7..c0cc3d9cf 100644 --- a/network/sonus/sbc/plugin.pm +++ b/network/sonus/sbc/plugin.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package network::sonus::sbc::1000::snmp::plugin; +package network::sonus::sbc::snmp::plugin; use strict; use warnings;