diff --git a/storage/emc/DataDomain/mode/components/battery.pm b/storage/emc/DataDomain/mode/components/battery.pm index cb56fdedb..df53f1060 100644 --- a/storage/emc/DataDomain/mode/components/battery.pm +++ b/storage/emc/DataDomain/mode/components/battery.pm @@ -28,12 +28,18 @@ my %map_battery_status = (); my ($oid_nvramBatteryStatus, $oid_nvramBatteryCharge); my $oid_nvramBatteryEntry = '.1.3.6.1.4.1.19746.1.2.3.1.1'; +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_nvramBatteryEntry }; +} + sub check { my ($self) = @_; $self->{output}->output_add(long_msg => "Checking nvram batteries"); $self->{components}->{battery} = {name => 'nvram batteries', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'battery')); + return if ($self->check_filter(section => 'battery')); if (centreon::plugins::misc::minimal_version($self->{os_version}, '5.x')) { $oid_nvramBatteryStatus = '.1.3.6.1.4.1.19746.1.2.3.1.1.3'; @@ -53,7 +59,7 @@ sub check { $map_battery_status{$self->{results}->{$oid_nvramBatteryEntry}->{$oid}} : 'unknown'; my $batt_value = $self->{results}->{$oid_nvramBatteryEntry}->{$oid_nvramBatteryCharge . '.' . $instance}; - next if ($self->check_exclude(section => 'battery', instance => $instance)); + next if ($self->check_filter(section => 'battery', instance => $instance)); next if ($batt_status =~ /disabled/i && $self->absent_problem(section => 'battery', instance => $instance)); diff --git a/storage/emc/DataDomain/mode/components/disk.pm b/storage/emc/DataDomain/mode/components/disk.pm index 668c8b179..02d8a330d 100644 --- a/storage/emc/DataDomain/mode/components/disk.pm +++ b/storage/emc/DataDomain/mode/components/disk.pm @@ -35,19 +35,23 @@ my %map_disk_status = ( 6 => 'available', # since OS 5.4 ); -sub check { +sub load { my ($self) = @_; - - $self->{output}->output_add(long_msg => "Checking disks"); - $self->{components}->{disk} = {name => 'disks', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'disk')); - my $oid_diskPropState; if (centreon::plugins::misc::minimal_version($self->{os_version}, '5.x')) { $oid_diskPropState = '.1.3.6.1.4.1.19746.1.6.1.1.1.8'; } else { $oid_diskPropState = '.1.3.6.1.4.1.19746.1.6.1.1.1.7'; } + push @{$self->{request}}, { oid => $oid_diskPropState }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking disks"); + $self->{components}->{disk} = {name => 'disks', total => 0, skip => 0}; + return if ($self->check_filter(section => 'disk')); foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_diskPropState}})) { $oid =~ /^$oid_diskPropState\.(.*)$/; @@ -55,7 +59,7 @@ sub check { my $disk_status = defined($map_disk_status{$self->{results}->{$oid_diskPropState}->{$oid}}) ? $map_disk_status{$self->{results}->{$oid_diskPropState}->{$oid}} : 'unknown'; - next if ($self->check_exclude(section => 'disk', instance => $instance)); + next if ($self->check_filter(section => 'disk', instance => $instance)); next if ($disk_status =~ /absent/i && $self->absent_problem(section => 'disk', instance => $instance)); diff --git a/storage/emc/DataDomain/mode/components/fan.pm b/storage/emc/DataDomain/mode/components/fan.pm index 63f4b207e..afa602edc 100644 --- a/storage/emc/DataDomain/mode/components/fan.pm +++ b/storage/emc/DataDomain/mode/components/fan.pm @@ -39,12 +39,18 @@ my %level_map = ( my ($oid_fanDescription, $oid_fanLevel, $oid_fanStatus); my $oid_fanPropertiesEntry = '.1.3.6.1.4.1.19746.1.1.3.1.1.1'; +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_fanPropertiesEntry }; +} + 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_exclude(section => 'fan')); + return if ($self->check_filter(section => 'fan')); if (centreon::plugins::misc::minimal_version($self->{os_version}, '5.x')) { $oid_fanDescription = '.1.3.6.1.4.1.19746.1.1.3.1.1.1.4'; @@ -64,7 +70,7 @@ sub check { $map_fan_status{$self->{results}->{$oid_fanPropertiesEntry}->{$oid}} : 'unknown'; my $fan_level = $self->{results}->{$oid_fanPropertiesEntry}->{$oid_fanLevel . '.' . $instance}; - next if ($self->check_exclude(section => 'fan', instance => $instance)); + next if ($self->check_filter(section => 'fan', instance => $instance)); next if ($fan_status =~ /notfound/i && $self->absent_problem(section => 'fan', instance => $instance)); diff --git a/storage/emc/DataDomain/mode/components/psu.pm b/storage/emc/DataDomain/mode/components/psu.pm index e93b5eb0b..84a8fcd08 100644 --- a/storage/emc/DataDomain/mode/components/psu.pm +++ b/storage/emc/DataDomain/mode/components/psu.pm @@ -27,12 +27,18 @@ my %map_psu_status = (); my ($oid_powerModuleDescription, $oid_powerModuleStatus); my $oid_powerModuleEntry = '.1.3.6.1.4.1.19746.1.1.1.1.1.1'; +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_powerModuleEntry }; +} + sub check { my ($self) = @_; $self->{output}->output_add(long_msg => "Checking power supplies"); $self->{components}->{psu} = {name => 'psus', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'psu')); + return if ($self->check_filter(section => 'psu')); if (centreon::plugins::misc::minimal_version($self->{os_version}, '5.x')) { $oid_powerModuleDescription = '.1.3.6.1.4.1.19746.1.1.1.1.1.1.3'; @@ -53,7 +59,7 @@ sub check { my $psu_status = defined($map_psu_status{$self->{results}->{$oid_powerModuleEntry}->{$oid}}) ? $map_psu_status{$self->{results}->{$oid_powerModuleEntry}->{$oid}} : 'unknown'; - next if ($self->check_exclude(section => 'psu', instance => $instance)); + next if ($self->check_filter(section => 'psu', instance => $instance)); next if ($psu_status =~ /absent/i && $self->absent_problem(section => 'psu', instance => $instance)); diff --git a/storage/emc/DataDomain/mode/components/temperature.pm b/storage/emc/DataDomain/mode/components/temperature.pm index 98d7e8c70..182e4517a 100644 --- a/storage/emc/DataDomain/mode/components/temperature.pm +++ b/storage/emc/DataDomain/mode/components/temperature.pm @@ -28,12 +28,18 @@ my %map_temp_status = (); my ($oid_tempSensorDescription, $oid_tempSensorCurrentValue, $oid_tempSensorStatus); my $oid_temperatureSensorEntry = '.1.3.6.1.4.1.19746.1.1.2.1.1.1'; +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_temperatureSensorEntry }; +} + 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_exclude(section => 'temperature')); + return if ($self->check_filter(section => 'temperature')); if (centreon::plugins::misc::minimal_version($self->{os_version}, '5.x')) { $oid_tempSensorDescription = '.1.3.6.1.4.1.19746.1.1.2.1.1.1.4'; @@ -57,7 +63,7 @@ sub check { $map_temp_status{$self->{results}->{$oid_temperatureSensorEntry}->{$oid}} : 'unknown'; my $temp_value = $self->{results}->{$oid_temperatureSensorEntry}->{$oid_tempSensorCurrentValue . '.' . $instance}; - next if ($self->check_exclude(section => 'temperature', instance => $instance)); + next if ($self->check_filter(section => 'temperature', instance => $instance)); next if ($temp_status =~ /absent|notfound/i && $self->absent_problem(section => 'temperature', instance => $instance)); diff --git a/storage/emc/DataDomain/mode/filesystem.pm b/storage/emc/DataDomain/mode/filesystem.pm index a52f80d39..f2e97a929 100644 --- a/storage/emc/DataDomain/mode/filesystem.pm +++ b/storage/emc/DataDomain/mode/filesystem.pm @@ -20,35 +20,40 @@ package storage::emc::DataDomain::mode::filesystem; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::counter); use strict; use warnings; use storage::emc::DataDomain::lib::functions; -use centreon::plugins::values; -my $oid_fileSystemSpaceEntry = '.1.3.6.1.4.1.19746.1.3.2.1.1'; -my $oid_sysDescr = '.1.3.6.1.2.1.1.1'; # 'Data Domain OS 5.4.1.1-411752' -my ($oid_fileSystemResourceName, $oid_fileSystemSpaceUsed, $oid_fileSystemSpaceAvail); +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'fs', type => 1, cb_prefix_output => 'prefix_fs_output', message_multiple => 'All filesystems are ok.' }, + ]; + + $self->{maps_counters}->{ap} = [ + { label => 'usage', set => { + key_values => [ { name => 'free' }, { name => 'used' }, { name => 'display' } ], + closure_custom_calc => $self->can('custom_used_calc'), + closure_custom_output => $self->can('custom_used_output'), + threshold_use => 'used_prct', output_error_template => '%s', + perfdatas => [ + { value => 'used', label => 'used', cast_int => 1, + unit => 'B', min => 0, max => 'total', threshold_total => 'total', + label_extra_instance => 1, instance_use => 'display' }, + ], + } + }, + ]; +} -my $maps_counters = { - usage => { class => 'centreon::plugins::values', obj => undef, - set => { - key_values => [ - { name => 'free' }, { name => 'used' }, { name => 'display' }, - ], - closure_custom_calc => \&custom_used_calc, - closure_custom_output => \&custom_used_output, - threshold_use => 'used_prct', - output_error_template => '%s', - perfdatas => [ - { value => 'used', label => 'used', cast_int => 1, - unit => 'B', min => 0, max => 'total', threshold_total => 'total', - label_extra_instance => 1, instance_use => 'display' }, - ], - } - }, -}; +sub prefix_fs_output { + my ($self, %options) = @_; + + return "Filesystem '" . $options{instance_value}->{display} . "' "; +} sub custom_used_calc { my ($self, %options) = @_; @@ -87,95 +92,14 @@ sub new { "filesystem:s" => { name => 'filesystem' }, "regexp" => { name => 'use_regexp' }, "regexp-isensitive" => { name => 'use_regexpi' }, - }); - - $self->{filesystem_id_selected} = {}; - - foreach (keys %{$maps_counters}) { - $options{options}->add_options(arguments => { - 'warning-' . $_ . ':s' => { name => 'warning-' . $_ }, - 'critical-' . $_ . ':s' => { name => 'critical-' . $_ }, - }); - my $class = $maps_counters->{$_}->{class}; - $maps_counters->{$_}->{obj} = $class->new(statefile => $self->{statefile_value}, - output => $self->{output}, perfdata => $self->{perfdata}, - label => $_); - $maps_counters->{$_}->{obj}->set(%{$maps_counters->{$_}->{set}}); - } + }); return $self; } -sub check_options { - my ($self, %options) = @_; - $self->SUPER::init(%options); - - foreach (keys %{$maps_counters}) { - $maps_counters->{$_}->{obj}->init(option_results => $self->{option_results}); - } -} - -sub run { - my ($self, %options) = @_; - # $options{snmp} = snmp object - $self->{snmp} = $options{snmp}; - - $self->manage_selection(); - - my $multiple = 1; - if (scalar(keys %{$self->{filesystem_id_selected}}) == 1) { - $multiple = 0; - } - - if ($multiple == 1) { - $self->{output}->output_add(severity => 'OK', - short_msg => 'All filesystems are ok.'); - } - - foreach my $id (sort keys %{$self->{filesystem_id_selected}}) { - my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', ''); - my @exits; - foreach (sort keys %{$maps_counters}) { - $maps_counters->{$_}->{obj}->set(instance => $id); - - my ($value_check) = $maps_counters->{$_}->{obj}->execute(values => $self->{filesystem_id_selected}->{$id}); - - if ($value_check != 0) { - $long_msg .= $long_msg_append . $maps_counters->{$_}->{obj}->output_error(); - $long_msg_append = ', '; - next; - } - my $exit2 = $maps_counters->{$_}->{obj}->threshold_check(); - push @exits, $exit2; - - my $output = $maps_counters->{$_}->{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 = ', '; - } - - $maps_counters->{$_}->{obj}->perfdata(extra_instance => $multiple); - } - - $self->{output}->output_add(long_msg => "Filesystem '" . $self->{filesystem_id_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 => "Filesystem '" . $self->{filesystem_id_selected}->{$id}->{display} . "' $short_msg" - ); - } - - if ($multiple == 0) { - $self->{output}->output_add(short_msg => "Filesystem '" . $self->{filesystem_id_selected}->{$id}->{display} . "' $long_msg"); - } - } - - $self->{output}->display(); - $self->{output}->exit(); -} +my $oid_fileSystemSpaceEntry = '.1.3.6.1.4.1.19746.1.3.2.1.1'; +my $oid_sysDescr = '.1.3.6.1.2.1.1.1'; # 'Data Domain OS 5.4.1.1-411752' +my ($oid_fileSystemResourceName, $oid_fileSystemSpaceUsed, $oid_fileSystemSpaceAvail); sub add_result { my ($self, %options) = @_; @@ -189,11 +113,11 @@ sub add_result { sub manage_selection { my ($self, %options) = @_; - $self->{results} = $self->{snmp}->get_multiple_table(oids => [ + $self->{results} = $options{snmp}->get_multiple_table(oids => [ { oid => $oid_sysDescr }, { oid => $oid_fileSystemSpaceEntry }, - ], - , nothing_quit => 1); + ], + nothing_quit => 1); if (!($self->{os_version} = storage::emc::DataDomain::lib::functions::get_version(value => $self->{results}->{$oid_sysDescr}->{$oid_sysDescr . '.0'}))) { $self->{output}->output_add(severity => 'UNKNOWN', short_msg => 'Cannot get DataDomain OS version.'); @@ -265,7 +189,6 @@ sub disco_show { } } - 1; __END__ diff --git a/storage/emc/DataDomain/mode/hardware.pm b/storage/emc/DataDomain/mode/hardware.pm index f7f7114e6..cd0f8b77b 100644 --- a/storage/emc/DataDomain/mode/hardware.pm +++ b/storage/emc/DataDomain/mode/hardware.pm @@ -20,61 +20,70 @@ package storage::emc::DataDomain::mode::hardware; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::hardware); use strict; use warnings; use storage::emc::DataDomain::lib::functions; -use storage::emc::DataDomain::mode::components::temperature; -use storage::emc::DataDomain::mode::components::psu; -use storage::emc::DataDomain::mode::components::fan; -use storage::emc::DataDomain::mode::components::disk; -use storage::emc::DataDomain::mode::components::battery; -my $oid_sysDescr = '.1.3.6.1.2.1.1.1'; # 'Data Domain OS 5.4.1.1-411752' -my $oid_powerModuleEntry = '.1.3.6.1.4.1.19746.1.1.1.1.1.1'; -my $oid_temperatureSensorEntry = '.1.3.6.1.4.1.19746.1.1.2.1.1.1'; -my $oid_fanPropertiesEntry = '.1.3.6.1.4.1.19746.1.1.3.1.1.1'; -my $oid_nvramBatteryEntry = '.1.3.6.1.4.1.19746.1.2.3.1.1'; +sub set_system { + my ($self, %options) = @_; + + $self->{regexp_threshold_overload_check_section_option} = '^(fan|temperature|psu|disk|battery)$'; + $self->{regexp_threshold_numeric_check_section_option} = '^(battery|temperature)$'; + + $self->{cb_hook1} = 'get_version'; # before the loads + $self->{cb_hook2} = 'snmp_execute'; + + $self->{thresholds} = { + fan => [ + ['notfound', 'OK'], + ['ok', 'OK'], + ['failed', 'CRITICAL'], + ], + temperature => [ + ['failed', 'CRITICAL'], + ['ok', 'OK'], + ['notfound', 'OK'], + ['absent', 'OK'], + ['overheatWarning', 'WARNING'], + ['overheatCritical', 'CRITICAL'], + ], + psu => [ + ['absent', 'OK'], + ['ok', 'OK'], + ['failed', 'CRITICAL'], + ['faulty', 'WARNING'], + ['acnone', 'WARNING'], + ['unknown', 'UNKNOWN'], + ], + disk => [ + ['ok', 'OK'], + ['spare', 'OK'], + ['available', 'OK'], + ['unknown', 'UNKNOWN'], + ['absent', 'OK'], + ['failed', 'CRITICAL'], + ], + battery => [ + ['ok', 'OK'], + ['disabled', 'OK'], + ['discharged', 'WARNING'], + ['softdisabled', 'OK'], + ['UNKNOWN', 'UNKNOWN'], + ], + }; + + $self->{components_path} = 'storage::emc::DataDomain::mode::components'; + $self->{components_module} = ['fan', 'temperature', 'psu', 'disk', 'battery']; +} -my $thresholds = { - fan => [ - ['notfound', 'OK'], - ['ok', 'OK'], - ['failed', 'CRITICAL'], - ], - temperature => [ - ['failed', 'CRITICAL'], - ['ok', 'OK'], - ['notfound', 'OK'], - ['absent', 'OK'], - ['overheatWarning', 'WARNING'], - ['overheatCritical', 'CRITICAL'], - ], - psu => [ - ['absent', 'OK'], - ['ok', 'OK'], - ['failed', 'CRITICAL'], - ['faulty', 'WARNING'], - ['acnone', 'WARNING'], - ['unknown', 'UNKNOWN'], - ], - disk => [ - ['ok', 'OK'], - ['spare', 'OK'], - ['available', 'OK'], - ['unknown', 'UNKNOWN'], - ['absent', 'OK'], - ['failed', 'CRITICAL'], - ], - battery => [ - ['ok', 'OK'], - ['disabled', 'OK'], - ['discharged', 'WARNING'], - ['softdisabled', 'OK'], - ['UNKNOWN', 'UNKNOWN'], - ], -}; +sub snmp_execute { + my ($self, %options) = @_; + + $self->{snmp} = $options{snmp}; + $self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request}); +} sub new { my ($class, %options) = @_; @@ -83,223 +92,25 @@ sub new { $self->{version} = '1.0'; $options{options}->add_options(arguments => - { - "exclude:s" => { name => 'exclude' }, - "component:s" => { name => 'component', default => 'all' }, - "absent-problem:s" => { name => 'absent' }, - "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 { +sub get_version { 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->{overload_th} = {}; - foreach my $val (@{$self->{option_results}->{threshold_overload}}) { - if ($val !~ /^(.*?),(.*?),(.*)$/) { - $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload option '" . $val . "'."); - $self->{output}->option_exit(); - } - my ($section, $status, $filter) = ($1, $2, $3); - 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}; - } - - $self->{numeric_threshold} = {}; - foreach my $option (('warning', 'critical')) { - foreach my $val (@{$self->{option_results}->{$option}}) { - if ($val !~ /^(.*?),(.*?),(.*)$/) { - $self->{output}->add_option_msg(short_msg => "Wrong $option option '" . $val . "'."); - $self->{output}->option_exit(); - } - my ($section, $regexp, $value) = ($1, $2, $3); - if ($section !~ /(battery|temperature)/) { - $self->{output}->add_option_msg(short_msg => "Wrong $option option '" . $val . "' (type must be: battery or temperature)."); - $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, regexp => $regexp }; - } - } -} - -sub run { - my ($self, %options) = @_; - # $options{snmp} = snmp object - $self->{snmp} = $options{snmp}; - - $self->{results_leef} = $self->{snmp}->get_leef(oids => [ $oid_sysDescr . '.0' ]); - if (!($self->{os_version} = storage::emc::DataDomain::lib::functions::get_version(value => $self->{results_leef}->{$oid_sysDescr . '.0'}))) { + my $oid_sysDescr = '.1.3.6.1.2.1.1.1.0'; # 'Data Domain OS 5.4.1.1-411752' + my $result = $self->{snmp}->get_leef(oids => [ $oid_sysDescr ]); + if (!($self->{os_version} = storage::emc::DataDomain::lib::functions::get_version(value => $result->{$oid_sysDescr}))) { $self->{output}->output_add(severity => 'UNKNOWN', short_msg => 'Cannot get DataDomain OS version.'); $self->{output}->display(); $self->{output}->exit(); } - my $oid_diskPropState; - if (centreon::plugins::misc::minimal_version($self->{os_version}, '5.x')) { - $oid_diskPropState = '.1.3.6.1.4.1.19746.1.6.1.1.1.8'; - } else { - $oid_diskPropState = '.1.3.6.1.4.1.19746.1.6.1.1.1.7'; - } - - $self->{results} = $self->{snmp}->get_multiple_table(oids => [ - { oid => $oid_powerModuleEntry }, - { oid => $oid_temperatureSensorEntry }, - { oid => $oid_fanPropertiesEntry }, - { oid => $oid_diskPropState }, - { oid => $oid_nvramBatteryEntry }, - ]); - - $self->{output}->output_add(long_msg => 'DataDomain OS version: ' . $self->{os_version} . '.'); - if ($self->{option_results}->{component} eq 'all') { - storage::emc::DataDomain::mode::components::psu::check($self); - storage::emc::DataDomain::mode::components::fan::check($self); - storage::emc::DataDomain::mode::components::disk::check($self); - storage::emc::DataDomain::mode::components::temperature::check($self); - storage::emc::DataDomain::mode::components::battery::check($self); - } elsif ($self->{option_results}->{component} eq 'fan') { - storage::emc::DataDomain::mode::components::fan::check($self); - } elsif ($self->{option_results}->{component} eq 'psu') { - storage::emc::DataDomain::mode::components::psu::check($self); - } elsif ($self->{option_results}->{component} eq 'disk') { - storage::emc::DataDomain::mode::components::disk::check($self); - } elsif ($self->{option_results}->{component} eq 'temperature') { - storage::emc::DataDomain::mode::components::temperature::check($self); - } elsif ($self->{option_results}->{component} eq 'battery') { - storage::emc::DataDomain::mode::components::battery::check($self); - } else { - $self->{output}->add_option_msg(short_msg => "Wrong option. Cannot find component '" . $self->{option_results}->{component} . "'."); - $self->{output}->option_exit(); - } - - 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 check_exclude { - my ($self, %options) = @_; - - if (defined($options{instance})) { - if (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)${options{section}}[^,]*#\Q$options{instance}\E#/) { - $self->{components}->{$options{section}}->{skip}++; - $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance.")); - return 1; - } - } elsif (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)$options{section}(\s|,|$)/) { - $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section.")); - return 1; - } - return 0; -} - -sub absent_problem { - my ($self, %options) = @_; - - if (defined($self->{option_results}->{absent}) && - $self->{option_results}->{absent} =~ /(^|\s|,)($options{section}(\s*,|$)|${options{section}}[^,]*#\Q$options{instance}\E#)/) { - $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; -} - -sub get_severity_numeric { - my ($self, %options) = @_; - my $status = 'OK'; # default - my $thresholds = { warning => undef, critical => undef }; - - if (defined($self->{numeric_threshold}->{$options{section}})) { - my $exits = []; - foreach (@{$self->{numeric_threshold}->{$options{section}}}) { - if ($options{instance} =~ /$_->{regexp}/) { - 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}); - - } - } - $status = $self->{output}->get_most_critical(status => $exits) if (scalar(@{$exits}) > 0); - } - - return ($status, $thresholds->{warning}, $thresholds->{critical}); -} - -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) { - $status = $_->{status}; - return $status; - } - } - } - foreach (@{$thresholds->{$options{section}}}) { - if ($options{value} =~ /$$_[0]/i) { - $status = $$_[1]; - return $status; - } - } - - return $status; } 1; @@ -314,18 +125,18 @@ Check components (Fans, Power Supplies, Temperatures, Disks, Nvram Batteries). =item B<--component> -Which component to check (Default: 'all'). +Which component to check (Default: '.*'). Can be: 'psu', 'fan', 'disk', 'temperature', 'battery'. -=item B<--exclude> +=item B<--filter> -Exclude some parts (comma seperated list) (Example: --exclude=psu) -Can also exclude specific instance: --exclude='psu#3.3#' +Exclude some parts (comma seperated list) (Example: --filter=fan --filter=psu) +Can also exclude specific instance: --filter=psu,3.3 =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.1# +Return an error if an entity is not 'present' (default is skipping) +Can be specific or global: --absent-problem=psu,1 =item B<--no-component> @@ -334,14 +145,14 @@ If total (with skipped) is 0. (Default: 'critical' returns). =item B<--threshold-overload> -Set to overload default threshold values (syntax: section,status,regexp) +Set to overload default threshold values (syntax: section,[instance,]status,regexp) It used before default thresholds (order stays). Example: --threshold-overload='fan,CRITICAL,^(?!(ok)$)' =item B<--warning> -Set warning threshold for temperatures (syntax: regexp,treshold) -Example: --warning='.*,20' +Set warning threshold for temperatures (syntax: type,regexp,treshold) +Example: --warning='temperature,.*,20' =item B<--critical>