From e9aeffb7248190b64afa67a3e00fd93e2460d946 Mon Sep 17 00:00:00 2001 From: qgarnier Date: Wed, 21 Apr 2021 15:46:23 +0200 Subject: [PATCH] add(plugin): bdt multistak snmp (#2727) --- .../multistak/snmp/mode/components/device.pm | 70 ++++++++++ .../multistak/snmp/mode/components/module.pm | 100 ++++++++++++++ storage/bdt/multistak/snmp/mode/hardware.pm | 128 ++++++++++++++++++ storage/bdt/multistak/snmp/plugin.pm | 48 +++++++ 4 files changed, 346 insertions(+) create mode 100644 storage/bdt/multistak/snmp/mode/components/device.pm create mode 100644 storage/bdt/multistak/snmp/mode/components/module.pm create mode 100644 storage/bdt/multistak/snmp/mode/hardware.pm create mode 100644 storage/bdt/multistak/snmp/plugin.pm diff --git a/storage/bdt/multistak/snmp/mode/components/device.pm b/storage/bdt/multistak/snmp/mode/components/device.pm new file mode 100644 index 000000000..e67389f78 --- /dev/null +++ b/storage/bdt/multistak/snmp/mode/components/device.pm @@ -0,0 +1,70 @@ +# +# 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 storage::bdt::multistak::snmp::mode::components::device; + +use strict; +use warnings; + +my $map_health = { + 1 => 'unknown', 2 => 'ok', 3 => 'warning', 4 => 'critical' +}; + +my $mapping = { + health => { oid => '.1.3.6.1.4.1.20884.2.3', map => $map_health } # bdtDeviceStatHealth +}; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $mapping->{health}->{oid} }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => 'checking device'); + $self->{components}->{device} = { name => 'device', total => 0, skip => 0 }; + return if ($self->check_filter(section => 'device')); + + my $instance = 0; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{ $mapping->{health}->{oid} }, instance => $instance); + return if (!defined($result->{health})); + + $self->{components}->{device}->{total}++; + $self->{output}->output_add( + long_msg => sprintf( + "device health status is '%s' [instance: %s]", + $result->{health}, $instance + ) + ); + my $exit = $self->get_severity(label => 'health', section => 'device', instance => $instance, value => $result->{health}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf( + "Device health status is '%s'", + $result->{health} + ) + ); + } +} + +1; diff --git a/storage/bdt/multistak/snmp/mode/components/module.pm b/storage/bdt/multistak/snmp/mode/components/module.pm new file mode 100644 index 000000000..77b945c67 --- /dev/null +++ b/storage/bdt/multistak/snmp/mode/components/module.pm @@ -0,0 +1,100 @@ +# +# 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 storage::bdt::multistak::snmp::mode::components::module; + +use strict; +use warnings; + +my $mapping = { + physical_id => { oid => '.1.3.6.1.4.1.20884.2.4.1.2' }, # bdtDeviceStatModEntryIDPhys + module_status => { oid => '.1.3.6.1.4.1.20884.2.4.1.4' }, # bdtDeviceStatModEntryDPwr1 + board_status => { oid => '.1.3.6.1.4.1.20884.2.4.1.5' }, # bdtDeviceStatModEntryDPwr2 + psu_status => { oid => '.1.3.6.1.4.1.20884.2.4.1.6' } # bdtDeviceStatModEntryPwrSupply +}; +my $oid_module_entry = '.1.3.6.1.4.1.20884.2.4.1'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_module_entry }; +} + +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_module_entry }})) { + next if ($oid !~ /^$mapping->{physical_id}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{ $oid_module_entry }, instance => $instance); + + next if ($self->check_filter(section => 'module', instance => $result->{physical_id})); + $self->{components}->{module}->{total}++; + + $self->{output}->output_add( + long_msg => sprintf( + "module '%s' status is '%s' [board status: %s] [power supply: %s][instance: %s].", + $result->{physical_id}, + $result->{module_status}, + $result->{board_status}, + $result->{psu_status}, + $result->{physical_id} + ) + ); + my $exit = $self->get_severity(label => 'status', section => 'module', instance => $result->{physical_id}, value => $result->{module_status}); + 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->{module_status} + ) + ); + } + + $exit = $self->get_severity(label => 'status', section => 'module.board', instance => $result->{physical_id}, value => $result->{board_status}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf( + "Module '%s' board status is '%s'", + $instance, $result->{board_status} + ) + ); + } + + $exit = $self->get_severity(label => 'status', section => 'module.psu', instance => $result->{physical_id}, value => $result->{psu_status}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf( + "Module '%s' power supply status is '%s'", + $instance, $result->{psu_status} + ) + ); + } + } +} + +1; diff --git a/storage/bdt/multistak/snmp/mode/hardware.pm b/storage/bdt/multistak/snmp/mode/hardware.pm new file mode 100644 index 000000000..9360babe2 --- /dev/null +++ b/storage/bdt/multistak/snmp/mode/hardware.pm @@ -0,0 +1,128 @@ +# +# 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 storage::bdt::multistak::snmp::mode::hardware; + +use base qw(centreon::plugins::templates::hardware); + +use strict; +use warnings; + +sub set_system { + my ($self, %options) = @_; + + $self->{cb_hook1} = 'get_system_information'; + $self->{cb_hook2} = 'snmp_execute'; + + $self->{thresholds} = { + health => [ + ['ok', 'OK'], + ['unknown', 'UNKNOWN'], + ['warning', 'WARNING'], + ['critical', 'CRITICAL'] + ], + status => [ + ['OK', 'OK'], + ['N/A', 'OK'], + ['.*', 'CRITICAL'] + ] + }; + + $self->{components_path} = 'storage::bdt::multistak::snmp::mode::components'; + $self->{components_module} = ['device', 'module']; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, no_performance => 1, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => {}); + + return $self; +} + +sub get_system_information { + my ($self, %options) = @_; + + my $oid_vendor = '.1.3.6.1.4.1.20884.1.1.0'; # bdtDeviceDatVendor + my $oid_product_id = '.1.3.6.1.4.1.20884.1.2.0'; # bdtDeviceDatVendor + my $oid_serial = '.1.3.6.1.4.1.20884.1.3.0'; # bdtDeviceDatSerialNum + my $oid_revision = '.1.3.6.1.4.1.20884.1.4.0'; # bdtDeviceDatSWRevision + my $result = $options{snmp}->get_leef( + oids => [ + $oid_vendor, $oid_product_id, + $oid_serial, $oid_revision + ] + ); + + my $vendor = defined($result->{$oid_vendor}) ? centreon::plugins::misc::trim($result->{$oid_vendor}) : 'unknown'; + my $product_id = defined($result->{$oid_product_id}) ? centreon::plugins::misc::trim($result->{$oid_product_id}) : 'unknown'; + my $serial = defined($result->{$oid_serial}) ? centreon::plugins::misc::trim($result->{$oid_serial}) : 'unknown'; + my $revision = defined($result->{$oid_revision}) ? centreon::plugins::misc::trim($result->{$oid_revision}) : 'unknown'; + $self->{output}->output_add( + long_msg => sprintf( + 'vendor: %s, product: %s, serial: %s, revision: %s', + $vendor, $product_id, $serial, $revision + ) + ); +} + +sub snmp_execute { + my ($self, %options) = @_; + + $self->{snmp} = $options{snmp}; + $self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request}); +} + +1; + +__END__ + +=head1 MODE + +Check hardware. + +=over 8 + +=item B<--component> + +Which component to check (Default: '.*'). +Can be: 'module', 'device'. + +=item B<--filter> + +Exclude some parts (comma seperated list) (Example: --filter=disk --filter=psu) +Can also exclude specific instance: --filter=module,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='module,WARNING,N/A' + +=back + +=cut diff --git a/storage/bdt/multistak/snmp/plugin.pm b/storage/bdt/multistak/snmp/plugin.pm new file mode 100644 index 000000000..f627fa9f9 --- /dev/null +++ b/storage/bdt/multistak/snmp/plugin.pm @@ -0,0 +1,48 @@ +# +# 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 storage::bdt::multistak::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} = '0.1'; + %{$self->{modes}} = ( + 'hardware' => 'storage::bdt::multistak::snmp::mode::hardware' + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check BDT MultiStak in SNMP. + +=cut