From 9ab973478676af3adfc8e41c50faf4eacf03bcde Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Fri, 10 Apr 2020 14:53:05 +0200 Subject: [PATCH] add ibm bladecenter and lenovo flexsystem snmp plugins --- .../ibm/nos}/snmp/mode/components/faultled.pm | 11 +- .../nos}/snmp/mode/components/temperature.pm | 57 +++++---- .../common/ibm/nos}/snmp/mode/cpu.pm | 26 ++-- .../common/ibm/nos}/snmp/mode/disk.pm | 6 +- .../common/ibm/nos}/snmp/mode/environment.pm | 35 ++++-- .../common/ibm/nos}/snmp/mode/memory.pm | 30 ++--- network/ibm/bladecenter/snmp/mode/disk.pm | 104 ---------------- network/ibm/bladecenter/snmp/plugin.pm | 20 ++-- .../snmp/mode/components/faultled.pm | 9 +- .../snmp/mode/components/temperature.pm | 111 +++++++++++------- network/lenovo/flexsystem/snmp/mode/cpu.pm | 94 ++++++++------- .../flexsystem/snmp/mode/environment.pm | 28 ++++- network/lenovo/flexsystem/snmp/mode/memory.pm | 99 ++++++++-------- network/lenovo/flexsystem/snmp/plugin.pm | 16 +-- 14 files changed, 305 insertions(+), 341 deletions(-) rename {network/ibm/bladecenter => centreon/common/ibm/nos}/snmp/mode/components/faultled.pm (90%) rename {network/ibm/bladecenter => centreon/common/ibm/nos}/snmp/mode/components/temperature.pm (55%) rename {network/ibm/bladecenter => centreon/common/ibm/nos}/snmp/mode/cpu.pm (74%) rename {network/lenovo/flexsystem => centreon/common/ibm/nos}/snmp/mode/disk.pm (95%) rename {network/ibm/bladecenter => centreon/common/ibm/nos}/snmp/mode/environment.pm (69%) rename {network/ibm/bladecenter => centreon/common/ibm/nos}/snmp/mode/memory.pm (82%) delete mode 100644 network/ibm/bladecenter/snmp/mode/disk.pm diff --git a/network/ibm/bladecenter/snmp/mode/components/faultled.pm b/centreon/common/ibm/nos/snmp/mode/components/faultled.pm similarity index 90% rename from network/ibm/bladecenter/snmp/mode/components/faultled.pm rename to centreon/common/ibm/nos/snmp/mode/components/faultled.pm index 7fc415513..f77620cb9 100644 --- a/network/ibm/bladecenter/snmp/mode/components/faultled.pm +++ b/centreon/common/ibm/nos/snmp/mode/components/faultled.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package network::ibm::bladecenter::snmp::mode::components::faultled; +package centreon::common::ibm::nos::snmp::mode::components::faultled; use strict; use warnings; @@ -31,7 +31,7 @@ sub check_faultled { my ($self, %options) = @_; $self->{components}->{faultled}->{total}++; - + $self->{output}->output_add(long_msg => sprintf( "Fault LED state is %s", @@ -52,13 +52,14 @@ sub check_faultled { sub check { my ($self) = @_; - - $self->{output}->output_add(long_msg => "Checking fault LED"); + + $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); + my $results = $self->{snmp}->get_leef(oids => [$oid_mmspFaultLED]); + return if (!defined($results->{$oid_mmspFaultLED})); check_faultled($self, value => $map_faultled_states{$results->{$oid_mmspFaultLED}}); } diff --git a/network/ibm/bladecenter/snmp/mode/components/temperature.pm b/centreon/common/ibm/nos/snmp/mode/components/temperature.pm similarity index 55% rename from network/ibm/bladecenter/snmp/mode/components/temperature.pm rename to centreon/common/ibm/nos/snmp/mode/components/temperature.pm index 036fc21be..704bf3121 100644 --- a/network/ibm/bladecenter/snmp/mode/components/temperature.pm +++ b/centreon/common/ibm/nos/snmp/mode/components/temperature.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package network::ibm::bladecenter::snmp::mode::components::temperature; +package centreon::common::ibm::nos::snmp::mode::components::temperature; use strict; use warnings; @@ -27,59 +27,70 @@ sub load {} sub check { my ($self) = @_; - - $self->{output}->output_add(long_msg => "Checking temperatures"); + + $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); + my $results = $self->{snmp}->get_leef(oids => [$oid_hwTemperatureWarn, $oid_hwTemperatureShut]); + return if (!defined($results->{$oid_hwTemperatureWarn})); + + my $instance = 'system'; # .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; + my ($temperature, $warning_mib) = ($1, $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; + $temperature = $1 if ($1 > $temperature); + my $critical_mib = ($warning_mib + $2) / 2; $self->{components}->{temperature}->{total}++; - + $self->{output}->output_add(long_msg => sprintf( - "Temperature is %.1f C", - $temperature + "temperature '%s' is %.1f C [instance: %s]", + $instance, + $temperature, + $instance ) ); - my $exit = 'OK'; - if ($temperature >= $warning) { - $exit = 'WARNING'; - } - if ($temperature >= $critical) { - $exit = 'CRITICAL'; + my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, value => $temperature); + if ($checked == 0) { + $self->{perfdata}->threshold_validate(label => 'warning-temperature-instance-' . $instance, value => $warning_mib); + $self->{perfdata}->threshold_validate(label => 'critical-temperature-instance-' . $instance, value => $critical_mib); + $warn = $self->{perfdata}->get_perfdata_for_output(label => 'warning-temperature-instance-' . $instance); + $crit = $self->{perfdata}->get_perfdata_for_output(label => 'critical-temperature-instance-' . $instance); + $exit = $self->{perfdata}->threshold_check( + value => $temperature, + threshold => [ + { label => 'critical-temperature-instance-' . $instance, exit_litteral => 'critical' }, + { label => 'warning-temperature-instance-' . $instance, exit_litteral => 'warning' } + ] + ); } + 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 '%s' is %.1f C", + $instance, $temperature ) ); } $self->{output}->perfdata_add( - label => 'temperature', unit => 'C', + unit => 'C', nlabel => 'hardware.temperature.celsius', instances => 'system', value => $temperature, - warning => $warning, - critical => $critical + warning => $warn, + critical => $crit ); } diff --git a/network/ibm/bladecenter/snmp/mode/cpu.pm b/centreon/common/ibm/nos/snmp/mode/cpu.pm similarity index 74% rename from network/ibm/bladecenter/snmp/mode/cpu.pm rename to centreon/common/ibm/nos/snmp/mode/cpu.pm index ef7893af7..4363afd0b 100644 --- a/network/ibm/bladecenter/snmp/mode/cpu.pm +++ b/centreon/common/ibm/nos/snmp/mode/cpu.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package network::ibm::bladecenter::snmp::mode::cpu; +package centreon::common::ibm::nos::snmp::mode::cpu; use base qw(centreon::plugins::templates::counter); @@ -29,25 +29,25 @@ sub set_counters { my ($self, %options) = @_; $self->{maps_counters_type} = [ - { name => 'cpu', type => 0, skipped_code => { -10 => 1 } }, + { 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 %%', + { label => 'average-1m', nlabel => 'cpu.utilization.1m.percentage', set => { + key_values => [ { name => 'average_1m' } ], + output_template => 'CPU(s) average usage: %.2f %% (1min)', perfdatas => [ - { label => 'total_cpu_avg', value => 'average_absolute', template => '%.2f', - min => 0, max => 100, unit => '%' }, - ], + { value => 'average_1m_absolute', template => '%.2f', + min => 0, max => 100, unit => '%' } + ] } - }, + } ]; } sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; return $self; @@ -60,7 +60,7 @@ sub manage_selection { my $result = $options{snmp}->get_leef(oids => [$oid_mpCpuStatsUtil1Minute], nothing_quit => 1); $self->{cpu} = { - average => $result->{$oid_mpCpuStatsUtil1Minute}, + average_1m => $result->{$oid_mpCpuStatsUtil1Minute} } } @@ -74,11 +74,11 @@ Check CPU usage (over the last minute). =over 8 -=item B<--warning-average> +=item B<--warning-average-1m> Warning threshold average CPU utilization. -=item B<--critical-average> +=item B<--critical-average-1m> Critical threshold average CPU utilization. diff --git a/network/lenovo/flexsystem/snmp/mode/disk.pm b/centreon/common/ibm/nos/snmp/mode/disk.pm similarity index 95% rename from network/lenovo/flexsystem/snmp/mode/disk.pm rename to centreon/common/ibm/nos/snmp/mode/disk.pm index 16ec7a79b..3a08b9161 100644 --- a/network/lenovo/flexsystem/snmp/mode/disk.pm +++ b/centreon/common/ibm/nos/snmp/mode/disk.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package network::lenovo::flexsystem::snmp::mode::disk; +package centreon::common::ibm::nos::snmp::mode::disk; use base qw(snmp_standard::mode::storage); @@ -39,7 +39,7 @@ sub prefix_storage_output { sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; return $self; @@ -51,7 +51,7 @@ __END__ =head1 MODE -Check disk. +Check disks. =over 8 diff --git a/network/ibm/bladecenter/snmp/mode/environment.pm b/centreon/common/ibm/nos/snmp/mode/environment.pm similarity index 69% rename from network/ibm/bladecenter/snmp/mode/environment.pm rename to centreon/common/ibm/nos/snmp/mode/environment.pm index 935e17f2d..c61f15ad4 100644 --- a/network/ibm/bladecenter/snmp/mode/environment.pm +++ b/centreon/common/ibm/nos/snmp/mode/environment.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package network::ibm::bladecenter::snmp::mode::environment; +package centreon::common::ibm::nos::snmp::mode::environment; use base qw(centreon::plugins::templates::hardware); @@ -27,32 +27,33 @@ use warnings; sub set_system { my ($self, %options) = @_; - - $self->{regexp_threshold_overload_check_section_option} = '^(faultled|temperature)$'; + + $self->{regexp_threshold_overload_check_section_option} = '^(faultled)$'; + $self->{regexp_threshold_numeric_check_section_option} = '^(?:temperature)$'; $self->{cb_hook2} = 'snmp_execute'; $self->{thresholds} = { 'faultled' => [ ['on', 'CRITICAL'], - ['off', 'OK'], - ], + ['off', 'OK'] + ] }; - $self->{components_path} = 'network::ibm::bladecenter::snmp::mode::components'; + $self->{components_path} = 'centreon::common::ibm::nos::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); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - + $options{options}->add_options(arguments => { }); @@ -79,6 +80,22 @@ Can be: 'faultled', 'temperature'. 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,status,regexp) +It used before default thresholds (order stays). +Example: --threshold-overload='faulted,WARNING,on' + +=item B<--warning> + +Set warning threshold for temperatures (syntax: type,regexp,threshold) +Example: --warning='temperature,.*,30' + +=item B<--critical> + +Set critical threshold for temperatures (syntax: type,regexp,threshold) +Example: --critical='temperature,.*,40' + =back =cut diff --git a/network/ibm/bladecenter/snmp/mode/memory.pm b/centreon/common/ibm/nos/snmp/mode/memory.pm similarity index 82% rename from network/ibm/bladecenter/snmp/mode/memory.pm rename to centreon/common/ibm/nos/snmp/mode/memory.pm index 35c2279bd..fe9559cbc 100644 --- a/network/ibm/bladecenter/snmp/mode/memory.pm +++ b/centreon/common/ibm/nos/snmp/mode/memory.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package network::ibm::bladecenter::snmp::mode::memory; +package centreon::common::ibm::nos::snmp::mode::memory; use base qw(centreon::plugins::templates::counter); @@ -42,7 +42,7 @@ sub set_counters { my ($self, %options) = @_; $self->{maps_counters_type} = [ - { name => 'memory', type => 0, skipped_code => { -10 => 1 } }, + { name => 'memory', type => 0, skipped_code => { -10 => 1 } } ]; $self->{maps_counters}->{memory} = [ @@ -50,35 +50,35 @@ sub set_counters { 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 }, - ], + { 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 }, - ], + { 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 %%', + output_template => 'Ram Used : %.2f %%', perfdatas => [ - { label => 'used_prct', value => 'prct_used_absolute', template => '%.2f', min => 0, max => 100, - unit => '%' }, - ], + { value => 'prct_used_absolute', template => '%.2f', min => 0, max => 100, + unit => '%' } + ] } - }, + } ]; } sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; return $self; @@ -99,7 +99,7 @@ sub manage_selection { used => $total - $free, free => $free, prct_used => $prct_used, - prct_free => 100 - $prct_used, + prct_free => 100 - $prct_used } } diff --git a/network/ibm/bladecenter/snmp/mode/disk.pm b/network/ibm/bladecenter/snmp/mode/disk.pm deleted file mode 100644 index b8466a931..000000000 --- a/network/ibm/bladecenter/snmp/mode/disk.pm +++ /dev/null @@ -1,104 +0,0 @@ -# -# 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/plugin.pm b/network/ibm/bladecenter/snmp/plugin.pm index 4ec79937b..99f935054 100644 --- a/network/ibm/bladecenter/snmp/plugin.pm +++ b/network/ibm/bladecenter/snmp/plugin.pm @@ -30,16 +30,16 @@ sub new { 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', - ); + $self->{modes} = { + 'cpu' => 'centreon::common::ibm::nos::snmp::mode::cpu', + 'disk' => 'centreon::common::ibm::nos::snmp::mode::disk', + 'environment' => 'centreon::common::ibm::nos::snmp::mode::environment', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'memory' => 'centreon::common::ibm::nos::snmp::mode::memory', + 'time' => 'snmp_standard::mode::ntp', + 'uptime' => 'snmp_standard::mode::uptime' + }; return $self; } diff --git a/network/lenovo/flexsystem/snmp/mode/components/faultled.pm b/network/lenovo/flexsystem/snmp/mode/components/faultled.pm index b987d1162..d7635308a 100644 --- a/network/lenovo/flexsystem/snmp/mode/components/faultled.pm +++ b/network/lenovo/flexsystem/snmp/mode/components/faultled.pm @@ -31,7 +31,7 @@ sub check_faultled { my ($self, %options) = @_; $self->{components}->{faultled}->{total}++; - + $self->{output}->output_add(long_msg => sprintf( "Fault LED state is %s", @@ -52,13 +52,14 @@ sub check_faultled { sub check { my ($self) = @_; - - $self->{output}->output_add(long_msg => "Checking fault LED"); + + $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.20301.2.5.1.3.10.12.0'; - my $results = $self->{snmp}->get_leef(oids => [$oid_mmspFaultLED], nothing_quit => 1); + my $results = $self->{snmp}->get_leef(oids => [$oid_mmspFaultLED]); + return if (!defined($results->{$oid_mmspFaultLED})); check_faultled($self, value => $map_faultled_states{$results->{$oid_mmspFaultLED}}); } diff --git a/network/lenovo/flexsystem/snmp/mode/components/temperature.pm b/network/lenovo/flexsystem/snmp/mode/components/temperature.pm index 3fb804d38..76bc6ca46 100644 --- a/network/lenovo/flexsystem/snmp/mode/components/temperature.pm +++ b/network/lenovo/flexsystem/snmp/mode/components/temperature.pm @@ -23,64 +23,85 @@ package network::lenovo::flexsystem::snmp::mode::components::temperature; use strict; use warnings; -sub load {} +my $mapping = { + hwInfoTemperatureWarn => { oid => '.1.3.6.1.4.1.20301.2.5.1.3.1.41.1.1.20' }, # "44 C (Warning at 66 C / Recover at 61 C)" + hwInfoTemperatureShut => { oid => '.1.3.6.1.4.1.20301.2.5.1.3.1.41.1.1.21' }, # "44 C (Shutdown at 72 C / Recover at 67 C)" +}; +my $oid_hwInfoTableEntry = '.1.3.6.1.4.1.20301.2.5.1.3.1.41.1.1'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { + oid => $oid_hwInfoTableEntry, + start => $mapping->{hwInfoTemperatureWarn}->{oid}, + end => $mapping->{hwInfoTemperatureShut}->{oid} + }; +} sub check { my ($self) = @_; - - $self->{output}->output_add(long_msg => "Checking temperatures"); + + $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.20301.2.5.1.3.1.22.0'; - my $oid_hwTemperatureShut = '.1.3.6.1.4.1.20301.2.5.1.3.1.23.0'; - my $results = $self->{snmp}->get_leef(oids => [$oid_hwTemperatureWarn, $oid_hwTemperatureShut], nothing_quit => 1); + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_hwInfoTableEntry}})) { + next if ($oid !~ /^$mapping->{hwInfoTemperatureShut}->{oid}\.(\d+)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_hwInfoTableEntry}, instance => $instance); - # .1.3.6.1.4.1.20301.2.5.1.3.1.41.1.1.20.1 = STRING: "44 C (Warning 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; + next if ($self->check_filter(section => 'temperature', instance => $instance)); + $self->{components}->{temperature}->{total}++; - $self->{components}->{temperature}->{total}++; - - $self->{output}->output_add(long_msg => - sprintf( - "Temperature is %.1f C", - $temperature - ) - ); + $result->{hwInfoTemperatureWarn} =~ /^([.0-9]+)\s*C\s*\(Warn(?:ing)?\s*at\s*([.0-9]+)\s*C/i; + my ($temperature, $warning_mib) = ($1, $2); + $result->{hwInfoTemperatureShut} =~ /^([.0-9]+)\s*C\s*\(Shutdown\s*at\s*([.0-9]+)\s*C/i; + $temperature = $1 if ($1 > $temperature); + my $critical_mib = ($warning_mib + $2) / 2; - 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 + long_msg => sprintf( + "temperature switch '%s' is %s C [instance: %s]", + $instance, + $temperature, + $instance ) ); - } - $self->{output}->perfdata_add( - label => 'temperature', unit => 'C', - nlabel => 'hardware.temperature.celsius', - instances => 'system', - value => $temperature, - warning => $warning, - critical => $critical - ); + my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, value => $temperature); + if ($checked == 0) { + $self->{perfdata}->threshold_validate(label => 'warning-temperature-instance-' . $instance, value => $warning_mib); + $self->{perfdata}->threshold_validate(label => 'critical-temperature-instance-' . $instance, value => $critical_mib); + $warn = $self->{perfdata}->get_perfdata_for_output(label => 'warning-temperature-instance-' . $instance); + $crit = $self->{perfdata}->get_perfdata_for_output(label => 'critical-temperature-instance-' . $instance); + $exit = $self->{perfdata}->threshold_check( + value => $temperature, + threshold => [ + { label => 'critical-temperature-instance-' . $instance, exit_litteral => 'critical' }, + { label => 'warning-temperature-instance-' . $instance, exit_litteral => 'warning' } + ] + ); + } + + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf( + "temperature switch '%s' is %s C", + $instance, + $temperature + ) + ); + } + $self->{output}->perfdata_add( + nlabel => 'hardware.temperature.celsius', unit => 'C', + instances => 'switch=' . $instance, + value => $temperature, + warning => $warn, + critical => $crit + ); + } } 1; diff --git a/network/lenovo/flexsystem/snmp/mode/cpu.pm b/network/lenovo/flexsystem/snmp/mode/cpu.pm index c17707bcb..c297f0eb3 100644 --- a/network/lenovo/flexsystem/snmp/mode/cpu.pm +++ b/network/lenovo/flexsystem/snmp/mode/cpu.pm @@ -29,73 +29,80 @@ sub set_counters { my ($self, %options) = @_; $self->{maps_counters_type} = [ - { name => 'cpu', type => 1, cb_prefix_output => 'prefix_message_output', message_multiple => 'All CPU usages are ok' }, + { name => 'cpu', type => 1, cb_prefix_output => 'prefix_message_output', message_multiple => 'All CPU usages are ok' } ]; $self->{maps_counters}->{cpu} = [ - { label => 'average', nlabel => 'cpu.utilization.percentage', set => { - key_values => [ { name => 'average' }, { name => 'display' } ], - output_template => '%.2f %%', + { label => 'average-1min', nlabel => 'switch.cpu.utilization.1min.percentage', set => { + key_values => [ { name => 'average_1min' }, { name => 'display' } ], + output_template => '%.2f %% (1min)', perfdatas => [ - { label => 'total_cpu_avg', value => 'average_absolute', template => '%.2f', - min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'display_absolute' }, - ], + { value => 'average_1min_absolute', template => '%.2f', + min => 0, max => 100, unit => '%', label_extra_instance => 1 } + ] } }, + { label => 'average-5min', nlabel => 'switch.cpu.utilization.5min.percentage', set => { + key_values => [ { name => 'average_5min' }, { name => 'display' } ], + output_template => '%.2f %% (5min)', + perfdatas => [ + { value => 'average_5min_absolute', template => '%.2f', + min => 0, max => 100, unit => '%', label_extra_instance => 1 } + ] + } + } ]; } sub prefix_message_output { my ($self, %options) = @_; - return "Switch '" . $options{instance_value}->{display} . "' "; + return "Switch '" . $options{instance_value}->{display} . "' CPU average usage: "; } sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; $options{options}->add_options(arguments => { - 'filter:s' => { name => 'filter', default => '.*' } + 'filter-switch-num:s' => { name => 'filter_switch_num' } }); return $self; } +my $mapping = { + average_1min => { oid => '.1.3.6.1.4.1.20301.2.5.1.2.2.12.1.1.5' }, # mpCpuStatsUtil1MinuteSwRev + average_5min => { oid => '.1.3.6.1.4.1.20301.2.5.1.2.2.12.1.1.6' } # mpCpuStatsUtil5MinutesSwRev +}; + +my $oid_mpCpuStatsRevTableEntry = '.1.3.6.1.4.1.20301.2.5.1.2.2.12.1.1'; + sub manage_selection { my ($self, %options) = @_; - my $oid_mpCpuSwitchNumberRev = '.1.3.6.1.4.1.20301.2.5.1.2.2.12.1.1.1'; - my $oid_mpCpuStatsUtil1MinuteSwRev = '.1.3.6.1.4.1.20301.2.5.1.2.2.12.1.1.5'; - - my $result = $options{snmp}->get_table(oid => $oid_mpCpuSwitchNumberRev, nothing_quit => 1); - my @instance_oids = (); - foreach my $oid (keys %$result) { - if ($result->{$oid} =~ /$self->{option_results}->{filter}/i) { - push @instance_oids, $oid; - } - } - - if (scalar(@instance_oids) == 0) { - $self->{output}->add_option_msg(short_msg => "Cannot find switch number '$self->{option_results}->{filter}'."); - $self->{output}->option_exit(); - } - - $options{snmp}->load( - oids => [$oid_mpCpuStatsUtil1MinuteSwRev], - instances => \@instance_oids, - instance_regexp => "^" . $oid_mpCpuSwitchNumberRev . '\.(.+)' + my $snmp_result = $options{snmp}->get_table( + oid => $oid_mpCpuStatsRevTableEntry, + start => $mapping->{average_1min}->{oid}, + nothing_quit => 1 ); - my $result2 = $options{snmp}->get_leef(); - foreach my $instance (@instance_oids) { - $instance =~ /^$oid_mpCpuSwitchNumberRev\.(.+)/; - $instance = $1; - + $self->{cpu} = {}; + foreach my $oid (keys %$snmp_result) { + next if ($oid !~ /^$mapping->{average_1min}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); + + if (defined($self->{option_results}->{filter_switch_num}) && $self->{option_results}->{filter_switch_num} ne '' && + $instance !~ /$self->{option_results}->{filter_switch_num}/) { + $self->{output}->output_add(long_msg => "skipping member '" . $instance . "': no matching filter.", debug => 1); + next; + } + $self->{cpu}->{$instance} = { - display => $result->{$oid_mpCpuSwitchNumberRev . '.' . $instance}, - average => $result2->{$oid_mpCpuStatsUtil1MinuteSwRev . '.' . $instance}, + display => $instance, + %$result }; } } @@ -110,17 +117,14 @@ Check CPU usage (over the last minute). =over 8 -=item B<--filter> +=item B<--filter-switch-num> -Filter switch number (Default: '.*'). +Filter switch number. -=item B<--warning-average> +=item B<--warning-*> B<--critical-*> -Warning threshold average CPU utilization. - -=item B<--critical-average> - -Critical threshold average CPU utilization. +Thresholds. +Can be: 'average-1min' (%), 'average-5min' (%). =back diff --git a/network/lenovo/flexsystem/snmp/mode/environment.pm b/network/lenovo/flexsystem/snmp/mode/environment.pm index 632d32a71..ff39352e7 100644 --- a/network/lenovo/flexsystem/snmp/mode/environment.pm +++ b/network/lenovo/flexsystem/snmp/mode/environment.pm @@ -27,15 +27,16 @@ use warnings; sub set_system { my ($self, %options) = @_; - - $self->{regexp_threshold_overload_check_section_option} = '^(faultled|temperature)$'; + + $self->{regexp_threshold_overload_check_section_option} = '^(?:faultled)$'; + $self->{regexp_threshold_numeric_check_section_option} = '^(?:temperature)$'; $self->{cb_hook2} = 'snmp_execute'; $self->{thresholds} = { 'faultled' => [ ['on', 'CRITICAL'], - ['off', 'OK'], - ], + ['off', 'OK'] + ] }; $self->{components_path} = 'network::lenovo::flexsystem::snmp::mode::components'; @@ -46,11 +47,12 @@ 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); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; $options{options}->add_options(arguments => { @@ -79,6 +81,22 @@ Can be: 'faultled', 'temperature'. 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,status,regexp) +It used before default thresholds (order stays). +Example: --threshold-overload='faulted,WARNING,on' + +=item B<--warning> + +Set warning threshold for temperatures (syntax: type,regexp,threshold) +Example: --warning='temperature,.*,30' + +=item B<--critical> + +Set critical threshold for temperatures (syntax: type,regexp,threshold) +Example: --critical='temperature,.*,40' + =back =cut diff --git a/network/lenovo/flexsystem/snmp/mode/memory.pm b/network/lenovo/flexsystem/snmp/mode/memory.pm index 232a2c98e..c3eae2c60 100644 --- a/network/lenovo/flexsystem/snmp/mode/memory.pm +++ b/network/lenovo/flexsystem/snmp/mode/memory.pm @@ -46,33 +46,33 @@ sub set_counters { ]; $self->{maps_counters}->{memory} = [ - { label => 'usage', nlabel => 'memory.usage.bytes', set => { + { label => 'usage', nlabel => 'switch.memory.usage.bytes', set => { key_values => [ { name => 'used' }, { name => 'free' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' }, { name => 'display' } ], 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_extra_instance => 1, instance_use => 'display_absolute' }, - ], + { value => 'used_absolute', template => '%d', min => 0, max => 'total_absolute', + unit => 'B', cast_int => 1, label_extra_instance => 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' } ], + { label => 'usage-free', display_ok => 0, nlabel => 'switch.memory.free.bytes', set => { + key_values => [ { name => 'free' }, { name => 'used' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' }, { name => 'display' } ], 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_extra_instance => 1, instance_use => 'display_absolute' }, - ], + { value => 'free_absolute', template => '%d', min => 0, max => 'total_absolute', + unit => 'B', cast_int => 1, label_extra_instance => 1 } + ] } }, - { label => 'usage-prct', display_ok => 0, nlabel => 'memory.usage.percentage', set => { - key_values => [ { name => 'prct_used' } ], - output_template => 'Used : %.2f %%', + { label => 'usage-prct', display_ok => 0, nlabel => 'switch.memory.usage.percentage', set => { + key_values => [ { name => 'prct_used' }, { name => 'display' } ], + output_template => 'Ram Used : %.2f %%', perfdatas => [ - { label => 'used_prct', value => 'prct_used_absolute', template => '%.2f', min => 0, max => 100, - unit => '%', label_extra_instance => 1, instance_use => 'display_absolute' }, - ], + { value => 'prct_used_absolute', template => '%.2f', min => 0, max => 100, + unit => '%', label_extra_instance => 1 } + ] } - }, + } ]; } @@ -84,57 +84,52 @@ sub prefix_message_output { sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; $options{options}->add_options(arguments => { - 'filter:s' => { name => 'filter', default => '.*' } + 'filter-switch-num:s' => { name => 'filter_switch_num' } }); return $self; } +my $mapping = { + total => { oid => '.1.3.6.1.4.1.20301.2.5.1.2.12.9.1.1.3' }, # totalMemoryStatsRev + free => { oid => '.1.3.6.1.4.1.20301.2.5.1.2.12.9.1.1.4' } # memoryFreeStatsRev +}; + +my $oid_memoryStatsEntry = '.1.3.6.1.4.1.20301.2.5.1.2.12.9.1.1'; + sub manage_selection { my ($self, %options) = @_; - my $oid_switchNumber = '.1.3.6.1.4.1.20301.2.5.1.2.12.9.1.1.1'; - my $oid_totalMemoryStatsRev = '.1.3.6.1.4.1.20301.2.5.1.2.12.9.1.1.3'; # in bytes - my $oid_memoryFreeStatsRev = '.1.3.6.1.4.1.20301.2.5.1.2.12.9.1.1.4'; # in bytes - - my $result = $options{snmp}->get_table(oid => $oid_switchNumber, nothing_quit => 1); - my @instance_oids = (); - foreach my $oid (keys %$result) { - if ($result->{$oid} =~ /$self->{option_results}->{filter}/i) { - push @instance_oids, $oid; - } - } - - if (scalar(@instance_oids) == 0) { - $self->{output}->add_option_msg(short_msg => "Cannot find switch number '$self->{option_results}->{filter}'."); - $self->{output}->option_exit(); - } - - $options{snmp}->load( - oids => [$oid_totalMemoryStatsRev, $oid_memoryFreeStatsRev], - instances => \@instance_oids, - instance_regexp => "^" . $oid_switchNumber . '\.(.+)' + my $snmp_result = $options{snmp}->get_table( + oid => $oid_memoryStatsEntry, + start => $mapping->{total}->{oid}, + end => $mapping->{free}->{oid}, + nothing_quit => 1 ); - my $result2 = $options{snmp}->get_leef(); - foreach my $instance (@instance_oids) { - $instance =~ /^$oid_switchNumber\.(.+)/; - $instance = $1; + $self->{memory} = {}; + foreach my $oid (keys %$snmp_result) { + next if ($oid !~ /^$mapping->{free}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); - my $free = $result2->{$oid_memoryFreeStatsRev . '.' . $instance}; - my $total = $result2->{$oid_totalMemoryStatsRev . '.' . $instance}; - my $prct_used = ($total - $free) * 100 / $total; + if (defined($self->{option_results}->{filter_switch_num}) && $self->{option_results}->{filter_switch_num} ne '' && + $instance !~ /$self->{option_results}->{filter_switch_num}/) { + $self->{output}->output_add(long_msg => "skipping member '" . $instance . "': no matching filter.", debug => 1); + next; + } + + my $prct_used = ($result->{total} - $result->{free}) * 100 / $result->{total}; $self->{memory}->{$instance} = { - display => $result->{$oid_switchNumber . '.' . $instance}, - total => $total, - used => $total - $free, - free => $free, + display => $instance, prct_used => $prct_used, prct_free => 100 - $prct_used, + used => $result->{total} - $result->{free}, + %$result }; } } @@ -149,9 +144,9 @@ Check memory usage. =over 8 -=item B<--filter> +=item B<--filter-switch-num> -Filter switch number (Default: '.*'). +Filter switch number. =item B<--warning-*> B<--critical-*> diff --git a/network/lenovo/flexsystem/snmp/plugin.pm b/network/lenovo/flexsystem/snmp/plugin.pm index 15dfa65b6..e8a4cbf1b 100644 --- a/network/lenovo/flexsystem/snmp/plugin.pm +++ b/network/lenovo/flexsystem/snmp/plugin.pm @@ -31,14 +31,14 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'cpu' => 'network::lenovo::flexsystem::snmp::mode::cpu', - 'disk' => 'network::lenovo::flexsystem::snmp::mode::disk', - 'environment' => 'network::lenovo::flexsystem::snmp::mode::environment', - 'interfaces' => 'snmp_standard::mode::interfaces', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - 'memory' => 'network::lenovo::flexsystem::snmp::mode::memory', - 'time' => 'snmp_standard::mode::ntp', - 'uptime' => 'snmp_standard::mode::uptime', + 'cpu' => 'network::lenovo::flexsystem::snmp::mode::cpu', + 'disk' => 'centreon::common::ibm::nos::snmp::mode::disk', + 'environment' => 'network::lenovo::flexsystem::snmp::mode::environment', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'memory' => 'network::lenovo::flexsystem::snmp::mode::memory', + 'time' => 'snmp_standard::mode::ntp', + 'uptime' => 'snmp_standard::mode::uptime', ); return $self;