From 87676efcee9009ede662ce776894ead690aa616a Mon Sep 17 00:00:00 2001 From: qgarnier Date: Wed, 28 Jun 2017 10:51:33 +0200 Subject: [PATCH] optimize qsan request --- .../qsan/nas/snmp/mode/components/fan.pm | 27 ++++++----- .../qsan/nas/snmp/mode/components/psu.pm | 26 +++++----- .../nas/snmp/mode/components/resources.pm | 47 +++++++++++++++++++ .../nas/snmp/mode/components/temperature.pm | 26 +++++----- .../qsan/nas/snmp/mode/components/voltage.pm | 26 +++++----- .../storage/qsan/nas/snmp/mode/hardware.pm | 8 +++- 6 files changed, 106 insertions(+), 54 deletions(-) create mode 100644 centreon-plugins/storage/qsan/nas/snmp/mode/components/resources.pm diff --git a/centreon-plugins/storage/qsan/nas/snmp/mode/components/fan.pm b/centreon-plugins/storage/qsan/nas/snmp/mode/components/fan.pm index f6402ee30..b36a959d5 100644 --- a/centreon-plugins/storage/qsan/nas/snmp/mode/components/fan.pm +++ b/centreon-plugins/storage/qsan/nas/snmp/mode/components/fan.pm @@ -22,16 +22,16 @@ package storage::qsan::nas::snmp::mode::components::fan; use strict; use warnings; +use storage::qsan::nas::snmp::mode::components::resources qw($mapping); -my $mapping = { - ems_type => { oid => '.1.3.6.1.4.1.22274.2.3.2.1.2' }, - ems_item => { oid => '.1.3.6.1.4.1.22274.2.3.2.1.3' }, - ems_value => { oid => '.1.3.6.1.4.1.22274.2.3.2.1.4' }, - ems_status => { oid => '.1.3.6.1.4.1.22274.2.3.2.1.5' }, -}; -my $oid_monitorEntry = '.1.3.6.1.4.1.22274.2.3.2.1'; - -sub load {} +sub load { + my ($self) = @_; + + if ($self->{monitor_loaded} == 0) { + storage::qsan::nas::snmp::mode::components::resources::load_monitor(request => $self->{request}); + $self->{monitor_loaded} = 1; + } +} sub check { my ($self) = @_; @@ -41,11 +41,12 @@ sub check { return if ($self->check_filter(section => 'fan')); my ($exit, $warn, $crit, $checked); - foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_monitorEntry}})) { + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results_monitor}})) { next if ($oid !~ /^$mapping->{ems_type}->{oid}\.(.*)$/); my $instance = $1; - next if ($self->{results}->{$oid_monitorEntry}->{$oid} !~ /Cooling/i); - my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_monitorEntry}, instance => $instance); + next if ($self->{results_monitor}->{$oid} !~ /Cooling/i); + + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results_monitor}, instance => $instance); next if ($self->check_filter(section => 'fan', instance => $instance)); @@ -76,4 +77,4 @@ sub check { } } -1; \ No newline at end of file +1; diff --git a/centreon-plugins/storage/qsan/nas/snmp/mode/components/psu.pm b/centreon-plugins/storage/qsan/nas/snmp/mode/components/psu.pm index b8f0c663f..c11feb7d8 100644 --- a/centreon-plugins/storage/qsan/nas/snmp/mode/components/psu.pm +++ b/centreon-plugins/storage/qsan/nas/snmp/mode/components/psu.pm @@ -22,16 +22,16 @@ package storage::qsan::nas::snmp::mode::components::psu; use strict; use warnings; +use storage::qsan::nas::snmp::mode::components::resources qw($mapping); -my $mapping = { - ems_type => { oid => '.1.3.6.1.4.1.22274.2.3.2.1.2' }, - ems_item => { oid => '.1.3.6.1.4.1.22274.2.3.2.1.3' }, - ems_value => { oid => '.1.3.6.1.4.1.22274.2.3.2.1.4' }, - ems_status => { oid => '.1.3.6.1.4.1.22274.2.3.2.1.5' }, -}; -my $oid_monitorEntry = '.1.3.6.1.4.1.22274.2.3.2.1'; - -sub load {} +sub load { + my ($self) = @_; + + if ($self->{monitor_loaded} == 0) { + storage::qsan::nas::snmp::mode::components::resources::load_monitor(request => $self->{request}); + $self->{monitor_loaded} = 1; + } +} sub check { my ($self) = @_; @@ -41,12 +41,12 @@ sub check { return if ($self->check_filter(section => 'psu')); my ($exit, $warn, $crit, $checked); - foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_monitorEntry}})) { + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results_monitor}})) { next if ($oid !~ /^$mapping->{ems_type}->{oid}\.(.*)$/); my $instance = $1; - next if ($self->{results}->{$oid_monitorEntry}->{$oid} !~ /Power Supply/i); + next if ($self->{results_monitor}->{$oid} !~ /Power Supply/i); - my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_monitorEntry}, instance => $instance); + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results_monitor}, instance => $instance); next if ($self->check_filter(section => 'psu', instance => $instance)); @@ -61,4 +61,4 @@ sub check { } } -1; \ No newline at end of file +1; diff --git a/centreon-plugins/storage/qsan/nas/snmp/mode/components/resources.pm b/centreon-plugins/storage/qsan/nas/snmp/mode/components/resources.pm new file mode 100644 index 000000000..2e80e1857 --- /dev/null +++ b/centreon-plugins/storage/qsan/nas/snmp/mode/components/resources.pm @@ -0,0 +1,47 @@ +# +# 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 storage::qsan::nas::snmp::mode::components::resources; + +use strict; +use warnings; +use Exporter; + +our $mapping; + +our @ISA = qw(Exporter); +our @EXPORT_OK = qw($mapping); + +$mapping = { + ems_type => { oid => '.1.3.6.1.4.1.22274.2.3.2.1.2' }, + ems_item => { oid => '.1.3.6.1.4.1.22274.2.3.2.1.3' }, + ems_value => { oid => '.1.3.6.1.4.1.22274.2.3.2.1.4' }, + ems_status => { oid => '.1.3.6.1.4.1.22274.2.3.2.1.5' }, +}; + +sub load_monitor { + my (%options) = @_; + + push @{$options{request}}, { oid => $mapping->{ems_type}->{oid} }, + { oid => $mapping->{ems_item}->{oid} }, { oid => $mapping->{ems_value}->{oid} }, + { oid => $mapping->{ems_status}->{oid} }; +} + +1; diff --git a/centreon-plugins/storage/qsan/nas/snmp/mode/components/temperature.pm b/centreon-plugins/storage/qsan/nas/snmp/mode/components/temperature.pm index 73ca93f44..28d3a3ddd 100644 --- a/centreon-plugins/storage/qsan/nas/snmp/mode/components/temperature.pm +++ b/centreon-plugins/storage/qsan/nas/snmp/mode/components/temperature.pm @@ -22,16 +22,16 @@ package storage::qsan::nas::snmp::mode::components::temperature; use strict; use warnings; +use storage::qsan::nas::snmp::mode::components::resources qw($mapping); -my $mapping = { - ems_type => { oid => '.1.3.6.1.4.1.22274.2.3.2.1.2' }, - ems_item => { oid => '.1.3.6.1.4.1.22274.2.3.2.1.3' }, - ems_value => { oid => '.1.3.6.1.4.1.22274.2.3.2.1.4' }, - ems_status => { oid => '.1.3.6.1.4.1.22274.2.3.2.1.5' }, -}; -my $oid_monitorEntry = '.1.3.6.1.4.1.22274.2.3.2.1'; - -sub load {} +sub load { + my ($self) = @_; + + if ($self->{monitor_loaded} == 0) { + storage::qsan::nas::snmp::mode::components::resources::load_monitor(request => $self->{request}); + $self->{monitor_loaded} = 1; + } +} sub check { my ($self) = @_; @@ -41,12 +41,12 @@ sub check { return if ($self->check_filter(section => 'temperature')); my ($exit, $warn, $crit, $checked); - foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_monitorEntry}})) { + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results_monitor}})) { next if ($oid !~ /^$mapping->{ems_type}->{oid}\.(.*)$/); my $instance = $1; - next if ($self->{results}->{$oid_monitorEntry}->{$oid} !~ /Temperature/i); + next if ($self->{results_monitor}->{$oid} !~ /Temperature/i); - my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_monitorEntry}, instance => $instance); + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results_monitor}, instance => $instance); next if ($self->check_filter(section => 'temperature', instance => $instance)); # +72.0 (C) (hyst = +5.0 (C), high = +90.0 (C)) @@ -76,4 +76,4 @@ sub check { } } -1; \ No newline at end of file +1; diff --git a/centreon-plugins/storage/qsan/nas/snmp/mode/components/voltage.pm b/centreon-plugins/storage/qsan/nas/snmp/mode/components/voltage.pm index 042cfe84a..62548693e 100644 --- a/centreon-plugins/storage/qsan/nas/snmp/mode/components/voltage.pm +++ b/centreon-plugins/storage/qsan/nas/snmp/mode/components/voltage.pm @@ -22,16 +22,16 @@ package storage::qsan::nas::snmp::mode::components::voltage; use strict; use warnings; +use storage::qsan::nas::snmp::mode::components::resources qw($mapping); -my $mapping = { - ems_type => { oid => '.1.3.6.1.4.1.22274.2.3.2.1.2' }, - ems_item => { oid => '.1.3.6.1.4.1.22274.2.3.2.1.3' }, - ems_value => { oid => '.1.3.6.1.4.1.22274.2.3.2.1.4' }, - ems_status => { oid => '.1.3.6.1.4.1.22274.2.3.2.1.5' }, -}; -my $oid_monitorEntry = '.1.3.6.1.4.1.22274.2.3.2.1'; - -sub load {} +sub load { + my ($self) = @_; + + if ($self->{monitor_loaded} == 0) { + storage::qsan::nas::snmp::mode::components::resources::load_monitor(request => $self->{request}); + $self->{monitor_loaded} = 1; + } +} sub check { my ($self) = @_; @@ -41,12 +41,12 @@ sub check { return if ($self->check_filter(section => 'voltage')); my ($exit, $warn, $crit, $checked); - foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_monitorEntry}})) { + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results_monitor}})) { next if ($oid !~ /^$mapping->{ems_type}->{oid}\.(.*)$/); my $instance = $1; - next if ($self->{results}->{$oid_monitorEntry}->{$oid} !~ /Voltage/i); + next if ($self->{results_monitor}->{$oid} !~ /Voltage/i); - my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_monitorEntry}, instance => $instance); + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results_monitor}, instance => $instance); next if ($self->check_filter(section => 'voltage', instance => $instance)); #+0.99 V (min = +0.75 V, max = +1.35 V) @@ -76,4 +76,4 @@ sub check { } } -1; \ No newline at end of file +1; diff --git a/centreon-plugins/storage/qsan/nas/snmp/mode/hardware.pm b/centreon-plugins/storage/qsan/nas/snmp/mode/hardware.pm index 577343d44..d86c6be6d 100644 --- a/centreon-plugins/storage/qsan/nas/snmp/mode/hardware.pm +++ b/centreon-plugins/storage/qsan/nas/snmp/mode/hardware.pm @@ -24,6 +24,7 @@ use base qw(centreon::plugins::templates::hardware); use strict; use warnings; +use storage::qsan::nas::snmp::mode::components::resources qw($mapping); sub set_system { my ($self, %options) = @_; @@ -45,6 +46,7 @@ sub set_system { ], }; + $self->{monitor_loaded} = 0; $self->{components_path} = 'storage::qsan::nas::snmp::mode::components'; $self->{components_module} = ['disk', 'voltage', 'temperature', 'psu', 'fan']; } @@ -53,9 +55,11 @@ sub snmp_execute { my ($self, %options) = @_; $self->{snmp} = $options{snmp}; - my $oid_monitorEntry = '.1.3.6.1.4.1.22274.2.3.2.1'; - push @{$self->{request}}, { oid => $oid_monitorEntry }; $self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request}); + if ($self->{monitor_loaded} == 1) { + $self->{results_monitor} = { %{$self->{results}->{$mapping->{ems_type}->{oid}}}, %{$self->{results}->{$mapping->{ems_item}->{oid}}}, + %{$self->{results}->{$mapping->{ems_value}->{oid}}}, %{$self->{results}->{$mapping->{ems_status}->{oid}}} }; + } } sub new {