From c288c8f9636c844c906d3496a4fe2a37ee396952 Mon Sep 17 00:00:00 2001 From: UrBnW <40244829+UrBnW@users.noreply.github.com> Date: Wed, 8 Apr 2020 19:02:30 +0200 Subject: [PATCH] network::ibm::bladecenter new plugin --- .../snmp/mode/components/faultled.pm | 66 ++++++++++ .../snmp/mode/components/temperature.pm | 86 ++++++++++++ network/ibm/bladecenter/snmp/mode/cpu.pm | 87 +++++++++++++ network/ibm/bladecenter/snmp/mode/disk.pm | 104 +++++++++++++++ .../ibm/bladecenter/snmp/mode/environment.pm | 84 ++++++++++++ network/ibm/bladecenter/snmp/mode/memory.pm | 123 ++++++++++++++++++ network/ibm/bladecenter/snmp/plugin.pm | 55 ++++++++ 7 files changed, 605 insertions(+) create mode 100644 network/ibm/bladecenter/snmp/mode/components/faultled.pm create mode 100644 network/ibm/bladecenter/snmp/mode/components/temperature.pm create mode 100644 network/ibm/bladecenter/snmp/mode/cpu.pm create mode 100644 network/ibm/bladecenter/snmp/mode/disk.pm create mode 100644 network/ibm/bladecenter/snmp/mode/environment.pm create mode 100644 network/ibm/bladecenter/snmp/mode/memory.pm create mode 100644 network/ibm/bladecenter/snmp/plugin.pm diff --git a/network/ibm/bladecenter/snmp/mode/components/faultled.pm b/network/ibm/bladecenter/snmp/mode/components/faultled.pm new file mode 100644 index 000000000..7fc415513 --- /dev/null +++ b/network/ibm/bladecenter/snmp/mode/components/faultled.pm @@ -0,0 +1,66 @@ +# +# Copyright 2020 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::ibm::bladecenter::snmp::mode::components::faultled; + +use strict; +use warnings; + +my %map_faultled_states = ( 1 => 'on', 2 => 'off' ); + +sub load {} + +sub check_faultled { + my ($self, %options) = @_; + + $self->{components}->{faultled}->{total}++; + + $self->{output}->output_add(long_msg => + sprintf( + "Fault LED state is %s", + $options{value} + ) + ); + my $exit = $self->get_severity(section => 'faultled', value => $options{value}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf( + "Fault LED state is %s", + $options{value} + ) + ); + } +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking fault LED"); + $self->{components}->{faultled} = { name => 'faultled', total => 0, skip => 0 }; + return if ($self->check_filter(section => 'faultled')); + + my $oid_mmspFaultLED = '.1.3.6.1.4.1.26543.2.5.1.3.10.12.0'; + my $results = $self->{snmp}->get_leef(oids => [$oid_mmspFaultLED], nothing_quit => 1); + + check_faultled($self, value => $map_faultled_states{$results->{$oid_mmspFaultLED}}); +} + +1; diff --git a/network/ibm/bladecenter/snmp/mode/components/temperature.pm b/network/ibm/bladecenter/snmp/mode/components/temperature.pm new file mode 100644 index 000000000..036fc21be --- /dev/null +++ b/network/ibm/bladecenter/snmp/mode/components/temperature.pm @@ -0,0 +1,86 @@ +# +# Copyright 2020 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::ibm::bladecenter::snmp::mode::components::temperature; + +use strict; +use warnings; + +sub load {} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking temperatures"); + $self->{components}->{temperature} = { name => 'temperatures', total => 0, skip => 0 }; + return if ($self->check_filter(section => 'temperature')); + + my $oid_hwTemperatureWarn = '.1.3.6.1.4.1.26543.2.5.1.3.1.22.0'; + my $oid_hwTemperatureShut = '.1.3.6.1.4.1.26543.2.5.1.3.1.23.0'; + my $results = $self->{snmp}->get_leef(oids => [$oid_hwTemperatureWarn, $oid_hwTemperatureShut], nothing_quit => 1); + + # .1.3.6.1.4.1.20301.2.5.1.3.1.41.1.1.20.1 = STRING: "44 C (Warn at 66 C / Recover at 61 C)" + # .1.3.6.1.4.1.20301.2.5.1.3.1.41.1.1.21.1 = STRING: "44 C (Shutdown at 72 C / Recover at 67 C)" + $results->{$oid_hwTemperatureWarn} =~ /^([.0-9]+)\s*C\s*\(Warn(?:ing)?\s*at\s*([.0-9]+)\s*C/i; + my $temperature = $1; + my $warning = $2; + $results->{$oid_hwTemperatureShut} =~ /^([.0-9]+)\s*C\s*\(Shutdown\s*at\s*([.0-9]+)\s*C/i; + if ($1 > $temperature) { + $temperature = $1; + } + my $critical = ($warning + $2) / 2; + + $self->{components}->{temperature}->{total}++; + + $self->{output}->output_add(long_msg => + sprintf( + "Temperature is %.1f C", + $temperature + ) + ); + + my $exit = 'OK'; + if ($temperature >= $warning) { + $exit = 'WARNING'; + } + if ($temperature >= $critical) { + $exit = 'CRITICAL'; + } + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf( + "Temperature is %.1f C", + $temperature + ) + ); + } + + $self->{output}->perfdata_add( + label => 'temperature', unit => 'C', + nlabel => 'hardware.temperature.celsius', + instances => 'system', + value => $temperature, + warning => $warning, + critical => $critical + ); +} + +1; diff --git a/network/ibm/bladecenter/snmp/mode/cpu.pm b/network/ibm/bladecenter/snmp/mode/cpu.pm new file mode 100644 index 000000000..ef7893af7 --- /dev/null +++ b/network/ibm/bladecenter/snmp/mode/cpu.pm @@ -0,0 +1,87 @@ +# +# Copyright 2020 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::ibm::bladecenter::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 => 'cpu', type => 0, skipped_code => { -10 => 1 } }, + ]; + + $self->{maps_counters}->{cpu} = [ + { label => 'average', nlabel => 'cpu.utilization.percentage', set => { + key_values => [ { name => 'average' } ], + output_template => '%.2f %%', + perfdatas => [ + { label => 'total_cpu_avg', value => 'average_absolute', template => '%.2f', + min => 0, max => 100, unit => '%' }, + ], + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + return $self; +} + +sub manage_selection { + my ($self, %options) = @_; + + my $oid_mpCpuStatsUtil1Minute = '.1.3.6.1.4.1.26543.2.5.1.2.2.3.0'; + my $result = $options{snmp}->get_leef(oids => [$oid_mpCpuStatsUtil1Minute], nothing_quit => 1); + + $self->{cpu} = { + average => $result->{$oid_mpCpuStatsUtil1Minute}, + } +} + +1; + +__END__ + +=head1 MODE + +Check CPU usage (over the last minute). + +=over 8 + +=item B<--warning-average> + +Warning threshold average CPU utilization. + +=item B<--critical-average> + +Critical threshold average CPU utilization. + +=back + +=cut diff --git a/network/ibm/bladecenter/snmp/mode/disk.pm b/network/ibm/bladecenter/snmp/mode/disk.pm new file mode 100644 index 000000000..b8466a931 --- /dev/null +++ b/network/ibm/bladecenter/snmp/mode/disk.pm @@ -0,0 +1,104 @@ +# +# Copyright 2020 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::ibm::bladecenter::snmp::mode::disk; + +use base qw(snmp_standard::mode::storage); + +use strict; +use warnings; + +sub default_storage_type { + my ($self, %options) = @_; + + return '^(?!(hrStorageRam)$)'; +} + +sub prefix_storage_output { + my ($self, %options) = @_; + + return "Disk '" . $options{instance_value}->{display} . "' "; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + return $self; +} + +1; + +__END__ + +=head1 MODE + +Check disk. + +=over 8 + +=item B<--warning-usage> + +Threshold warning. + +=item B<--critical-usage> + +Threshold critical. + +=item B<--units> + +Units of thresholds (Default: '%') ('%', 'B'). + +=item B<--free> + +Thresholds are on free space left. + +=item B<--storage> + +Set the storage (number expected) ex: 1, 2,... (empty means 'check all storage'). + +=item B<--name> + +Allows to use storage name with option --storage instead of storage oid index. + +=item B<--regexp> + +Allows to use regexp to filter storage (with option --name). + +=item B<--regexp-isensitive> + +Allows to use regexp non case-sensitive (with --regexp). + +=item B<--reload-cache-time> + +Time in minutes before reloading cache file (default: 180). + +=item B<--show-cache> + +Display cache storage datas. + +=item B<--filter-storage-type> + +Filter storage types with a regexp (Default: '^(?!(hrStorageRam)$)'). + +=back + +=cut diff --git a/network/ibm/bladecenter/snmp/mode/environment.pm b/network/ibm/bladecenter/snmp/mode/environment.pm new file mode 100644 index 000000000..935e17f2d --- /dev/null +++ b/network/ibm/bladecenter/snmp/mode/environment.pm @@ -0,0 +1,84 @@ +# +# Copyright 2020 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::ibm::bladecenter::snmp::mode::environment; + +use base qw(centreon::plugins::templates::hardware); + +use strict; +use warnings; + +sub set_system { + my ($self, %options) = @_; + + $self->{regexp_threshold_overload_check_section_option} = '^(faultled|temperature)$'; + + $self->{cb_hook2} = 'snmp_execute'; + $self->{thresholds} = { + 'faultled' => [ + ['on', 'CRITICAL'], + ['off', 'OK'], + ], + }; + + $self->{components_path} = 'network::ibm::bladecenter::snmp::mode::components'; + $self->{components_module} = ['faultled', 'temperature']; +} + +sub snmp_execute { + my ($self, %options) = @_; + + $self->{snmp} = $options{snmp}; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $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: 'faultled', 'temperature'. + +=item B<--no-component> + +Return an error if no compenents are checked. +If total (with skipped) is 0. (Default: 'critical' returns). + +=back + +=cut diff --git a/network/ibm/bladecenter/snmp/mode/memory.pm b/network/ibm/bladecenter/snmp/mode/memory.pm new file mode 100644 index 000000000..35c2279bd --- /dev/null +++ b/network/ibm/bladecenter/snmp/mode/memory.pm @@ -0,0 +1,123 @@ +# +# Copyright 2020 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::ibm::bladecenter::snmp::mode::memory; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +sub custom_usage_output { + my ($self, %options) = @_; + + return sprintf( + 'Ram Total: %s %s Used: %s %s (%.2f%%) Free: %s %s (%.2f%%)', + $self->{perfdata}->change_bytes(value => $self->{result_values}->{total_absolute}), + $self->{perfdata}->change_bytes(value => $self->{result_values}->{used_absolute}), + $self->{result_values}->{prct_used_absolute}, + $self->{perfdata}->change_bytes(value => $self->{result_values}->{free_absolute}), + $self->{result_values}->{prct_free_absolute} + ); +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'memory', type => 0, skipped_code => { -10 => 1 } }, + ]; + + $self->{maps_counters}->{memory} = [ + { label => 'usage', nlabel => 'memory.usage.bytes', set => { + key_values => [ { name => 'used' }, { name => 'free' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ], + closure_custom_output => $self->can('custom_usage_output'), + perfdatas => [ + { label => 'used', value => 'used_absolute', template => '%d', min => 0, max => 'total_absolute', + unit => 'B', cast_int => 1 }, + ], + } + }, + { label => 'usage-free', display_ok => 0, nlabel => 'memory.free.bytes', set => { + key_values => [ { name => 'free' }, { name => 'used' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ], + closure_custom_output => $self->can('custom_usage_output'), + perfdatas => [ + { label => 'free', value => 'free_absolute', template => '%d', min => 0, max => 'total_absolute', + unit => 'B', cast_int => 1 }, + ], + } + }, + { label => 'usage-prct', display_ok => 0, nlabel => 'memory.usage.percentage', set => { + key_values => [ { name => 'prct_used' } ], + output_template => 'Used : %.2f %%', + perfdatas => [ + { label => 'used_prct', value => 'prct_used_absolute', template => '%.2f', min => 0, max => 100, + unit => '%' }, + ], + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + return $self; +} + +sub manage_selection { + my ($self, %options) = @_; + + my $oid_totalMemoryStats = '.1.3.6.1.4.1.26543.2.5.1.2.12.1.0'; # in bytes + my $oid_memoryFreeStats = '.1.3.6.1.4.1.26543.2.5.1.2.12.2.0'; # in bytes + my $result = $options{snmp}->get_leef(oids => [$oid_totalMemoryStats, $oid_memoryFreeStats], nothing_quit => 1); + + my $free = $result->{$oid_memoryFreeStats}; + my $total = $result->{$oid_totalMemoryStats}; + my $prct_used = ($total - $free) * 100 / $total; + $self->{memory} = { + total => $total, + used => $total - $free, + free => $free, + prct_used => $prct_used, + prct_free => 100 - $prct_used, + } +} + +1; + +__END__ + +=head1 MODE + +Check memory usage. + +=over 8 + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'usage' (B), 'usage-free' (B), 'usage-prct' (%). + +=back + +=cut diff --git a/network/ibm/bladecenter/snmp/plugin.pm b/network/ibm/bladecenter/snmp/plugin.pm new file mode 100644 index 000000000..4ec79937b --- /dev/null +++ b/network/ibm/bladecenter/snmp/plugin.pm @@ -0,0 +1,55 @@ +# +# Copyright 2020 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::ibm::bladecenter::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::ibm::bladecenter::snmp::mode::cpu', + 'disk' => 'network::ibm::bladecenter::snmp::mode::disk', + 'environment' => 'network::ibm::bladecenter::snmp::mode::environment', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'memory' => 'network::ibm::bladecenter::snmp::mode::memory', + 'time' => 'snmp_standard::mode::ntp', + 'uptime' => 'snmp_standard::mode::uptime', + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check IBM BladeCenter switches in SNMP. + +=cut