diff --git a/centreon-plugins/network/hp/procurve/snmp/mode/components/temperature.pm b/centreon-plugins/network/hp/procurve/snmp/mode/components/temperature.pm new file mode 100644 index 000000000..1bad80948 --- /dev/null +++ b/centreon-plugins/network/hp/procurve/snmp/mode/components/temperature.pm @@ -0,0 +1,97 @@ +# +# 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 network::hp::procurve::snmp::mode::components::temperature; + +use strict; +use warnings; + +my $mapping = { + name => { oid => '.1.3.6.1.4.1.11.2.14.11.1.2.8.1.1.2' }, # hpSystemAirName + value => { oid => '.1.3.6.1.4.1.11.2.14.11.1.2.8.1.1.3' }, # hpSystemAirCurrentTemp + threshold => { oid => '.1.3.6.1.4.1.11.2.14.11.1.2.8.1.1.7' } # hpSystemAirThresholdTemp +}; +my $oid_airTempTable = '.1.3.6.1.4.1.11.2.14.11.1.2.8.1'; # hpSystemAirTempTable + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { + oid => $oid_airTempTable, + start => $mapping->{name}->{oid}, + end => $mapping->{threshold}->{oid} + }; +} + +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')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{ $oid_airTempTable }})) { + next if ($oid !~ /^$mapping->{name}->{oid}\.(.*)$/); + my $instance = $1; + + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{ $oid_airTempTable }, instance => $instance); + + next if ($self->check_filter(section => 'temperature', instance => $instance)); + + next if ($result->{value} !~ /^(\d+)C/i); + my $value = $1; + + $self->{components}->{temperature}->{total}++; + $self->{output}->output_add( + long_msg => sprintf( + "temperature '%s' is '%s' celsius [instance: %s]", + $result->{name}, $value, $instance + ) + ); + + my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, value => $value); + if ($checked == 0 && $result->{threshold} =~ /^(\d+)C/i) { + my $crit_th = $1; + $self->{perfdata}->threshold_validate(label => 'critical-temperature-instance-' . $instance, value => $crit_th); + + $crit = $self->{perfdata}->get_perfdata_for_output(label => 'critical-temperature-instance-' . $instance); + } + + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf( + "temperature '%s' is '%s' celsius", $result->{name}, $value + ) + ); + } + + $self->{output}->perfdata_add( + nlabel => 'hardware.temperature.celsius', + unit => 'C', + instances => $result->{name}, + value => $value, + warning => $warn, + critical => $crit + ); + } +} + +1; diff --git a/centreon-plugins/network/hp/procurve/snmp/mode/environment.pm b/centreon-plugins/network/hp/procurve/snmp/mode/environment.pm index e84a41b1a..5d0f73fbb 100644 --- a/centreon-plugins/network/hp/procurve/snmp/mode/environment.pm +++ b/centreon-plugins/network/hp/procurve/snmp/mode/environment.pm @@ -27,16 +27,18 @@ use warnings; sub set_system { my ($self, %options) = @_; - + + $self->{regexp_threshold_numeric_check_section_option} = '^temperature$'; + $self->{cb_hook2} = 'snmp_execute'; - + $self->{thresholds} = { sensor => [ ['unknown', 'UNKNOWN'], ['bad', 'CRITICAL'], ['warning', 'WARNING'], ['good', 'OK'], - ['not present', 'WARNING'], + ['not present', 'OK'] ], psu => [ ['psNotPresent', 'OK'], @@ -47,7 +49,7 @@ sub set_system { ['psMax', 'WARNING'], ['psAuxFailure', 'CRITICAL'], ['psNotPowered', 'WARNING'], - ['psAuxNotPowered', 'CRITICAL'], + ['psAuxNotPowered', 'CRITICAL'] ], fan => [ ['failed', 'CRITICAL'], @@ -56,24 +58,24 @@ sub set_system { ['underspeed', 'WARNING'], ['overspeed', 'WARNING'], ['ok', 'OK'], - ['maxstate', 'WARNING'], - ], + ['maxstate', 'WARNING'] + ] }; - + $self->{components_path} = 'network::hp::procurve::snmp::mode::components'; - $self->{components_module} = ['sensor', 'psu', 'fan']; + $self->{components_module} = ['fan', 'psu', 'sensor', 'temperature']; } 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); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; $options{options}->add_options(arguments => { @@ -95,7 +97,7 @@ Check sensors (hpicfChassis.mib). =item B<--component> Which component to check (Default: '.*'). -Can be: 'sensor', 'psu', 'fan'. +Can be: 'fan', 'psu', 'sensor', 'temperature'. =item B<--filter> @@ -118,7 +120,16 @@ Set to overload default threshold values (syntax: section,[instance,]status,rege It used before default thresholds (order stays). Example: --threshold-overload='sensor,CRITICAL,^(?!(good)$)' +=item B<--warning> + +Set warning threshold for 'temperature' (syntax: type,regexp,threshold) +Example: --warning='temperature,.*,40' + +=item B<--critical> + +Set critical threshold for 'temperature' (syntax: type,regexp,threshold) +Example: --critical='temperature,.*,50' + =back =cut - diff --git a/centreon-plugins/network/hp/procurve/snmp/mode/memory.pm b/centreon-plugins/network/hp/procurve/snmp/mode/memory.pm index 11498de52..128bf13cd 100644 --- a/centreon-plugins/network/hp/procurve/snmp/mode/memory.pm +++ b/centreon-plugins/network/hp/procurve/snmp/mode/memory.pm @@ -30,11 +30,10 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "warning:s" => { name => 'warning' }, - "critical:s" => { name => 'critical' }, - }); + $options{options}->add_options(arguments => { + 'warning:s' => { name => 'warning' } + 'critical:s' => { name => 'critical' } + }); return $self; } @@ -42,14 +41,14 @@ sub new { sub check_options { my ($self, %options) = @_; $self->SUPER::init(%options); - + if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'."); - $self->{output}->option_exit(); + $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'."); + $self->{output}->option_exit(); } if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); - $self->{output}->option_exit(); + $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); + $self->{output}->option_exit(); } } @@ -63,10 +62,12 @@ sub run { my $oid_hpGlobalMemAllocBytes = '.1.3.6.1.4.1.11.2.14.11.5.1.1.2.2.1.1.7'; # in B my $oid_hpGlobalMemFreeBytes = '.1.3.6.1.4.1.11.2.14.11.5.1.1.2.2.1.1.6'; # in B my $result = $self->{snmp}->get_table(oid => $oid_hpGlobalMemEntry, nothing_quit => 1); - - $self->{output}->output_add(severity => 'OK', - short_msg => 'All memories are ok.'); - + + $self->{output}->output_add( + severity => 'OK', + short_msg => 'All memories are ok.' + ); + foreach my $oid (keys %$result) { next if ($oid !~ /^$oid_hpGlobalMemSlotIndex/); $oid =~ /\.([0-9]+)$/; @@ -82,23 +83,33 @@ sub run { my ($used_value, $used_unit) = $self->{perfdata}->change_bytes(value => $memory_used); my ($free_value, $free_unit) = $self->{perfdata}->change_bytes(value => $memory_free); - $self->{output}->output_add(long_msg => sprintf("Memory '%s' Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", $instance, - $total_value . " " . $total_unit, - $used_value . " " . $used_unit, $prct_used, - $free_value . " " . $free_unit, $prct_free)); + $self->{output}->output_add( + long_msg => sprintf( + "Memory '%s' Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", $instance, + $total_value . " " . $total_unit, + $used_value . " " . $used_unit, $prct_used, + $free_value . " " . $free_unit, $prct_free + ) + ); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Memory '%s' Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", $instance, - $total_value . " " . $total_unit, - $used_value . " " . $used_unit, $prct_used, - $free_value . " " . $free_unit, $prct_free)); + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf( + "Memory '%s' Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", $instance, + $total_value . " " . $total_unit, + $used_value . " " . $used_unit, $prct_used, + $free_value . " " . $free_unit, $prct_free + ) + ); } - $self->{output}->perfdata_add(label => "used_" . $instance, unit => 'B', - value => $memory_used, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning', total => $total_size), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical', total => $total_size), - min => 0, max => $total_size); + $self->{output}->perfdata_add( + label => "used_" . $instance, unit => 'B', + value => $memory_used, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning', total => $total_size), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical', total => $total_size), + min => 0, max => $total_size + ); } $self->{output}->display(); diff --git a/centreon-plugins/network/hp/procurve/snmp/mode/virtualchassis.pm b/centreon-plugins/network/hp/procurve/snmp/mode/virtualchassis.pm index 5a1a16d1b..0dfcc8fe0 100644 --- a/centreon-plugins/network/hp/procurve/snmp/mode/virtualchassis.pm +++ b/centreon-plugins/network/hp/procurve/snmp/mode/virtualchassis.pm @@ -76,7 +76,8 @@ sub custom_memory_usage_output { my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total}); my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used}); my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free}); - my $msg = sprintf("memory usage total: %s used: %s (%.2f%%) free: %s (%.2f%%)", + my $msg = sprintf( + "memory usage total: %s used: %s (%.2f%%) free: %s (%.2f%%)", $total_size_value . " " . $total_size_unit, $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used}, $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free} @@ -103,17 +104,17 @@ sub set_counters { closure_custom_calc => \&catalog_status_calc, closure_custom_output => $self->can('custom_status_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold, + closure_custom_threshold_check => \&catalog_status_threshold } }, { label => 'members-total', nlabel => 'stack.members.total.count', set => { - key_values => [ { name => 'members'} ], + key_values => [ { name => 'members' } ], output_template => 'total members: %s', perfdatas => [ - { value => 'members', template => '%s', min => 0 }, - ], + { template => '%s', min => 0 } + ] } - }, + } ]; $self->{maps_counters}->{member_global} = [ @@ -122,45 +123,45 @@ sub set_counters { closure_custom_calc => $self->can('custom_member_status_calc'), closure_custom_output => $self->can('custom_member_status_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold, + closure_custom_threshold_check => \&catalog_status_threshold } }, { label => 'cpu-utilization', nlabel => 'member.cpu.utilization.percentage', set => { - key_values => [ { name => 'cpu'}, { name => 'display'} ], + key_values => [ { name => 'cpu' }, { name => 'display'} ], output_template => 'cpu usage: %.2f%%', perfdatas => [ - { value => 'cpu', template => '%.2f', unit => '%', min => 0, max => 100, - label_extra_instance => 1 }, - ], + { template => '%.2f', unit => '%', min => 0, max => 100, + label_extra_instance => 1 } + ] } }, { label => 'memory-usage', nlabel => 'member.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_memory_usage_output'), perfdatas => [ - { value => 'used', template => '%d', min => 0, max => 'total', - unit => 'B', cast_int => 1, label_extra_instance => 1 }, - ], + { template => '%d', min => 0, max => 'total', + unit => 'B', cast_int => 1, label_extra_instance => 1 } + ] } }, { label => 'memory-usage-free', display_ok => 0, nlabel => 'member.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_memory_usage_output'), perfdatas => [ - { value => 'free', template => '%d', min => 0, max => 'total', - unit => 'B', cast_int => 1, label_extra_instance => 1 }, - ], + { template => '%d', min => 0, max => 'total', + unit => 'B', cast_int => 1, label_extra_instance => 1 } + ] } }, { label => 'memory-usage-prct', display_ok => 0, nlabel => 'member.memory.usage.percentage', set => { key_values => [ { name => 'prct_used' }, { name => 'display' } ], output_template => 'memory used : %.2f %%', perfdatas => [ - { value => 'prct_used', template => '%.2f', min => 0, max => 100, - unit => '%', label_extra_instance => 1 }, - ], + { template => '%.2f', min => 0, max => 100, + unit => '%', label_extra_instance => 1 } + ] } - }, + } ]; $self->{maps_counters}->{link} = [ @@ -169,9 +170,9 @@ sub set_counters { closure_custom_calc => \&catalog_status_calc, closure_custom_output => $self->can('custom_link_status_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold, + closure_custom_threshold_check => \&catalog_status_threshold } - }, + } ]; } @@ -247,18 +248,18 @@ my $mapping_link_status = { my $mapping = { hpicfVsfVCOperStatus => { oid => '.1.3.6.1.4.1.11.2.14.11.5.1.116.1.1.2', map => $mapping_oper_status }, - hpicfVsfVCAdminStatus => { oid => '.1.3.6.1.4.1.11.2.14.11.5.1.116.1.1.3', map => $mapping_admin_status }, + hpicfVsfVCAdminStatus => { oid => '.1.3.6.1.4.1.11.2.14.11.5.1.116.1.1.3', map => $mapping_admin_status } }; my $mapping2 = { hpicfVsfVCMemberState => { oid => '.1.3.6.1.4.1.11.2.14.11.5.1.116.1.3.1.9', map => $mapping_member_state }, hpicfVsfVCMemberSerialNum => { oid => '.1.3.6.1.4.1.11.2.14.11.5.1.116.1.3.1.14' }, hpicfVsfVCMemberCpuUtil => { oid => '.1.3.6.1.4.1.11.2.14.11.5.1.116.1.3.1.19' }, hpicfVsfVCMemberTotalMemory => { oid => '.1.3.6.1.4.1.11.2.14.11.5.1.116.1.3.1.20' }, - hpicfVsfVCMemberFreeMemory => { oid => '.1.3.6.1.4.1.11.2.14.11.5.1.116.1.3.1.21' }, + hpicfVsfVCMemberFreeMemory => { oid => '.1.3.6.1.4.1.11.2.14.11.5.1.116.1.3.1.21' } }; my $mapping3 = { hpicfVsfVCLinkName => { oid => '.1.3.6.1.4.1.11.2.14.11.5.1.116.1.4.1.3' }, - hpicfVsfVCLinkOperStatus => { oid => '.1.3.6.1.4.1.11.2.14.11.5.1.116.1.4.1.4', map => $mapping_link_status }, + hpicfVsfVCLinkOperStatus => { oid => '.1.3.6.1.4.1.11.2.14.11.5.1.116.1.4.1.4', map => $mapping_link_status } }; my $oid_hpicfVsfVCConfig = '.1.3.6.1.4.1.11.2.14.11.5.1.116.1.1'; my $oid_hpicfVsfVCMemberEntry = '.1.3.6.1.4.1.11.2.14.11.5.1.116.1.3.1'; @@ -275,7 +276,7 @@ sub manage_selection { ], nothing_quit => 1 ); - + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result->{$oid_hpicfVsfVCConfig}, instance => '0'); if ($result->{hpicfVsfVCAdminStatus} eq 'disable') { $self->{output}->output_add( diff --git a/centreon-plugins/network/hp/procurve/snmp/plugin.pm b/centreon-plugins/network/hp/procurve/snmp/plugin.pm index f646bf8ea..01ba75046 100644 --- a/centreon-plugins/network/hp/procurve/snmp/plugin.pm +++ b/centreon-plugins/network/hp/procurve/snmp/plugin.pm @@ -30,14 +30,14 @@ sub new { bless $self, $class; $self->{version} = '1.0'; - %{$self->{modes}} = ( + $self->{modes} = { 'cpu' => 'network::hp::procurve::snmp::mode::cpu', 'environment' => 'network::hp::procurve::snmp::mode::environment', 'interfaces' => 'snmp_standard::mode::interfaces', 'list-interfaces' => 'snmp_standard::mode::listinterfaces', 'memory' => 'network::hp::procurve::snmp::mode::memory', - 'virtual-chassis' => 'network::hp::procurve::snmp::mode::virtualchassis', - ); + 'virtual-chassis' => 'network::hp::procurve::snmp::mode::virtualchassis' + }; return $self; }