diff --git a/apps/vmware/wsman/mode/components/cim_card.pm b/apps/vmware/wsman/mode/components/cim_card.pm index 825253e93..93c93557c 100644 --- a/apps/vmware/wsman/mode/components/cim_card.pm +++ b/apps/vmware/wsman/mode/components/cim_card.pm @@ -23,14 +23,16 @@ package apps::vmware::wsman::mode::components::cim_card; use strict; use warnings; +sub load {} + sub check { my ($self) = @_; - my $result = $self->{wsman}->request(uri => 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_Card'); + my $result = $self->{wsman}->request(uri => 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_Card', dont_quit => 1); $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')); + return if ($self->check_filter(section => 'cim_card') || !defined($result)); foreach (@{$result}) { my $instance = defined($_->{Name}) && $_->{Name} ne '' ? $_->{Name} : $_->{ElementName}; @@ -57,4 +59,4 @@ sub check { } } -1; \ No newline at end of file +1; diff --git a/apps/vmware/wsman/mode/components/cim_computersystem.pm b/apps/vmware/wsman/mode/components/cim_computersystem.pm index 242f5099b..75abc89fd 100644 --- a/apps/vmware/wsman/mode/components/cim_computersystem.pm +++ b/apps/vmware/wsman/mode/components/cim_computersystem.pm @@ -23,14 +23,16 @@ package apps::vmware::wsman::mode::components::cim_computersystem; use strict; use warnings; +sub load {} + sub check { my ($self) = @_; - my $result = $self->{wsman}->request(uri => 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ComputerSystem'); + my $result = $self->{wsman}->request(uri => 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ComputerSystem', dont_quit => 1); $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')); + return if ($self->check_filter(section => 'cim_computersystem') || !defined($result)); foreach (@{$result}) { my $instance = defined($_->{Name}) && $_->{Name} ne '' ? $_->{Name} : $_->{ElementName}; @@ -57,4 +59,4 @@ sub check { } } -1; \ No newline at end of file +1; diff --git a/apps/vmware/wsman/mode/components/cim_memory.pm b/apps/vmware/wsman/mode/components/cim_memory.pm index 7a062bff7..072d33637 100644 --- a/apps/vmware/wsman/mode/components/cim_memory.pm +++ b/apps/vmware/wsman/mode/components/cim_memory.pm @@ -23,14 +23,16 @@ package apps::vmware::wsman::mode::components::cim_memory; use strict; use warnings; +sub load {} + sub check { my ($self) = @_; - my $result = $self->{wsman}->request(uri => 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_Memory'); + my $result = $self->{wsman}->request(uri => 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_Memory', dont_quit => 1); $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')); + return if ($self->check_filter(section => 'cim_memory') || !defined($result)); foreach (@{$result}) { my $instance = defined($_->{Name}) && $_->{Name} ne '' ? $_->{Name} : $_->{ElementName}; @@ -57,4 +59,4 @@ sub check { } } -1; \ No newline at end of file +1; diff --git a/apps/vmware/wsman/mode/components/cim_numericsensor.pm b/apps/vmware/wsman/mode/components/cim_numericsensor.pm index 3f1254c10..a81655b1f 100644 --- a/apps/vmware/wsman/mode/components/cim_numericsensor.pm +++ b/apps/vmware/wsman/mode/components/cim_numericsensor.pm @@ -24,14 +24,16 @@ use strict; use warnings; use apps::vmware::wsman::mode::components::resources qw($mapping_units $mapping_sensortype); +sub load {} + sub check { my ($self) = @_; - my $result = $self->{wsman}->request(uri => 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_NumericSensor'); + my $result = $self->{wsman}->request(uri => 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_NumericSensor', dont_quit => 1); $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')); + return if ($self->check_filter(section => 'cim_numericsensor') || !defined($result)); foreach (@{$result}) { my $sensor_type = defined($mapping_sensortype->{$_->{SensorType}}) ? $mapping_sensortype->{$_->{SensorType}} : 'unknown'; @@ -108,4 +110,4 @@ sub check { } } -1; \ No newline at end of file +1; diff --git a/apps/vmware/wsman/mode/components/cim_processor.pm b/apps/vmware/wsman/mode/components/cim_processor.pm index 5d5833f87..990774d16 100644 --- a/apps/vmware/wsman/mode/components/cim_processor.pm +++ b/apps/vmware/wsman/mode/components/cim_processor.pm @@ -23,14 +23,16 @@ package apps::vmware::wsman::mode::components::cim_processor; use strict; use warnings; +sub load {} + sub check { my ($self) = @_; - my $result = $self->{wsman}->request(uri => 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_Processor'); + my $result = $self->{wsman}->request(uri => 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_Processor', dont_quit => 1); $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')); + return if ($self->check_filter(section => 'cim_processor') || !defined($result)); foreach (@{$result}) { my $instance = defined($_->{Name}) && $_->{Name} ne '' ? $_->{Name} : $_->{ElementName}; @@ -59,4 +61,4 @@ sub check { } } -1; \ No newline at end of file +1; diff --git a/apps/vmware/wsman/mode/components/cim_recordlog.pm b/apps/vmware/wsman/mode/components/cim_recordlog.pm index 820be9634..7c57647d8 100644 --- a/apps/vmware/wsman/mode/components/cim_recordlog.pm +++ b/apps/vmware/wsman/mode/components/cim_recordlog.pm @@ -23,14 +23,16 @@ package apps::vmware::wsman::mode::components::cim_recordlog; use strict; use warnings; +sub load {} + sub check { my ($self) = @_; - my $result = $self->{wsman}->request(uri => 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_RecordLog'); + my $result = $self->{wsman}->request(uri => 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_RecordLog', dont_quit => 1); $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')); + return if ($self->check_filter(section => 'cim_recordlog') || !defined($result)); foreach (@{$result}) { my $instance = defined($_->{Name}) && $_->{Name} ne '' ? $_->{Name} : $_->{ElementName}; @@ -57,4 +59,4 @@ sub check { } } -1; \ No newline at end of file +1; diff --git a/apps/vmware/wsman/mode/components/omc_discretesensor.pm b/apps/vmware/wsman/mode/components/omc_discretesensor.pm index ff6d3fa26..cafc5ff37 100644 --- a/apps/vmware/wsman/mode/components/omc_discretesensor.pm +++ b/apps/vmware/wsman/mode/components/omc_discretesensor.pm @@ -24,14 +24,16 @@ use strict; use warnings; use apps::vmware::wsman::mode::components::resources qw($mapping_EnableState); +sub load {} + sub check { my ($self) = @_; - my $result = $self->{wsman}->request(uri => 'http://schema.omc-project.org/wbem/wscim/1/cim-schema/2/OMC_DiscreteSensor'); + my $result = $self->{wsman}->request(uri => 'http://schema.omc-project.org/wbem/wscim/1/cim-schema/2/OMC_DiscreteSensor', dont_quit => 1); $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')); + return if ($self->check_filter(section => 'omc_discretesensor') || !defined($result)); foreach (@{$result}) { my $instance = $_->{Name}; @@ -62,4 +64,4 @@ sub check { } } -1; \ No newline at end of file +1; diff --git a/apps/vmware/wsman/mode/components/omc_fan.pm b/apps/vmware/wsman/mode/components/omc_fan.pm index f0e8c929a..53e30c7e2 100644 --- a/apps/vmware/wsman/mode/components/omc_fan.pm +++ b/apps/vmware/wsman/mode/components/omc_fan.pm @@ -23,14 +23,16 @@ package apps::vmware::wsman::mode::components::omc_fan; use strict; use warnings; +sub load {} + sub check { my ($self) = @_; - my $result = $self->{wsman}->request(uri => 'http://schema.omc-project.org/wbem/wscim/1/cim-schema/2/OMC_Fan'); + my $result = $self->{wsman}->request(uri => 'http://schema.omc-project.org/wbem/wscim/1/cim-schema/2/OMC_Fan', dont_quit => 1); $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')); + return if ($self->check_filter(section => 'omc_fan') || !defined($result)); foreach (@{$result}) { my $instance = $_->{Name}; @@ -57,4 +59,4 @@ sub check { } } -1; \ No newline at end of file +1; diff --git a/apps/vmware/wsman/mode/components/omc_psu.pm b/apps/vmware/wsman/mode/components/omc_psu.pm index 1fcd1a4f3..74f95893c 100644 --- a/apps/vmware/wsman/mode/components/omc_psu.pm +++ b/apps/vmware/wsman/mode/components/omc_psu.pm @@ -23,14 +23,16 @@ package apps::vmware::wsman::mode::components::omc_psu; use strict; use warnings; +sub load {} + sub check { my ($self) = @_; - my $result = $self->{wsman}->request(uri => 'http://schema.omc-project.org/wbem/wscim/1/cim-schema/2/OMC_PowerSupply'); + my $result = $self->{wsman}->request(uri => 'http://schema.omc-project.org/wbem/wscim/1/cim-schema/2/OMC_PowerSupply', dont_quit => 1); $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')); + return if ($self->check_filter(section => 'omc_psu') || !defined($result)); foreach (@{$result}) { my $instance = $_->{Name}; @@ -57,4 +59,4 @@ sub check { } } -1; \ No newline at end of file +1; diff --git a/apps/vmware/wsman/mode/components/vmware_battery.pm b/apps/vmware/wsman/mode/components/vmware_battery.pm index 56943bdf5..3981080e3 100644 --- a/apps/vmware/wsman/mode/components/vmware_battery.pm +++ b/apps/vmware/wsman/mode/components/vmware_battery.pm @@ -23,14 +23,16 @@ package apps::vmware::wsman::mode::components::vmware_battery; use strict; use warnings; +sub load {} + sub check { my ($self) = @_; - my $result = $self->{wsman}->request(uri => 'http://schemas.vmware.com/wbem/wscim/1/cim-schema/2/VMware_Battery'); + my $result = $self->{wsman}->request(uri => 'http://schemas.vmware.com/wbem/wscim/1/cim-schema/2/VMware_Battery', dont_quit => 1); $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')); + return if ($self->check_filter(section => 'vmware_battery') || !defined($result)); foreach (@{$result}) { my $instance = defined($_->{Name}) && $_->{Name} ne '' ? $_->{Name} : $_->{ElementName}; @@ -57,4 +59,4 @@ sub check { } } -1; \ No newline at end of file +1; diff --git a/apps/vmware/wsman/mode/components/vmware_controller.pm b/apps/vmware/wsman/mode/components/vmware_controller.pm index 9757a2f1f..09cf24fe6 100644 --- a/apps/vmware/wsman/mode/components/vmware_controller.pm +++ b/apps/vmware/wsman/mode/components/vmware_controller.pm @@ -23,14 +23,16 @@ package apps::vmware::wsman::mode::components::vmware_controller; use strict; use warnings; +sub load {} + sub check { my ($self) = @_; - my $result = $self->{wsman}->request(uri => 'http://schemas.vmware.com/wbem/wscim/1/cim-schema/2/VMware_Controller'); + my $result = $self->{wsman}->request(uri => 'http://schemas.vmware.com/wbem/wscim/1/cim-schema/2/VMware_Controller', dont_quit => 1); $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')); + return if ($self->check_filter(section => 'vmware_controller') || !defined($result)); foreach (@{$result}) { my $instance = defined($_->{Name}) && $_->{Name} ne '' ? $_->{Name} : $_->{ElementName}; @@ -57,4 +59,4 @@ sub check { } } -1; \ No newline at end of file +1; diff --git a/apps/vmware/wsman/mode/components/vmware_sassataport.pm b/apps/vmware/wsman/mode/components/vmware_sassataport.pm index edb188cfd..99d89d6bd 100644 --- a/apps/vmware/wsman/mode/components/vmware_sassataport.pm +++ b/apps/vmware/wsman/mode/components/vmware_sassataport.pm @@ -23,14 +23,16 @@ package apps::vmware::wsman::mode::components::vmware_sassataport; use strict; use warnings; +sub load {} + sub check { my ($self) = @_; - my $result = $self->{wsman}->request(uri => 'http://schemas.vmware.com/wbem/wscim/1/cim-schema/2/VMware_SASSATAPort'); + my $result = $self->{wsman}->request(uri => 'http://schemas.vmware.com/wbem/wscim/1/cim-schema/2/VMware_SASSATAPort', dont_quit => 1); $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')); + return if ($self->check_filter(section => 'vmware_sassataport') || !defined($result)); foreach (@{$result}) { my $instance = defined($_->{Name}) && $_->{Name} ne '' ? $_->{Name} : $_->{ElementName}; @@ -57,4 +59,4 @@ sub check { } } -1; \ No newline at end of file +1; diff --git a/apps/vmware/wsman/mode/components/vmware_storageextent.pm b/apps/vmware/wsman/mode/components/vmware_storageextent.pm index d13d25b70..200e1304d 100644 --- a/apps/vmware/wsman/mode/components/vmware_storageextent.pm +++ b/apps/vmware/wsman/mode/components/vmware_storageextent.pm @@ -23,14 +23,16 @@ package apps::vmware::wsman::mode::components::vmware_storageextent; use strict; use warnings; +sub load {} + sub check { my ($self) = @_; - my $result = $self->{wsman}->request(uri => 'http://schemas.vmware.com/wbem/wscim/1/cim-schema/2/VMware_StorageExtent'); + my $result = $self->{wsman}->request(uri => 'http://schemas.vmware.com/wbem/wscim/1/cim-schema/2/VMware_StorageExtent', dont_quit => 1); $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')); + return if ($self->check_filter(section => 'vmware_storageextent') || !defined($result)); foreach (@{$result}) { my $instance = defined($_->{Name}) && $_->{Name} ne '' ? $_->{Name} : $_->{ElementName}; @@ -57,4 +59,4 @@ sub check { } } -1; \ No newline at end of file +1; diff --git a/apps/vmware/wsman/mode/components/vmware_storagevolume.pm b/apps/vmware/wsman/mode/components/vmware_storagevolume.pm index 9efd36696..fc504f09f 100644 --- a/apps/vmware/wsman/mode/components/vmware_storagevolume.pm +++ b/apps/vmware/wsman/mode/components/vmware_storagevolume.pm @@ -23,14 +23,16 @@ package apps::vmware::wsman::mode::components::vmware_storagevolume; use strict; use warnings; +sub load {} + sub check { my ($self) = @_; - my $result = $self->{wsman}->request(uri => 'http://schemas.vmware.com/wbem/wscim/1/cim-schema/2/VMware_StorageVolume'); + my $result = $self->{wsman}->request(uri => 'http://schemas.vmware.com/wbem/wscim/1/cim-schema/2/VMware_StorageVolume', dont_quit => 1); $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')); + return if ($self->check_filter(section => 'vmware_storagevolume') || !defined($result)); foreach (@{$result}) { my $instance = defined($_->{Name}) && $_->{Name} ne '' ? $_->{Name} : $_->{ElementName}; @@ -57,4 +59,4 @@ sub check { } } -1; \ No newline at end of file +1; diff --git a/apps/vmware/wsman/mode/hardware.pm b/apps/vmware/wsman/mode/hardware.pm index 7aed1e56d..3b667920a 100644 --- a/apps/vmware/wsman/mode/hardware.pm +++ b/apps/vmware/wsman/mode/hardware.pm @@ -20,16 +20,22 @@ package apps::vmware::wsman::mode::hardware; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::hardware); use strict; use warnings; use apps::vmware::wsman::mode::components::resources qw($mapping_HealthState $mapping_OperationalStatus); -my %type = ('cim_numericsensor' => 1); - -my $thresholds = { - default => [ +sub set_system { + my ($self, %options) = @_; + + $self->{regexp_threshold_overload_check_section_option} = + '^(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)$'; + $self->{regexp_threshold_numeric_check_section_option} = '^(cim_numericsensor)$'; + + $self->{cb_hook1} = 'get_type'; + + $self->{thresholds} = { ['Unknown', 'OK'], ['OK', 'OK'], ['Degraded', 'WARNING'], @@ -53,8 +59,13 @@ my $thresholds = { ['Completed', 'OK'], ['Power Mode', 'OK'], ['Relocating', 'WARNING'], - ], -}; + }; + + $self->{components_path} = 'apps::vmware::wsman::mode::components::components'; + $self->{components_module} = ['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']; +} sub new { my ($class, %options) = @_; @@ -63,95 +74,16 @@ sub new { $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'); + my $result = $options{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 '') { @@ -163,6 +95,8 @@ sub get_type { 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)); + + $self->{wsman} = $options{wsman}; } sub get_status { @@ -179,115 +113,6 @@ sub get_status { 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__ @@ -335,4 +160,4 @@ Example: --critical='cim_numericsensor,.*,40' =back -=cut \ No newline at end of file +=cut