diff --git a/apps/vmware/wsman/mode/components/cim_card.pm b/apps/vmware/wsman/mode/components/cim_card.pm new file mode 100644 index 000000000..de4df27ca --- /dev/null +++ b/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/apps/vmware/wsman/mode/components/cim_computersystem.pm b/apps/vmware/wsman/mode/components/cim_computersystem.pm new file mode 100644 index 000000000..8b02cfbc5 --- /dev/null +++ b/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/apps/vmware/wsman/mode/components/cim_memory.pm b/apps/vmware/wsman/mode/components/cim_memory.pm new file mode 100644 index 000000000..9994b2a21 --- /dev/null +++ b/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/apps/vmware/wsman/mode/components/cim_numericsensor.pm b/apps/vmware/wsman/mode/components/cim_numericsensor.pm new file mode 100644 index 000000000..c0f8d0325 --- /dev/null +++ b/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/apps/vmware/wsman/mode/components/cim_processor.pm b/apps/vmware/wsman/mode/components/cim_processor.pm new file mode 100644 index 000000000..e2b6f7785 --- /dev/null +++ b/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/apps/vmware/wsman/mode/components/cim_recordlog.pm b/apps/vmware/wsman/mode/components/cim_recordlog.pm new file mode 100644 index 000000000..24f279fff --- /dev/null +++ b/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/apps/vmware/wsman/mode/components/omc_discretesensor.pm b/apps/vmware/wsman/mode/components/omc_discretesensor.pm new file mode 100644 index 000000000..524735c6a --- /dev/null +++ b/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/apps/vmware/wsman/mode/components/omc_fan.pm b/apps/vmware/wsman/mode/components/omc_fan.pm new file mode 100644 index 000000000..55a034b4d --- /dev/null +++ b/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/apps/vmware/wsman/mode/components/omc_psu.pm b/apps/vmware/wsman/mode/components/omc_psu.pm new file mode 100644 index 000000000..b720a66d5 --- /dev/null +++ b/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/apps/vmware/wsman/mode/components/resources.pm b/apps/vmware/wsman/mode/components/resources.pm new file mode 100644 index 000000000..706877fb9 --- /dev/null +++ b/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/apps/vmware/wsman/mode/components/vmware_battery.pm b/apps/vmware/wsman/mode/components/vmware_battery.pm new file mode 100644 index 000000000..bd69cc7ce --- /dev/null +++ b/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/apps/vmware/wsman/mode/components/vmware_controller.pm b/apps/vmware/wsman/mode/components/vmware_controller.pm new file mode 100644 index 000000000..f254f5790 --- /dev/null +++ b/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/apps/vmware/wsman/mode/components/vmware_sassataport.pm b/apps/vmware/wsman/mode/components/vmware_sassataport.pm new file mode 100644 index 000000000..a95dc3069 --- /dev/null +++ b/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/apps/vmware/wsman/mode/components/vmware_storageextent.pm b/apps/vmware/wsman/mode/components/vmware_storageextent.pm new file mode 100644 index 000000000..5d4acee7c --- /dev/null +++ b/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/apps/vmware/wsman/mode/components/vmware_storagevolume.pm b/apps/vmware/wsman/mode/components/vmware_storagevolume.pm new file mode 100644 index 000000000..1a2e741ce --- /dev/null +++ b/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/apps/vmware/wsman/mode/hardware.pm b/apps/vmware/wsman/mode/hardware.pm new file mode 100644 index 000000000..b263de894 --- /dev/null +++ b/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/apps/vmware/wsman/plugin.pm b/apps/vmware/wsman/plugin.pm new file mode 100644 index 000000000..f29127443 --- /dev/null +++ b/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/wsman.pm b/centreon/plugins/wsman.pm index be34c8147..791874c00 100644 --- a/centreon/plugins/wsman.pm +++ b/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));