From b5f0cde0d782fccfb5ca72981bd0afbb57768c25 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Thu, 9 Mar 2017 16:24:38 +0100 Subject: [PATCH] add audiocodes snmp plugin (WIP) --- .../snmp/mode/components/fantray.pm | 78 ++++++++++++ .../audiocodes/snmp/mode/components/module.pm | 79 ++++++++++++ .../audiocodes/snmp/mode/components/psu.pm | 78 ++++++++++++ network/audiocodes/snmp/mode/cpu.pm | 106 ++++++++++++++++ network/audiocodes/snmp/mode/hardware.pm | 117 ++++++++++++++++++ network/audiocodes/snmp/mode/memory.pm | 106 ++++++++++++++++ network/audiocodes/snmp/plugin.pm | 52 ++++++++ 7 files changed, 616 insertions(+) create mode 100644 network/audiocodes/snmp/mode/components/fantray.pm create mode 100644 network/audiocodes/snmp/mode/components/module.pm create mode 100644 network/audiocodes/snmp/mode/components/psu.pm create mode 100644 network/audiocodes/snmp/mode/cpu.pm create mode 100644 network/audiocodes/snmp/mode/hardware.pm create mode 100644 network/audiocodes/snmp/mode/memory.pm create mode 100644 network/audiocodes/snmp/plugin.pm diff --git a/network/audiocodes/snmp/mode/components/fantray.pm b/network/audiocodes/snmp/mode/components/fantray.pm new file mode 100644 index 000000000..984ba78c2 --- /dev/null +++ b/network/audiocodes/snmp/mode/components/fantray.pm @@ -0,0 +1,78 @@ +# +# Copyright 2017 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::audiocodes::snmp::mode::components::fantray; + +use strict; +use warnings; + +my %map_status = ( + 0 => 'cleared', + 1 => 'indeterminate', + 2 => 'warning', + 3 => 'minor', + 4 => 'major', + 5 => 'critical', +); +my %map_existence = ( + 1 => 'present', + 2 => 'missing', +); + +my $mapping = { + acSysFanTrayExistence => { oid => '.1.3.6.1.4.1.5003.9.10.10.4.22.1.3', map => \%map_existence }, + acSysFanTraySeverity => { oid => '.1.3.6.1.4.1.5003.9.10.10.4.22.1.6', map => \%map_status }, +}; +my $oid_acSysFanTrayEntry = '.1.3.6.1.4.1.5003.9.10.10.4.22.1'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_acSysFanTrayEntry }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking fantray"); + $self->{components}->{fantray} = {name => 'fantray', total => 0, skip => 0}; + return if ($self->check_filter(section => 'fantray')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_acSysFanTrayEntry}})) { + next if ($oid !~ /^$mapping->{acSysFanTraySeverity}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_acSysFanTrayEntry}, instance => $instance); + + next if ($result->{acSysFanTrayExistence} eq 'missing' && + $self->absent_problem(section => 'fantray', instance => $instance)); + next if ($self->check_filter(section => 'fantray', instance => $instance)); + + $self->{components}->{fantray}->{total}++; + $self->{output}->output_add(long_msg => sprintf("Fan tray '%s' status is '%s' [instance = %s]", + $instance, $result->{acSysFanTraySeverity}, $instance)); + my $exit = $self->get_severity(label => 'default', section => 'fantray', value => $result->{acSysFanTraySeverity}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Fan tray '%s' status is '%s'", $instance, $result->{acSysFanTraySeverity})); + } + } +} + +1; \ No newline at end of file diff --git a/network/audiocodes/snmp/mode/components/module.pm b/network/audiocodes/snmp/mode/components/module.pm new file mode 100644 index 000000000..72a9be9fe --- /dev/null +++ b/network/audiocodes/snmp/mode/components/module.pm @@ -0,0 +1,79 @@ +# +# Copyright 2017 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::audiocodes::snmp::mode::components::module; + +use strict; +use warnings; + +my %map_status = ( + 1 => 'moduleNotExist', + 2 => 'moduleExistOk', + 3 => 'moduleOutOfService', + 4 => 'moduleBackToServiceStart', + 5 => 'moduleMismatch', + 6 => 'moduleFaulty', + 7 => 'notApplicable', +); +my %map_existence = ( + 1 => 'present', + 2 => 'missing', +); + +my $mapping = { + acSysModulePresence => { oid => '.1.3.6.1.4.1.5003.9.10.10.4.21.1.4', map => \%map_existence }, + acSysModuleFRUstatus => { oid => '.1.3.6.1.4.1.5003.9.10.10.4.21.1.14', map => \%map_status }, +}; +my $oid_acSysModuleEntry = '.1.3.6.1.4.1.5003.9.10.10.4.21.1'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_acSysModuleEntry }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking modules"); + $self->{components}->{module} = {name => 'modules', total => 0, skip => 0}; + return if ($self->check_filter(section => 'module')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_acSysModuleEntry}})) { + next if ($oid !~ /^$mapping->{acSysModuleFRUstatus}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_acSysModuleEntry}, instance => $instance); + + next if ($result->{acSysModulePresence} eq 'missing' && + $self->absent_problem(section => 'module', instance => $instance)); + next if ($self->check_filter(section => 'module', instance => $instance)); + + $self->{components}->{module}->{total}++; + $self->{output}->output_add(long_msg => sprintf("module '%s' status is '%s' [instance = %s]", + $instance, $result->{acSysModuleFRUstatus}, $instance)); + my $exit = $self->get_severity(section => 'module', value => $result->{acSysModuleFRUstatus}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Module '%s' status is '%s'", $instance, $result->{acSysModuleFRUstatus})); + } + } +} + +1; \ No newline at end of file diff --git a/network/audiocodes/snmp/mode/components/psu.pm b/network/audiocodes/snmp/mode/components/psu.pm new file mode 100644 index 000000000..02870b9cd --- /dev/null +++ b/network/audiocodes/snmp/mode/components/psu.pm @@ -0,0 +1,78 @@ +# +# Copyright 2017 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::audiocodes::snmp::mode::components::psu; + +use strict; +use warnings; + +my %map_status = ( + 1 => 'cleared', + 2 => 'indeterminate', + 3 => 'warning', + 4 => 'minor', + 5 => 'major', + 6 => 'critical', +); +my %map_existence = ( + 1 => 'present', + 2 => 'missing', +); + +my $mapping = { + acSysPowerSupplyExistence => { oid => '.1.3.6.1.4.1.5003.9.10.10.4.23.1.3', map => \%map_existence }, + acSysPowerSupplySeverity => { oid => '.1.3.6.1.4.1.5003.9.10.10.4.23.1.6', map => \%map_status }, +}; +my $oid_acSysPowerSupplyEntry = '.1.3.6.1.4.1.5003.9.10.10.4.23.1'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_acSysPowerSupplyEntry }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking power supplies"); + $self->{components}->{psu} = {name => 'psus', total => 0, skip => 0}; + return if ($self->check_filter(section => 'psu')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_acSysPowerSupplyEntry}})) { + next if ($oid !~ /^$mapping->{acSysPowerSupplySeverity}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_acSysPowerSupplyEntry}, instance => $instance); + + next if ($result->{acSysPowerSupplyExistence} eq 'missing' && + $self->absent_problem(section => 'psu', instance => $instance)); + next if ($self->check_filter(section => 'psu', instance => $instance)); + + $self->{components}->{psu}->{total}++; + $self->{output}->output_add(long_msg => sprintf("power supply '%s' status is '%s' [instance = %s]", + $instance, $result->{acSysPowerSupplySeverity}, $instance)); + my $exit = $self->get_severity(label => 'default', section => 'psu', value => $result->{acSysPowerSupplySeverity}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Power supply '%s' status is '%s'", $instance, $result->{acSysPowerSupplySeverity})); + } + } +} + +1; \ No newline at end of file diff --git a/network/audiocodes/snmp/mode/cpu.pm b/network/audiocodes/snmp/mode/cpu.pm new file mode 100644 index 000000000..86475ae57 --- /dev/null +++ b/network/audiocodes/snmp/mode/cpu.pm @@ -0,0 +1,106 @@ +# +# Copyright 2017 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::audiocodes::snmp::mode::cpu; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0, message_separator => ' - ' }, + ]; + $self->{maps_counters}->{global} = [ + { label => 'voip', set => { + key_values => [ { name => 'voip' } ], + output_template => 'CPU VoIp Usage : %.2f %%', + perfdatas => [ + { label => 'cpu_voip', value => 'voip_absolute', template => '%.2f', min => 0, max => 100, unit => '%' }, + ], + } + }, + { label => 'data', set => { + key_values => [ { name => 'data' } ], + output_template => 'CPU Data Usage : %.2f %%', + perfdatas => [ + { label => 'cpu_data', value => 'data_absolute', template => '%.2f', min => 0, max => 100, unit => '%' }, + ], + } + }, + ]; +} + +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 => + { + }); + + return $self; +} + +sub manage_selection { + my ($self, %options) = @_; + + my $oid_acSysStateVoIpCpuUtilization = '.1.3.6.1.4.1.5003.9.10.10.2.5.10.0'; + my $oid_acSysStateDataCpuUtilization = '.1.3.6.1.4.1.5003.9.10.10.2.5.8.0'; + my $snmp_result = $options{snmp}->get_leef(oids => [ + $oid_acSysStateVoIpCpuUtilization, $oid_acSysStateDataCpuUtilization + ], nothing_quit => 1); + + $self->{global} = { data => $snmp_result->{$oid_acSysStateDataCpuUtilization}, voip => $snmp_result->{$oid_acSysStateVoIpCpuUtilization} }; +} + +1; + +__END__ + +=head1 MODE + +Check CPU usages. + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='^voip$' + +=item B<--warning-*> + +Threshold warning. +Can be: 'voip', 'data'. + +=item B<--critical-*> + +Threshold critical. +Can be: 'voip', 'data'. + +=back + +=cut diff --git a/network/audiocodes/snmp/mode/hardware.pm b/network/audiocodes/snmp/mode/hardware.pm new file mode 100644 index 000000000..cd029440b --- /dev/null +++ b/network/audiocodes/snmp/mode/hardware.pm @@ -0,0 +1,117 @@ +# +# Copyright 2017 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::audiocodes::snmp::mode::hardware; + +use base qw(centreon::plugins::templates::hardware); + +use strict; +use warnings; + +sub set_system { + my ($self, %options) = @_; + + $self->{regexp_threshold_overload_check_section_option} = '^(module|fantray|psu)$'; + + $self->{cb_hook2} = 'snmp_execute'; + + $self->{thresholds} = { + default => [ + ['cleared', 'OK'], + ['indeterminate', 'UNKNOWN'], + ['warning', 'WARNING'], + ['minor', 'WARNING'], + ['major', 'CRITICAL'], + ['critical', 'CRITICAL'], + ], + module => [ + ['moduleNotExist', 'OK'], + ['moduleExistOk', 'OK'], + ['moduleOutOfService', 'CRITICAL'], + ['moduleBackToServiceStart', 'WARNING'], + ['moduleMismatch', 'WARNING'], + ['moduleFaulty', 'CRITICAL'], + ['notApplicable', 'OK'], + ], + }; + + $self->{components_path} = 'network::audiocodes::snmp::mode::components'; + $self->{components_module} = ['module', 'fantray', 'psu']; +} + +sub snmp_execute { + my ($self, %options) = @_; + + $self->{snmp} = $options{snmp}; + $self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request}); +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_performance => 1); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + }); + + return $self; +} + +1; + +__END__ + +=head1 MODE + +Check Hardware. + +=over 8 + +=item B<--component> + +Which component to check (Default: '.*'). +Can be: 'fantray', 'module', 'psu'. + +=item B<--filter> + +Exclude some parts (comma seperated list) (Example: --filter=fan --filter=psu) +Can also exclude specific instance: --filter=fantray,1 + +=item B<--absent-problem> + +Return an error if an entity is not 'present' (default is skipping) (comma seperated list) +Can be specific or global: --absent-problem=psu,1 + +=item B<--no-component> + +Return an error if no compenents are checked. +If total (with skipped) is 0. (Default: 'critical' returns). + +=item B<--threshold-overload> + +Set to overload default threshold values (syntax: section,[instance,]status,regexp) +It used before default thresholds (order stays). +Example: --threshold-overload='psu,CRITICAL,^(?!(cleared)$)' + +=back + +=cut \ No newline at end of file diff --git a/network/audiocodes/snmp/mode/memory.pm b/network/audiocodes/snmp/mode/memory.pm new file mode 100644 index 000000000..bcea3b8da --- /dev/null +++ b/network/audiocodes/snmp/mode/memory.pm @@ -0,0 +1,106 @@ +# +# Copyright 2017 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::audiocodes::snmp::mode::memory; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0, message_separator => ' - ' }, + ]; + $self->{maps_counters}->{global} = [ + { label => 'voip', set => { + key_values => [ { name => 'voip' } ], + output_template => 'Memory VoIp Usage : %.2f %%', + perfdatas => [ + { label => 'used_voip', value => 'voip_absolute', template => '%.2f', min => 0, max => 100, unit => '%' }, + ], + } + }, + { label => 'data', set => { + key_values => [ { name => 'data' } ], + output_template => 'Memory Data Usage : %.2f %%', + perfdatas => [ + { label => 'used_data', value => 'data_absolute', template => '%.2f', min => 0, max => 100, unit => '%' }, + ], + } + }, + ]; +} + +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 => + { + }); + + return $self; +} + +sub manage_selection { + my ($self, %options) = @_; + + my $oid_acSysStateVoIpMemoryUtilization = '.1.3.6.1.4.1.5003.9.10.10.2.5.11.0'; + my $oid_acSysStateDataMemoryUtilization = '.1.3.6.1.4.1.5003.9.10.10.2.5.9.0'; + my $snmp_result = $options{snmp}->get_leef(oids => [ + $oid_acSysStateVoIpMemoryUtilization, $oid_acSysStateDataMemoryUtilization + ], nothing_quit => 1); + + $self->{global} = { data => $snmp_result->{$oid_acSysStateDataMemoryUtilization}, voip => $snmp_result->{$oid_acSysStateVoIpMemoryUtilization} }; +} + +1; + +__END__ + +=head1 MODE + +Check memory usages. + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='^voip$' + +=item B<--warning-*> + +Threshold warning. +Can be: 'voip', 'data'. + +=item B<--critical-*> + +Threshold critical. +Can be: 'voip', 'data'. + +=back + +=cut diff --git a/network/audiocodes/snmp/plugin.pm b/network/audiocodes/snmp/plugin.pm new file mode 100644 index 000000000..dde1f2345 --- /dev/null +++ b/network/audiocodes/snmp/plugin.pm @@ -0,0 +1,52 @@ +# +# Copyright 2017 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::audiocodes::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; + + $self->{version} = '1.0'; + %{$self->{modes}} = ( + 'cpu' => 'network::audiocodes::snmp::mode::cpu', + 'hardware' => 'network::audiocodes::snmp::mode::hardware', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'memory' => 'network::audiocodes::snmp::mode::memory', + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Audiocodes equipments (Mediant) in SNMP. + +=cut