From 50a49e5e77d1bba25d2641b0861113b7411f3d0e Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Tue, 24 Nov 2015 11:51:27 +0100 Subject: [PATCH 01/26] + Enhance cisco standard hardware mode (some cases) --- .../common/cisco/standard/snmp/mode/components/physical.pm | 5 +++++ .../cisco/standard/snmp/mode/components/temperature.pm | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/physical.pm b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/physical.pm index 999930181..2f48c0f48 100644 --- a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/physical.pm +++ b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/physical.pm @@ -56,6 +56,11 @@ sub check { my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_cefcPhysicalStatus}, instance => $instance); my $physical_descr = $self->{results}->{$oid_entPhysicalDescr}->{$oid_entPhysicalDescr . '.' . $instance}; + if (!defined($physical_descr)) { + $self->{output}->output_add(long_msg => sprintf("skipped instance '%s': no description", $instance)); + next; + } + next if ($self->check_exclude(section => 'physical', instance => $instance)); $self->{components}->{physical}->{total}++; diff --git a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/temperature.pm b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/temperature.pm index 833eea2f4..11c143960 100644 --- a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/temperature.pm +++ b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/temperature.pm @@ -64,7 +64,7 @@ sub check { $self->{output}->output_add(long_msg => sprintf("Temperature '%s' status is %s [instance: %s] [value: %s C]", $result->{ciscoEnvMonTemperatureStatusDescr}, $result->{ciscoEnvMonTemperatureState}, - $instance, $result->{ciscoEnvMonTemperatureStatusValue})); + $instance, defined($result->{ciscoEnvMonTemperatureStatusValue}) ? $result->{ciscoEnvMonTemperatureStatusValue} : '-')); my $exit = $self->get_severity(section => 'temperature', value => $result->{ciscoEnvMonTemperatureState}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit, @@ -72,6 +72,8 @@ sub check { $result->{ciscoEnvMonTemperatureStatusDescr}, $result->{ciscoEnvMonTemperatureState})); } + next if (!defined($result->{ciscoEnvMonTemperatureStatusValue})); + my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, value => $result->{ciscoEnvMonTemperatureStatusValue}); if ($checked == 0) { my $warn_th = undef; From 0ddaa817578e1f0f164006dfa2f0d06320952a29 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Tue, 24 Nov 2015 16:41:15 +0100 Subject: [PATCH 02/26] + add code perfdata for cmdreturn linux local mode --- centreon-plugins/os/linux/local/mode/cmdreturn.pm | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/centreon-plugins/os/linux/local/mode/cmdreturn.pm b/centreon-plugins/os/linux/local/mode/cmdreturn.pm index bf16172fe..bff8517c7 100644 --- a/centreon-plugins/os/linux/local/mode/cmdreturn.pm +++ b/centreon-plugins/os/linux/local/mode/cmdreturn.pm @@ -99,6 +99,11 @@ sub run { short_msg => 'Exit code from command'); } + if (defined($exit_code)) { + $self->{output}->perfdata_add(label => "code", + value => $exit_code); + } + $self->{output}->display(); $self->{output}->exit(); } From 81d62a907ebb8ffdd011c7499c8dd18f1d5254fa Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Thu, 26 Nov 2015 14:50:36 +0100 Subject: [PATCH 03/26] + add plugin for dell s-series --- .../force10/snmp/mode/components/fan.pm | 82 +++++ .../force10/snmp/mode/components/psu.pm | 90 +++++ .../snmp/mode/components/temperature.pm | 76 ++++ .../centreon/common/force10/snmp/mode/cpu.pm | 243 +++++++++++++ .../common/force10/snmp/mode/hardware.pm | 338 ++++++++++++++++++ .../common/force10/snmp/mode/memory.pm | 213 +++++++++++ .../network/dell/sseries/snmp/plugin.pm | 53 +++ 7 files changed, 1095 insertions(+) create mode 100644 centreon-plugins/centreon/common/force10/snmp/mode/components/fan.pm create mode 100644 centreon-plugins/centreon/common/force10/snmp/mode/components/psu.pm create mode 100644 centreon-plugins/centreon/common/force10/snmp/mode/components/temperature.pm create mode 100644 centreon-plugins/centreon/common/force10/snmp/mode/cpu.pm create mode 100644 centreon-plugins/centreon/common/force10/snmp/mode/hardware.pm create mode 100644 centreon-plugins/centreon/common/force10/snmp/mode/memory.pm create mode 100644 centreon-plugins/network/dell/sseries/snmp/plugin.pm diff --git a/centreon-plugins/centreon/common/force10/snmp/mode/components/fan.pm b/centreon-plugins/centreon/common/force10/snmp/mode/components/fan.pm new file mode 100644 index 000000000..0f0cc9c0f --- /dev/null +++ b/centreon-plugins/centreon/common/force10/snmp/mode/components/fan.pm @@ -0,0 +1,82 @@ +# +# Copyright 2015 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 centreon::common::force10::snmp::mode::components::fan; + +use strict; +use warnings; + +my %map_status = ( + 1 => 'up', + 2 => 'down', + 3 => 'absent', +); + +my $mapping = { + sseries => { + OperStatus => { oid => '.1.3.6.1.4.1.6027.3.10.1.2.4.1.2', map => \%map_status }, + }, + mseries => { + OperStatus => { oid => '.1.3.6.1.4.1.6027.3.19.1.2.3.1.2', map => \%map_status }, + }, + zseries => { + OperStatus => { oid => '.1.3.6.1.4.1.6027.3.25.1.2.7.1.2', map => \%map_status }, + }, +}; + +sub load { + my (%options) = @_; + + push @{$options{request}}, { oid => $mapping->{sseries}->{OperStatus}->{oid} }, + { oid => $mapping->{mseries}->{OperStatus}->{oid} }, { oid => $mapping->{zseries}->{OperStatus}->{oid} }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking fans"); + $self->{components}->{fan} = {name => 'fans', total => 0, skip => 0}; + return if ($self->check_filter(section => 'fan')); + + foreach my $name (keys %{$mapping}) { + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$mapping->{$name}->{OperStatus}->{oid}}})) { + next if ($oid !~ /^$mapping->{$name}->{OperStatus}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping->{$name}, results => $self->{results}->{$mapping->{$name}->{OperStatus}->{oid}}, instance => $instance); + + next if ($result->{OperStatus} =~ /absent/i && + $self->absent_problem(section => 'fan', instance => $instance)); + next if ($self->check_filter(section => 'fan', instance => $instance)); + $self->{components}->{fan}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("Fan '%s' status is '%s' [instance: %s]", + $instance, $result->{OperStatus}, + $instance)); + my $exit = $self->get_severity(section => 'fan', value => $result->{OperStatus}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Fan '%s' status is %s", + $instance, $result->{OperStatus})); + } + } + } +} + +1; \ No newline at end of file diff --git a/centreon-plugins/centreon/common/force10/snmp/mode/components/psu.pm b/centreon-plugins/centreon/common/force10/snmp/mode/components/psu.pm new file mode 100644 index 000000000..853f25d6f --- /dev/null +++ b/centreon-plugins/centreon/common/force10/snmp/mode/components/psu.pm @@ -0,0 +1,90 @@ +# +# Copyright 2015 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 centreon::common::force10::snmp::mode::components::psu; + +use strict; +use warnings; + +my %map_status = ( + 1 => 'up', + 2 => 'down', + 3 => 'absent', +); +my %map_mstatus = ( + 1 => 'normal', + 2 => 'warning', + 3 => 'critical', + 4 => 'shutdown', + 5 => 'notPresent', + 6 => 'notFunctioning', +); + +my $mapping = { + sseries => { + OperStatus => { oid => '.1.3.6.1.4.1.6027.3.10.1.2.3.1.2', map => \%map_status }, + }, + mseries => { + OperStatus => { oid => '.1.3.6.1.4.1.6027.3.19.1.2.2.1.2', map => \%map_mstatus }, + }, + zseries => { + OperStatus => { oid => '.1.3.6.1.4.1.6027.3.25.1.2.6.1.2', map => \%map_status }, + }, +}; + +sub load { + my (%options) = @_; + + push @{$options{request}}, { oid => $mapping->{sseries}->{OperStatus}->{oid} }, + { oid => $mapping->{mseries}->{OperStatus}->{oid} }, { oid => $mapping->{zseries}->{OperStatus}->{oid} }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking power supplies"); + $self->{components}->{psu} = {name => 'power supplies', total => 0, skip => 0}; + return if ($self->check_filter(section => 'psu')); + + foreach my $name (keys %{$mapping}) { + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$mapping->{$name}->{OperStatus}->{oid}}})) { + next if ($oid !~ /^$mapping->{$name}->{OperStatus}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping->{$name}, results => $self->{results}->{$mapping->{$name}->{OperStatus}->{oid}}, instance => $instance); + + next if ($result->{OperStatus} =~ /absent|notPresent/i && + $self->absent_problem(section => 'psu', instance => $instance)); + next if ($self->check_filter(section => 'psu', instance => $instance)); + $self->{components}->{psu}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("Power supply '%s' status is '%s' [instance: %s]", + $instance, $result->{OperStatus}, + $instance)); + my $exit = $self->get_severity(section => 'psu', value => $result->{OperStatus}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Power supply '%s' status is %s", + $instance, $result->{OperStatus})); + } + } + } +} + +1; \ No newline at end of file diff --git a/centreon-plugins/centreon/common/force10/snmp/mode/components/temperature.pm b/centreon-plugins/centreon/common/force10/snmp/mode/components/temperature.pm new file mode 100644 index 000000000..7e38f45bd --- /dev/null +++ b/centreon-plugins/centreon/common/force10/snmp/mode/components/temperature.pm @@ -0,0 +1,76 @@ +# +# Copyright 2015 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 centreon::common::force10::snmp::mode::components::temperature; + +use strict; +use warnings; + +my $mapping = { + sseries => { + Temp => { oid => '.1.3.6.1.4.1.6027.3.10.1.2.2.1.14' }, + }, + mseries => { + Temp => { oid => '.1.3.6.1.4.1.6027.3.19.1.2.1.1.14' }, + }, +}; +my $oid_deviceSensorValueEntry = '.1.3.6.1.4.1.3417.2.1.1.1.1.1'; + +sub load { + my (%options) = @_; + + push @{$options{request}}, { oid => $mapping->{sseries}->{Temp}->{oid} }, + { oid => $mapping->{mseries}->{Temp}->{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 $name (keys %{$mapping}) { + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$mapping->{$name}->{Temp}->{oid}}})) { + next if ($oid !~ /^$mapping->{$name}->{Temp}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping->{$name}, results => $self->{results}->{$mapping->{$name}->{Temp}->{oid}}, instance => $instance); + + next if ($self->check_filter(section => 'temperature', instance => $instance)); + $self->{components}->{temperature}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("Temperature '%s' is %s C [instance: %s]", + $instance, $result->{Temp}, + $instance)); + + my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, value => $result->{Temp}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Temperature '%s' is %s C", $instance, $result->{Temp})); + } + $self->{output}->perfdata_add(label => 'temp_' . $instance, unit => 'C', + value => $result->{Temp}, + warning => $warn, + critical => $crit); + } + } +} + +1; \ No newline at end of file diff --git a/centreon-plugins/centreon/common/force10/snmp/mode/cpu.pm b/centreon-plugins/centreon/common/force10/snmp/mode/cpu.pm new file mode 100644 index 000000000..e308a6a56 --- /dev/null +++ b/centreon-plugins/centreon/common/force10/snmp/mode/cpu.pm @@ -0,0 +1,243 @@ +# +# Copyright 2015 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 centreon::common::force10::snmp::mode::cpu; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; +use centreon::plugins::values; + +my $instance_mode; + +my $maps_counters = { + cpu => { + '000_5s' => { + set => { + key_values => [ { name => 'usage_5s' }, { name => 'display' } ], + output_template => '%s %% (5sec)', output_error_template => "%s (5sec)", + perfdatas => [ + { label => 'cpu_5s', value => 'usage_5s_absolute', template => '%d', + unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + }, + }, + '001_1m' => { + set => { + key_values => [ { name => 'usage_1m' }, { name => 'display' } ], + output_template => '%s %% (1m)', output_error_template => "%s (1min)", + perfdatas => [ + { label => 'cpu_1m', value => 'usage_1m_absolute', template => '%d', + unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + }, + }, + '002_5m' => { + set => { + key_values => [ { name => 'usage_5m' }, { name => 'display' } ], + output_template => '%s %% (5min)', output_error_template => "%s (5min)", + perfdatas => [ + { label => 'cpu_5m', value => 'usage_5m_absolute', template => '%d', + unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + }, + }, + } +}; + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + }); + + foreach my $key (('cpu')) { + foreach (keys %{$maps_counters->{$key}}) { + my ($id, $name) = split /_/; + if (!defined($maps_counters->{$key}->{$_}->{threshold}) || $maps_counters->{$key}->{$_}->{threshold} != 0) { + $options{options}->add_options(arguments => { + 'warning-' . $name . ':s' => { name => 'warning-' . $name }, + 'critical-' . $name . ':s' => { name => 'critical-' . $name }, + }); + } + $maps_counters->{$key}->{$_}->{obj} = centreon::plugins::values->new(output => $self->{output}, perfdata => $self->{perfdata}, + label => $name); + $maps_counters->{$key}->{$_}->{obj}->set(%{$maps_counters->{$key}->{$_}->{set}}); + } + } + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); + + foreach my $key (('cpu')) { + foreach (keys %{$maps_counters->{$key}}) { + $maps_counters->{$key}->{$_}->{obj}->init(option_results => $self->{option_results}); + } + } + $instance_mode = $self; +} + +sub run_instances { + my ($self, %options) = @_; + + my $multiple = 1; + if (scalar(keys %{$self->{cpu}}) == 1) { + $multiple = 0; + } + + if ($multiple == 1) { + $self->{output}->output_add(severity => 'OK', + short_msg => 'All CPU usages are ok'); + } + + foreach my $id (sort keys %{$self->{cpu}}) { + my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', ''); + my @exits = (); + foreach (sort keys %{$maps_counters->{cpu}}) { + my $obj = $maps_counters->{cpu}->{$_}->{obj}; + $obj->set(instance => $id); + + my ($value_check) = $obj->execute(values => $self->{cpu}->{$id}); + + if ($value_check != 0) { + $long_msg .= $long_msg_append . $obj->output_error(); + $long_msg_append = ', '; + next; + } + my $exit2 = $obj->threshold_check(); + push @exits, $exit2; + + my $output = $obj->output(); + $long_msg .= $long_msg_append . $output; + $long_msg_append = ', '; + + if (!$self->{output}->is_status(litteral => 1, value => $exit2, compare => 'ok')) { + $short_msg .= $short_msg_append . $output; + $short_msg_append = ', '; + } + + $obj->perfdata(extra_instance => $multiple); + } + + my $prefix = "CPU Usage "; + if ($multiple == 1) { + $prefix = sprintf("CPU '%s' Usage ", $self->{cpu}->{$id}->{display}); + } + $self->{output}->output_add(long_msg => "${prefix}$long_msg"); + my $exit = $self->{output}->get_most_critical(status => [ @exits ]); + if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) { + $self->{output}->output_add(severity => $exit, + short_msg => "${prefix}$short_msg" + ); + } + + if ($multiple == 0) { + $self->{output}->output_add(short_msg => "${prefix}$long_msg"); + } + } +} + +sub run { + my ($self, %options) = @_; + + $self->manage_selection(%options); + $self->run_instances(); + + $self->{output}->display(); + $self->{output}->exit(); +} + +my $mapping = { + sseries => { + Util5Sec => { oid => '.1.3.6.1.4.1.6027.3.10.1.2.9.1.2' }, + Util1Min => { oid => '.1.3.6.1.4.1.6027.3.10.1.2.9.1.3' }, + Util5Min => { oid => '.1.3.6.1.4.1.6027.3.10.1.2.9.1.4' }, + }, + mseries => { + Util5Sec => { oid => '.1.3.6.1.4.1.6027.3.19.1.2.8.1.2' }, + Util1Min => { oid => '.1.3.6.1.4.1.6027.3.19.1.2.8.1.3' }, + Util5Min => { oid => '.1.3.6.1.4.1.6027.3.19.1.2.8.1.4' }, + }, + zseries => { + Util5Sec => { oid => '.1.3.6.1.4.1.6027.3.25.1.2.3.1.1' }, + Util1Min => { oid => '.1.3.6.1.4.1.6027.3.25.1.2.3.1.2' }, + Util5Min => { oid => '.1.3.6.1.4.1.6027.3.25.1.2.3.1.3' }, + }, +}; + +sub manage_selection { + my ($self, %options) = @_; + + my $oids = { sseries => '.1.3.6.1.4.1.6027.3.10.1.2.9.1', mseries => '.1.3.6.1.4.1.6027.3.19.1.2.8.1', zseries => '.1.3.6.1.4.1.6027.3.25.1.2.3.1' }; + my $results = $options{snmp}->get_multiple_table(oids => [ { oid => $oids->{sseries} }, { oid => $oids->{mseries} }, { oid => $oids->{zseries} } ], + nothing_quit => 1); + $self->{cpu} = {}; + foreach my $name (keys %{$oids}) { + foreach my $oid (keys %{$results->{$oids->{$name}}}) { + next if ($oid !~ /^$mapping->{$name}->{Util5Min}->{oid}\.(.*)/); + my $instance = $1; + my $result = $options{snmp}->map_instance(mapping => $mapping->{$name}, results => $results->{$oids->{$name}}, instance => $instance); + + $self->{cpu}->{$instance} = { display => $instance, + usage_5s => $result->{Util5Sec}, + usage_1m => $result->{Util1Min}, + usage_5m => $result->{Util5Min}, + }; + } + } + + if (scalar(keys %{$self->{cpu}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No entry found."); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check cpu usages. + +=over 8 + +=item B<--warning-*> + +Threshold warning. +Can be: '5s', '1m', '5m'. + +=item B<--critical-*> + +Threshold critical. +Can be: '5s', '1m', '5m'. + +=back + +=cut diff --git a/centreon-plugins/centreon/common/force10/snmp/mode/hardware.pm b/centreon-plugins/centreon/common/force10/snmp/mode/hardware.pm new file mode 100644 index 000000000..b7617cdaf --- /dev/null +++ b/centreon-plugins/centreon/common/force10/snmp/mode/hardware.pm @@ -0,0 +1,338 @@ +# +# Copyright 2015 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 centreon::common::force10::snmp::mode::hardware; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; +use centreon::plugins::misc; + +my $thresholds = { + fan => [ + ['up', 'OK'], + ['absent', 'OK'], + ['down', 'CRITICAL'], + ], + psu => [ + ['up', 'OK'], + ['absent', 'OK'], + ['down', 'CRITICAL'], + + ['normal', 'OK'], + ['warning', 'WARNING'], + ['critical', 'CRITICAL'], + ['shutdown', 'CRITICAL'], + ['notPresent', 'OK'], + ['notFunctioning', 'CRITICAL'], + ], +}; + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + "filter:s@" => { name => 'filter' }, + "absent-problem:s@" => { name => 'absent_problem' }, + "component:s" => { name => 'component', default => '.*' }, + "no-component:s" => { name => 'no_component' }, + "threshold-overload:s@" => { name => 'threshold_overload' }, + "warning:s@" => { name => 'warning' }, + "critical:s@" => { name => 'critical' }, + }); + + $self->{components} = {}; + $self->{no_components} = undef; + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); + + if (defined($self->{option_results}->{no_component})) { + if ($self->{option_results}->{no_component} ne '') { + $self->{no_components} = $self->{option_results}->{no_component}; + } else { + $self->{no_components} = 'critical'; + } + } + + $self->{filter} = []; + foreach my $val (@{$self->{option_results}->{filter}}) { + next if (!defined($val) || $val eq ''); + my @values = split (/,/, $val); + push @{$self->{filter}}, { filter => $values[0], instance => $values[1] }; + } + + $self->{absent_problem} = []; + foreach my $val (@{$self->{option_results}->{absent_problem}}) { + next if (!defined($val) || $val eq ''); + my @values = split (/,/, $val); + push @{$self->{absent_problem}}, { filter => $values[0], instance => $values[1] }; + } + + $self->{overload_th} = {}; + foreach my $val (@{$self->{option_results}->{threshold_overload}}) { + next if (!defined($val) || $val eq ''); + my @values = split (/,/, $val); + if (scalar(@values) < 3) { + $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload option '" . $val . "'."); + $self->{output}->option_exit(); + } + my ($section, $instance, $status, $filter); + if (scalar(@values) == 3) { + ($section, $status, $filter) = @values; + $instance = '.*'; + } else { + ($section, $instance, $status, $filter) = @values; + } + if ($section !~ /^psu|fan$/) { + $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload section '" . $val . "'."); + $self->{output}->option_exit(); + } + if ($self->{output}->is_litteral_status(status => $status) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload status '" . $val . "'."); + $self->{output}->option_exit(); + } + $self->{overload_th}->{$section} = [] if (!defined($self->{overload_th}->{$section})); + push @{$self->{overload_th}->{$section}}, {filter => $filter, status => $status, instance => $instance }; + } + + $self->{numeric_threshold} = {}; + foreach my $option (('warning', 'critical')) { + foreach my $val (@{$self->{option_results}->{$option}}) { + next if (!defined($val) || $val eq ''); + if ($val !~ /^(.*?),(.*?),(.*)$/) { + $self->{output}->add_option_msg(short_msg => "Wrong $option option '" . $val . "'."); + $self->{output}->option_exit(); + } + my ($section, $instance, $value) = ($1, $2, $3); + if ($section !~ /^temperature$/) { + $self->{output}->add_option_msg(short_msg => "Wrong $option option '" . $val . "'."); + $self->{output}->option_exit(); + } + my $position = 0; + if (defined($self->{numeric_threshold}->{$section})) { + $position = scalar(@{$self->{numeric_threshold}->{$section}}); + } + if (($self->{perfdata}->threshold_validate(label => $option . '-' . $section . '-' . $position, value => $value)) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong $option threshold '" . $value . "'."); + $self->{output}->option_exit(); + } + $self->{numeric_threshold}->{$section} = [] if (!defined($self->{numeric_threshold}->{$section})); + push @{$self->{numeric_threshold}->{$section}}, { label => $option . '-' . $section . '-' . $position, threshold => $option, instance => $instance }; + } + } +} + +sub run { + my ($self, %options) = @_; + $self->{snmp} = $options{snmp}; + + my $snmp_request = []; + my @components = ('fan', 'psu', 'temperature'); + foreach (@components) { + if (/$self->{option_results}->{component}/) { + my $mod_name = "centreon::common::force10::snmp::mode::components::$_"; + centreon::plugins::misc::mymodule_load(output => $self->{output}, module => $mod_name, + error_msg => "Cannot load module '$mod_name'."); + my $func = $mod_name->can('load'); + $func->(request => $snmp_request); + } + } + + if (scalar(@{$snmp_request}) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong option. Cannot find component '" . $self->{option_results}->{component} . "'."); + $self->{output}->option_exit(); + } + $self->{results} = $self->{snmp}->get_multiple_table(oids => $snmp_request); + + foreach (@components) { + if (/$self->{option_results}->{component}/) { + my $mod_name = "centreon::common::force10::snmp::mode::components::$_"; + my $func = $mod_name->can('check'); + $func->($self); + } + } + + my $total_components = 0; + my $display_by_component = ''; + my $display_by_component_append = ''; + foreach my $comp (sort(keys %{$self->{components}})) { + # Skipping short msg when no components + next if ($self->{components}->{$comp}->{total} == 0 && $self->{components}->{$comp}->{skip} == 0); + $total_components += $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip}; + my $count_by_components = $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip}; + $display_by_component .= $display_by_component_append . $self->{components}->{$comp}->{total} . '/' . $count_by_components . ' ' . $self->{components}->{$comp}->{name}; + $display_by_component_append = ', '; + } + + $self->{output}->output_add(severity => 'OK', + short_msg => sprintf("All %s components are ok [%s].", + $total_components, + $display_by_component) + ); + + if (defined($self->{option_results}->{no_component}) && $total_components == 0) { + $self->{output}->output_add(severity => $self->{no_components}, + short_msg => 'No components are checked.'); + } + + $self->{output}->display(); + $self->{output}->exit(); +} + +sub absent_problem { + my ($self, %options) = @_; + + foreach (@{$self->{absent_problem}}) { + if ($options{section} =~ /$_->{filter}/) { + if (!defined($_->{instance}) || $options{instance} =~ /$_->{instance}/) { + $self->{output}->output_add(severity => 'CRITICAL', + short_msg => sprintf("Component '%s' instance '%s' is not present", + $options{section}, $options{instance})); + $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance (not present)")); + $self->{components}->{$options{section}}->{skip}++; + return 1; + } + } + } + + return 0; +} + +sub check_filter { + my ($self, %options) = @_; + + foreach (@{$self->{filter}}) { + if ($options{section} =~ /$_->{filter}/) { + if (!defined($options{instance}) && !defined($_->{instance})) { + $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section.")); + return 1; + } elsif (defined($options{instance}) && $options{instance} =~ /$_->{instance}/) { + $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance.")); + return 1; + } + } + } + + return 0; +} + +sub get_severity_numeric { + my ($self, %options) = @_; + my $status = 'OK'; # default + my $thresholds = { warning => undef, critical => undef }; + my $checked = 0; + + if (defined($self->{numeric_threshold}->{$options{section}})) { + my $exits = []; + foreach (@{$self->{numeric_threshold}->{$options{section}}}) { + if ($options{instance} =~ /$_->{instance}/) { + push @{$exits}, $self->{perfdata}->threshold_check(value => $options{value}, threshold => [ { label => $_->{label}, exit_litteral => $_->{threshold} } ]); + $thresholds->{$_->{threshold}} = $self->{perfdata}->get_perfdata_for_output(label => $_->{label}); + $checked = 1; + } + } + $status = $self->{output}->get_most_critical(status => $exits) if (scalar(@{$exits}) > 0); + } + + return ($status, $thresholds->{warning}, $thresholds->{critical}, $checked); +} + +sub get_severity { + my ($self, %options) = @_; + my $status = 'UNKNOWN'; # default + + if (defined($self->{overload_th}->{$options{section}})) { + foreach (@{$self->{overload_th}->{$options{section}}}) { + if ($options{value} =~ /$_->{filter}/i && + (!defined($options{instance}) || $options{instance} =~ /$_->{instance}/)) { + $status = $_->{status}; + return $status; + } + } + } + my $label = defined($options{label}) ? $options{label} : $options{section}; + foreach (@{$thresholds->{$label}}) { + if ($options{value} =~ /$$_[0]/i) { + $status = $$_[1]; + return $status; + } + } + + return $status; +} + +1; + +__END__ + +=head1 MODE + +Check Hardware (Fan, Power Supply, Temperature). + +=over 8 + +=item B<--component> + +Which component to check (Default: '.*'). +Can be: 'temperature', 'fan', 'psu'. + +=item B<--filter> + +Exclude some parts (comma seperated list) (Example: --filter=temperature --filter=psu) +Can also exclude specific instance: --filter=fan,1 + +=item B<--absent-problem> + +Return an error if an entity is not 'present' (default is skipping) (comma seperated list) +Can be specific or global: --absent-problem=fan,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='psu,WARNING,^(?!(up)$)' + +=item B<--warning> + +Set warning threshold for temperatures (syntax: type,instance,threshold) +Example: --warning='temperature,.*,30' + +=item B<--critical> + +Set critical threshold for temperatures (syntax: type,instance,threshold) +Example: --critical='temperature,.*,40' +=back + +=cut \ No newline at end of file diff --git a/centreon-plugins/centreon/common/force10/snmp/mode/memory.pm b/centreon-plugins/centreon/common/force10/snmp/mode/memory.pm new file mode 100644 index 000000000..9843d1429 --- /dev/null +++ b/centreon-plugins/centreon/common/force10/snmp/mode/memory.pm @@ -0,0 +1,213 @@ +# +# Copyright 2015 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 centreon::common::force10::snmp::mode::memory; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; +use centreon::plugins::values; + +my $instance_mode; + +my $maps_counters = { + mem => { + '000_usage' => { + set => { + key_values => [ { name => 'usage' }, { name => 'display' } ], + output_template => '%s %%', output_error_template => "%s", + perfdatas => [ + { label => 'used', value => 'usage_absolute', template => '%d', + unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + }, + }, + } +}; + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + }); + + foreach my $key (('mem')) { + foreach (keys %{$maps_counters->{$key}}) { + my ($id, $name) = split /_/; + if (!defined($maps_counters->{$key}->{$_}->{threshold}) || $maps_counters->{$key}->{$_}->{threshold} != 0) { + $options{options}->add_options(arguments => { + 'warning-' . $name . ':s' => { name => 'warning-' . $name }, + 'critical-' . $name . ':s' => { name => 'critical-' . $name }, + }); + } + $maps_counters->{$key}->{$_}->{obj} = centreon::plugins::values->new(output => $self->{output}, perfdata => $self->{perfdata}, + label => $name); + $maps_counters->{$key}->{$_}->{obj}->set(%{$maps_counters->{$key}->{$_}->{set}}); + } + } + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); + + foreach my $key (('mem')) { + foreach (keys %{$maps_counters->{$key}}) { + $maps_counters->{$key}->{$_}->{obj}->init(option_results => $self->{option_results}); + } + } + $instance_mode = $self; +} + +sub run_instances { + my ($self, %options) = @_; + + my $multiple = 1; + if (scalar(keys %{$self->{mem}}) == 1) { + $multiple = 0; + } + + if ($multiple == 1) { + $self->{output}->output_add(severity => 'OK', + short_msg => 'All memory usages are ok'); + } + + foreach my $id (sort keys %{$self->{mem}}) { + my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', ''); + my @exits = (); + foreach (sort keys %{$maps_counters->{mem}}) { + my $obj = $maps_counters->{mem}->{$_}->{obj}; + $obj->set(instance => $id); + + my ($value_check) = $obj->execute(values => $self->{mem}->{$id}); + + if ($value_check != 0) { + $long_msg .= $long_msg_append . $obj->output_error(); + $long_msg_append = ', '; + next; + } + my $exit2 = $obj->threshold_check(); + push @exits, $exit2; + + my $output = $obj->output(); + $long_msg .= $long_msg_append . $output; + $long_msg_append = ', '; + + if (!$self->{output}->is_status(litteral => 1, value => $exit2, compare => 'ok')) { + $short_msg .= $short_msg_append . $output; + $short_msg_append = ', '; + } + + $obj->perfdata(extra_instance => $multiple); + } + + my $prefix = "Memory Usage "; + if ($multiple == 1) { + $prefix = sprintf("Memory '%s' Usage ", $self->{mem}->{$id}->{display}); + } + $self->{output}->output_add(long_msg => "${prefix}$long_msg"); + my $exit = $self->{output}->get_most_critical(status => [ @exits ]); + if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) { + $self->{output}->output_add(severity => $exit, + short_msg => "${prefix}$short_msg" + ); + } + + if ($multiple == 0) { + $self->{output}->output_add(short_msg => "${prefix}$long_msg"); + } + } +} + +sub run { + my ($self, %options) = @_; + + $self->manage_selection(%options); + $self->run_instances(); + + $self->{output}->display(); + $self->{output}->exit(); +} + +my $mapping = { + sseries => { + MemUsageUtil => { oid => '.1.3.6.1.4.1.6027.3.10.1.2.9.1.5' }, + }, + mseries => { + MemUsageUtil => { oid => '.1.3.6.1.4.1.6027.3.19.1.2.8.1.5' }, + }, + zseries => { + MemUsageUtil => { oid => '.1.3.6.1.4.1.6027.3.25.1.2.3.1.4' }, + }, +}; + +sub manage_selection { + my ($self, %options) = @_; + + my $oids = { sseries => '.1.3.6.1.4.1.6027.3.10.1.2.9.1', mseries => '.1.3.6.1.4.1.6027.3.19.1.2.8.1', zseries => '.1.3.6.1.4.1.6027.3.25.1.2.3.1' }; + my $results = $options{snmp}->get_multiple_table(oids => [ { oid => $oids->{sseries} }, { oid => $oids->{mseries} }, { oid => $oids->{zseries} } ], + nothing_quit => 1); + $self->{mem} = {}; + foreach my $name (keys %{$oids}) { + foreach my $oid (keys %{$results->{$oids->{$name}}}) { + next if ($oid !~ /^$mapping->{$name}->{MemUsageUtil}->{oid}\.(.*)/); + my $instance = $1; + my $result = $options{snmp}->map_instance(mapping => $mapping->{$name}, results => $results->{$oids->{$name}}, instance => $instance); + + $self->{mem}->{$instance} = { display => $instance, + usage => $result->{MemUsageUtil}, + }; + } + } + + if (scalar(keys %{$self->{mem}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No entry found."); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check memory usages. + +=over 8 + +=item B<--warning-usage> + +Threshold warning (in percent). + +=item B<--critical-usage> + +Threshold critical (in percent). + +=back + +=cut diff --git a/centreon-plugins/network/dell/sseries/snmp/plugin.pm b/centreon-plugins/network/dell/sseries/snmp/plugin.pm new file mode 100644 index 000000000..a2deb5533 --- /dev/null +++ b/centreon-plugins/network/dell/sseries/snmp/plugin.pm @@ -0,0 +1,53 @@ +# +# Copyright 2015 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::dell::sseries::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; + # $options->{options} = options object + + $self->{version} = '1.0'; + %{$self->{modes}} = ( + 'cpu' => 'centreon::common::force10::snmp::mode::cpu', + 'hardware' => 'centreon::common::force10::snmp::mode::hardware', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'memory' => 'centreon::common::force10::snmp::mode::memory', + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Dell S-Series in SNMP. + +=cut From 0543c47f4985121c71d37c21c264b9deeba49318 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Thu, 26 Nov 2015 15:07:49 +0100 Subject: [PATCH 04/26] + Remove module prerequisite --- centreon-plugins/cloud/aws/mode/cloudwatch.pm | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/centreon-plugins/cloud/aws/mode/cloudwatch.pm b/centreon-plugins/cloud/aws/mode/cloudwatch.pm index a89f91b27..636a09ec8 100644 --- a/centreon-plugins/cloud/aws/mode/cloudwatch.pm +++ b/centreon-plugins/cloud/aws/mode/cloudwatch.pm @@ -27,7 +27,6 @@ use warnings; use centreon::plugins::misc; use POSIX; use JSON; -use Module::Load; my $CloudwatchMetrics = { cpu => "cloud::aws::mode::metrics::ec2instancecpu", @@ -192,12 +191,12 @@ sub run { my ( $msg, $exit_code, $awsapi ); - if ( defined( $CloudwatchMetrics->{ $self->{option_results}->{metric} } ) ) - { - load $CloudwatchMetrics->{ $self->{option_results}->{metric} },qw/cloudwatchCheck/; - cloudwatchCheck($self); - } - else { + if ( defined( $CloudwatchMetrics->{ $self->{option_results}->{metric} } ) ) { + centreon::plugins::misc::mymodule_load(output => $options{output}, module => $CloudwatchMetrics->{$self->{option_results}->{metric}}, + error_msg => "Cannot load module '" . $CloudwatchMetrics->{$self->{option_results}->{metric}} . "'."); + my $func = $CloudwatchMetrics->{$self->{option_results}->{metric}}->can('cloudwatchCheck'); + $func->($self); + } else { $self->{output} ->add_option_msg( short_msg => "Wrong option. Cannot find metric '" . $self->{option_results}->{metric} From 9973306c2e89b727f4cfedad1fb330551999d2dd Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Thu, 26 Nov 2015 15:19:54 +0100 Subject: [PATCH 05/26] + Fix #221 (Thanks targuan!) --- centreon-plugins/snmp_standard/mode/interfaces.pm | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/centreon-plugins/snmp_standard/mode/interfaces.pm b/centreon-plugins/snmp_standard/mode/interfaces.pm index 08467699e..875647532 100644 --- a/centreon-plugins/snmp_standard/mode/interfaces.pm +++ b/centreon-plugins/snmp_standard/mode/interfaces.pm @@ -1217,6 +1217,10 @@ sub add_result_cast { } } + foreach (('iucast', 'imcast', 'ibcast', 'oucast', 'omcast', 'omcast')) { + $self->{interface_selected}->{$_} = 0 if (!defined($self->{interface_selected}->{$_})); + } + $self->{interface_selected}->{$options{instance}}->{total_in_packets} = $self->{interface_selected}->{$options{instance}}->{iucast} + $self->{interface_selected}->{$options{instance}}->{imcast} + $self->{interface_selected}->{$options{instance}}->{ibcast}; $self->{interface_selected}->{$options{instance}}->{total_out_packets} = $self->{interface_selected}->{$options{instance}}->{oucast} + $self->{interface_selected}->{$options{instance}}->{omcast} + $self->{interface_selected}->{$options{instance}}->{obcast}; } From e046da8d71b87dd12bbf15c1c86d707d9571607a Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Thu, 26 Nov 2015 15:28:30 +0100 Subject: [PATCH 06/26] + fix interfaces --- centreon-plugins/snmp_standard/mode/interfaces.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/centreon-plugins/snmp_standard/mode/interfaces.pm b/centreon-plugins/snmp_standard/mode/interfaces.pm index 875647532..fd06e2512 100644 --- a/centreon-plugins/snmp_standard/mode/interfaces.pm +++ b/centreon-plugins/snmp_standard/mode/interfaces.pm @@ -1218,7 +1218,7 @@ sub add_result_cast { } foreach (('iucast', 'imcast', 'ibcast', 'oucast', 'omcast', 'omcast')) { - $self->{interface_selected}->{$_} = 0 if (!defined($self->{interface_selected}->{$_})); + $self->{interface_selected}->{$options{instance}}->{$_} = 0 if (!defined($self->{interface_selected}->{$options{instance}}->{$_})); } $self->{interface_selected}->{$options{instance}}->{total_in_packets} = $self->{interface_selected}->{$options{instance}}->{iucast} + $self->{interface_selected}->{$options{instance}}->{imcast} + $self->{interface_selected}->{$options{instance}}->{ibcast}; From bd9fd07391aba9105db9021a2d87c7df8f0ef74b Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Thu, 26 Nov 2015 15:36:55 +0100 Subject: [PATCH 07/26] + Fix #219 --- .../apps/selenium/mode/scenario.pm | 1 - centreon-plugins/centreon/plugins/dbi.pm | 39 +++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/centreon-plugins/apps/selenium/mode/scenario.pm b/centreon-plugins/apps/selenium/mode/scenario.pm index 409bceba6..dd41cc2cd 100644 --- a/centreon-plugins/apps/selenium/mode/scenario.pm +++ b/centreon-plugins/apps/selenium/mode/scenario.pm @@ -94,7 +94,6 @@ sub check_options { $self->{output}->add_option_msg(short_msg => "Please specify a scenario name" . $self->{option_results}->{scenario} . "."); $self->{output}->option_exit(); } - } sub run { diff --git a/centreon-plugins/centreon/plugins/dbi.pm b/centreon-plugins/centreon/plugins/dbi.pm index 47eb472e1..1fd4ddc7a 100644 --- a/centreon-plugins/centreon/plugins/dbi.pm +++ b/centreon-plugins/centreon/plugins/dbi.pm @@ -25,6 +25,8 @@ use warnings; use DBI; use Digest::MD5 qw(md5_hex); +my %handlers = ( ALRM => {} ); + sub new { my ($class, %options) = @_; my $self = {}; @@ -50,6 +52,7 @@ sub new { "password:s@" => { name => 'password' }, "connect-options:s@" => { name => 'connect_options' }, "sql-errors-exit:s" => { name => 'sql_errors_exit', default => 'unknown' }, + "timeout:i" => { name => 'timeout' }, }); } $options{options}->add_help(package => __PACKAGE__, sections => 'DBI OPTIONS', once => 1); @@ -69,9 +72,33 @@ sub new { # Sometimes, we need to set ENV $self->{env} = undef; + $self->set_signal_handlers(); + return $self; } +sub set_signal_handlers { + my $self = shift; + + $SIG{ALRM} = \&class_handle_ALRM; + $handlers{ALRM}->{$self} = sub { $self->handle_ALRM() }; +} + +sub class_handle_ALRM { + foreach (keys %{$handlers{ALRM}}) { + &{$handlers{ALRM}->{$_}}(); + } +} + +sub handle_ALRM { + my $self = shift; + + $self->{output}->output_add(severity => $self->{sql_errors_exit}, + short_msg => "Timeout"); + $self->{output}->display(); + $self->{output}->exit(); +} + # Method to manage multiples sub set_options { my ($self, %options) = @_; @@ -111,6 +138,12 @@ sub check_options { $self->{env} = (defined($self->{option_results}->{env})) ? shift(@{$self->{option_results}->{env}}) : undef; $self->{sql_errors_exit} = $self->{option_results}->{sql_errors_exit}; + $self->{timeout} = 10; + if (defined($self->{option_results}->{timeout}) && $self->{option_results}->{timeout} =~ /^\d+$/ && + $self->{option_results}->{timeout} > 0) { + $self->{timeout} = $self->{option_results}->{timeout}; + } + if (!defined($self->{data_source}) || $self->{data_source} eq '') { $self->{output}->add_option_msg(short_msg => "Need to specify data_source arguments."); $self->{output}->option_exit(exit_litteral => $self->{sql_errors_exit}); @@ -169,12 +202,14 @@ sub connect { } } + alarm($self->{timeout}) if (defined($self->{timeout})); $self->{instance} = DBI->connect( "DBI:". $self->{data_source}, $self->{username}, $self->{password}, { "RaiseError" => 0, "PrintError" => 0, "AutoCommit" => 1, %{$self->{connect_options_hash}} } ); + alarm(0) if (defined($self->{timeout})); if (!defined($self->{instance})) { my $err_msg = sprintf("Cannot connect: %s", defined($DBI::errstr) ? $DBI::errstr : "(no error string)"); @@ -272,6 +307,10 @@ Format: name=value,name2=value2,... Exit code for DB Errors (default: unknown) +=item B<--timeout> + +Timeout in seconds for connection + =back =head1 DESCRIPTION From a2272f189d3217d41d5f546a6dcd738db17fa4ae Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Thu, 26 Nov 2015 15:49:14 +0100 Subject: [PATCH 08/26] + Fix #222 --- .../centreon/common/force10/snmp/mode/hardware.pm | 2 +- centreon-plugins/snmp_standard/mode/inodes.pm | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/centreon-plugins/centreon/common/force10/snmp/mode/hardware.pm b/centreon-plugins/centreon/common/force10/snmp/mode/hardware.pm index b7617cdaf..65b78494c 100644 --- a/centreon-plugins/centreon/common/force10/snmp/mode/hardware.pm +++ b/centreon-plugins/centreon/common/force10/snmp/mode/hardware.pm @@ -161,7 +161,7 @@ sub run { centreon::plugins::misc::mymodule_load(output => $self->{output}, module => $mod_name, error_msg => "Cannot load module '$mod_name'."); my $func = $mod_name->can('load'); - $func->(request => $snmp_request); + $func->(request => $snmp_request); } } diff --git a/centreon-plugins/snmp_standard/mode/inodes.pm b/centreon-plugins/snmp_standard/mode/inodes.pm index 32a995eab..fbd2834b5 100644 --- a/centreon-plugins/snmp_standard/mode/inodes.pm +++ b/centreon-plugins/snmp_standard/mode/inodes.pm @@ -91,6 +91,11 @@ sub run { foreach (sort @{$self->{diskpath_id_selected}}) { my $name_diskpath = $self->get_display_value(id => $_); + if (!defined($result->{$oid_dskPercentNode . '.' . $_})) { + $self->{output}->output_add(long_msg => "Cannot usage for '" . $name_diskpath . "'", debug => 1); + next; + } + my $prct_used = $result->{$oid_dskPercentNode . '.' . $_}; my $prct_free = 100 - $prct_used; From 7a5777fb99f7677360552ec64662a833e7ff9e72 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Thu, 26 Nov 2015 15:53:26 +0100 Subject: [PATCH 09/26] + add version and begin a changelog --- centreon-plugins/centreon/plugins/script.pm | 2 +- centreon-plugins/changelog | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 centreon-plugins/changelog diff --git a/centreon-plugins/centreon/plugins/script.pm b/centreon-plugins/centreon/plugins/script.pm index 7cf310f13..8ff1070a8 100644 --- a/centreon-plugins/centreon/plugins/script.pm +++ b/centreon-plugins/centreon/plugins/script.pm @@ -31,7 +31,7 @@ use Pod::Find qw(pod_where); my %handlers = (DIE => {}); -my $global_version = 20151110; +my $global_version = 20151126; sub new { my $class = shift; diff --git a/centreon-plugins/changelog b/centreon-plugins/changelog new file mode 100644 index 000000000..9c609d475 --- /dev/null +++ b/centreon-plugins/changelog @@ -0,0 +1,2 @@ +2015-11-26 Quentin Garnier + * initial release \ No newline at end of file From 466c534136e34b11927bc02045696c2189451507 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Fri, 27 Nov 2015 09:46:51 +0100 Subject: [PATCH 10/26] + Fix #223 --- centreon-plugins/network/extreme/snmp/mode/cpu.pm | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/centreon-plugins/network/extreme/snmp/mode/cpu.pm b/centreon-plugins/network/extreme/snmp/mode/cpu.pm index bd8925471..1ead97521 100644 --- a/centreon-plugins/network/extreme/snmp/mode/cpu.pm +++ b/centreon-plugins/network/extreme/snmp/mode/cpu.pm @@ -260,6 +260,10 @@ sub manage_selection { my $instance = $1; my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_extremeCpuMonitorSystemEntry}, instance => $instance); + foreach (keys %{$mapping}) { + $result->{$_} = undef if (defined($result->{$_}) && $result->{$_} =~ /n\/a/i); + } + $self->{cpu}->{$instance} = {num => $instance, %$result}; } From 09926b3fe35c761f5b0869c52713432dbf969b54 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Fri, 27 Nov 2015 11:54:33 +0100 Subject: [PATCH 11/26] + test --- centreon-plugins/README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/centreon-plugins/README.md b/centreon-plugins/README.md index 579643861..c0eabe095 100644 --- a/centreon-plugins/README.md +++ b/centreon-plugins/README.md @@ -1,4 +1,7 @@ # centreon-plugins + +|downloads| + “centreon-plugins” is a free and open source project to monitor systems. The project can be used with Centreon and all monitoring softwares compatible with Nagios plugins. You can monitor many systems: From cecbce53245647895ed8b67bc1263cd1742a64f0 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Fri, 27 Nov 2015 11:56:11 +0100 Subject: [PATCH 12/26] + remove dl --- centreon-plugins/README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/centreon-plugins/README.md b/centreon-plugins/README.md index c0eabe095..3285a8943 100644 --- a/centreon-plugins/README.md +++ b/centreon-plugins/README.md @@ -1,7 +1,5 @@ # centreon-plugins -|downloads| - “centreon-plugins” is a free and open source project to monitor systems. The project can be used with Centreon and all monitoring softwares compatible with Nagios plugins. You can monitor many systems: From 4fc933d5f538edf2ce75288461571ecd41625517 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Fri, 27 Nov 2015 14:06:48 +0100 Subject: [PATCH 13/26] + add nimble in changelog --- centreon-plugins/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/centreon-plugins/README.md b/centreon-plugins/README.md index 3285a8943..f9ca13ec2 100644 --- a/centreon-plugins/README.md +++ b/centreon-plugins/README.md @@ -9,7 +9,7 @@ You can monitor many systems: * hardware: printers (rfc3805), UPS (Powerware, Mge, Standard), Sun Hardware, Cisco UCS, SensorIP, HP Proliant, HP Bladechassis, Dell Openmanage, Dell CMC, Raritan,... * network: Aruba, Brocade, Bluecoat, Brocade, Checkpoint, Cisco AP/IronPort/ASA/Standard, Extreme, Fortigate, H3C, Hirschmann, HP Procurve, F5 BIG-IP, Juniper, PaloAlto, Redback, Riverbed, Ruggedcom, Stonesoft,... * os: Linux (SNMP, NRPE), Freebsd (SNMP), AIX (SNMP), Solaris (SNMP)... -* storage: EMC Clariion, Netapp, HP MSA p2000, Dell EqualLogic, Qnap, Panzura, Synology... +* storage: EMC Clariion, Netapp, Nimble, HP MSA p2000, Dell EqualLogic, Qnap, Panzura, Synology... ## Basic Usage From 5d4eab46b8ebe0c81105fe9b2eacdc0fc479e16a Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Mon, 30 Nov 2015 16:27:27 +0100 Subject: [PATCH 14/26] + Add plugin hardware vmware wsman --- .../vmware/wsman/mode/components/cim_card.pm | 60 ++++ .../mode/components/cim_computersystem.pm | 60 ++++ .../wsman/mode/components/cim_memory.pm | 60 ++++ .../mode/components/cim_numericsensor.pm | 111 ++++++ .../wsman/mode/components/cim_processor.pm | 62 ++++ .../wsman/mode/components/cim_recordlog.pm | 60 ++++ .../mode/components/omc_discretesensor.pm | 65 ++++ .../vmware/wsman/mode/components/omc_fan.pm | 60 ++++ .../vmware/wsman/mode/components/omc_psu.pm | 60 ++++ .../vmware/wsman/mode/components/resources.pm | 173 +++++++++ .../wsman/mode/components/vmware_battery.pm | 60 ++++ .../mode/components/vmware_controller.pm | 60 ++++ .../mode/components/vmware_sassataport.pm | 60 ++++ .../mode/components/vmware_storageextent.pm | 60 ++++ .../mode/components/vmware_storagevolume.pm | 60 ++++ .../apps/vmware/wsman/mode/hardware.pm | 336 ++++++++++++++++++ centreon-plugins/apps/vmware/wsman/plugin.pm | 49 +++ centreon-plugins/centreon/plugins/wsman.pm | 13 +- 18 files changed, 1464 insertions(+), 5 deletions(-) create mode 100644 centreon-plugins/apps/vmware/wsman/mode/components/cim_card.pm create mode 100644 centreon-plugins/apps/vmware/wsman/mode/components/cim_computersystem.pm create mode 100644 centreon-plugins/apps/vmware/wsman/mode/components/cim_memory.pm create mode 100644 centreon-plugins/apps/vmware/wsman/mode/components/cim_numericsensor.pm create mode 100644 centreon-plugins/apps/vmware/wsman/mode/components/cim_processor.pm create mode 100644 centreon-plugins/apps/vmware/wsman/mode/components/cim_recordlog.pm create mode 100644 centreon-plugins/apps/vmware/wsman/mode/components/omc_discretesensor.pm create mode 100644 centreon-plugins/apps/vmware/wsman/mode/components/omc_fan.pm create mode 100644 centreon-plugins/apps/vmware/wsman/mode/components/omc_psu.pm create mode 100644 centreon-plugins/apps/vmware/wsman/mode/components/resources.pm create mode 100644 centreon-plugins/apps/vmware/wsman/mode/components/vmware_battery.pm create mode 100644 centreon-plugins/apps/vmware/wsman/mode/components/vmware_controller.pm create mode 100644 centreon-plugins/apps/vmware/wsman/mode/components/vmware_sassataport.pm create mode 100644 centreon-plugins/apps/vmware/wsman/mode/components/vmware_storageextent.pm create mode 100644 centreon-plugins/apps/vmware/wsman/mode/components/vmware_storagevolume.pm create mode 100644 centreon-plugins/apps/vmware/wsman/mode/hardware.pm create mode 100644 centreon-plugins/apps/vmware/wsman/plugin.pm diff --git a/centreon-plugins/apps/vmware/wsman/mode/components/cim_card.pm b/centreon-plugins/apps/vmware/wsman/mode/components/cim_card.pm new file mode 100644 index 000000000..de4df27ca --- /dev/null +++ b/centreon-plugins/apps/vmware/wsman/mode/components/cim_card.pm @@ -0,0 +1,60 @@ +# +# Copyright 2015 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 apps::vmware::wsman::mode::components::cim_card; + +use strict; +use warnings; + +sub check { + my ($self) = @_; + + my $result = $self->{wsman}->request(uri => 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_Card'); + + $self->{output}->output_add(long_msg => "Checking cim cards"); + $self->{components}->{cim_card} = {name => 'cards', total => 0, skip => 0}; + return if ($self->check_filter(section => 'cim_card')); + + foreach (@{$result}) { + my $instance = defined($_->{Name}) && $_->{Name} ne '' ? $_->{Name} : $_->{ElementName}; + + next if ($self->check_filter(section => 'cim_card', instance => $instance)); + my $status = $self->get_status(entry => $_); + if (!defined($status)) { + $self->{output}->output_add(long_msg => sprintf("skipping card '%s' : no status", $_->{ElementName}), debug => 1); + next; + } + + $self->{components}->{cim_card}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("Card '%s' status is '%s' [instance: %s].", + $_->{ElementName}, $status, + $instance + )); + my $exit = $self->get_severity(section => 'cim_card', label => 'default', value => $status); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Card '%s' status is '%s'", + $_->{ElementName}, $status)); + } + } +} + +1; \ No newline at end of file diff --git a/centreon-plugins/apps/vmware/wsman/mode/components/cim_computersystem.pm b/centreon-plugins/apps/vmware/wsman/mode/components/cim_computersystem.pm new file mode 100644 index 000000000..8b02cfbc5 --- /dev/null +++ b/centreon-plugins/apps/vmware/wsman/mode/components/cim_computersystem.pm @@ -0,0 +1,60 @@ +# +# Copyright 2015 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 apps::vmware::wsman::mode::components::cim_computersystem; + +use strict; +use warnings; + +sub check { + my ($self) = @_; + + my $result = $self->{wsman}->request(uri => 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ComputerSystem'); + + $self->{output}->output_add(long_msg => "Checking cim computer systems"); + $self->{components}->{cim_computersystem} = {name => 'computer systems', total => 0, skip => 0}; + return if ($self->check_filter(section => 'cim_computersystem')); + + foreach (@{$result}) { + my $instance = defined($_->{Name}) && $_->{Name} ne '' ? $_->{Name} : $_->{ElementName}; + + next if ($self->check_filter(section => 'cim_computersystem', instance => $instance)); + my $status = $self->get_status(entry => $_); + if (!defined($status)) { + $self->{output}->output_add(long_msg => sprintf("skipping computer system '%s' : no status", $_->{ElementName}), debug => 1); + next; + } + + $self->{components}->{cim_computersystem}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("Computer system '%s' status is '%s' [instance: %s].", + $_->{ElementName}, $status, + $instance + )); + my $exit = $self->get_severity(section => 'cim_computersystem', label => 'default', value => $status); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Computer system '%s' status is '%s'", + $_->{ElementName}, $status)); + } + } +} + +1; \ No newline at end of file diff --git a/centreon-plugins/apps/vmware/wsman/mode/components/cim_memory.pm b/centreon-plugins/apps/vmware/wsman/mode/components/cim_memory.pm new file mode 100644 index 000000000..9994b2a21 --- /dev/null +++ b/centreon-plugins/apps/vmware/wsman/mode/components/cim_memory.pm @@ -0,0 +1,60 @@ +# +# Copyright 2015 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 apps::vmware::wsman::mode::components::cim_memory; + +use strict; +use warnings; + +sub check { + my ($self) = @_; + + my $result = $self->{wsman}->request(uri => 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_Memory'); + + $self->{output}->output_add(long_msg => "Checking cim memories"); + $self->{components}->{cim_memory} = {name => 'memories', total => 0, skip => 0}; + return if ($self->check_filter(section => 'cim_memory')); + + foreach (@{$result}) { + my $instance = defined($_->{Name}) && $_->{Name} ne '' ? $_->{Name} : $_->{ElementName}; + + next if ($self->check_filter(section => 'cim_memory', instance => $instance)); + my $status = $self->get_status(entry => $_); + if (!defined($status)) { + $self->{output}->output_add(long_msg => sprintf("skipping memory '%s' : no status", $_->{ElementName}), debug => 1); + next; + } + + $self->{components}->{cim_memory}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("Memory '%s' status is '%s' [instance: %s].", + $_->{ElementName}, $status, + $instance + )); + my $exit = $self->get_severity(section => 'cim_memory', label => 'default', value => $status); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Memory '%s' status is '%s'", + $_->{ElementName}, $status)); + } + } +} + +1; \ No newline at end of file diff --git a/centreon-plugins/apps/vmware/wsman/mode/components/cim_numericsensor.pm b/centreon-plugins/apps/vmware/wsman/mode/components/cim_numericsensor.pm new file mode 100644 index 000000000..c0f8d0325 --- /dev/null +++ b/centreon-plugins/apps/vmware/wsman/mode/components/cim_numericsensor.pm @@ -0,0 +1,111 @@ +# +# Copyright 2015 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 apps::vmware::wsman::mode::components::cim_numericsensor; + +use strict; +use warnings; +use apps::vmware::wsman::mode::components::resources qw($mapping_units $mapping_sensortype); + +sub check { + my ($self) = @_; + + my $result = $self->{wsman}->request(uri => 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_NumericSensor'); + + $self->{output}->output_add(long_msg => "Checking cim numeric sensors"); + $self->{components}->{cim_numericsensor} = {name => 'numeric sensors', total => 0, skip => 0}; + return if ($self->check_filter(section => 'cim_numericsensor')); + + foreach (@{$result}) { + my $sensor_type = defined($mapping_sensortype->{$_->{SensorType}}) ? $mapping_sensortype->{$_->{SensorType}} : 'unknown'; + my $name = defined($_->{Name}) && $_->{Name} ne '' ? $_->{Name} : $_->{ElementName}; + my $instance = $sensor_type . '_' . $name; + + next if ($self->check_filter(section => 'cim_numericsensor', instance => $instance)); + my $status = $self->get_status(entry => $_); + if (!defined($status)) { + $self->{output}->output_add(long_msg => sprintf("skipping numeric sensor '%s' : no status", $_->{ElementName}), debug => 1); + next; + } + + $self->{components}->{cim_numericsensor}->{total}++; + my $value = $_->{CurrentReading}; + + $value = $value * 10 ** int($_->{UnitModifier}) if (defined($value) && $value =~ /\d/); + + $self->{output}->output_add(long_msg => sprintf("Numeric sensor '%s' status is '%s' [instance: %s, current value: %s].", + $_->{ElementName}, $status, + $instance, defined($value) ? $value : '-' + )); + my $exit = $self->get_severity(section => 'cim_numericsensor', label => 'default', value => $status); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Numeric sensor '%s' status is '%s'", + $_->{ElementName}, $status)); + } + + + next if (!defined($value) || $value !~ /\d/); + + my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'cim_numericsensor', instance => $instance, value => $value); + if ($checked == 0) { + my ($warn_th, $crit_th); + + $warn_th = $_->{LowerThresholdNonCritical} * 10 ** int($_->{UnitModifier}) . ':' if (defined($_->{LowerThresholdNonCritical}) && + $_->{LowerThresholdNonCritical} =~ /\d/); + if (defined($warn_th)) { + $warn_th .= ($_->{UpperThresholdNonCritical} * 10 ** int($_->{UnitModifier})) if (defined($_->{UpperThresholdNonCritical}) && + $_->{UpperThresholdNonCritical} =~ /\d/); + } else { + $warn_th = '~:' . ($_->{UpperThresholdNonCritical} * 10 ** int($_->{UnitModifier})) if (defined($_->{UpperThresholdNonCritical}) && + $_->{UpperThresholdNonCritical} =~ /\d/); + } + $crit_th = $_->{LowerThresholdCritical} * 10 ** int($_->{UnitModifier}) . ':' if (defined($_->{LowerThresholdCritical}) && + $_->{LowerThresholdCritical} =~ /\d/); + if (defined($crit_th)) { + $crit_th .= ($_->{UpperThresholdCritical} * 10 ** int($_->{UnitModifier})) if (defined($_->{UpperThresholdCritical}) && + $_->{UpperThresholdCritical} =~ /\d/); + } else { + $crit_th = '~:' . ($_->{UpperThresholdCritical} * 10 ** int($_->{UnitModifier})) if (defined($_->{UpperThresholdCritical}) && + $_->{UpperThresholdCritical} =~ /\d/); + } + $self->{perfdata}->threshold_validate(label => 'warning-cim_numericsensor-instance-' . $instance, value => $warn_th); + $self->{perfdata}->threshold_validate(label => 'critical-cim_numericsensor-instance-' . $instance, value => $crit_th); + $warn = $self->{perfdata}->get_perfdata_for_output(label => 'warning-cim_numericsensor-instance-' . $instance); + $crit = $self->{perfdata}->get_perfdata_for_output(label => 'critical-cim_numericsensor-instance-' . $instance); + } + if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit2, + short_msg => sprintf("Numeric sensor '%s' value is %s %s", + $_->{ElementName}, $value, + defined($mapping_units->{$_->{BaseUnits}}) ? $mapping_units->{$_->{BaseUnits}} : '-')); + } + + my $min = defined($_->{MinReadable}) && $_->{MinReadable} =~ /\d/ ? $_->{MinReadable} * 10 ** int($_->{UnitModifier}) : undef; + my $max = defined($_->{MaxReadable}) && $_->{MaxReadable} =~ /\d/ ? $_->{MaxReadable} * 10 ** int($_->{UnitModifier}) : undef; + $self->{output}->perfdata_add(label => $instance, unit => $mapping_units->{$_->{BaseUnits}}, + value => $value, + warning => $warn, + critical => $crit, + min => $min, max => $max); + } +} + +1; \ No newline at end of file diff --git a/centreon-plugins/apps/vmware/wsman/mode/components/cim_processor.pm b/centreon-plugins/apps/vmware/wsman/mode/components/cim_processor.pm new file mode 100644 index 000000000..e2b6f7785 --- /dev/null +++ b/centreon-plugins/apps/vmware/wsman/mode/components/cim_processor.pm @@ -0,0 +1,62 @@ +# +# Copyright 2015 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 apps::vmware::wsman::mode::components::cim_processor; + +use strict; +use warnings; + +sub check { + my ($self) = @_; + + my $result = $self->{wsman}->request(uri => 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_Processor'); + + $self->{output}->output_add(long_msg => "Checking cim processors"); + $self->{components}->{cim_processor} = {name => 'processors', total => 0, skip => 0}; + return if ($self->check_filter(section => 'cim_processor')); + + foreach (@{$result}) { + my $instance = defined($_->{Name}) && $_->{Name} ne '' ? $_->{Name} : $_->{ElementName}; + + next if ($self->check_filter(section => 'cim_processor', instance => $instance)); + my $status = $self->get_status(entry => $_); + if (!defined($status)) { + $self->{output}->output_add(long_msg => sprintf("skipping processor '%s' : no status", $_->{ElementName}), debug => 1); + next; + } + + $self->{components}->{cim_processor}->{total}++; + my $model_name = defined($_->{ModelName}) && $_->{ModelName} ne '' ? $_->{ModelName} : 'unknown'; + $model_name =~ s/\s+/ /g; + + $self->{output}->output_add(long_msg => sprintf("Processor '%s' status is '%s' [instance: %s, Model: %s].", + $_->{ElementName}, $status, + $instance, $model_name + )); + my $exit = $self->get_severity(section => 'cim_processor', label => 'default', value => $status); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Processor '%s' status is '%s'", + $_->{ElementName}, $status)); + } + } +} + +1; \ No newline at end of file diff --git a/centreon-plugins/apps/vmware/wsman/mode/components/cim_recordlog.pm b/centreon-plugins/apps/vmware/wsman/mode/components/cim_recordlog.pm new file mode 100644 index 000000000..24f279fff --- /dev/null +++ b/centreon-plugins/apps/vmware/wsman/mode/components/cim_recordlog.pm @@ -0,0 +1,60 @@ +# +# Copyright 2015 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 apps::vmware::wsman::mode::components::cim_recordlog; + +use strict; +use warnings; + +sub check { + my ($self) = @_; + + my $result = $self->{wsman}->request(uri => 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_RecordLog'); + + $self->{output}->output_add(long_msg => "Checking cim recordlog"); + $self->{components}->{cim_recordlog} = {name => 'recordlog', total => 0, skip => 0}; + return if ($self->check_filter(section => 'cim_recordlog')); + + foreach (@{$result}) { + my $instance = defined($_->{Name}) && $_->{Name} ne '' ? $_->{Name} : $_->{ElementName}; + + next if ($self->check_filter(section => 'cim_recordlog', instance => $instance)); + my $status = $self->get_status(entry => $_); + if (!defined($status)) { + $self->{output}->output_add(long_msg => sprintf("skipping record log '%s' : no status", $_->{ElementName}), debug => 1); + next; + } + + $self->{components}->{cim_recordlog}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("Record log '%s' status is '%s' [instance: %s].", + $_->{ElementName}, $status, + $instance + )); + my $exit = $self->get_severity(section => 'cim_recordlog', label => 'default', value => $status); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Record log '%s' status is '%s'", + $_->{ElementName}, $status)); + } + } +} + +1; \ No newline at end of file diff --git a/centreon-plugins/apps/vmware/wsman/mode/components/omc_discretesensor.pm b/centreon-plugins/apps/vmware/wsman/mode/components/omc_discretesensor.pm new file mode 100644 index 000000000..524735c6a --- /dev/null +++ b/centreon-plugins/apps/vmware/wsman/mode/components/omc_discretesensor.pm @@ -0,0 +1,65 @@ +# +# Copyright 2015 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 apps::vmware::wsman::mode::components::omc_discretesensor; + +use strict; +use warnings; +use apps::vmware::wsman::mode::components::resources qw($mapping_EnableState); + +sub check { + my ($self) = @_; + + my $result = $self->{wsman}->request(uri => 'http://schema.omc-project.org/wbem/wscim/1/cim-schema/2/OMC_DiscreteSensor'); + + $self->{output}->output_add(long_msg => "Checking OMC discrete sensors"); + $self->{components}->{omc_discretesensor} = {name => 'omc discrete sensors', total => 0, skip => 0}; + return if ($self->check_filter(section => 'omc_discretesensor')); + + foreach (@{$result}) { + my $instance = $_->{Name}; + + next if ($self->check_filter(section => 'omc_discretesensor', instance => $instance)); + if (defined($mapping_EnableState->{$_->{EnabledState}}) && $mapping_EnableState->{$_->{EnabledState}} !~ /enabled/i) { + $self->{output}->output_add(long_msg => sprintf("skipping discrete sensor '%s' : not enabled", $_->{Name}), debug => 1); + next; + } + my $status = $self->get_status(entry => $_); + if (!defined($status)) { + $self->{output}->output_add(long_msg => sprintf("skipping discrete sensor '%s' : no status", $_->{Name}), debug => 1); + next; + } + + $self->{components}->{omc_discretesensor}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("Discrete sensor '%s' status is '%s' [instance: %s].", + $_->{Name}, $status, + $instance + )); + my $exit = $self->get_severity(section => 'omc_discretesensor', label => 'default', value => $status); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Discrete sensor '%s' status is '%s'", + $_->{Name}, $status)); + } + } +} + +1; \ No newline at end of file diff --git a/centreon-plugins/apps/vmware/wsman/mode/components/omc_fan.pm b/centreon-plugins/apps/vmware/wsman/mode/components/omc_fan.pm new file mode 100644 index 000000000..55a034b4d --- /dev/null +++ b/centreon-plugins/apps/vmware/wsman/mode/components/omc_fan.pm @@ -0,0 +1,60 @@ +# +# Copyright 2015 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 apps::vmware::wsman::mode::components::omc_fan; + +use strict; +use warnings; + +sub check { + my ($self) = @_; + + my $result = $self->{wsman}->request(uri => 'http://schema.omc-project.org/wbem/wscim/1/cim-schema/2/OMC_Fan'); + + $self->{output}->output_add(long_msg => "Checking OMC fans"); + $self->{components}->{omc_fan} = {name => 'omc fans', total => 0, skip => 0}; + return if ($self->check_filter(section => 'omc_fan')); + + foreach (@{$result}) { + my $instance = $_->{Name}; + + next if ($self->check_filter(section => 'omc_fan', instance => $instance)); + my $status = $self->get_status(entry => $_); + if (!defined($status)) { + $self->{output}->output_add(long_msg => sprintf("skipping fan '%s' : no status", $_->{Name}), debug => 1); + next; + } + + $self->{components}->{omc_fan}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("Fan '%s' status is '%s' [instance: %s].", + $_->{Name}, $status, + $instance + )); + my $exit = $self->get_severity(section => 'omc_fan', label => 'default', value => $status); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Fan '%s' status is '%s'", + $_->{Name}, $status)); + } + } +} + +1; \ No newline at end of file diff --git a/centreon-plugins/apps/vmware/wsman/mode/components/omc_psu.pm b/centreon-plugins/apps/vmware/wsman/mode/components/omc_psu.pm new file mode 100644 index 000000000..b720a66d5 --- /dev/null +++ b/centreon-plugins/apps/vmware/wsman/mode/components/omc_psu.pm @@ -0,0 +1,60 @@ +# +# Copyright 2015 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 apps::vmware::wsman::mode::components::omc_psu; + +use strict; +use warnings; + +sub check { + my ($self) = @_; + + my $result = $self->{wsman}->request(uri => 'http://schema.omc-project.org/wbem/wscim/1/cim-schema/2/OMC_PowerSupply'); + + $self->{output}->output_add(long_msg => "Checking OMC power supplies"); + $self->{components}->{omc_psu} = {name => 'omc psus', total => 0, skip => 0}; + return if ($self->check_filter(section => 'omc_psu')); + + foreach (@{$result}) { + my $instance = $_->{Name}; + + next if ($self->check_filter(section => 'omc_psu', instance => $instance)); + my $status = $self->get_status(entry => $_); + if (!defined($status)) { + $self->{output}->output_add(long_msg => sprintf("skipping power supply '%s' : no status", $_->{Name}), debug => 1); + next; + } + + $self->{components}->{omc_psu}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("Power supply '%s' status is '%s' [instance: %s].", + $_->{Name}, $status, + $instance + )); + my $exit = $self->get_severity(section => 'omc_psu', label => 'default', value => $status); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Power supply '%s' status is '%s'", + $_->{Name}, $status)); + } + } +} + +1; \ No newline at end of file diff --git a/centreon-plugins/apps/vmware/wsman/mode/components/resources.pm b/centreon-plugins/apps/vmware/wsman/mode/components/resources.pm new file mode 100644 index 000000000..706877fb9 --- /dev/null +++ b/centreon-plugins/apps/vmware/wsman/mode/components/resources.pm @@ -0,0 +1,173 @@ +# +# Copyright 2015 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 apps::vmware::wsman::mode::components::resources; + +use strict; +use warnings; +use Exporter; + +our $mapping_HealthState; +our $mapping_OperationalStatus; +our $mapping_EnableState; +our $mapping_units; +our $mapping_sensortype; + +our @ISA = qw(Exporter); +our @EXPORT_OK = qw($mapping_HealthState $mapping_OperationalStatus $mapping_EnableState $mapping_units $mapping_sensortype); + +$mapping_EnableState = { + 0 => 'Unknown', + 1 => 'Other', + 2 => 'Enabled', + 3 => 'Disabled', + 4 => 'Shutting Down', + 5 => 'Not Applicable', + 6 => 'Enabled but Offline', + 7 => 'In Test', + 8 => 'Deferred', + 9 => 'Quiesce', + 10 => 'Starting', +}; + +$mapping_HealthState = { + 0 => 'Unknown', + 5 => 'OK', + 10 => 'Degraded', + 15 => 'Minor failure', + 20 => 'Major failure', + 25 => 'Critical failure', + 30 => 'Non-recoverable error', +}; + +$mapping_OperationalStatus = { + 0 => 'Unknown', + 1 => 'Other', + 2 => 'OK', + 3 => 'Degraded', + 4 => 'Stressed', + 5 => 'Predictive Failure', + 6 => 'Error', + 7 => 'Non-Recoverable Error', + 8 => 'Starting', + 9 => 'Stopping', + 10 => 'Stopped', + 11 => 'In Service', + 12 => 'No Contact', + 13 => 'Lost Communication', + 14 => 'Aborted', + 15 => 'Dormant', + 16 => 'Supporting Entity in Error', + 17 => 'Completed', + 18 => 'Power Mode', + 19 => 'Relocating', +}; + +$mapping_sensortype = { + 0 => 'unknown', + 1 => 'other', + 2 => 'temp', # Temperature + 3 => 'volt', # Voltage + 4 => 'current', # Current + 5 => 'tachometer', + 6 => 'counter', + 7 => 'switch', + 8 => 'lock', + 9 => 'hum', # Humidity + 10 => 'smoke_detection', # Smoke Detection + 11 => 'presence', + 12 => 'air_flow', # Air Flow + 13 => 'power_consumption', # Power Consumption + 14 => 'power_production', # Power Production + 15 => 'pressure_intrusion', # PressureIntrusion + 16 => 'intrusion', +}; + +$mapping_units = { + 0 => '', + 1 => '', + 2 => 'C', # Degrees C + 3 => 'F', # Degrees F + 4 => 'K', # Degrees K + 5 => 'V', # Volts + 6 => 'A', # Amps, + 7 => 'W', # Watts + 8 => 'Joules', + 9 => 'Coulombs', + 10 => 'VA', + 11 => 'Nits', + 12 => 'Lumens', + 13 => 'Lux', + 14 => 'Candelas', + 15 => 'kPa', + 16 => 'PSI', + 17 => 'Newtons', + 18 => 'CFM', + 19 => 'rpm', + 20 => 'Hz', # Hertz + 21 => 'Seconds', + 22 => 'Minutes', + 23 => 'Hours', + 24 => 'Days', + 25 => 'Weeks', + 26 => 'Mils', + 27 => 'Inches', + 28 => 'Feet', + 29 => 'Cubic_Inches', + 30 => 'Cubic_Feet', + 31 => 'Meters', + 32 => 'Cubic_Centimeters', + 33 => 'Cubic_Meters', + 34 => 'Liters', + 35 => 'Fluid_Ounces', + 36 => 'Radians', + 37 => 'Steradians', + 38 => 'Revolutions', + 39 => 'Cycles', + 40 => 'Gravities', + 41 => 'Ounces', + 42 => 'Pounds', + 43 => 'Foot_Pounds', + 44 => 'Ounce_Inches', + 45 => 'Gauss', + 46 => 'Gilberts', + 47 => 'Henries', + 48 => 'Farads', + 49 => 'Ohms', + 50 => 'Siemens', + 51 => 'Moles', + 52 => 'Becquerels', + 53 => 'PPM', + 54 => 'Decibels', + 55 => 'DbA', + 56 => 'DbC', + 57 => 'Grays', + 58 => 'Sieverts', + 59 => 'Color_Temperature_Degrees_K', + 60 => 'b', # bits + 61 => 'B', # Bytes + 62 => 'Words', + 63 => 'DoubleWords', + 64 => 'QuadWords', + 65 => '%', # Percentage, + 66 => 'Pascals', +}; + +1; \ No newline at end of file diff --git a/centreon-plugins/apps/vmware/wsman/mode/components/vmware_battery.pm b/centreon-plugins/apps/vmware/wsman/mode/components/vmware_battery.pm new file mode 100644 index 000000000..bd69cc7ce --- /dev/null +++ b/centreon-plugins/apps/vmware/wsman/mode/components/vmware_battery.pm @@ -0,0 +1,60 @@ +# +# Copyright 2015 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 apps::vmware::wsman::mode::components::vmware_battery; + +use strict; +use warnings; + +sub check { + my ($self) = @_; + + my $result = $self->{wsman}->request(uri => 'http://schemas.vmware.com/wbem/wscim/1/cim-schema/2/VMware_Battery'); + + $self->{output}->output_add(long_msg => "Checking vmware batteries"); + $self->{components}->{vmware_battery} = {name => 'batteries', total => 0, skip => 0}; + return if ($self->check_filter(section => 'vmware_battery')); + + foreach (@{$result}) { + my $instance = defined($_->{Name}) && $_->{Name} ne '' ? $_->{Name} : $_->{ElementName}; + + next if ($self->check_filter(section => 'vmware_battery', instance => $instance)); + my $status = $self->get_status(entry => $_); + if (!defined($status)) { + $self->{output}->output_add(long_msg => sprintf("skipping battery '%s' : no status", $_->{ElementName}), debug => 1); + next; + } + + $self->{components}->{vmware_battery}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("Battery '%s' status is '%s' [instance: %s].", + $_->{ElementName}, $status, + $instance + )); + my $exit = $self->get_severity(section => 'vmware_battery', label => 'default', value => $status); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Battery '%s' status is '%s'", + $_->{ElementName}, $status)); + } + } +} + +1; \ No newline at end of file diff --git a/centreon-plugins/apps/vmware/wsman/mode/components/vmware_controller.pm b/centreon-plugins/apps/vmware/wsman/mode/components/vmware_controller.pm new file mode 100644 index 000000000..f254f5790 --- /dev/null +++ b/centreon-plugins/apps/vmware/wsman/mode/components/vmware_controller.pm @@ -0,0 +1,60 @@ +# +# Copyright 2015 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 apps::vmware::wsman::mode::components::vmware_controller; + +use strict; +use warnings; + +sub check { + my ($self) = @_; + + my $result = $self->{wsman}->request(uri => 'http://schemas.vmware.com/wbem/wscim/1/cim-schema/2/VMware_Controller'); + + $self->{output}->output_add(long_msg => "Checking vmware controller"); + $self->{components}->{vmware_controller} = {name => 'controller', total => 0, skip => 0}; + return if ($self->check_filter(section => 'vmware_controller')); + + foreach (@{$result}) { + my $instance = defined($_->{Name}) && $_->{Name} ne '' ? $_->{Name} : $_->{ElementName}; + + next if ($self->check_filter(section => 'vmware_controller', instance => $instance)); + my $status = $self->get_status(entry => $_); + if (!defined($status)) { + $self->{output}->output_add(long_msg => sprintf("skipping controller '%s' : no status", $_->{ElementName}), debug => 1); + next; + } + + $self->{components}->{vmware_controller}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("Controller '%s' status is '%s' [instance: %s].", + $_->{ElementName}, $status, + $instance + )); + my $exit = $self->get_severity(section => 'vmware_controller', label => 'default', value => $status); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Controller '%s' status is '%s'", + $_->{ElementName}, $status)); + } + } +} + +1; \ No newline at end of file diff --git a/centreon-plugins/apps/vmware/wsman/mode/components/vmware_sassataport.pm b/centreon-plugins/apps/vmware/wsman/mode/components/vmware_sassataport.pm new file mode 100644 index 000000000..a95dc3069 --- /dev/null +++ b/centreon-plugins/apps/vmware/wsman/mode/components/vmware_sassataport.pm @@ -0,0 +1,60 @@ +# +# Copyright 2015 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 apps::vmware::wsman::mode::components::vmware_sassataport; + +use strict; +use warnings; + +sub check { + my ($self) = @_; + + my $result = $self->{wsman}->request(uri => 'http://schemas.vmware.com/wbem/wscim/1/cim-schema/2/VMware_SASSATAPort'); + + $self->{output}->output_add(long_msg => "Checking vmware sas/sata ports"); + $self->{components}->{vmware_sassataport} = {name => 'sas/sata ports', total => 0, skip => 0}; + return if ($self->check_filter(section => 'vmware_sassataport')); + + foreach (@{$result}) { + my $instance = defined($_->{Name}) && $_->{Name} ne '' ? $_->{Name} : $_->{ElementName}; + + next if ($self->check_filter(section => 'vmware_sassataport', instance => $instance)); + my $status = $self->get_status(entry => $_); + if (!defined($status)) { + $self->{output}->output_add(long_msg => sprintf("skipping sas/sata port '%s' : no status", $_->{ElementName}), debug => 1); + next; + } + + $self->{components}->{vmware_sassataport}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("Sas/Sata port '%s' status is '%s' [instance: %s].", + $_->{ElementName}, $status, + $instance + )); + my $exit = $self->get_severity(section => 'vmware_sassataport', label => 'default', value => $status); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Sas/Sata port '%s' status is '%s'", + $_->{ElementName}, $status)); + } + } +} + +1; \ No newline at end of file diff --git a/centreon-plugins/apps/vmware/wsman/mode/components/vmware_storageextent.pm b/centreon-plugins/apps/vmware/wsman/mode/components/vmware_storageextent.pm new file mode 100644 index 000000000..5d4acee7c --- /dev/null +++ b/centreon-plugins/apps/vmware/wsman/mode/components/vmware_storageextent.pm @@ -0,0 +1,60 @@ +# +# Copyright 2015 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 apps::vmware::wsman::mode::components::vmware_storageextent; + +use strict; +use warnings; + +sub check { + my ($self) = @_; + + my $result = $self->{wsman}->request(uri => 'http://schemas.vmware.com/wbem/wscim/1/cim-schema/2/VMware_StorageExtent'); + + $self->{output}->output_add(long_msg => "Checking vmware storage extent"); + $self->{components}->{vmware_storageextent} = {name => 'storage extent', total => 0, skip => 0}; + return if ($self->check_filter(section => 'vmware_storageextent')); + + foreach (@{$result}) { + my $instance = defined($_->{Name}) && $_->{Name} ne '' ? $_->{Name} : $_->{ElementName}; + + next if ($self->check_filter(section => 'vmware_storageextent', instance => $instance)); + my $status = $self->get_status(entry => $_); + if (!defined($status)) { + $self->{output}->output_add(long_msg => sprintf("skipping storage extent '%s' : no status", $_->{ElementName}), debug => 1); + next; + } + + $self->{components}->{vmware_storageextent}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("Storage extent '%s' status is '%s' [instance: %s].", + $_->{ElementName}, $status, + $instance + )); + my $exit = $self->get_severity(section => 'vmware_storageextent', label => 'default', value => $status); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Storage extent '%s' status is '%s'", + $_->{ElementName}, $status)); + } + } +} + +1; \ No newline at end of file diff --git a/centreon-plugins/apps/vmware/wsman/mode/components/vmware_storagevolume.pm b/centreon-plugins/apps/vmware/wsman/mode/components/vmware_storagevolume.pm new file mode 100644 index 000000000..1a2e741ce --- /dev/null +++ b/centreon-plugins/apps/vmware/wsman/mode/components/vmware_storagevolume.pm @@ -0,0 +1,60 @@ +# +# Copyright 2015 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 apps::vmware::wsman::mode::components::vmware_storagevolume; + +use strict; +use warnings; + +sub check { + my ($self) = @_; + + my $result = $self->{wsman}->request(uri => 'http://schemas.vmware.com/wbem/wscim/1/cim-schema/2/VMware_StorageVolume'); + + $self->{output}->output_add(long_msg => "Checking vmware storage volumes"); + $self->{components}->{vmware_storagevolume} = {name => 'storage volumes', total => 0, skip => 0}; + return if ($self->check_filter(section => 'vmware_storagevolume')); + + foreach (@{$result}) { + my $instance = defined($_->{Name}) && $_->{Name} ne '' ? $_->{Name} : $_->{ElementName}; + + next if ($self->check_filter(section => 'vmware_storagevolume', instance => $instance)); + my $status = $self->get_status(entry => $_); + if (!defined($status)) { + $self->{output}->output_add(long_msg => sprintf("skipping storage volume '%s' : no status", $_->{ElementName}), debug => 1); + next; + } + + $self->{components}->{vmware_storagevolume}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("Storage volume '%s' status is '%s' [instance: %s].", + $_->{ElementName}, $status, + $instance + )); + my $exit = $self->get_severity(section => 'vmware_storagevolume', label => 'default', value => $status); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Storage volume '%s' status is '%s'", + $_->{ElementName}, $status)); + } + } +} + +1; \ No newline at end of file diff --git a/centreon-plugins/apps/vmware/wsman/mode/hardware.pm b/centreon-plugins/apps/vmware/wsman/mode/hardware.pm new file mode 100644 index 000000000..b263de894 --- /dev/null +++ b/centreon-plugins/apps/vmware/wsman/mode/hardware.pm @@ -0,0 +1,336 @@ +# +# Copyright 2015 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 apps::vmware::wsman::mode::hardware; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; +use apps::vmware::wsman::mode::components::resources qw($mapping_HealthState $mapping_OperationalStatus); + +my %type = ('cim_numericsensor' => 1); + +my $thresholds = { + default => [ + ['Unknown', 'OK'], + ['OK', 'OK'], + ['Degraded', 'WARNING'], + ['Minor failure', 'WARNING'], + ['Major failure', 'CRITICAL'], + ['Critical failure', 'CRITICAL'], + ['Non-recoverable error', 'CRITICAL'], + + ['Other', 'UNKNOWN'], + ['Stressed', 'WARNING'], + ['Predictive Failure', 'WARNING'], + ['Error', 'CRITICAL'], + ['Starting', 'OK'], + ['Stopping', 'WARNING'], + ['In Service', 'OK'], + ['No Contact', 'CRITICAL'], + ['Lost Communication', 'CRITICAL'], + ['Aborted', 'CRITICAL'], + ['Dormant', 'OK'], + ['Supporting Entity in Error', 'CRITICAL'], + ['Completed', 'OK'], + ['Power Mode', 'OK'], + ['Relocating', 'WARNING'], + ], +}; + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + "filter:s@" => { name => 'filter' }, + "component:s" => { name => 'component', default => '.*' }, + "no-component:s" => { name => 'no_component' }, + "threshold-overload:s@" => { name => 'threshold_overload' }, + "warning:s@" => { name => 'warning' }, + "critical:s@" => { name => 'critical' }, + }); + + $self->{components} = {}; + $self->{no_components} = undef; + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); + + if (defined($self->{option_results}->{no_component})) { + if ($self->{option_results}->{no_component} ne '') { + $self->{no_components} = $self->{option_results}->{no_component}; + } else { + $self->{no_components} = 'critical'; + } + } + + $self->{filter} = []; + foreach my $val (@{$self->{option_results}->{filter}}) { + next if (!defined($val) || $val eq ''); + my @values = split (/,/, $val); + push @{$self->{filter}}, { filter => $values[0], instance => $values[1] }; + } + + $self->{overload_th} = {}; + foreach my $val (@{$self->{option_results}->{threshold_overload}}) { + next if (!defined($val) || $val eq ''); + my @values = split (/,/, $val); + if (scalar(@values) < 3) { + $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload option '" . $val . "'."); + $self->{output}->option_exit(); + } + my ($section, $instance, $status, $filter); + if (scalar(@values) == 3) { + ($section, $status, $filter) = @values; + $instance = '.*'; + } else { + ($section, $instance, $status, $filter) = @values; + } + if ($self->{output}->is_litteral_status(status => $status) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload status '" . $val . "'."); + $self->{output}->option_exit(); + } + $self->{overload_th}->{$section} = [] if (!defined($self->{overload_th}->{$section})); + push @{$self->{overload_th}->{$section}}, {filter => $filter, status => $status, instance => $instance }; + } + + $self->{numeric_threshold} = {}; + foreach my $option (('warning', 'critical')) { + foreach my $val (@{$self->{option_results}->{$option}}) { + next if (!defined($val) || $val eq ''); + if ($val !~ /^(.*?),(.*?),(.*)$/) { + $self->{output}->add_option_msg(short_msg => "Wrong $option option '" . $val . "'."); + $self->{output}->option_exit(); + } + my ($section, $instance, $value) = ($1, $2, $3); + if (!defined($type{$section})) { + $self->{output}->add_option_msg(short_msg => "Wrong $option option '" . $val . "'."); + $self->{output}->option_exit(); + } + my $position = 0; + if (defined($self->{numeric_threshold}->{$section})) { + $position = scalar(@{$self->{numeric_threshold}->{$section}}); + } + if (($self->{perfdata}->threshold_validate(label => $option . '-' . $section . '-' . $position, value => $value)) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong $option threshold '" . $value . "'."); + $self->{output}->option_exit(); + } + $self->{numeric_threshold}->{$section} = [] if (!defined($self->{numeric_threshold}->{$section})); + push @{$self->{numeric_threshold}->{$section}}, { label => $option . '-' . $section . '-' . $position, threshold => $option, instance => $instance }; + } + } +} + + +sub get_type { + my ($self, %options) = @_; + + my $result = $self->{wsman}->request(uri => 'http://schema.omc-project.org/wbem/wscim/1/cim-schema/2/OMC_SMASHFirmwareIdentity'); + $result = pop(@$result); + $self->{manufacturer} = 'unknown'; + if (defined($result->{Manufacturer}) && $result->{Manufacturer} ne '') { + $self->{manufacturer} = $result->{Manufacturer}; + } + + $result = $self->{wsman}->request(uri => 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_Chassis'); + $result = pop(@$result); + my $model = defined($result->{Model}) && $result->{Model} ne '' ? $result->{Model} : 'unknown'; + + $self->{output}->output_add(long_msg => sprintf("Manufacturer : %s, Model : %s", $self->{manufacturer}, $model)); +} + +sub get_status { + my ($self, %options) = @_; + + my $status; + if ($self->{manufacturer} =~ /HP/i) { + $status = $mapping_HealthState->{$options{entry}->{HealthState}} if (defined($options{entry}->{HealthState}) && + defined($mapping_HealthState->{$options{entry}->{HealthState}})); + } else { + $status = $mapping_OperationalStatus->{$options{entry}->{OperationalStatus}} if (defined($options{entry}->{OperationalStatus}) && + defined($mapping_OperationalStatus->{$options{entry}->{OperationalStatus}})); + } + return $status; +} + +sub run { + my ($self, %options) = @_; + $self->{wsman} = $options{wsman}; + + $self->get_type(); + + my @components = ('omc_discretesensor', 'omc_fan', 'omc_psu', 'vmware_storageextent', 'vmware_controller', + 'vmware_storagevolume', 'vmware_battery', 'vmware_sassataport', 'cim_card', + 'cim_computersystem', 'cim_numericsensor', 'cim_memory', 'cim_processor', 'cim_recordlog'); + foreach (@components) { + if (/$self->{option_results}->{component}/) { + my $mod_name = "apps::vmware::wsman::mode::components::$_"; + centreon::plugins::misc::mymodule_load(output => $self->{output}, module => $mod_name, + error_msg => "Cannot load module '$mod_name'."); + my $func = $mod_name->can('check'); + $func->($self); + } + } + + my $total_components = 0; + my $display_by_component = ''; + my $display_by_component_append = ''; + foreach my $comp (sort(keys %{$self->{components}})) { + # Skipping short msg when no components + next if ($self->{components}->{$comp}->{total} == 0 && $self->{components}->{$comp}->{skip} == 0); + $total_components += $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip}; + my $count_by_components = $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip}; + $display_by_component .= $display_by_component_append . $self->{components}->{$comp}->{total} . '/' . $count_by_components . ' ' . $self->{components}->{$comp}->{name}; + $display_by_component_append = ', '; + } + + $self->{output}->output_add(severity => 'OK', + short_msg => sprintf("All %s sensors are ok [%s].", + $total_components, + $display_by_component) + ); + + if (defined($self->{option_results}->{no_component}) && $total_components == 0) { + $self->{output}->output_add(severity => $self->{no_components}, + short_msg => 'No sensors are checked.'); + } + + $self->{output}->display(); + $self->{output}->exit(); +} + +sub check_filter { + my ($self, %options) = @_; + + foreach (@{$self->{filter}}) { + if ($options{section} =~ /$_->{filter}/) { + if (!defined($options{instance}) && !defined($_->{instance})) { + $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section.")); + return 1; + } elsif (defined($options{instance}) && $options{instance} =~ /$_->{instance}/) { + $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance.")); + return 1; + } + } + } + + return 0; +} + +sub get_severity_numeric { + my ($self, %options) = @_; + my $status = 'OK'; # default + my $thresholds = { warning => undef, critical => undef }; + my $checked = 0; + + if (defined($self->{numeric_threshold}->{$options{section}})) { + my $exits = []; + foreach (@{$self->{numeric_threshold}->{$options{section}}}) { + if ($options{instance} =~ /$_->{instance}/) { + push @{$exits}, $self->{perfdata}->threshold_check(value => $options{value}, threshold => [ { label => $_->{label}, exit_litteral => $_->{threshold} } ]); + $thresholds->{$_->{threshold}} = $self->{perfdata}->get_perfdata_for_output(label => $_->{label}); + $checked = 1; + } + } + $status = $self->{output}->get_most_critical(status => $exits) if (scalar(@{$exits}) > 0); + } + + return ($status, $thresholds->{warning}, $thresholds->{critical}, $checked); +} + +sub get_severity { + my ($self, %options) = @_; + my $status = 'UNKNOWN'; # default + + if (defined($self->{overload_th}->{$options{section}})) { + foreach (@{$self->{overload_th}->{$options{section}}}) { + if ($options{value} =~ /$_->{filter}/i && + (!defined($options{instance}) || $options{instance} =~ /$_->{instance}/)) { + $status = $_->{status}; + return $status; + } + } + } + my $label = defined($options{label}) ? $options{label} : $options{section}; + foreach (@{$thresholds->{$label}}) { + if ($options{value} =~ /$$_[0]/i) { + $status = $$_[1]; + return $status; + } + } + + return $status; +} + +1; + +__END__ + +=head1 MODE + +Check ESXi Hardware. + +=over 8 + +=item B<--component> + +Which component to check (Default: '.*'). +Can be: 'omc_discretesensor', 'omc_fan', 'omc_psu', 'vmware_storageextent', 'vmware_controller', +'vmware_storagevolume', 'vmware_battery', 'vmware_sassataport', 'cim_card', +'cim_computersystem', 'cim_numericsensor', 'cim_memory', 'cim_processor', 'cim_recordlog'. + +=item B<--filter> + +Exclude some parts (comma seperated list) (Example: --filter=cim_card --filter=cim_recordlog) +Can also exclude specific instance: --filter='omc_psu,Power Supply 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='cim_card,CRITICAL,^(?!(OK)$)' + +=item B<--warning> + +Set warning threshold for temperatures (syntax: type,instance,threshold) +Example: --warning='cim_numericsensor,.*,30' + +=item B<--critical> + +Set critical threshold for temperatures (syntax: type,instance,threshold) +Example: --critical='cim_numericsensor,.*,40' + +=back + +=cut \ No newline at end of file diff --git a/centreon-plugins/apps/vmware/wsman/plugin.pm b/centreon-plugins/apps/vmware/wsman/plugin.pm new file mode 100644 index 000000000..f29127443 --- /dev/null +++ b/centreon-plugins/apps/vmware/wsman/plugin.pm @@ -0,0 +1,49 @@ +# +# Copyright 2015 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 apps::vmware::wsman::plugin; + +use strict; +use warnings; +use base qw(centreon::plugins::script_wsman); + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + # $options->{options} = options object + + $self->{version} = '0.1'; + %{$self->{modes}} = ( + 'hardware' => 'apps::vmware::wsman::mode::hardware', + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check VMWare ESXi Hardware (ws-management protocol). + +=cut diff --git a/centreon-plugins/centreon/plugins/wsman.pm b/centreon-plugins/centreon/plugins/wsman.pm index be34c8147..791874c00 100644 --- a/centreon-plugins/centreon/plugins/wsman.pm +++ b/centreon-plugins/centreon/plugins/wsman.pm @@ -312,8 +312,8 @@ sub request { ###### # Check options - if (!defined($options{uri}) || !defined($options{wql_filter})) { - $self->{output}->add_option_msg(short_msg => 'Need to specify wql_filter and uri options'); + if (!defined($options{uri})) { + $self->{output}->add_option_msg(short_msg => 'Need to specify uri option'); $self->{output}->option_exit(exit_litteral => $self->{wsman_errors_exit}); } @@ -328,10 +328,13 @@ sub request { ###### # Filter/Enumerate - my $filter = new openwsman::Filter::() + my $filter; + if (defined($options{wql_filter})) { + $filter = new openwsman::Filter::() or $self->internal_exit(msg => 'Could not create filter'); - $filter->wql($options{wql_filter}); - + $filter->wql($options{wql_filter}); + } + my $result = $self->{client}->enumerate($client_options, $filter, $options{uri}); return undef if ($self->handle_dialog_fault(result => $result, msg => 'Could not enumerate instances: ', dont_quit => $dont_quit)); From 09f9d6672e418ce775244bc1083d72b2fe18bf07 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Mon, 30 Nov 2015 16:41:31 +0100 Subject: [PATCH 15/26] + add command example --- centreon-plugins/apps/vmware/wsman/mode/hardware.pm | 2 ++ 1 file changed, 2 insertions(+) diff --git a/centreon-plugins/apps/vmware/wsman/mode/hardware.pm b/centreon-plugins/apps/vmware/wsman/mode/hardware.pm index b263de894..bcac00b63 100644 --- a/centreon-plugins/apps/vmware/wsman/mode/hardware.pm +++ b/centreon-plugins/apps/vmware/wsman/mode/hardware.pm @@ -295,6 +295,8 @@ __END__ =head1 MODE Check ESXi Hardware. +Example: centreon_plugins.pl --plugin=apps::vmware::wsman::plugin --mode=hardware --hostname='XXX.XXX.XXX.XXX' +--wsman-username='XXXX' --wsman-password='XXXX' --wsman-scheme=https --wsman-port=443 --verbose =over 8 From 5da933c56bcf49c5d8bf55fa80f9d424e73d6dd9 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Tue, 1 Dec 2015 10:20:35 +0100 Subject: [PATCH 16/26] + Fix #225 --- .../ups/standard/rfc1628/snmp/mode/batterystatus.pm | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/centreon-plugins/hardware/ups/standard/rfc1628/snmp/mode/batterystatus.pm b/centreon-plugins/hardware/ups/standard/rfc1628/snmp/mode/batterystatus.pm index ebd71964d..3c4ecc8e9 100644 --- a/centreon-plugins/hardware/ups/standard/rfc1628/snmp/mode/batterystatus.pm +++ b/centreon-plugins/hardware/ups/standard/rfc1628/snmp/mode/batterystatus.pm @@ -76,11 +76,15 @@ sub run { my $result = $self->{snmp}->get_table(oid => $oid_upsBattery, nothing_quit => 1); - my $current = defined($result->{$oid_upsBatteryCurrent}) ? $result->{$oid_upsBatteryCurrent} * 0.1 : 0; - my $voltage = defined($result->{$oid_upsBatteryVoltage}) ? $result->{$oid_upsBatteryVoltage} * 0.1 : 0; + my $current = (defined($result->{$oid_upsBatteryCurrent}) && $result->{$oid_upsBatteryCurrent} =~ /\d/) ? + $result->{$oid_upsBatteryCurrent} * 0.1 : 0; + my $voltage = (defined($result->{$oid_upsBatteryVoltage}) && $result->{$oid_upsBatteryVoltage} =~ /\d/) ? + $result->{$oid_upsBatteryVoltage} * 0.1 : 0; my $temp = defined($result->{$oid_upsBatteryTemperature}) ? $result->{$oid_upsBatteryTemperature} : 0; - my $min_remain = defined($result->{$oid_upsEstimatedMinutesRemaining}) ? $result->{$oid_upsEstimatedMinutesRemaining} : 'unknown'; - my $charge_remain = defined($result->{$oid_upsEstimatedChargeRemaining}) ? $result->{$oid_upsEstimatedChargeRemaining} : 'unknown'; + my $min_remain = (defined($result->{$oid_upsEstimatedMinutesRemaining}) && $result->{$oid_upsEstimatedMinutesRemaining} =~ /\d/) ? + $result->{$oid_upsEstimatedMinutesRemaining} : 'unknown'; + my $charge_remain = (defined($result->{$oid_upsEstimatedChargeRemaining}) && $result->{$oid_upsEstimatedChargeRemaining} =~ /\d/) ? + $result->{$oid_upsEstimatedChargeRemaining} : 'unknown'; my $status = defined($result->{$oid_upsBatteryStatus}) ? $result->{$oid_upsBatteryStatus} : 1; # we put unknown ??? $self->{output}->output_add(severity => ${$battery_status{$status}}[1], From f13e045a7e31c61d58c0457161ae001ebcc79b08 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Tue, 1 Dec 2015 10:28:47 +0100 Subject: [PATCH 17/26] + Fix #225 --- .../hardware/ups/standard/rfc1628/snmp/mode/inputlines.pm | 4 ++-- .../hardware/ups/standard/rfc1628/snmp/mode/outputlines.pm | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/centreon-plugins/hardware/ups/standard/rfc1628/snmp/mode/inputlines.pm b/centreon-plugins/hardware/ups/standard/rfc1628/snmp/mode/inputlines.pm index 0a6d31623..cc25c5aa7 100644 --- a/centreon-plugins/hardware/ups/standard/rfc1628/snmp/mode/inputlines.pm +++ b/centreon-plugins/hardware/ups/standard/rfc1628/snmp/mode/inputlines.pm @@ -142,7 +142,7 @@ sub run { my @exits; foreach (keys %{$maps_counters}) { foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) { - if (defined($self->{counters_value}->{$instance}->{$_}) && $self->{counters_value}->{$instance}->{$_} != 0) { + if (defined($self->{counters_value}->{$instance}->{$_}) && $self->{counters_value}->{$instance}->{$_} ne '' && $self->{counters_value}->{$instance}->{$_} != 0) { push @exits, $self->{perfdata}->threshold_check(value => $self->{counters_value}->{$instance}->{$_} * $maps_counters->{$_}->{factor}, threshold => [ { label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, 'exit_litteral' => $maps_counters->{$_}->{thresholds}->{$name}->{exit_value} }]); } } @@ -155,7 +155,7 @@ sub run { my $str_output = "Input Line '$instance_output' "; my $str_append = ''; foreach (keys %{$maps_counters}) { - next if (!defined($self->{counters_value}->{$instance}->{$_}) || $self->{counters_value}->{$instance}->{$_} == 0); + next if (!defined($self->{counters_value}->{$instance}->{$_}) || $self->{counters_value}->{$instance}->{$_} == 0 || $self->{counters_value}->{$instance}->{$_} eq ''); $str_output .= $str_append . sprintf($maps_counters->{$_}->{output_msg}, $self->{counters_value}->{$instance}->{$_} * $maps_counters->{$_}->{factor}); $str_append = ', '; diff --git a/centreon-plugins/hardware/ups/standard/rfc1628/snmp/mode/outputlines.pm b/centreon-plugins/hardware/ups/standard/rfc1628/snmp/mode/outputlines.pm index b4805867d..937ccfba3 100644 --- a/centreon-plugins/hardware/ups/standard/rfc1628/snmp/mode/outputlines.pm +++ b/centreon-plugins/hardware/ups/standard/rfc1628/snmp/mode/outputlines.pm @@ -182,7 +182,7 @@ sub run { my @exits; foreach (keys %{$maps_counters}) { foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) { - if (defined($self->{counters_value}->{$instance}->{$_}) && $self->{counters_value}->{$instance}->{$_} == $maps_counters->{$_}->{no_present}) { + if (defined($self->{counters_value}->{$instance}->{$_}) && $self->{counters_value}->{$instance}->{$_} ne '' && $self->{counters_value}->{$instance}->{$_} != $maps_counters->{$_}->{no_present}) { push @exits, $self->{perfdata}->threshold_check(value => $self->{counters_value}->{$instance}->{$_} * $maps_counters->{$_}->{factor}, threshold => [ { label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, 'exit_litteral' => $maps_counters->{$_}->{thresholds}->{$name}->{exit_value} }]); } } @@ -195,7 +195,7 @@ sub run { my $str_output = "Output Line '$instance_output' "; my $str_append = ''; foreach (keys %{$maps_counters}) { - next if (!defined($self->{counters_value}->{$instance}->{$_}) || $self->{counters_value}->{$instance}->{$_} == $maps_counters->{$_}->{no_present}); + next if (!defined($self->{counters_value}->{$instance}->{$_}) || $self->{counters_value}->{$instance}->{$_} == $maps_counters->{$_}->{no_present} || $self->{counters_value}->{$instance}->{$_} eq ''); $str_output .= $str_append . sprintf($maps_counters->{$_}->{output_msg}, $self->{counters_value}->{$instance}->{$_} * $maps_counters->{$_}->{factor}); $str_append = ', '; From dad8c0da56a96b95438d0d32132323a461f79dc2 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Tue, 1 Dec 2015 10:31:22 +0100 Subject: [PATCH 18/26] + Fix #225 --- .../hardware/ups/standard/rfc1628/snmp/mode/inputlines.pm | 4 ++-- .../hardware/ups/standard/rfc1628/snmp/mode/outputlines.pm | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/centreon-plugins/hardware/ups/standard/rfc1628/snmp/mode/inputlines.pm b/centreon-plugins/hardware/ups/standard/rfc1628/snmp/mode/inputlines.pm index cc25c5aa7..4f4d2b9c6 100644 --- a/centreon-plugins/hardware/ups/standard/rfc1628/snmp/mode/inputlines.pm +++ b/centreon-plugins/hardware/ups/standard/rfc1628/snmp/mode/inputlines.pm @@ -142,7 +142,7 @@ sub run { my @exits; foreach (keys %{$maps_counters}) { foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) { - if (defined($self->{counters_value}->{$instance}->{$_}) && $self->{counters_value}->{$instance}->{$_} ne '' && $self->{counters_value}->{$instance}->{$_} != 0) { + if (defined($self->{counters_value}->{$instance}->{$_}) && $self->{counters_value}->{$instance}->{$_} != 0 && $self->{counters_value}->{$instance}->{$_} =~ /\d/) { push @exits, $self->{perfdata}->threshold_check(value => $self->{counters_value}->{$instance}->{$_} * $maps_counters->{$_}->{factor}, threshold => [ { label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, 'exit_litteral' => $maps_counters->{$_}->{thresholds}->{$name}->{exit_value} }]); } } @@ -155,7 +155,7 @@ sub run { my $str_output = "Input Line '$instance_output' "; my $str_append = ''; foreach (keys %{$maps_counters}) { - next if (!defined($self->{counters_value}->{$instance}->{$_}) || $self->{counters_value}->{$instance}->{$_} == 0 || $self->{counters_value}->{$instance}->{$_} eq ''); + next if (!defined($self->{counters_value}->{$instance}->{$_}) || $self->{counters_value}->{$instance}->{$_} == 0 || $self->{counters_value}->{$instance}->{$_} !~ /\d/); $str_output .= $str_append . sprintf($maps_counters->{$_}->{output_msg}, $self->{counters_value}->{$instance}->{$_} * $maps_counters->{$_}->{factor}); $str_append = ', '; diff --git a/centreon-plugins/hardware/ups/standard/rfc1628/snmp/mode/outputlines.pm b/centreon-plugins/hardware/ups/standard/rfc1628/snmp/mode/outputlines.pm index 937ccfba3..c59c34b12 100644 --- a/centreon-plugins/hardware/ups/standard/rfc1628/snmp/mode/outputlines.pm +++ b/centreon-plugins/hardware/ups/standard/rfc1628/snmp/mode/outputlines.pm @@ -182,7 +182,7 @@ sub run { my @exits; foreach (keys %{$maps_counters}) { foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) { - if (defined($self->{counters_value}->{$instance}->{$_}) && $self->{counters_value}->{$instance}->{$_} ne '' && $self->{counters_value}->{$instance}->{$_} != $maps_counters->{$_}->{no_present}) { + if (defined($self->{counters_value}->{$instance}->{$_}) && $self->{counters_value}->{$instance}->{$_} != $maps_counters->{$_}->{no_present} && $self->{counters_value}->{$instance}->{$_} =~ /\d/) { push @exits, $self->{perfdata}->threshold_check(value => $self->{counters_value}->{$instance}->{$_} * $maps_counters->{$_}->{factor}, threshold => [ { label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, 'exit_litteral' => $maps_counters->{$_}->{thresholds}->{$name}->{exit_value} }]); } } @@ -195,7 +195,7 @@ sub run { my $str_output = "Output Line '$instance_output' "; my $str_append = ''; foreach (keys %{$maps_counters}) { - next if (!defined($self->{counters_value}->{$instance}->{$_}) || $self->{counters_value}->{$instance}->{$_} == $maps_counters->{$_}->{no_present} || $self->{counters_value}->{$instance}->{$_} eq ''); + next if (!defined($self->{counters_value}->{$instance}->{$_}) || $self->{counters_value}->{$instance}->{$_} == $maps_counters->{$_}->{no_present} || $self->{counters_value}->{$instance}->{$_} !~ /\d/); $str_output .= $str_append . sprintf($maps_counters->{$_}->{output_msg}, $self->{counters_value}->{$instance}->{$_} * $maps_counters->{$_}->{factor}); $str_append = ', '; From e945a7e83e5f3e82f5a41beef3f5f3a54fbf6963 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Tue, 1 Dec 2015 10:33:46 +0100 Subject: [PATCH 19/26] + Fix #225 --- .../hardware/ups/standard/rfc1628/snmp/mode/inputlines.pm | 4 ++-- .../hardware/ups/standard/rfc1628/snmp/mode/outputlines.pm | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/centreon-plugins/hardware/ups/standard/rfc1628/snmp/mode/inputlines.pm b/centreon-plugins/hardware/ups/standard/rfc1628/snmp/mode/inputlines.pm index 4f4d2b9c6..c32268205 100644 --- a/centreon-plugins/hardware/ups/standard/rfc1628/snmp/mode/inputlines.pm +++ b/centreon-plugins/hardware/ups/standard/rfc1628/snmp/mode/inputlines.pm @@ -142,7 +142,7 @@ sub run { my @exits; foreach (keys %{$maps_counters}) { foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) { - if (defined($self->{counters_value}->{$instance}->{$_}) && $self->{counters_value}->{$instance}->{$_} != 0 && $self->{counters_value}->{$instance}->{$_} =~ /\d/) { + if (defined($self->{counters_value}->{$instance}->{$_}) && $self->{counters_value}->{$instance}->{$_} =~ /\d/ && $self->{counters_value}->{$instance}->{$_} != 0) { push @exits, $self->{perfdata}->threshold_check(value => $self->{counters_value}->{$instance}->{$_} * $maps_counters->{$_}->{factor}, threshold => [ { label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, 'exit_litteral' => $maps_counters->{$_}->{thresholds}->{$name}->{exit_value} }]); } } @@ -155,7 +155,7 @@ sub run { my $str_output = "Input Line '$instance_output' "; my $str_append = ''; foreach (keys %{$maps_counters}) { - next if (!defined($self->{counters_value}->{$instance}->{$_}) || $self->{counters_value}->{$instance}->{$_} == 0 || $self->{counters_value}->{$instance}->{$_} !~ /\d/); + next if (!defined($self->{counters_value}->{$instance}->{$_}) || $self->{counters_value}->{$instance}->{$_} !~ /\d/ || $self->{counters_value}->{$instance}->{$_} == 0); $str_output .= $str_append . sprintf($maps_counters->{$_}->{output_msg}, $self->{counters_value}->{$instance}->{$_} * $maps_counters->{$_}->{factor}); $str_append = ', '; diff --git a/centreon-plugins/hardware/ups/standard/rfc1628/snmp/mode/outputlines.pm b/centreon-plugins/hardware/ups/standard/rfc1628/snmp/mode/outputlines.pm index c59c34b12..d1efb86c4 100644 --- a/centreon-plugins/hardware/ups/standard/rfc1628/snmp/mode/outputlines.pm +++ b/centreon-plugins/hardware/ups/standard/rfc1628/snmp/mode/outputlines.pm @@ -182,7 +182,7 @@ sub run { my @exits; foreach (keys %{$maps_counters}) { foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) { - if (defined($self->{counters_value}->{$instance}->{$_}) && $self->{counters_value}->{$instance}->{$_} != $maps_counters->{$_}->{no_present} && $self->{counters_value}->{$instance}->{$_} =~ /\d/) { + if (defined($self->{counters_value}->{$instance}->{$_}) && $self->{counters_value}->{$instance}->{$_} =~ /\d/ && $self->{counters_value}->{$instance}->{$_} != $maps_counters->{$_}->{no_present}) { push @exits, $self->{perfdata}->threshold_check(value => $self->{counters_value}->{$instance}->{$_} * $maps_counters->{$_}->{factor}, threshold => [ { label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, 'exit_litteral' => $maps_counters->{$_}->{thresholds}->{$name}->{exit_value} }]); } } @@ -195,7 +195,7 @@ sub run { my $str_output = "Output Line '$instance_output' "; my $str_append = ''; foreach (keys %{$maps_counters}) { - next if (!defined($self->{counters_value}->{$instance}->{$_}) || $self->{counters_value}->{$instance}->{$_} == $maps_counters->{$_}->{no_present} || $self->{counters_value}->{$instance}->{$_} !~ /\d/); + next if (!defined($self->{counters_value}->{$instance}->{$_}) || $self->{counters_value}->{$instance}->{$_} !~ /\d/ || $self->{counters_value}->{$instance}->{$_} == $maps_counters->{$_}->{no_present}); $str_output .= $str_append . sprintf($maps_counters->{$_}->{output_msg}, $self->{counters_value}->{$instance}->{$_} * $maps_counters->{$_}->{factor}); $str_append = ', '; From 43b036939c5235aac40d584ea7006941403da825 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Tue, 1 Dec 2015 13:18:21 +0100 Subject: [PATCH 20/26] + fix cisco environment voltage threshold --- .../common/cisco/standard/snmp/mode/components/voltage.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/voltage.pm b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/voltage.pm index 33530f526..99647b622 100644 --- a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/voltage.pm +++ b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/voltage.pm @@ -77,8 +77,8 @@ sub check { my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'voltage', instance => $instance, value => $result->{ciscoEnvMonVoltageStatusValue}); if ($checked == 0) { my $warn_th = undef; - my $crit_th = (defined($result->{ciscoEnvMonVoltageThresholdLow}) ? sprintf("%.3f", $result->{ciscoEnvMonVoltageThresholdLow}) : 0) . ':' . - (defined($result->{ciscoEnvMonVoltageThresholdHigh}) ? sprintf("%.3f", $result->{ciscoEnvMonVoltageThresholdHigh}) : ''); + my $crit_th = ((defined($result->{ciscoEnvMonVoltageThresholdLow}) && $result->{ciscoEnvMonVoltageThresholdLow} =~ /\d/) ? sprintf("%.3f", $result->{ciscoEnvMonVoltageThresholdLow} / 1000) : 0) . ':' . + ((defined($result->{ciscoEnvMonVoltageThresholdHigh}) && $result->{ciscoEnvMonVoltageThresholdHigh} =~ /\d/) ? sprintf("%.3f", $result->{ciscoEnvMonVoltageThresholdHigh} / 1000) : ''); $self->{perfdata}->threshold_validate(label => 'warning-voltage-instance-' . $instance, value => $warn_th); $self->{perfdata}->threshold_validate(label => 'critical-voltage-instance-' . $instance, value => $crit_th); $warn = $self->{perfdata}->get_perfdata_for_output(label => 'warning-voltage-instance-' . $instance); From a3429ea2714210a0de61793c6523d80aeb414cdd Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Tue, 1 Dec 2015 14:02:20 +0100 Subject: [PATCH 21/26] + Set alternative mode for options (for performance) --- centreon-plugins/centreon/plugins/options.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/centreon-plugins/centreon/plugins/options.pm b/centreon-plugins/centreon/plugins/options.pm index 925095429..3a0cec151 100644 --- a/centreon-plugins/centreon/plugins/options.pm +++ b/centreon-plugins/centreon/plugins/options.pm @@ -25,7 +25,7 @@ use Pod::Find qw(pod_where); use strict; use warnings; -my $alternative = 0; +my $alternative = 1; sub new { my $class = shift; From 22e705608e0c6fa78220bca5b78e2aa29fac7601 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Wed, 2 Dec 2015 11:41:26 +0100 Subject: [PATCH 22/26] + add command for vmware connector 2.1.0 --- .../apps/vmware/connector/mode/servicehost.pm | 102 ++++++++++++++++++ .../apps/vmware/connector/plugin.pm | 1 + 2 files changed, 103 insertions(+) create mode 100644 centreon-plugins/apps/vmware/connector/mode/servicehost.pm diff --git a/centreon-plugins/apps/vmware/connector/mode/servicehost.pm b/centreon-plugins/apps/vmware/connector/mode/servicehost.pm new file mode 100644 index 000000000..6e9ee4a86 --- /dev/null +++ b/centreon-plugins/apps/vmware/connector/mode/servicehost.pm @@ -0,0 +1,102 @@ +# +# Copyright 2015 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 apps::vmware::connector::mode::servicehost; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + "esx-hostname:s" => { name => 'esx_hostname' }, + "filter" => { name => 'filter' }, + "scope-datacenter:s" => { name => 'scope_datacenter' }, + "scope-cluster:s" => { name => 'scope_cluster' }, + "disconnect-status:s" => { name => 'disconnect_status', default => 'unknown' }, + "filter-services:s" => { name => 'filter_services' }, + }); + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); + + if ($self->{output}->is_litteral_status(status => $self->{option_results}->{disconnect_status}) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong disconnect-status status option '" . $self->{option_results}->{disconnect_status} . "'."); + $self->{output}->option_exit(); + } +} + +sub run { + my ($self, %options) = @_; + $self->{connector} = $options{custom}; + + $self->{connector}->add_params(params => $self->{option_results}, + command => 'servicehost'); + $self->{connector}->run(); +} + +1; + +__END__ + +=head1 MODE + +Check ESX services. + +=over 8 + +=item B<--esx-hostname> + +ESX hostname to check. +If not set, we check all ESX. + +=item B<--filter> + +ESX hostname is a regexp. + +=item B<--scope-datacenter> + +Search in following datacenter(s) (can be a regexp). + +=item B<--scope-cluster> + +Search in following cluster(s) (can be a regexp). + +=item B<--disconnect-status> + +Status if ESX host disconnected (default: 'unknown'). + +=item B<--filter-services> + +Filter services you want to check (can be a regexp). + +=back + +=cut diff --git a/centreon-plugins/apps/vmware/connector/plugin.pm b/centreon-plugins/apps/vmware/connector/plugin.pm index a05921c45..f7196b9fc 100644 --- a/centreon-plugins/apps/vmware/connector/plugin.pm +++ b/centreon-plugins/apps/vmware/connector/plugin.pm @@ -54,6 +54,7 @@ sub new { 'memory-host' => 'apps::vmware::connector::mode::memoryhost', 'memory-vm' => 'apps::vmware::connector::mode::memoryvm', 'net-host' => 'apps::vmware::connector::mode::nethost', + 'service-host' => 'apps::vmware::connector::mode::servicehost', 'snapshot-vm' => 'apps::vmware::connector::mode::snapshotvm', 'stat-connectors' => 'apps::vmware::connector::mode::statconnectors', 'status-host' => 'apps::vmware::connector::mode::statushost', From 80bd56fbb7428923125ca09c2afc696be7863302 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Wed, 2 Dec 2015 16:35:30 +0100 Subject: [PATCH 23/26] + Ref #224 : begin the refactoring (WIP) --- centreon-plugins/snmp_standard/mode/inodes.pm | 258 +++++++++--------- 1 file changed, 127 insertions(+), 131 deletions(-) diff --git a/centreon-plugins/snmp_standard/mode/inodes.pm b/centreon-plugins/snmp_standard/mode/inodes.pm index fbd2834b5..ea25cf07b 100644 --- a/centreon-plugins/snmp_standard/mode/inodes.pm +++ b/centreon-plugins/snmp_standard/mode/inodes.pm @@ -24,10 +24,22 @@ use base qw(centreon::plugins::mode); use strict; use warnings; -use centreon::plugins::statefile; +use centreon::plugins::values; -my $oid_dskPath = '.1.3.6.1.4.1.2021.9.1.2'; -my $oid_dskPercentNode = '.1.3.6.1.4.1.2021.9.1.10'; +my $maps_counters = { + disk => { + '000_usage' => { + set => { + key_values => [ { name => 'usage' }, { name => 'display' } ], + output_template => 'Used: %s %%', output_error_template => "%s", + perfdatas => [ + { label => 'used', value => 'usage_absolute', template => '%d', + unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + }, + }, + } +}; sub new { my ($class, %options) = @_; @@ -36,21 +48,29 @@ sub new { $self->{version} = '1.0'; $options{options}->add_options(arguments => - { - "warning:s" => { name => 'warning' }, - "critical:s" => { name => 'critical' }, - "reload-cache-time:s" => { name => 'reload_cache_time', default => 180 }, + { "name" => { name => 'use_name' }, "diskpath:s" => { name => 'diskpath' }, "regexp" => { name => 'use_regexp' }, "regexp-isensitive" => { name => 'use_regexpi' }, "display-transform-src:s" => { name => 'display_transform_src' }, "display-transform-dst:s" => { name => 'display_transform_dst' }, - "show-cache" => { name => 'show_cache' }, }); - $self->{diskpath_id_selected} = []; - $self->{statefile_cache} = centreon::plugins::statefile->new(%options); + foreach my $key (('disk')) { + foreach (keys %{$maps_counters->{$key}}) { + my ($id, $name) = split /_/; + if (!defined($maps_counters->{$key}->{$_}->{threshold}) || $maps_counters->{$key}->{$_}->{threshold} != 0) { + $options{options}->add_options(arguments => { + 'warning-' . $name . ':s' => { name => 'warning-' . $name }, + 'critical-' . $name . ':s' => { name => 'critical-' . $name }, + }); + } + $maps_counters->{$key}->{$_}->{obj} = centreon::plugins::values->new(output => $self->{output}, perfdata => $self->{perfdata}, + label => $name); + $maps_counters->{$key}->{$_}->{obj}->set(%{$maps_counters->{$key}->{$_}->{set}}); + } + } return $self; } @@ -58,151 +78,135 @@ 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(); - } - 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->{statefile_cache}->check_options(%options); + foreach my $key (('disk')) { + foreach (keys %{$maps_counters->{$key}}) { + $maps_counters->{$key}->{$_}->{obj}->init(option_results => $self->{option_results}); + } + } } sub run { my ($self, %options) = @_; - # $options{snmp} = snmp object $self->{snmp} = $options{snmp}; - $self->{hostname} = $self->{snmp}->get_hostname(); - $self->{snmp_port} = $self->{snmp}->get_port(); $self->manage_selection(); - - $self->{snmp}->load(oids => [$oid_dskPercentNode], instances => $self->{diskpath_id_selected}); - my $result = $self->{snmp}->get_leef(nothing_quit => 1); - - if (!defined($self->{option_results}->{diskpath}) || defined($self->{option_results}->{use_regexp})) { - $self->{output}->output_add(severity => 'OK', - short_msg => 'All inode partitions are ok.'); + + my $multiple = 1; + if (scalar(keys %{$self->{disk_selected}}) == 1) { + $multiple = 0; } + + if ($multiple == 1) { + $self->{output}->output_add(severity => 'OK', + short_msg => 'All inode partitions are ok'); + } + + foreach my $id (sort keys %{$self->{disk_selected}}) { + my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', ''); + my @exits; + foreach (sort keys %{$maps_counters->{disk}}) { + my $obj = $maps_counters->{disk}->{$_}->{obj}; + $obj->set(instance => $id); + + my ($value_check) = $obj->execute(values => $self->{disk_selected}->{$id}); - foreach (sort @{$self->{diskpath_id_selected}}) { - my $name_diskpath = $self->get_display_value(id => $_); + if ($value_check != 0) { + $long_msg .= $long_msg_append . $obj->output_error(); + $long_msg_append = ', '; + next; + } + my $exit2 = $obj->threshold_check(); + push @exits, $exit2; - if (!defined($result->{$oid_dskPercentNode . '.' . $_})) { - $self->{output}->output_add(long_msg => "Cannot usage for '" . $name_diskpath . "'", debug => 1); - next; + my $output = $obj->output(); + $long_msg .= $long_msg_append . $output; + $long_msg_append = ', '; + + if (!$self->{output}->is_status(litteral => 1, value => $exit2, compare => 'ok')) { + $short_msg .= $short_msg_append . $output; + $short_msg_append = ', '; + } + + $obj->perfdata(extra_instance => $multiple); + } + + $self->{output}->output_add(long_msg => "Inode partition '" . $self->{disk_selected}->{$id}->{display} . "' $long_msg"); + my $exit = $self->{output}->get_most_critical(status => [ @exits ]); + if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) { + $self->{output}->output_add(severity => $exit, + short_msg => "Inode partition '" . $self->{disk_selected}->{$id}->{display} . "' $short_msg" + ); } - my $prct_used = $result->{$oid_dskPercentNode . '.' . $_}; - my $prct_free = 100 - $prct_used; - - my $exit = $self->{perfdata}->threshold_check(value => $prct_used, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - - $self->{output}->output_add(long_msg => sprintf("Inodes partition '%s' Used: %s %% Free: %s %%", - $name_diskpath, $prct_used, $prct_free)); - if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1) || (defined($self->{option_results}->{diskpath}) && !defined($self->{option_results}->{use_regexp}))) { - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Inodes partition '%s' Used: %s %% Free: %s %%", - $name_diskpath, $prct_used, $prct_free)); - } - - my $label = 'used'; - my $extra_label = ''; - $extra_label = '_' . $name_diskpath if (!defined($self->{option_results}->{diskpath}) || defined($self->{option_results}->{use_regexp})); - $self->{output}->perfdata_add(label => $label . $extra_label, unit => '%', - value => $prct_used, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), - min => 0, max => 100); + if ($multiple == 0) { + $self->{output}->output_add(short_msg => "Inode partition '" . $self->{disk_selected}->{$id}->{display} . "' $long_msg"); + } } - + $self->{output}->display(); $self->{output}->exit(); } -sub reload_cache { - my ($self) = @_; - my $datas = {}; - - my $result = $self->{snmp}->get_table(oid => $oid_dskPath); - $datas->{last_timestamp} = time(); - $datas->{all_ids} = []; - foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) { - next if ($key !~ /\.([0-9]+)$/); - push @{$datas->{all_ids}}, $1; - $datas->{'dskPath_' . $1} = $self->{output}->to_utf8($result->{$key}); - } - - if (scalar(@{$datas->{all_ids}}) <= 0) { - $self->{output}->add_option_msg(short_msg => "Can't construct cache..."); - $self->{output}->option_exit(); - } - - $self->{statefile_cache}->write(data => $datas); -} +my $mapping = { + dskPath => { oid => '.1.3.6.1.4.1.2021.9.1.2' }, + dskDevice => { oid => '.1.3.6.1.4.1.2021.9.1.3' }, + dskPercentNode => { oid => '.1.3.6.1.4.1.2021.9.1.10' }, +}; sub manage_selection { my ($self, %options) = @_; - - # init cache file - my $has_cache_file = $self->{statefile_cache}->read(statefile => 'cache_snmpstandard_' . $self->{hostname} . '_' . $self->{snmp_port} . '_' . $self->{mode}); - if (defined($self->{option_results}->{show_cache})) { - $self->{output}->add_option_msg(long_msg => $self->{statefile_cache}->get_string_content()); - $self->{output}->option_exit(); - } - - my $timestamp_cache = $self->{statefile_cache}->get(name => 'last_timestamp'); - if ($has_cache_file == 0 || !defined($timestamp_cache) || - ((time() - $timestamp_cache) > (($self->{option_results}->{reload_cache_time}) * 60))) { - $self->reload_cache(); - $self->{statefile_cache}->read(); - } - - my $all_ids = $self->{statefile_cache}->get(name => 'all_ids'); - if (!defined($self->{option_results}->{use_name}) && defined($self->{option_results}->{diskpath})) { - # get by ID - push @{$self->{diskpath_id_selected}}, $self->{option_results}->{diskpath}; - my $name = $self->{statefile_cache}->get(name => 'dskPath_' . $self->{option_results}->{diskpath}); - if (!defined($name)) { - $self->{output}->add_option_msg(short_msg => "No disk path found for id '" . $self->{option_results}->{diskpath} . "'."); - $self->{output}->option_exit(); + + my $results = $self->{snmp}->get_multiple_table(oids => [ { oid => $mapping->{dskPath}->{oid} }, + { oid => $mapping->{dskDevice}->{oid} }, + { oid => $mapping->{dskPercentNode}->{oid} } ], + return_type => 1, nothing_quit => 1); + $self->{disk_selected} = {}; + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$results})) { + next if ($oid !~ /^$mapping->{dskPath}->{oid}\.(.*)/); + my $instance = $1; + + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $results, instance => $instance); + $result->{dskPath} = $self->get_display_value(value => $result->{dskPath}); + + if (!defined($result->{dskPercentNode})) { + $self->{output}->output_add(long_msg => sprintf("skipping '%s' : no inode usage value", $result->{dskPath}), debug => 1); + next; } - } else { - foreach my $i (@{$all_ids}) { - my $filter_name = $self->{statefile_cache}->get(name => 'dskPath_' . $i); - next if (!defined($filter_name)); - if (!defined($self->{option_results}->{diskpath})) { - push @{$self->{diskpath_id_selected}}, $i; + + if (!defined($self->{option_results}->{use_name}) && defined($self->{option_results}->{diskpath})) { + if ($self->{option_results}->{diskpath} !~ /(^|\s|,)$instance(\s*,|$)/) { + $self->{output}->output_add(long_msg => sprintf("skipping '%s' : filter id disk path", $result->{dskPath}), debug => 1); next; } - if (defined($self->{option_results}->{use_regexp}) && defined($self->{option_results}->{use_regexpi}) && $filter_name =~ /$self->{option_results}->{diskpath}/i) { - push @{$self->{diskpath_id_selected}}, $i; + } elsif (defined($self->{option_results}->{diskpath}) && $self->{option_results}->{diskpath} ne '') { + if (defined($self->{option_results}->{use_regexp}) && defined($self->{option_results}->{use_regexpi}) && $result->{dskPath} !~ /$self->{option_results}->{diskpath}/i) { + $self->{output}->output_add(long_msg => sprintf("skipping '%s' : filter disk path", $result->{dskPath}), debug => 1); + next; } - if (defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi}) && $filter_name =~ /$self->{option_results}->{diskpath}/) { - push @{$self->{diskpath_id_selected}}, $i; + if (defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi}) && $result->{dskPath} !~ /$self->{option_results}->{diskpath}/) { + $self->{output}->output_add(long_msg => sprintf("skipping '%s' : filter disk path", $result->{dskPath}), debug => 1); + next; } - if (!defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi}) && $filter_name eq $self->{option_results}->{diskpath}) { - push @{$self->{diskpath_id_selected}}, $i; + if (!defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi}) && $result->{dskPath} ne $self->{option_results}->{diskpath}) { + $self->{output}->output_add(long_msg => sprintf("skipping '%s' : filter disk path", $result->{dskPath}), debug => 1); + next; } } - if (scalar(@{$self->{diskpath_id_selected}}) <= 0) { - if (defined($self->{option_results}->{diskpath})) { - $self->{output}->add_option_msg(short_msg => "No disk path found for name '" . $self->{option_results}->{diskpath} . "' (maybe you should reload cache file)."); - } else { - $self->{output}->add_option_msg(short_msg => "No disk path found (maybe you should reload cache file)."); - } - $self->{output}->option_exit(); - } + $self->{disk_selected}->{$instance} = { display => $result->{dskPath}, + usage => $result->{dskPercentNode} }; + } + + if (scalar(keys %{$self->{disk_selected}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No entry found."); + $self->{output}->option_exit(); } } sub get_display_value { my ($self, %options) = @_; - my $value = $self->{statefile_cache}->get(name => 'dskPath_' . $options{id}); + my $value = $options{value}; if (defined($self->{option_results}->{display_transform_src})) { $self->{option_results}->{display_transform_dst} = '' if (!defined($self->{option_results}->{display_transform_dst})); @@ -222,11 +226,11 @@ Need to enable "includeAllDisks 10%" on snmpd.conf. =over 8 -=item B<--warning> +=item B<--warning-usage> Threshold warning in percent. -=item B<--critical> +=item B<--critical-usage> Threshold critical in percent. @@ -246,10 +250,6 @@ Allows to use regexp to filter diskpath (with option --name). Allows to use regexp non case-sensitive (with --regexp). -=item B<--reload-cache-time> - -Time in seconds before reloading cache file (default: 180). - =item B<--display-transform-src> Regexp src to transform display value. (security risk!!!) @@ -258,10 +258,6 @@ Regexp src to transform display value. (security risk!!!) Regexp dst to transform display value. (security risk!!!) -=item B<--show-cache> - -Display cache storage datas. - =back =cut From 54b571b692b8974842c9580ffb3b8fa2ac77cb8b Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Wed, 2 Dec 2015 16:41:18 +0100 Subject: [PATCH 24/26] + Fix #224 --- centreon-plugins/snmp_standard/mode/inodes.pm | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/centreon-plugins/snmp_standard/mode/inodes.pm b/centreon-plugins/snmp_standard/mode/inodes.pm index ea25cf07b..6f61e8058 100644 --- a/centreon-plugins/snmp_standard/mode/inodes.pm +++ b/centreon-plugins/snmp_standard/mode/inodes.pm @@ -53,6 +53,7 @@ sub new { "diskpath:s" => { name => 'diskpath' }, "regexp" => { name => 'use_regexp' }, "regexp-isensitive" => { name => 'use_regexpi' }, + "filter-device:s" => { name => 'filter_device' }, "display-transform-src:s" => { name => 'display_transform_src' }, "display-transform-dst:s" => { name => 'display_transform_dst' }, }); @@ -169,10 +170,17 @@ sub manage_selection { my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $results, instance => $instance); $result->{dskPath} = $self->get_display_value(value => $result->{dskPath}); + $self->{output}->output_add(long_msg => sprintf("disk path : '%s', device : '%s'", $result->{dskPath}, $result->{dskDevice}), debug => 1); + if (!defined($result->{dskPercentNode})) { $self->{output}->output_add(long_msg => sprintf("skipping '%s' : no inode usage value", $result->{dskPath}), debug => 1); next; } + if (defined($result->{dskDevice}) && defined($self->{option_results}->{filter_device}) && + $self->{option_results}->{filter_device} ne '' && $result->{dskDevice} !~ /$self->{option_results}->{filter_device}/) { + $self->{output}->output_add(long_msg => sprintf("skipping '%s' : filter disk device", $result->{dskPath}), debug => 1); + next; + } if (!defined($self->{option_results}->{use_name}) && defined($self->{option_results}->{diskpath})) { if ($self->{option_results}->{diskpath} !~ /(^|\s|,)$instance(\s*,|$)/) { @@ -258,6 +266,10 @@ Regexp src to transform display value. (security risk!!!) Regexp dst to transform display value. (security risk!!!) +=item B<--filter-device> + +Filter device name (Can be a regexp). + =back =cut From fa5eb63f78bed20358f5e20eef3ddf95132c885c Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Thu, 3 Dec 2015 10:55:09 +0100 Subject: [PATCH 25/26] + enhance netapp filesys mode (add inodes usage) --- .../storage/netapp/snmp/mode/filesys.pm | 42 ++++++++++++------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/centreon-plugins/storage/netapp/snmp/mode/filesys.pm b/centreon-plugins/storage/netapp/snmp/mode/filesys.pm index 139757f31..23f725026 100644 --- a/centreon-plugins/storage/netapp/snmp/mode/filesys.pm +++ b/centreon-plugins/storage/netapp/snmp/mode/filesys.pm @@ -28,14 +28,23 @@ use centreon::plugins::values; my $maps_counters = { '000_usage' => { set => { - key_values => [ { name => 'name' }, { name => 'used' }, { name => 'total' }, - { name => 'dfCompressSavedPercent' }, { name => 'dfDedupeSavedPercent' } ], - closure_custom_calc => \&custom_usage_calc, - closure_custom_output => \&custom_usage_output, - closure_custom_perfdata => \&custom_usage_perfdata, - closure_custom_threshold_check => \&custom_usage_threshold, - } - }, + key_values => [ { name => 'name' }, { name => 'used' }, { name => 'total' }, + { name => 'dfCompressSavedPercent' }, { name => 'dfDedupeSavedPercent' } ], + closure_custom_calc => \&custom_usage_calc, + closure_custom_output => \&custom_usage_output, + closure_custom_perfdata => \&custom_usage_perfdata, + closure_custom_threshold_check => \&custom_usage_threshold, + } + }, + '001_inodes' => { set => { + key_values => [ { name => 'dfPerCentInodeCapacity' }, { name => 'name' } ], + output_template => 'Inodes Used: %s %%', output_error_template => "%s", + perfdatas => [ + { label => 'inodes', value => 'dfPerCentInodeCapacity_absolute', template => '%d', + unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'name_absolute' }, + ], + } + }, }; my $instance_mode; @@ -178,7 +187,6 @@ sub check_options { sub run { my ($self, %options) = @_; - # $options{snmp} = snmp object $self->{snmp} = $options{snmp}; $self->manage_selection(); @@ -249,10 +257,11 @@ my $mapping = { dfType => { oid => '.1.3.6.1.4.1.789.1.5.4.1.23', map => \%map_types }, }; my $mapping2 = { - dfKBytesTotal => { oid => '.1.3.6.1.4.1.789.1.5.4.1.3' }, - dfKBytesUsed => { oid => '.1.3.6.1.4.1.789.1.5.4.1.4' }, - df64TotalKBytes => { oid => '.1.3.6.1.4.1.789.1.5.4.1.29' }, - df64UsedKBytes => { oid => '.1.3.6.1.4.1.789.1.5.4.1.30' }, + dfKBytesTotal => { oid => '.1.3.6.1.4.1.789.1.5.4.1.3' }, + dfKBytesUsed => { oid => '.1.3.6.1.4.1.789.1.5.4.1.4' }, + dfPerCentInodeCapacity => { oid => '.1.3.6.1.4.1.789.1.5.4.1.9' }, + df64TotalKBytes => { oid => '.1.3.6.1.4.1.789.1.5.4.1.29' }, + df64UsedKBytes => { oid => '.1.3.6.1.4.1.789.1.5.4.1.30' }, dfCompressSavedPercent => { oid => '.1.3.6.1.4.1.789.1.5.4.1.38' }, dfDedupeSavedPercent => { oid => '.1.3.6.1.4.1.789.1.5.4.1.40' }, }; @@ -308,6 +317,7 @@ sub manage_selection { } $self->{filesys_selected}->{$_}->{dfCompressSavedPercent} = $result->{dfCompressSavedPercent}; $self->{filesys_selected}->{$_}->{dfDedupeSavedPercent} = $result->{dfDedupeSavedPercent}; + $self->{filesys_selected}->{$_}->{dfPerCentInodeCapacity} = $result->{dfPerCentInodeCapacity}; } } @@ -321,13 +331,15 @@ Check filesystem usage (volumes, snapshots and aggregates also). =over 8 -=item B<--warning-usage> +=item B<--warning-*> Threshold warning. +Can be: usage, inodes (%). -=item B<--critical-usage> +=item B<--critical-*> Threshold critical. +Can be: usage, inodes (%). =item B<--units> From e35795fe3196945c56fa9ac33ad599f64ef8ea0c Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Thu, 3 Dec 2015 11:49:36 +0100 Subject: [PATCH 26/26] + Enhance netapp filesys mode (perf + inodes) --- .../storage/netapp/snmp/mode/filesys.pm | 66 ++++++++++--------- 1 file changed, 34 insertions(+), 32 deletions(-) diff --git a/centreon-plugins/storage/netapp/snmp/mode/filesys.pm b/centreon-plugins/storage/netapp/snmp/mode/filesys.pm index 23f725026..27f2ace05 100644 --- a/centreon-plugins/storage/netapp/snmp/mode/filesys.pm +++ b/centreon-plugins/storage/netapp/snmp/mode/filesys.pm @@ -38,7 +38,7 @@ my $maps_counters = { }, '001_inodes' => { set => { key_values => [ { name => 'dfPerCentInodeCapacity' }, { name => 'name' } ], - output_template => 'Inodes Used: %s %%', output_error_template => "%s", + output_template => 'Inodes Used : %s %%', output_error_template => "Inodes : %s", perfdatas => [ { label => 'inodes', value => 'dfPerCentInodeCapacity_absolute', template => '%d', unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'name_absolute' }, @@ -257,6 +257,7 @@ my $mapping = { dfType => { oid => '.1.3.6.1.4.1.789.1.5.4.1.23', map => \%map_types }, }; my $mapping2 = { + dfFileSys => { oid => '.1.3.6.1.4.1.789.1.5.4.1.2' }, dfKBytesTotal => { oid => '.1.3.6.1.4.1.789.1.5.4.1.3' }, dfKBytesUsed => { oid => '.1.3.6.1.4.1.789.1.5.4.1.4' }, dfPerCentInodeCapacity => { oid => '.1.3.6.1.4.1.789.1.5.4.1.9' }, @@ -268,19 +269,29 @@ my $mapping2 = { sub manage_selection { my ($self, %options) = @_; - - my $oid_dfFileSys = '.1.3.6.1.4.1.789.1.5.4.1.2'; - my $results = $self->{snmp}->get_multiple_table(oids => [ - { oid => $oid_dfFileSys }, - { oid => $mapping->{dfType}->{oid} }, - ], nothing_quit => 1); + my $oids = [ + { oid => $mapping->{dfType}->{oid} }, + { oid => $mapping2->{dfFileSys}->{oid} }, + { oid => $mapping2->{dfKBytesTotal}->{oid} }, + { oid => $mapping2->{dfKBytesUsed}->{oid} }, + { oid => $mapping2->{dfPerCentInodeCapacity}->{oid} }, + { oid => $mapping2->{dfCompressSavedPercent}->{oid} }, + { oid => $mapping2->{dfDedupeSavedPercent}->{oid} }, + ]; + if (!$self->{snmp}->is_snmpv1()) { + push @{$oids}, { oid => $mapping2->{df64TotalKBytes}->{oid} }, { oid => $mapping2->{df64UsedKBytes}->{oid} }; + } + + my $results = $self->{snmp}->get_multiple_table(oids => $oids, return_type => 1, nothing_quit => 1); $self->{filesys_selected} = {}; - foreach my $oid (keys %{$results->{$oid_dfFileSys}}) { - $oid =~ /^$oid_dfFileSys\.(\d+)/; + foreach my $oid (keys %{$results}) { + next if ($oid !~ /^$mapping2->{dfFileSys}->{oid}\.(\d+)/); my $instance = $1; - my $name = $results->{$oid_dfFileSys}->{$oid}; - my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $results->{$mapping->{dfType}->{oid}}, instance => $instance); + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $results, instance => $instance); + my $result2 = $self->{snmp}->map_instance(mapping => $mapping2, results => $results, instance => $instance); + + my $name = $result2->{dfFileSys}; if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && $name !~ /$self->{option_results}->{filter_name}/) { $self->{output}->output_add(long_msg => "Skipping '" . $name . "': no matching filter name."); @@ -292,33 +303,24 @@ sub manage_selection { next; } - $self->{filesys_selected}->{$instance} = { name => $name }; + $self->{filesys_selected}->{$instance} = { name => $name }; + $self->{filesys_selected}->{$instance}->{total} = $result2->{dfKBytesTotal} * 1024; + $self->{filesys_selected}->{$instance}->{used} = $result2->{dfKBytesUsed} * 1024; + if (defined($result2->{df64TotalKBytes}) && $result2->{df64TotalKBytes} > 0) { + $self->{filesys_selected}->{$instance}->{total} = $result2->{df64TotalKBytes} * 1024; + $self->{filesys_selected}->{$instance}->{used} = $result2->{df64UsedKBytes} * 1024; + } + $self->{filesys_selected}->{$instance}->{dfCompressSavedPercent} = $result2->{dfCompressSavedPercent}; + $self->{filesys_selected}->{$instance}->{dfDedupeSavedPercent} = $result2->{dfDedupeSavedPercent}; + if ($self->{filesys_selected}->{$instance}->{total} > 0) { + $self->{filesys_selected}->{$instance}->{dfPerCentInodeCapacity} = $result2->{dfPerCentInodeCapacity}; + } } if (scalar(keys %{$self->{filesys_selected}}) <= 0) { $self->{output}->add_option_msg(short_msg => "No entry found."); $self->{output}->option_exit(); } - - my $instances = [keys %{$self->{filesys_selected}}]; - if (!$self->{snmp}->is_snmpv1()) { - $self->{snmp}->load(oids => [$mapping2->{df64TotalKBytes}->{oid}, $mapping2->{df64UsedKBytes}->{oid}], instances => $instances); - } - $self->{snmp}->load(oids => [$mapping2->{dfKBytesTotal}->{oid}, $mapping2->{dfKBytesUsed}->{oid}, - $mapping2->{dfDedupeSavedPercent}->{oid}, $mapping2->{dfCompressSavedPercent}->{oid}], instances => $instances); - my $result = $self->{snmp}->get_leef(); - foreach (@$instances) { - my $result = $self->{snmp}->map_instance(mapping => $mapping2, results => $result, instance => $_); - $self->{filesys_selected}->{$_}->{total} = $result->{dfKBytesTotal} * 1024; - $self->{filesys_selected}->{$_}->{used} = $result->{dfKBytesUsed} * 1024; - if (defined($result->{df64TotalKBytes}) && $result->{df64TotalKBytes} > 0) { - $self->{filesys_selected}->{$_}->{total} = $result->{df64TotalKBytes} * 1024; - $self->{filesys_selected}->{$_}->{used} = $result->{df64UsedKBytes} * 1024; - } - $self->{filesys_selected}->{$_}->{dfCompressSavedPercent} = $result->{dfCompressSavedPercent}; - $self->{filesys_selected}->{$_}->{dfDedupeSavedPercent} = $result->{dfDedupeSavedPercent}; - $self->{filesys_selected}->{$_}->{dfPerCentInodeCapacity} = $result->{dfPerCentInodeCapacity}; - } } 1;