diff --git a/centreon/common/airespace/snmp/mode/hardware.pm b/centreon/common/airespace/snmp/mode/hardware.pm index 339a9db7a..a9818172b 100644 --- a/centreon/common/airespace/snmp/mode/hardware.pm +++ b/centreon/common/airespace/snmp/mode/hardware.pm @@ -32,7 +32,6 @@ sub set_system { $self->{cb_hook2} = 'snmp_execute'; - #Example for threshold: $self->{thresholds} = { psu => [ ['not operational', 'CRITICAL'], diff --git a/network/bluecoat/snmp/mode/components/disk.pm b/network/bluecoat/snmp/mode/components/disk.pm index 4f481c016..cb078d198 100644 --- a/network/bluecoat/snmp/mode/components/disk.pm +++ b/network/bluecoat/snmp/mode/components/disk.pm @@ -44,9 +44,9 @@ my $mapping = { my $oid_deviceDiskValueEntry = '.1.3.6.1.4.1.3417.2.2.1.1.1.1'; sub load { - my (%options) = @_; + my ($self) = @_; - push @{$options{request}}, { oid => $oid_deviceDiskValueEntry }; + push @{$self->{request}}, { oid => $oid_deviceDiskValueEntry }; } sub check { diff --git a/network/bluecoat/snmp/mode/components/sensor.pm b/network/bluecoat/snmp/mode/components/sensor.pm index 73caaff1a..940ab82e6 100644 --- a/network/bluecoat/snmp/mode/components/sensor.pm +++ b/network/bluecoat/snmp/mode/components/sensor.pm @@ -66,9 +66,9 @@ my $mapping = { my $oid_deviceSensorValueEntry = '.1.3.6.1.4.1.3417.2.1.1.1.1.1'; sub load { - my (%options) = @_; + my ($self) = @_; - push @{$options{request}}, { oid => $oid_deviceSensorValueEntry }; + push @{$self->{request}}, { oid => $oid_deviceSensorValueEntry }; } sub check { diff --git a/network/bluecoat/snmp/mode/hardware.pm b/network/bluecoat/snmp/mode/hardware.pm index af39b7603..9f9123069 100644 --- a/network/bluecoat/snmp/mode/hardware.pm +++ b/network/bluecoat/snmp/mode/hardware.pm @@ -20,49 +20,71 @@ package network::bluecoat::snmp::mode::hardware; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::hardware); use strict; use warnings; -use centreon::plugins::misc; my $thresholds = { - sensor_opstatus => [ - ['ok', 'OK'], - ['unavailable', 'UNKNOWN'], - ['nonoperational', 'UNKNOWN'], - ], - sensor => [ - ['ok', 'OK'], - ['unknown', 'UNKNOWN'], - ['nonInstalled', 'OK'], - ['voltageLowWarning', 'WARNING'], - ['voltageLowCritical', 'CRITICAL'], - ['noPower', 'CRITICAL'], - ['voltageHighWarning', 'WARNING'], - ['voltageHighCritical', 'CRITICAL'], - ['voltageHighSevere', 'CRITICAL'], - ['temperatureHighWarning', 'WARNING'], - ['temperatureHighCritical', 'CRITICAL'], - ['temperatureHighSevere', 'CRITICAL'], - ['fanSlowWarning', 'WARNING'], - ['fanSlowCritical', 'CRITICAL'], - ['fanStopped', 'CRITICAL'], - ], - disk => [ - ['present', 'OK'], - ['initializing', 'OK'], - ['inserted', 'OK'], - ['offline', 'WARNING'], - ['removed', 'WARNING'], - ['notpresent', 'OK'], - ['empty', 'WARNING'], - ['ioerror', 'CRITICAL'], - ['unusable', 'CRITICAL'], - ['unknown', 'UNKNOWN'], - ], + }; +sub set_system { + my ($self, %options) = @_; + + $self->{regexp_threshold_overload_check_section_option} = '^(sensor|disk|sensor_opstatus)$'; + $self->{regexp_threshold_numeric_check_section_option} = '^sensor$'; + + $self->{cb_hook2} = 'snmp_execute'; + + $self->{thresholds} = { + sensor_opstatus => [ + ['ok', 'OK'], + ['unavailable', 'UNKNOWN'], + ['nonoperational', 'UNKNOWN'], + ], + sensor => [ + ['ok', 'OK'], + ['unknown', 'UNKNOWN'], + ['nonInstalled', 'OK'], + ['voltageLowWarning', 'WARNING'], + ['voltageLowCritical', 'CRITICAL'], + ['noPower', 'CRITICAL'], + ['voltageHighWarning', 'WARNING'], + ['voltageHighCritical', 'CRITICAL'], + ['voltageHighSevere', 'CRITICAL'], + ['temperatureHighWarning', 'WARNING'], + ['temperatureHighCritical', 'CRITICAL'], + ['temperatureHighSevere', 'CRITICAL'], + ['fanSlowWarning', 'WARNING'], + ['fanSlowCritical', 'CRITICAL'], + ['fanStopped', 'CRITICAL'], + ], + disk => [ + ['present', 'OK'], + ['initializing', 'OK'], + ['inserted', 'OK'], + ['offline', 'WARNING'], + ['removed', 'WARNING'], + ['notpresent', 'OK'], + ['empty', 'WARNING'], + ['ioerror', 'CRITICAL'], + ['unusable', 'CRITICAL'], + ['unknown', 'UNKNOWN'], + ], + }; + + $self->{components_path} = 'network::bluecoat::snmp::mode::components'; + $self->{components_module} = ['sensor', 'disk']; +} + +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) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); @@ -70,241 +92,12 @@ sub new { $self->{version} = '1.0'; $options{options}->add_options(arguments => - { - "filter:s@" => { name => 'filter' }, - "absent-problem:s@" => { name => 'absent_problem' }, - "component:s" => { name => 'component', default => '.*' }, - "no-component:s" => { name => 'no_component' }, - "threshold-overload:s@" => { name => 'threshold_overload' }, - "warning:s@" => { name => 'warning' }, - "critical:s@" => { name => 'critical' }, + { }); - - $self->{components} = {}; - $self->{no_components} = undef; return $self; } -sub check_options { - my ($self, %options) = @_; - $self->SUPER::init(%options); - - if (defined($self->{option_results}->{no_component})) { - if ($self->{option_results}->{no_component} ne '') { - $self->{no_components} = $self->{option_results}->{no_component}; - } else { - $self->{no_components} = 'critical'; - } - } - - $self->{filter} = []; - foreach my $val (@{$self->{option_results}->{filter}}) { - next if (!defined($val) || $val eq ''); - my @values = split (/,/, $val); - push @{$self->{filter}}, { filter => $values[0], instance => $values[1] }; - } - - $self->{absent_problem} = []; - foreach my $val (@{$self->{option_results}->{absent_problem}}) { - next if (!defined($val) || $val eq ''); - my @values = split (/,/, $val); - push @{$self->{absent_problem}}, { filter => $values[0], instance => $values[1] }; - } - - $self->{overload_th} = {}; - foreach my $val (@{$self->{option_results}->{threshold_overload}}) { - next if (!defined($val) || $val eq ''); - my @values = split (/,/, $val); - if (scalar(@values) < 3) { - $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload option '" . $val . "'."); - $self->{output}->option_exit(); - } - my ($section, $instance, $status, $filter); - if (scalar(@values) == 3) { - ($section, $status, $filter) = @values; - $instance = '.*'; - } else { - ($section, $instance, $status, $filter) = @values; - } - if ($section !~ /^sensor|disk|sensor_opstatus$/) { - $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload section '" . $val . "'."); - $self->{output}->option_exit(); - } - if ($self->{output}->is_litteral_status(status => $status) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload status '" . $val . "'."); - $self->{output}->option_exit(); - } - $self->{overload_th}->{$section} = [] if (!defined($self->{overload_th}->{$section})); - push @{$self->{overload_th}->{$section}}, {filter => $filter, status => $status, instance => $instance }; - } - - $self->{numeric_threshold} = {}; - foreach my $option (('warning', 'critical')) { - foreach my $val (@{$self->{option_results}->{$option}}) { - next if (!defined($val) || $val eq ''); - if ($val !~ /^(.*?),(.*?),(.*)$/) { - $self->{output}->add_option_msg(short_msg => "Wrong $option option '" . $val . "'."); - $self->{output}->option_exit(); - } - my ($section, $instance, $value) = ($1, $2, $3); - if ($section !~ /^sensor$/) { - $self->{output}->add_option_msg(short_msg => "Wrong $option option '" . $val . "'."); - $self->{output}->option_exit(); - } - my $position = 0; - if (defined($self->{numeric_threshold}->{$section})) { - $position = scalar(@{$self->{numeric_threshold}->{$section}}); - } - if (($self->{perfdata}->threshold_validate(label => $option . '-' . $section . '-' . $position, value => $value)) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong $option threshold '" . $value . "'."); - $self->{output}->option_exit(); - } - $self->{numeric_threshold}->{$section} = [] if (!defined($self->{numeric_threshold}->{$section})); - push @{$self->{numeric_threshold}->{$section}}, { label => $option . '-' . $section . '-' . $position, threshold => $option, instance => $instance }; - } - } -} - -sub run { - my ($self, %options) = @_; - $self->{snmp} = $options{snmp}; - - my $snmp_request = []; - my @components = ('sensor', 'disk'); - foreach (@components) { - if (/$self->{option_results}->{component}/) { - my $mod_name = "network::bluecoat::snmp::mode::components::$_"; - centreon::plugins::misc::mymodule_load(output => $self->{output}, module => $mod_name, - error_msg => "Cannot load module '$mod_name'."); - my $func = $mod_name->can('load'); - $func->(request => $snmp_request); - } - } - - if (scalar(@{$snmp_request}) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong option. Cannot find component '" . $self->{option_results}->{component} . "'."); - $self->{output}->option_exit(); - } - $self->{results} = $self->{snmp}->get_multiple_table(oids => $snmp_request); - - foreach (@components) { - if (/$self->{option_results}->{component}/) { - my $mod_name = "network::bluecoat::snmp::mode::components::$_"; - my $func = $mod_name->can('check'); - $func->($self); - } - } - - my $total_components = 0; - my $display_by_component = ''; - my $display_by_component_append = ''; - foreach my $comp (sort(keys %{$self->{components}})) { - # Skipping short msg when no components - next if ($self->{components}->{$comp}->{total} == 0 && $self->{components}->{$comp}->{skip} == 0); - $total_components += $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip}; - my $count_by_components = $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip}; - $display_by_component .= $display_by_component_append . $self->{components}->{$comp}->{total} . '/' . $count_by_components . ' ' . $self->{components}->{$comp}->{name}; - $display_by_component_append = ', '; - } - - $self->{output}->output_add(severity => 'OK', - short_msg => sprintf("All %s components are ok [%s].", - $total_components, - $display_by_component) - ); - - if (defined($self->{option_results}->{no_component}) && $total_components == 0) { - $self->{output}->output_add(severity => $self->{no_components}, - short_msg => 'No components are checked.'); - } - - $self->{output}->display(); - $self->{output}->exit(); -} - -sub absent_problem { - my ($self, %options) = @_; - - foreach (@{$self->{absent_problem}}) { - if ($options{section} =~ /$_->{filter}/) { - if (!defined($_->{instance}) || $options{instance} =~ /$_->{instance}/) { - $self->{output}->output_add(severity => 'CRITICAL', - short_msg => sprintf("Component '%s' instance '%s' is not present", - $options{section}, $options{instance})); - $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance (not present)")); - $self->{components}->{$options{section}}->{skip}++; - return 1; - } - } - } - - return 0; -} - -sub check_filter { - my ($self, %options) = @_; - - foreach (@{$self->{filter}}) { - if ($options{section} =~ /$_->{filter}/) { - if (!defined($options{instance}) && !defined($_->{instance})) { - $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section.")); - return 1; - } elsif (defined($options{instance}) && $options{instance} =~ /$_->{instance}/) { - $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance.")); - return 1; - } - } - } - - return 0; -} - -sub get_severity_numeric { - my ($self, %options) = @_; - my $status = 'OK'; # default - my $thresholds = { warning => undef, critical => undef }; - my $checked = 0; - - if (defined($self->{numeric_threshold}->{$options{section}})) { - my $exits = []; - foreach (@{$self->{numeric_threshold}->{$options{section}}}) { - if ($options{instance} =~ /$_->{instance}/) { - push @{$exits}, $self->{perfdata}->threshold_check(value => $options{value}, threshold => [ { label => $_->{label}, exit_litteral => $_->{threshold} } ]); - $thresholds->{$_->{threshold}} = $self->{perfdata}->get_perfdata_for_output(label => $_->{label}); - $checked = 1; - } - } - $status = $self->{output}->get_most_critical(status => $exits) if (scalar(@{$exits}) > 0); - } - - return ($status, $thresholds->{warning}, $thresholds->{critical}, $checked); -} - -sub get_severity { - my ($self, %options) = @_; - my $status = 'UNKNOWN'; # default - - if (defined($self->{overload_th}->{$options{section}})) { - foreach (@{$self->{overload_th}->{$options{section}}}) { - if ($options{value} =~ /$_->{filter}/i && - (!defined($options{instance}) || $options{instance} =~ /$_->{instance}/)) { - $status = $_->{status}; - return $status; - } - } - } - my $label = defined($options{label}) ? $options{label} : $options{section}; - foreach (@{$thresholds->{$label}}) { - if ($options{value} =~ /$$_[0]/i) { - $status = $$_[1]; - return $status; - } - } - - return $status; -} - 1; __END__ diff --git a/network/checkpoint/mode/components/fan.pm b/network/checkpoint/mode/components/fan.pm index 3bee03320..97d3400f0 100644 --- a/network/checkpoint/mode/components/fan.pm +++ b/network/checkpoint/mode/components/fan.pm @@ -37,9 +37,9 @@ my $mapping = { my $oid_fanSpeedSensorEntry = '.1.3.6.1.4.1.2620.1.6.7.8.2.1'; sub load { - my (%options) = @_; + my ($self) = @_; - push @{$options{request}}, { oid => $oid_fanSpeedSensorEntry, start => $mapping->{fanSpeedSensorName}->{oid}, end => $mapping->{fanSpeedSensorStatus}->{oid} }; + push @{$self->{request}}, { oid => $oid_fanSpeedSensorEntry, start => $mapping->{fanSpeedSensorName}->{oid}, end => $mapping->{fanSpeedSensorStatus}->{oid} }; } sub check { @@ -47,14 +47,14 @@ sub check { $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')); foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_fanSpeedSensorEntry}})) { next if ($oid !~ /^$mapping->{fanSpeedSensorStatus}->{oid}\.(.*)$/); my $instance = $1; my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_fanSpeedSensorEntry}, instance => $instance); - next if ($self->check_exclude(section => 'fan', instance => $instance)); + next if ($self->check_filter(section => 'fan', instance => $instance)); next if ($result->{fanSpeedSensorName} !~ /^[0-9a-zA-Z ]+$/); # sometimes there is some wrong values in hex $self->{components}->{fan}->{total}++; diff --git a/network/checkpoint/mode/components/psu.pm b/network/checkpoint/mode/components/psu.pm index f3801f1b0..e987a2623 100644 --- a/network/checkpoint/mode/components/psu.pm +++ b/network/checkpoint/mode/components/psu.pm @@ -29,9 +29,9 @@ my $mapping = { my $oid_powerSupplyStatus = '.1.3.6.1.4.1.2620.1.6.7.9.1.1.2'; sub load { - my (%options) = @_; + my ($self) = @_; - push @{$options{request}}, { oid => $oid_powerSupplyStatus }; + push @{$self->{request}}, { oid => $oid_powerSupplyStatus }; } sub check { @@ -39,14 +39,14 @@ sub check { $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')); foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_powerSupplyStatus}})) { next if ($oid !~ /^$mapping->{powerSupplyStatus}->{oid}\.(.*)$/); my $instance = $1; my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_powerSupplyStatus}, instance => $instance); - next if ($self->check_exclude(section => 'psu', instance => $instance)); + next if ($self->check_filter(section => 'psu', instance => $instance)); $self->{components}->{psu}->{total}++; $self->{output}->output_add(long_msg => sprintf("Power supply '%s' status is '%s'", diff --git a/network/checkpoint/mode/components/temperature.pm b/network/checkpoint/mode/components/temperature.pm index 60d24298b..9dac9032a 100644 --- a/network/checkpoint/mode/components/temperature.pm +++ b/network/checkpoint/mode/components/temperature.pm @@ -37,9 +37,9 @@ my $mapping = { my $oid_tempertureSensorEntry = '.1.3.6.1.4.1.2620.1.6.7.8.1.1'; sub load { - my (%options) = @_; + my ($self) = @_; - push @{$options{request}}, { oid => $oid_tempertureSensorEntry, start => $mapping->{tempertureSensorName}->{oid}, end => $mapping->{tempertureSensorStatus}->{oid} }; + push @{$self->{request}}, { oid => $oid_tempertureSensorEntry, start => $mapping->{tempertureSensorName}->{oid}, end => $mapping->{tempertureSensorStatus}->{oid} }; } sub check { @@ -47,14 +47,14 @@ sub check { $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')); foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_tempertureSensorEntry}})) { next if ($oid !~ /^$mapping->{tempertureSensorStatus}->{oid}\.(.*)$/); my $instance = $1; my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_tempertureSensorEntry}, instance => $instance); - next if ($self->check_exclude(section => 'temperature', instance => $instance)); + next if ($self->check_filter(section => 'temperature', instance => $instance)); next if ($result->{tempertureSensorName} !~ /^[0-9a-zA-Z ]+$/); # sometimes there is some wrong values in hex $self->{components}->{temperature}->{total}++; diff --git a/network/checkpoint/mode/components/voltage.pm b/network/checkpoint/mode/components/voltage.pm index edc9aeb8b..b4d49bd5a 100644 --- a/network/checkpoint/mode/components/voltage.pm +++ b/network/checkpoint/mode/components/voltage.pm @@ -37,9 +37,9 @@ my $mapping = { my $oid_voltageSensorEntry = '.1.3.6.1.4.1.2620.1.6.7.8.3.1'; sub load { - my (%options) = @_; + my ($self) = @_; - push @{$options{request}}, { oid => $oid_voltageSensorEntry, start => $mapping->{voltageSensorName}->{oid}, end => $mapping->{voltageSensorStatus}->{oid} }; + push @{$self->{request}}, { oid => $oid_voltageSensorEntry, start => $mapping->{voltageSensorName}->{oid}, end => $mapping->{voltageSensorStatus}->{oid} }; } sub check { @@ -47,14 +47,14 @@ sub check { $self->{output}->output_add(long_msg => "Checking voltages"); $self->{components}->{voltage} = {name => 'voltages', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'voltage')); + return if ($self->check_filter(section => 'voltage')); foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_voltageSensorEntry}})) { next if ($oid !~ /^$mapping->{voltageSensorStatus}->{oid}\.(.*)$/); my $instance = $1; my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_voltageSensorEntry}, instance => $instance); - next if ($self->check_exclude(section => 'voltage', instance => $instance)); + next if ($self->check_filter(section => 'voltage', instance => $instance)); next if ($result->{voltageSensorName} !~ /^[0-9a-zA-Z ]+$/); # sometimes there is some wrong values in hex $self->{components}->{voltage}->{total}++; diff --git a/network/checkpoint/mode/hardware.pm b/network/checkpoint/mode/hardware.pm index 95a058b2e..4225386b6 100644 --- a/network/checkpoint/mode/hardware.pm +++ b/network/checkpoint/mode/hardware.pm @@ -20,176 +20,65 @@ package network::checkpoint::mode::hardware; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::hardware); use strict; use warnings; -my $thresholds = { - temperature => [ - ['true', 'CRITICAL'], - ['reading error', 'CRITICAL'], - ['false', 'OK'], - ], - voltage => [ - ['true', 'CRITICAL'], - ['reading error', 'CRITICAL'], - ['false', 'OK'], - ], - fan => [ - ['true', 'CRITICAL'], - ['reading error', 'CRITICAL'], - ['false', 'OK'], - ], - psu => [ - ['up', 'OK'], - ['down', 'CRITICAL'], - ['.*', 'UNKNOWN'], - ], -}; +sub set_system { + my ($self, %options) = @_; + + $self->{regexp_threshold_overload_check_section_option} = '^(temperature|voltage|fan|psu)$'; + + $self->{cb_hook2} = 'snmp_execute'; + + $self->{thresholds} = { + temperature => [ + ['true', 'CRITICAL'], + ['reading error', 'CRITICAL'], + ['false', 'OK'], + ], + voltage => [ + ['true', 'CRITICAL'], + ['reading error', 'CRITICAL'], + ['false', 'OK'], + ], + fan => [ + ['true', 'CRITICAL'], + ['reading error', 'CRITICAL'], + ['false', 'OK'], + ], + psu => [ + ['up', 'OK'], + ['down', 'CRITICAL'], + ['.*', 'UNKNOWN'], + ], + }; + + $self->{components_path} = 'network::checkpoint::mode::components'; + $self->{components_module} = ['voltage', 'fan', 'temperature', 'psu']; +} + +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) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_performance => 1, no_absent => 1); bless $self, $class; $self->{version} = '1.0'; $options{options}->add_options(arguments => - { - "exclude:s" => { name => 'exclude' }, - "component:s" => { name => 'component', default => '.*' }, - "no-component:s" => { name => 'no_component' }, - "threshold-overload:s@" => { name => 'threshold_overload' }, + { }); - $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->{overload_th} = {}; - foreach my $val (@{$self->{option_results}->{threshold_overload}}) { - if ($val !~ /^(.*?),(.*?),(.*)$/) { - $self->{output}->add_option_msg(short_msg => "Wrong treshold-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 treshold-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}; - } -} - -sub run { - my ($self, %options) = @_; - # $options{snmp} = snmp object - $self->{snmp} = $options{snmp}; - - my $snmp_request = []; - my @components = ('voltage', 'fan', 'temperature', 'psu'); - foreach (@components) { - if (/$self->{option_results}->{component}/) { - my $mod_name = "network::checkpoint::mode::components::$_"; - centreon::plugins::misc::mymodule_load(output => $self->{output}, module => $mod_name, - error_msg => "Cannot load module '$mod_name'."); - my $func = $mod_name->can('load'); - $func->(request => $snmp_request); - } - } - - if (scalar(@{$snmp_request}) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong option. Cannot find component '" . $self->{option_results}->{component} . "'."); - $self->{output}->option_exit(); - } - $self->{results} = $self->{snmp}->get_multiple_table(oids => $snmp_request); - - foreach (@components) { - if (/$self->{option_results}->{component}/) { - my $mod_name = "network::checkpoint::mode::components::$_"; - my $func = $mod_name->can('check'); - $func->($self); - } - } - - my $total_components = 0; - my $display_by_component = ''; - my $display_by_component_append = ''; - foreach my $comp (sort(keys %{$self->{components}})) { - # Skipping short msg when no components - next if ($self->{components}->{$comp}->{total} == 0 && $self->{components}->{$comp}->{skip} == 0); - $total_components += $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip}; - my $count_by_components = $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip}; - $display_by_component .= $display_by_component_append . $self->{components}->{$comp}->{total} . '/' . $count_by_components . ' ' . $self->{components}->{$comp}->{name}; - $display_by_component_append = ', '; - } - - $self->{output}->output_add(severity => 'OK', - short_msg => sprintf("All %s components are ok [%s].", - $total_components, - $display_by_component) - ); - - if (defined($self->{option_results}->{no_component}) && $total_components == 0) { - $self->{output}->output_add(severity => $self->{no_components}, - short_msg => 'No components are checked.'); - } - - $self->{output}->display(); - $self->{output}->exit(); -} - -sub 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 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; __END__ @@ -205,15 +94,10 @@ Check hardware (fans, power supplies, temperatures, voltages). Which component to check (Default: '.*'). Can be: 'psu', 'fan', 'temperature', 'voltage'. -=item B<--exclude> +=item B<--filter> -Exclude some parts (comma seperated list) (Example: --exclude=psu) -Can also exclude specific instance: --exclude='psu#1#' - -=item B<--absent-problem> - -Return an error if an entity is not 'present' (default is skipping) (comma seperated list) -Can be specific or global: --absent-problem=fan#1# +Exclude some parts (comma seperated list) (Example: --filter=fan --filter=psu) +Can also exclude specific instance: --filter=psu,1 =item B<--no-component> @@ -222,7 +106,7 @@ 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,^(?!(false)$)' diff --git a/network/cisco/ironport/snmp/mode/components/fan.pm b/network/cisco/ironport/snmp/mode/components/fan.pm index 6e91a53f8..708b6e310 100644 --- a/network/cisco/ironport/snmp/mode/components/fan.pm +++ b/network/cisco/ironport/snmp/mode/components/fan.pm @@ -30,9 +30,9 @@ my $mapping = { my $oid_fanEntry = '.1.3.6.1.4.1.15497.1.1.1.10.1'; sub load { - my (%options) = @_; + my ($self) = @_; - push @{$options{request}}, { oid => $oid_fanEntry, start => $mapping->{fanRPMs}->{oid} }; + push @{$self->{request}}, { oid => $oid_fanEntry, start => $mapping->{fanRPMs}->{oid} }; } sub check { @@ -40,14 +40,14 @@ sub check { $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')); foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_fanEntry}})) { next if ($oid !~ /^$mapping->{fanRPMs}->{oid}\.(.*)$/); my $instance = $1; my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_fanEntry}, instance => $instance); - next if ($self->check_exclude(section => 'fan', instance => $instance)); + next if ($self->check_filter(section => 'fan', instance => $instance)); $self->{components}->{fan}->{total}++; $self->{output}->output_add(long_msg => sprintf("Fan '%s' is '%s' rpm [instance = %s]", diff --git a/network/cisco/ironport/snmp/mode/components/psu.pm b/network/cisco/ironport/snmp/mode/components/psu.pm index 782c11de5..7e4343418 100644 --- a/network/cisco/ironport/snmp/mode/components/psu.pm +++ b/network/cisco/ironport/snmp/mode/components/psu.pm @@ -37,9 +37,9 @@ my $mapping = { my $oid_powerSupplyEntry = '.1.3.6.1.4.1.15497.1.1.1.8.1'; sub load { - my (%options) = @_; + my ($self) = @_; - push @{$options{request}}, { oid => $oid_powerSupplyEntry, start => $mapping->{powerSupplyStatus}->{oid} }; + push @{$self->{request}}, { oid => $oid_powerSupplyEntry, start => $mapping->{powerSupplyStatus}->{oid} }; } sub check { @@ -47,14 +47,14 @@ sub check { $self->{output}->output_add(long_msg => "Checking power supplies"); $self->{components}->{psu} = {name => 'power supplies', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'psu')); + return if ($self->check_filter(section => 'psu')); foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_powerSupplyEntry}})) { next if ($oid !~ /^$mapping->{powerSupplyStatus}->{oid}\.(.*)$/); my $instance = $1; my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_powerSupplyEntry}, instance => $instance); - next if ($self->check_exclude(section => 'psu', instance => $instance)); + next if ($self->check_filter(section => 'psu', instance => $instance)); if ($result->{powerSupplyStatus} =~ /powerSupplyNotInstalled/i) { $self->absent_problem(section => 'psu', instance => $instance); next; diff --git a/network/cisco/ironport/snmp/mode/components/raid.pm b/network/cisco/ironport/snmp/mode/components/raid.pm index 9b6a80b85..d57bb01e6 100644 --- a/network/cisco/ironport/snmp/mode/components/raid.pm +++ b/network/cisco/ironport/snmp/mode/components/raid.pm @@ -36,9 +36,9 @@ my $mapping = { my $oid_raidEntry = '.1.3.6.1.4.1.15497.1.1.1.18.1'; sub load { - my (%options) = @_; + my ($self) = @_; - push @{$options{request}}, { oid => $oid_raidEntry, start => $mapping->{raidStatus}->{oid} }; + push @{$self->{request}}, { oid => $oid_raidEntry, start => $mapping->{raidStatus}->{oid} }; } sub check { @@ -46,14 +46,14 @@ sub check { $self->{output}->output_add(long_msg => "Checking raids"); $self->{components}->{raid} = {name => 'raids', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'raid')); + return if ($self->check_filter(section => 'raid')); foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_raidEntry}})) { next if ($oid !~ /^$mapping->{raidStatus}->{oid}\.(.*)$/); my $instance = $1; my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_raidEntry}, instance => $instance); - next if ($self->check_exclude(section => 'raid', instance => $instance)); + next if ($self->check_filter(section => 'raid', instance => $instance)); $self->{components}->{raid}->{total}++; $self->{output}->output_add(long_msg => sprintf("Raid '%s' status is '%s' [instance = %s]", diff --git a/network/cisco/ironport/snmp/mode/components/temperature.pm b/network/cisco/ironport/snmp/mode/components/temperature.pm index 8140b4c58..f58ccc5ad 100644 --- a/network/cisco/ironport/snmp/mode/components/temperature.pm +++ b/network/cisco/ironport/snmp/mode/components/temperature.pm @@ -44,9 +44,9 @@ my $mapping = { my $oid_temperatureEntry = '.1.3.6.1.4.1.15497.1.1.1.9.1'; sub load { - my (%options) = @_; + my ($self) = @_; - push @{$options{request}}, { oid => $oid_temperatureEntry, start => $mapping->{degreesCelsius}->{oid} }; + push @{$self->{request}}, { oid => $oid_temperatureEntry, start => $mapping->{degreesCelsius}->{oid} }; } sub check { @@ -54,14 +54,14 @@ sub check { $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')); foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_temperatureEntry}})) { next if ($oid !~ /^$mapping->{degreesCelsius}->{oid}\.(.*)$/); my $instance = $1; my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_temperatureEntry}, instance => $instance); - next if ($self->check_exclude(section => 'temperature', instance => $instance)); + next if ($self->check_filter(section => 'temperature', instance => $instance)); $self->{components}->{temperature}->{total}++; $self->{output}->output_add(long_msg => sprintf("Temperature '%s' is '%s' degree centigrade [instance = %s]", diff --git a/network/cisco/ironport/snmp/mode/hardware.pm b/network/cisco/ironport/snmp/mode/hardware.pm index c7705df11..d1f10ff00 100644 --- a/network/cisco/ironport/snmp/mode/hardware.pm +++ b/network/cisco/ironport/snmp/mode/hardware.pm @@ -20,24 +20,43 @@ package network::cisco::ironport::snmp::mode::hardware; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::hardware); use strict; use warnings; -my $thresholds = { - psu => [ - ['powerSupplyNotInstalled', 'OK'], - ['powerSupplyHealthy', 'OK'], - ['powerSupplyNoAC', 'WARNING'], - ['powerSupplyFaulty', 'CRITICAL'], - ], - raid => [ - ['driveHealthy', 'OK'], - ['driveFailure', 'CRITICAL'], - ['driveRebuild', 'WARNING'], - ], -}; +sub set_system { + my ($self, %options) = @_; + + $self->{regexp_threshold_overload_check_section_option} = '^(raid|psu)$'; + $self->{regexp_threshold_numeric_check_section_option} = '^(temperature|fan)$'; + + $self->{cb_hook2} = 'snmp_execute'; + + $self->{thresholds} = { + psu => [ + ['powerSupplyNotInstalled', 'OK'], + ['powerSupplyHealthy', 'OK'], + ['powerSupplyNoAC', 'WARNING'], + ['powerSupplyFaulty', 'CRITICAL'], + ], + raid => [ + ['driveHealthy', 'OK'], + ['driveFailure', 'CRITICAL'], + ['driveRebuild', 'WARNING'], + ], + }; + + $self->{components_path} = 'network::cisco::ironport::snmp::mode::components'; + $self->{components_module} = ['fan', 'temperature', 'psu', 'raid']; +} + +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) = @_; @@ -46,207 +65,12 @@ sub new { $self->{version} = '1.0'; $options{options}->add_options(arguments => - { - "exclude:s" => { name => 'exclude' }, - "absent-problem:s" => { name => 'absent' }, - "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->{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 !~ /(temperature|fan)/) { - $self->{output}->add_option_msg(short_msg => "Wrong $option option '" . $val . "' (type must be: temperature or fan)."); - $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}; - - my $snmp_request = []; - my @components = ('fan', 'temperature', 'psu', 'raid'); - foreach (@components) { - if (/$self->{option_results}->{component}/) { - my $mod_name = "network::cisco::ironport::snmp::mode::components::$_"; - centreon::plugins::misc::mymodule_load(output => $self->{output}, module => $mod_name, - error_msg => "Cannot load module '$mod_name'."); - my $func = $mod_name->can('load'); - $func->(request => $snmp_request); - } - } - - if (scalar(@{$snmp_request}) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong option. Cannot find component '" . $self->{option_results}->{component} . "'."); - $self->{output}->option_exit(); - } - $self->{results} = $self->{snmp}->get_multiple_table(oids => $snmp_request); - - foreach (@components) { - if (/$self->{option_results}->{component}/) { - my $mod_name = "network::cisco::ironport::snmp::mode::components::$_"; - my $func = $mod_name->can('check'); - $func->($self); - } - } - - my $total_components = 0; - my $display_by_component = ''; - my $display_by_component_append = ''; - foreach my $comp (sort(keys %{$self->{components}})) { - # Skipping short msg when no components - next if ($self->{components}->{$comp}->{total} == 0 && $self->{components}->{$comp}->{skip} == 0); - $total_components += $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip}; - my $count_by_components = $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip}; - $display_by_component .= $display_by_component_append . $self->{components}->{$comp}->{total} . '/' . $count_by_components . ' ' . $self->{components}->{$comp}->{name}; - $display_by_component_append = ', '; - } - - $self->{output}->output_add(severity => 'OK', - short_msg => sprintf("All %s components are ok [%s].", - $total_components, - $display_by_component) - ); - - if (defined($self->{option_results}->{no_component}) && $total_components == 0) { - $self->{output}->output_add(severity => $self->{no_components}, - short_msg => 'No components are checked.'); - } - - $self->{output}->display(); - $self->{output}->exit(); -} - -sub 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 }; - my $checked = 0; - - 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}); - $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) { - $status = $_->{status}; - return $status; - } - } - } - foreach (@{$thresholds->{$options{section}}}) { - if ($options{value} =~ /$$_[0]/i) { - $status = $$_[1]; - return $status; - } - } - - return $status; -} - 1; __END__ @@ -262,10 +86,10 @@ Check Hardware (Fans, Power Supplies, Temperatures, Raids). Which component to check (Default: '.*'). Can be: 'fan', 'temperature', 'psu', 'raid'. -=item B<--exclude> +=item B<--filter> -Exclude some parts (comma seperated list) (Example: --exclude=fan,temperature) -Can also exclude specific instance: --exclude=fan#1#,temperature#2# +Exclude some parts (comma seperated list) (Example: --filter=fan --filter=temperature) +Can also exclude specific instance: --filter=fan,1 =item B<--absent-problem> @@ -279,7 +103,7 @@ 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='psu,CRITICAL,^(?!(powerSupplyHealthy)$)' diff --git a/network/dlink/dgs3100/snmp/mode/components/fan.pm b/network/dlink/dgs3100/snmp/mode/components/fan.pm index 915d4087a..6b056206c 100644 --- a/network/dlink/dgs3100/snmp/mode/components/fan.pm +++ b/network/dlink/dgs3100/snmp/mode/components/fan.pm @@ -40,9 +40,9 @@ my $mapping = { my $oid_rlEnvMonFanStatusEntry = '.1.3.6.1.4.1.171.10.94.89.89.83.1.1.1'; sub load { - my (%options) = @_; + my ($self) = @_; - push @{$options{request}}, { oid => $oid_rlEnvMonFanStatusEntry }; + push @{$self->{request}}, { oid => $oid_rlEnvMonFanStatusEntry }; } sub check { @@ -50,14 +50,14 @@ sub check { $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')); foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_rlEnvMonFanStatusEntry}})) { next if ($oid !~ /^$mapping->{rlEnvMonFanStatusDescr}->{oid}\.(.*)$/); my $instance = $1; my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_rlEnvMonFanStatusEntry}, instance => $instance); - next if ($self->check_exclude(section => 'fan', instance => $result->{rlEnvMonFanStatusDescr})); + next if ($self->check_filter(section => 'fan', instance => $result->{rlEnvMonFanStatusDescr})); next if ($result->{rlEnvMonFanState} eq 'notPresent' && $self->absent_problem(section => 'fan', instance => $result->{rlEnvMonFanStatusDescr})); $self->{components}->{fan}->{total}++; diff --git a/network/dlink/dgs3100/snmp/mode/components/psu.pm b/network/dlink/dgs3100/snmp/mode/components/psu.pm index e80dd4436..642cfb0bb 100644 --- a/network/dlink/dgs3100/snmp/mode/components/psu.pm +++ b/network/dlink/dgs3100/snmp/mode/components/psu.pm @@ -40,9 +40,9 @@ my $mapping = { my $oid_rlEnvMonSupplyStatusEntry = '.1.3.6.1.4.1.171.10.94.89.89.83.1.2.1'; sub load { - my (%options) = @_; + my ($self) = @_; - push @{$options{request}}, { oid => $oid_rlEnvMonSupplyStatusEntry }; + push @{$self->{request}}, { oid => $oid_rlEnvMonSupplyStatusEntry }; } sub check { @@ -50,14 +50,14 @@ sub check { $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')); foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_rlEnvMonSupplyStatusEntry}})) { next if ($oid !~ /^$mapping->{rlEnvMonSupplyStatusDescr}->{oid}\.(.*)$/); my $instance = $1; my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_rlEnvMonSupplyStatusEntry}, instance => $instance); - next if ($self->check_exclude(section => 'psu', instance => $result->{rlEnvMonSupplyStatusDescr})); + next if ($self->check_filter(section => 'psu', instance => $result->{rlEnvMonSupplyStatusDescr})); next if ($result->{rlEnvMonSupplyState} eq 'notPresent' && $self->absent_problem(section => 'psu', instance => $result->{rlEnvMonSupplyStatusDescr})); $self->{components}->{psu}->{total}++; diff --git a/network/dlink/dgs3100/snmp/mode/hardware.pm b/network/dlink/dgs3100/snmp/mode/hardware.pm index d56eb2ecc..ff20f4981 100644 --- a/network/dlink/dgs3100/snmp/mode/hardware.pm +++ b/network/dlink/dgs3100/snmp/mode/hardware.pm @@ -20,189 +20,61 @@ package network::dlink::dgs3100::snmp::mode::hardware; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::hardware); use strict; use warnings; -my $thresholds = { - psu => [ - ['shutdown', 'WARNING'], - ['warning', 'WARNING'], - ['critical', 'CRITICAL'], - ['notFunctioning', 'CRITICAL'], - ['notPresent', 'OK'], - ['normal', 'OK'], - ], - fan => [ - ['shutdown', 'WARNING'], - ['warning', 'WARNING'], - ['critical', 'CRITICAL'], - ['notFunctioning', 'CRITICAL'], - ['notPresent', 'OK'], - ['normal', 'OK'], - ], -}; +sub set_system { + my ($self, %options) = @_; + + $self->{regexp_threshold_overload_check_section_option} = '^(fan|psu)$'; + + $self->{cb_hook2} = 'snmp_execute'; + + $self->{thresholds} = { + psu => [ + ['shutdown', 'WARNING'], + ['warning', 'WARNING'], + ['critical', 'CRITICAL'], + ['notFunctioning', 'CRITICAL'], + ['notPresent', 'OK'], + ['normal', 'OK'], + ], + fan => [ + ['shutdown', 'WARNING'], + ['warning', 'WARNING'], + ['critical', 'CRITICAL'], + ['notFunctioning', 'CRITICAL'], + ['notPresent', 'OK'], + ['normal', 'OK'], + ], + }; + + $self->{components_path} = 'network::dlink::dgs3100::snmp::mode::components'; + $self->{components_module} = ['fan', 'psu']; +} + +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) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_performance => 1); bless $self, $class; $self->{version} = '1.0'; $options{options}->add_options(arguments => - { - "exclude:s" => { name => 'exclude' }, - "component:s" => { name => 'component', default => '.*' }, - "absent-problem:s" => { name => 'absent' }, - "no-component:s" => { name => 'no_component' }, - "threshold-overload:s@" => { name => 'threshold_overload' }, + { }); - $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->{overload_th} = {}; - foreach my $val (@{$self->{option_results}->{threshold_overload}}) { - if ($val !~ /^(.*?),(.*?),(.*)$/) { - $self->{output}->add_option_msg(short_msg => "Wrong treshold-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 treshold-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}; - } -} - -sub run { - my ($self, %options) = @_; - # $options{snmp} = snmp object - $self->{snmp} = $options{snmp}; - - my $snmp_request = []; - my @components = ('fan', 'psu'); - foreach (@components) { - if (/$self->{option_results}->{component}/) { - my $mod_name = "network::dlink::dgs3100::snmp::mode::components::$_"; - centreon::plugins::misc::mymodule_load(output => $self->{output}, module => $mod_name, - error_msg => "Cannot load module '$mod_name'."); - my $func = $mod_name->can('load'); - $func->(request => $snmp_request); - } - } - - if (scalar(@{$snmp_request}) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong option. Cannot find component '" . $self->{option_results}->{component} . "'."); - $self->{output}->option_exit(); - } - $self->{results} = $self->{snmp}->get_multiple_table(oids => $snmp_request); - - foreach (@components) { - if (/$self->{option_results}->{component}/) { - my $mod_name = "network::dlink::dgs3100::snmp::mode::components::$_"; - my $func = $mod_name->can('check'); - $func->($self); - } - } - - my $total_components = 0; - my $display_by_component = ''; - my $display_by_component_append = ''; - foreach my $comp (sort(keys %{$self->{components}})) { - # Skipping short msg when no components - next if ($self->{components}->{$comp}->{total} == 0 && $self->{components}->{$comp}->{skip} == 0); - $total_components += $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip}; - my $count_by_components = $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip}; - $display_by_component .= $display_by_component_append . $self->{components}->{$comp}->{total} . '/' . $count_by_components . ' ' . $self->{components}->{$comp}->{name}; - $display_by_component_append = ', '; - } - - $self->{output}->output_add(severity => 'OK', - short_msg => sprintf("All %s components are ok [%s].", - $total_components, - $display_by_component) - ); - - if (defined($self->{option_results}->{no_component}) && $total_components == 0) { - $self->{output}->output_add(severity => $self->{no_components}, - short_msg => 'No components are checked.'); - } - - $self->{output}->display(); - $self->{output}->exit(); -} - -sub 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 { - 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; __END__ @@ -218,10 +90,10 @@ Check hardware (Fans, Power Supplies). Which component to check (Default: '.*'). Can be: 'psu', 'fan'. -=item B<--exclude> +=item B<--filter> -Exclude some parts (comma seperated list) (Example: --exclude=psu) -Can also exclude specific instance: --exclude='fan#fan1_unit2#' +Exclude some parts (comma seperated list) (Example: --filter=psu) +Can also exclude specific instance: --filter=fan,fan1_unit2 =item B<--absent-problem> @@ -235,7 +107,7 @@ 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='psu,CRITICAL,^(?!(normal)$)' diff --git a/network/dlink/standard/snmp/mode/components/fan.pm b/network/dlink/standard/snmp/mode/components/fan.pm index 4d0d9e5c2..deb12ab4d 100644 --- a/network/dlink/standard/snmp/mode/components/fan.pm +++ b/network/dlink/standard/snmp/mode/components/fan.pm @@ -41,9 +41,9 @@ my $mapping = { my $oid_swFanEntry = '.1.3.6.1.4.1.171.12.11.1.7.1'; sub load { - my (%options) = @_; + my ($self) = @_; - push @{$options{request}}, { oid => $oid_swFanEntry }; + push @{$self->{request}}, { oid => $oid_swFanEntry }; } sub check { @@ -51,14 +51,14 @@ sub check { $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')); foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_swFanEntry}})) { next if ($oid !~ /^$mapping->{swFanStatus}->{oid}\.(.*)$/); my $instance = $1; my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_swFanEntry}, instance => $instance); - next if ($self->check_exclude(section => 'fan', instance => $instance)); + next if ($self->check_filter(section => 'fan', instance => $instance)); $self->{components}->{fan}->{total}++; $self->{output}->output_add(long_msg => sprintf("fan '%s' status is %s [speed = %s].", diff --git a/network/dlink/standard/snmp/mode/components/psu.pm b/network/dlink/standard/snmp/mode/components/psu.pm index 3f82dd5ba..fba713ac0 100644 --- a/network/dlink/standard/snmp/mode/components/psu.pm +++ b/network/dlink/standard/snmp/mode/components/psu.pm @@ -40,9 +40,9 @@ my $mapping = { my $oid_swPowerEntry = '.1.3.6.1.4.1.171.12.11.1.6.1'; sub load { - my (%options) = @_; + my ($self) = @_; - push @{$options{request}}, { oid => $oid_swPowerEntry }; + push @{$self->{request}}, { oid => $oid_swPowerEntry }; } sub check { @@ -50,14 +50,14 @@ sub check { $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')); foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_swPowerEntry}})) { next if ($oid !~ /^$mapping->{swPowerStatus}->{oid}\.(.*)$/); my $instance = $1; my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_swPowerEntry}, instance => $instance); - next if ($self->check_exclude(section => 'psu', instance => $instance)); + next if ($self->check_filter(section => 'psu', instance => $instance)); $self->{components}->{psu}->{total}++; $self->{output}->output_add(long_msg => sprintf("Power supply '%s' status is %s.", diff --git a/network/dlink/standard/snmp/mode/components/temperature.pm b/network/dlink/standard/snmp/mode/components/temperature.pm index 0fc334b51..463c51b49 100644 --- a/network/dlink/standard/snmp/mode/components/temperature.pm +++ b/network/dlink/standard/snmp/mode/components/temperature.pm @@ -30,9 +30,9 @@ my $mapping = { my $oid_swTemperatureEntry = '.1.3.6.1.4.1.171.12.11.1.8.1'; sub load { - my (%options) = @_; + my ($self) = @_; - push @{$options{request}}, { oid => $oid_swTemperatureEntry }; + push @{$self->{request}}, { oid => $oid_swTemperatureEntry }; } sub check { @@ -40,14 +40,14 @@ sub check { $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')); foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_swTemperatureEntry}})) { next if ($oid !~ /^$mapping->{swTemperatureCurrent}->{oid}\.(.*)$/); my $instance = $1; my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_swTemperatureEntry}, instance => $instance); - next if ($self->check_exclude(section => 'temperature', instance => $instance)); + next if ($self->check_filter(section => 'temperature', instance => $instance)); $self->{components}->{temperature}->{total}++; $self->{output}->output_add(long_msg => sprintf("Temperature '%s' is %dC.", diff --git a/network/dlink/standard/snmp/mode/hardware.pm b/network/dlink/standard/snmp/mode/hardware.pm index 4e982c94d..dad5c3d63 100644 --- a/network/dlink/standard/snmp/mode/hardware.pm +++ b/network/dlink/standard/snmp/mode/hardware.pm @@ -20,222 +20,64 @@ package network::dlink::standard::snmp::mode::hardware; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::hardware); use strict; use warnings; -my $thresholds = { - psu => [ - ['connect', 'OK'], - ['working', 'OK'], - ['other', 'UNKNOWN'], - ['lowVoltage', 'WARNING'], - ['overCurrent', 'CRITICAL'], - ['fail', 'CRITICAL'], - ['disconnect', 'WARNING'], - ], - fan => [ - ['working', 'OK'], - ['fail', 'CRITICAL'], - ['other', 'UNKNOWN'], - ['speed-0', 'WARNING'], - ['speed-low', 'WARNING'], - ['speed-middle', 'OK'], - ['speed-high', 'WARNING'], - ], -}; +sub set_system { + my ($self, %options) = @_; + + $self->{regexp_threshold_overload_check_section_option} = '^(fan|psu)$'; + $self->{regexp_threshold_numeric_check_section_option} = '^(fan|temperature)$'; + + $self->{cb_hook2} = 'snmp_execute'; + + $self->{thresholds} = { + psu => [ + ['connect', 'OK'], + ['working', 'OK'], + ['other', 'UNKNOWN'], + ['lowVoltage', 'WARNING'], + ['overCurrent', 'CRITICAL'], + ['fail', 'CRITICAL'], + ['disconnect', 'WARNING'], + ], + fan => [ + ['working', 'OK'], + ['fail', 'CRITICAL'], + ['other', 'UNKNOWN'], + ['speed-0', 'WARNING'], + ['speed-low', 'WARNING'], + ['speed-middle', 'OK'], + ['speed-high', 'WARNING'], + ], + }; + + $self->{components_path} = 'network::dlink::standard::snmp::mode::components'; + $self->{components_module} = ['fan', 'psu', 'temperature']; +} + +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) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1); bless $self, $class; $self->{version} = '1.0'; $options{options}->add_options(arguments => - { - "exclude:s" => { name => 'exclude' }, - "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->{overload_th} = {}; - foreach my $val (@{$self->{option_results}->{threshold_overload}}) { - if ($val !~ /^(.*?),(.*?),(.*)$/) { - $self->{output}->add_option_msg(short_msg => "Wrong treshold-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 treshold-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 !~ /(fan|temperature)/) { - $self->{output}->add_option_msg(short_msg => "Wrong $option option '" . $val . "' (type must be: temperature or fan)."); - $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}; - - my $snmp_request = []; - my @components = ('fan', 'psu', 'temperature'); - foreach (@components) { - if (/$self->{option_results}->{component}/) { - my $mod_name = "network::dlink::standard::snmp::mode::components::$_"; - centreon::plugins::misc::mymodule_load(output => $self->{output}, module => $mod_name, - error_msg => "Cannot load module '$mod_name'."); - my $func = $mod_name->can('load'); - $func->(request => $snmp_request); - } - } - - if (scalar(@{$snmp_request}) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong option. Cannot find component '" . $self->{option_results}->{component} . "'."); - $self->{output}->option_exit(); - } - $self->{results} = $self->{snmp}->get_multiple_table(oids => $snmp_request); - - foreach (@components) { - if (/$self->{option_results}->{component}/) { - my $mod_name = "network::dlink::standard::snmp::mode::components::$_"; - my $func = $mod_name->can('check'); - $func->($self); - } - } - - my $total_components = 0; - my $display_by_component = ''; - my $display_by_component_append = ''; - foreach my $comp (sort(keys %{$self->{components}})) { - # Skipping short msg when no components - next if ($self->{components}->{$comp}->{total} == 0 && $self->{components}->{$comp}->{skip} == 0); - $total_components += $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip}; - my $count_by_components = $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip}; - $display_by_component .= $display_by_component_append . $self->{components}->{$comp}->{total} . '/' . $count_by_components . ' ' . $self->{components}->{$comp}->{name}; - $display_by_component_append = ', '; - } - - $self->{output}->output_add(severity => 'OK', - short_msg => sprintf("All %s components are ok [%s].", - $total_components, - $display_by_component) - ); - - if (defined($self->{option_results}->{no_component}) && $total_components == 0) { - $self->{output}->output_add(severity => $self->{no_components}, - short_msg => 'No components are checked.'); - } - - $self->{output}->display(); - $self->{output}->exit(); -} - -sub 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 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; -} - -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} =~ /$_->{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}); - $checked = 1; - } - } - $status = $self->{output}->get_most_critical(status => $exits) if (scalar(@{$exits}) > 0); - } - - return ($status, $thresholds->{warning}, $thresholds->{critical}, $checked); -} - 1; __END__ @@ -251,10 +93,10 @@ Check hardware (Fans, Power Supplies, Temperatures). Which component to check (Default: '.*'). Can be: 'psu', 'fan', 'temperature'. -=item B<--exclude> +=item B<--filter> -Exclude some parts (comma seperated list) (Example: --exclude=psu) -Can also exclude specific instance: --exclude='fan#1.1#' +Exclude some parts (comma seperated list) (Example: --filter=psu) +Can also exclude specific instance: --filter=fan,1.1 =item B<--no-component> @@ -269,12 +111,12 @@ Example: --threshold-overload='fan,CRITICAL,^(?!(working)$)' =item B<--warning> -Set warning threshold for temperatures (syntax: type,regexp,threshold) +Set warning threshold for temperatures (syntax: section,[instance,]status,regexp) Example: --warning='temperature,.*,30' --warning='fan,.*,1000' =item B<--critical> -Set critical threshold for temperatures (syntax: type,regexp,threshold) +Set critical threshold for temperatures (syntax: section,[instance,]status,regexp) Example: --critical='temperature,.*,40' =back diff --git a/network/extreme/snmp/mode/hardware.pm b/network/extreme/snmp/mode/hardware.pm index 7d556d231..b7a908093 100644 --- a/network/extreme/snmp/mode/hardware.pm +++ b/network/extreme/snmp/mode/hardware.pm @@ -33,7 +33,6 @@ sub set_system { $self->{cb_hook2} = 'snmp_execute'; - #Example for threshold: $self->{thresholds} = { psu => [ ['notPresent', 'OK'], diff --git a/network/f5/bigip/mode/hardware.pm b/network/f5/bigip/mode/hardware.pm index 574e507ef..624e1c469 100644 --- a/network/f5/bigip/mode/hardware.pm +++ b/network/f5/bigip/mode/hardware.pm @@ -33,7 +33,6 @@ sub set_system { $self->{cb_hook2} = 'snmp_execute'; - #Example for threshold: $self->{thresholds} = { fan => [ ['bad', 'CRITICAL'], diff --git a/network/hirschmann/standard/snmp/mode/components/fan.pm b/network/hirschmann/standard/snmp/mode/components/fan.pm index d4695f9da..be913512e 100644 --- a/network/hirschmann/standard/snmp/mode/components/fan.pm +++ b/network/hirschmann/standard/snmp/mode/components/fan.pm @@ -34,9 +34,9 @@ my $mapping = { }; sub load { - my (%options) = @_; + my ($self) = @_; - push @{$options{request}}, { oid => $mapping->{hmFanState}->{oid} }; + push @{$self->{request}}, { oid => $mapping->{hmFanState}->{oid} }; } sub check { @@ -44,14 +44,14 @@ sub check { $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')); foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$mapping->{hmFanState}->{oid}}})) { next if ($oid !~ /^$mapping->{hmFanState}->{oid}\.(.*)$/); my $instance = $1; my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$mapping->{hmFanState}->{oid}}, instance => $instance); - next if ($self->check_exclude(section => 'fan', instance => $instance)); + next if ($self->check_filter(section => 'fan', instance => $instance)); $self->{components}->{fan}->{total}++; $self->{output}->output_add(long_msg => sprintf("fan '%s' status is %s [instance: %s].", diff --git a/network/hirschmann/standard/snmp/mode/components/led.pm b/network/hirschmann/standard/snmp/mode/components/led.pm index cce547c46..92ea47020 100644 --- a/network/hirschmann/standard/snmp/mode/components/led.pm +++ b/network/hirschmann/standard/snmp/mode/components/led.pm @@ -34,9 +34,9 @@ my %map_led_status = ( my $oid_hmLEDGroup = '.1.3.6.1.4.1.248.14.1.1.35'; sub load { - my (%options) = @_; + my ($self) = @_; - push @{$options{request}}, { oid => $oid_hmLEDGroup }; + push @{$self->{request}}, { oid => $oid_hmLEDGroup }; } sub check_led { @@ -49,7 +49,7 @@ sub check_led { $options{mapping}->{$name}->{oid} =~ /\.(\d+)$/; my $instance = $1; - next if ($self->check_exclude(section => 'led', instance => $instance)); + next if ($self->check_filter(section => 'led', instance => $instance)); $self->{components}->{led}->{total}++; $self->{output}->output_add(long_msg => sprintf("Led '%s' status is %s [instance: %s].", @@ -70,7 +70,7 @@ sub check { $self->{output}->output_add(long_msg => "Checking leds"); $self->{components}->{led} = {name => 'leds', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'led')); + return if ($self->check_filter(section => 'led')); my $mapping; if (defined($self->{results}->{$oid_hmLEDGroup}->{$oid_hmLEDGroup . '.1.1.0'})) { diff --git a/network/hirschmann/standard/snmp/mode/components/psu.pm b/network/hirschmann/standard/snmp/mode/components/psu.pm index 9af81b65a..66abdf17f 100644 --- a/network/hirschmann/standard/snmp/mode/components/psu.pm +++ b/network/hirschmann/standard/snmp/mode/components/psu.pm @@ -36,9 +36,9 @@ my $mapping = { }; sub load { - my (%options) = @_; + my ($self) = @_; - push @{$options{request}}, { oid => $mapping->{hmPSState}->{oid} }; + push @{$self->{request}}, { oid => $mapping->{hmPSState}->{oid} }; } sub check { @@ -46,14 +46,14 @@ sub check { $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')); foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$mapping->{hmPSState}->{oid}}})) { next if ($oid !~ /^$mapping->{hmPSState}->{oid}\.(.*)$/); my $instance = $1; my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$mapping->{hmPSState}->{oid}}, instance => $instance); - next if ($self->check_exclude(section => 'psu', instance => $instance)); + next if ($self->check_filter(section => 'psu', instance => $instance)); next if ($result->{hmPSState} =~ /notInstalled/i && $self->absent_problem(section => 'psu', instance => $instance)); $self->{components}->{psu}->{total}++; diff --git a/network/hirschmann/standard/snmp/mode/components/temperature.pm b/network/hirschmann/standard/snmp/mode/components/temperature.pm index 3f571bfb2..158bbe7ad 100644 --- a/network/hirschmann/standard/snmp/mode/components/temperature.pm +++ b/network/hirschmann/standard/snmp/mode/components/temperature.pm @@ -32,9 +32,9 @@ my $mapping = { my $oid_hmTempTable = '.1.3.6.1.4.1.248.14.2.5'; sub load { - my (%options) = @_; + my ($self) = @_; - push @{$options{request}}, { oid => $oid_hmTempTable }; + push @{$self->{request}}, { oid => $oid_hmTempTable }; } sub check { @@ -42,13 +42,13 @@ sub check { $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')); return if (!defined($self->{results}->{$oid_hmTempTable}->{$mapping->{hmTemperature}->{oid} . '.0'})); my $instance = 0; my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_hmTempTable}, instance => $instance); - next if ($self->check_exclude(section => 'temperature', instance => $instance)); + next if ($self->check_filter(section => 'temperature', instance => $instance)); $self->{components}->{temperature}->{total}++; $self->{output}->output_add(long_msg => sprintf("temperature is %dC [instance: %s].", diff --git a/network/hirschmann/standard/snmp/mode/hardware.pm b/network/hirschmann/standard/snmp/mode/hardware.pm index 5371baf6c..f3310e394 100644 --- a/network/hirschmann/standard/snmp/mode/hardware.pm +++ b/network/hirschmann/standard/snmp/mode/hardware.pm @@ -20,29 +20,48 @@ package network::hirschmann::standard::snmp::mode::hardware; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::hardware); use strict; use warnings; -my $thresholds = { - fan => [ - ['ok', 'OK'], - ['failed', 'CRITICAL'], - ], - psu => [ - ['ok', 'OK'], - ['failed', 'CRITICAL'], - ['notInstalled', 'OK'], - ['unknown', 'UNKNOWN'], - ], - led => [ - ['off', 'UNKNOWN'], - ['green', 'OK'], - ['yellow', 'WARNING'], - ['red', 'CRITICAL'], - ], -}; +sub set_system { + my ($self, %options) = @_; + + $self->{regexp_threshold_overload_check_section_option} = '^(fan|psu|led)$'; + $self->{regexp_threshold_numeric_check_section_option} = '^(temperature)$'; + + $self->{cb_hook2} = 'snmp_execute'; + + $self->{thresholds} = { + fan => [ + ['ok', 'OK'], + ['failed', 'CRITICAL'], + ], + psu => [ + ['ok', 'OK'], + ['failed', 'CRITICAL'], + ['notInstalled', 'OK'], + ['unknown', 'UNKNOWN'], + ], + led => [ + ['off', 'UNKNOWN'], + ['green', 'OK'], + ['yellow', 'WARNING'], + ['red', 'CRITICAL'], + ], + }; + + $self->{components_path} = 'network::hirschmann::standard::snmp::mode::components'; + $self->{components_module} = ['fan', 'psu', 'temperature', 'led']; +} + +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) = @_; @@ -51,208 +70,12 @@ sub new { $self->{version} = '1.0'; $options{options}->add_options(arguments => - { - "exclude:s" => { name => 'exclude' }, - "absent-problem:s" => { name => 'absent' }, - "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->{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 !~ /(temperature)/) { - $self->{output}->add_option_msg(short_msg => "Wrong $option option '" . $val . "' (type must be: 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}; - - my $snmp_request = []; - my @components = ('fan', 'psu', 'temperature', 'led'); - foreach (@components) { - if (/$self->{option_results}->{component}/) { - my $mod_name = "network::hirschmann::standard::snmp::mode::components::$_"; - centreon::plugins::misc::mymodule_load(output => $self->{output}, module => $mod_name, - error_msg => "Cannot load module '$mod_name'."); - my $func = $mod_name->can('load'); - $func->(request => $snmp_request); - } - } - - if (scalar(@{$snmp_request}) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong option. Cannot find component '" . $self->{option_results}->{component} . "'."); - $self->{output}->option_exit(); - } - $self->{results} = $self->{snmp}->get_multiple_table(oids => $snmp_request); - - foreach (@components) { - if (/$self->{option_results}->{component}/) { - my $mod_name = "network::hirschmann::standard::snmp::mode::components::$_"; - my $func = $mod_name->can('check'); - $func->($self); - } - } - - my $total_components = 0; - my $display_by_component = ''; - my $display_by_component_append = ''; - foreach my $comp (sort(keys %{$self->{components}})) { - # Skipping short msg when no components - next if ($self->{components}->{$comp}->{total} == 0 && $self->{components}->{$comp}->{skip} == 0); - $total_components += $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip}; - my $count_by_components = $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip}; - $display_by_component .= $display_by_component_append . $self->{components}->{$comp}->{total} . '/' . $count_by_components . ' ' . $self->{components}->{$comp}->{name}; - $display_by_component_append = ', '; - } - - $self->{output}->output_add(severity => 'OK', - short_msg => sprintf("All %s components are ok [%s].", - $total_components, - $display_by_component) - ); - - if (defined($self->{option_results}->{no_component}) && $total_components == 0) { - $self->{output}->output_add(severity => $self->{no_components}, - short_msg => 'No components are checked.'); - } - - $self->{output}->display(); - $self->{output}->exit(); -} - -sub 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 }; - my $checked = 0; - - 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}); - $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) { - $status = $_->{status}; - return $status; - } - } - } - foreach (@{$thresholds->{$options{section}}}) { - if ($options{value} =~ /$$_[0]/i) { - $status = $$_[1]; - return $status; - } - } - - return $status; -} - 1; __END__ @@ -268,15 +91,15 @@ Check Hardware (Power Supplies, Fans, Temperatures, LEDs). Which component to check (Default: '.*'). Can be: 'fan', 'psu', 'temperature', 'led'. -=item B<--exclude> +=item B<--filter> -Exclude some parts (comma seperated list) (Example: --exclude=fan) -Can also exclude specific instance: --exclude=fan#1.1#,psu#3.2# +Exclude some parts (comma seperated list) (Example: --filter=fan) +Can also exclude specific instance: --filter=fan,1.1 =item B<--absent-problem> Return an error if an entity is not 'present' (default is skipping) (comma seperated list) -Can be specific or global: --absent-problem=psu#1.1# +Can be specific or global: --absent-problem=psu,1.1 =item B<--no-component> @@ -285,7 +108,7 @@ 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='psu,CRITICAL,^(?!(ok)$)' diff --git a/network/hp/procurve/mode/components/sensor.pm b/network/hp/procurve/mode/components/sensor.pm index de152d1a0..8d4ba0fe1 100644 --- a/network/hp/procurve/mode/components/sensor.pm +++ b/network/hp/procurve/mode/components/sensor.pm @@ -45,9 +45,9 @@ my $mapping = { my $oid_hpicfSensorEntry = '.1.3.6.1.4.1.11.2.14.11.1.2.6.1'; sub load { - my (%options) = @_; + my ($self) = @_; - push @{$options{request}}, { oid => $oid_hpicfSensorEntry }; + push @{$self->{request}}, { oid => $oid_hpicfSensorEntry }; } sub check { @@ -56,7 +56,7 @@ sub check { $self->{output}->output_add(long_msg => "Checking sensors"); $self->{components}->{sensor} = {name => 'sensors', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'sensor')); + return if ($self->check_filter(section => 'sensor')); foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_hpicfSensorEntry}})) { next if ($oid !~ /^$mapping->{hpicfSensorStatus}->{oid}\.(.*)$/); @@ -64,7 +64,7 @@ sub check { my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_hpicfSensorEntry}, instance => $instance_mapping); my $instance = $result->{hpicfSensorObjectId} . '.' . $instance_mapping; - next if ($self->check_exclude(section => 'sensor', instance => $instance)); + next if ($self->check_filter(section => 'sensor', instance => $instance)); next if ($result->{hpicfSensorStatus} =~ /not present/i && $self->absent_problem(section => 'sensor', instance => $instance)); $self->{components}->{sensor}->{total}++; diff --git a/network/hp/procurve/mode/environment.pm b/network/hp/procurve/mode/environment.pm index 64d39f504..807578994 100644 --- a/network/hp/procurve/mode/environment.pm +++ b/network/hp/procurve/mode/environment.pm @@ -20,179 +20,52 @@ package network::hp::procurve::mode::environment; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::hardware); use strict; use warnings; -use centreon::plugins::misc; -my $thresholds = { - sensor => [ - ['unknown', 'UNKNOWN'], - ['bad', 'CRITICAL'], - ['warning', 'WARNING'], - ['good', 'OK'], - ['not present', 'WARNING'], - ], -}; +sub set_system { + my ($self, %options) = @_; + + $self->{regexp_threshold_overload_check_section_option} = '^(sensor)$'; + + $self->{cb_hook2} = 'snmp_execute'; + + $self->{thresholds} = { + sensor => [ + ['unknown', 'UNKNOWN'], + ['bad', 'CRITICAL'], + ['warning', 'WARNING'], + ['good', 'OK'], + ['not present', 'WARNING'], + ], + }; + + $self->{components_path} = 'network::hp::procurve::mode::components'; + $self->{components_module} = ['sensor']; +} + +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) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_performance => 1); bless $self, $class; $self->{version} = '1.0'; $options{options}->add_options(arguments => { - "exclude:s" => { name => 'exclude' }, - "absent-problem:s" => { name => 'absent' }, - "component:s" => { name => 'component', default => '.*' }, - "no-component:s" => { name => 'no_component' }, - "threshold-overload:s@" => { name => 'threshold_overload' }, }); 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->{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) = ('sensor', $1, $2); - 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}; - } -} - -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 { - 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; -} - -sub run { - my ($self, %options) = @_; - # $options{snmp} = snmp object - $self->{snmp} = $options{snmp}; - - my $snmp_request = []; - my @components = ('sensor'); - foreach (@components) { - if (/$self->{option_results}->{component}/) { - my $mod_name = "network::hp::procurve::mode::components::$_"; - centreon::plugins::misc::mymodule_load(output => $self->{output}, module => $mod_name, - error_msg => "Cannot load module '$mod_name'."); - my $func = $mod_name->can('load'); - $func->(request => $snmp_request); - } - } - - if (scalar(@{$snmp_request}) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong option. Cannot find component '" . $self->{option_results}->{component} . "'."); - $self->{output}->option_exit(); - } - $self->{results} = $self->{snmp}->get_multiple_table(oids => $snmp_request); - - foreach (@components) { - if (/$self->{option_results}->{component}/) { - my $mod_name = "network::hp::procurve::mode::components::$_"; - my $func = $mod_name->can('check'); - $func->($self); - } - } - - my $total_components = 0; - my $display_by_component = ''; - my $display_by_component_append = ''; - foreach my $comp (sort(keys %{$self->{components}})) { - # Skipping short msg when no components - next if ($self->{components}->{$comp}->{total} == 0 && $self->{components}->{$comp}->{skip} == 0); - $total_components += $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip}; - my $count_by_components = $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip}; - $display_by_component .= $display_by_component_append . $self->{components}->{$comp}->{total} . '/' . $count_by_components . ' ' . $self->{components}->{$comp}->{name}; - $display_by_component_append = ', '; - } - - $self->{output}->output_add(severity => 'OK', - short_msg => sprintf("All %s components are ok [%s].", - $total_components, - $display_by_component) - ); - - if (defined($self->{option_results}->{no_component}) && $total_components == 0) { - $self->{output}->output_add(severity => $self->{no_components}, - short_msg => 'No components are checked.'); - } - - $self->{output}->display(); - $self->{output}->exit(); -} - 1; __END__ @@ -208,15 +81,15 @@ Check sensors (hpicfChassis.mib). Which component to check (Default: '.*'). Can be: 'sensor'. -=item B<--exclude> +=item B<--filter> -Exclude some parts (comma seperated list) -Can also exclude specific instance: --exclude=sensor#fan.1# +Exclude some parts (comma seperated list) (Example: --filter=sensor) +Can also exclude specific instance: --filter=sensor,fan.1 =item B<--absent-problem> Return an error if an entity is not 'present' (default is skipping) (comma seperated list) -Can be specific or global: --absent-problem=sensor#temperature.2# +Can be specific or global: --absent-problem=sensor,temperature.2 =item B<--no-component> @@ -225,9 +98,9 @@ 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='CRITICAL,^(?!(good)$)' +Example: --threshold-overload='sensor,CRITICAL,^(?!(good)$)' =back diff --git a/network/juniper/common/junos/mode/components/fru.pm b/network/juniper/common/junos/mode/components/fru.pm index b9458b2e9..c45c8f059 100644 --- a/network/juniper/common/junos/mode/components/fru.pm +++ b/network/juniper/common/junos/mode/components/fru.pm @@ -76,9 +76,9 @@ my $mapping = { my $oid_jnxFruEntry = '.1.3.6.1.4.1.2636.3.1.15.1'; sub load { - my (%options) = @_; + my ($self) = @_; - push @{$options{request}}, { oid => $oid_jnxFruEntry, start => $mapping->{jnxFruName}->{oid}, end => $mapping->{jnxFruOfflineReason}->{oid} }; + push @{$self->{request}}, { oid => $oid_jnxFruEntry, start => $mapping->{jnxFruName}->{oid}, end => $mapping->{jnxFruOfflineReason}->{oid} }; } sub check { @@ -86,14 +86,14 @@ sub check { $self->{output}->output_add(long_msg => "Checking frus"); $self->{components}->{fru} = {name => 'frus', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'fru')); + return if ($self->check_filter(section => 'fru')); foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_jnxFruEntry}})) { next if ($oid !~ /^$mapping->{jnxFruName}->{oid}\.(.*)$/); my $instance = $1; my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_jnxFruEntry}, instance => $instance); - next if ($self->check_exclude(section => 'fru', instance => $instance)); + next if ($self->check_filter(section => 'fru', instance => $instance)); next if ($result->{jnxFruState} =~ /empty/i && $self->absent_problem(section => 'fru', instance => $instance)); $self->{components}->{fru}->{total}++; diff --git a/network/juniper/common/junos/mode/components/operating.pm b/network/juniper/common/junos/mode/components/operating.pm index 3b3ad5bea..f6be53c42 100644 --- a/network/juniper/common/junos/mode/components/operating.pm +++ b/network/juniper/common/junos/mode/components/operating.pm @@ -41,9 +41,9 @@ my $mapping = { my $oid_jnxOperatingEntry = '.1.3.6.1.4.1.2636.3.1.13.1'; sub load { - my (%options) = @_; + my ($self) = @_; - push @{$options{request}}, { oid => $oid_jnxOperatingEntry, start => $mapping->{jnxOperatingDescr}->{oid}, end => $mapping->{jnxOperatingState}->{oid} }; + push @{$self->{request}}, { oid => $oid_jnxOperatingEntry, start => $mapping->{jnxOperatingDescr}->{oid}, end => $mapping->{jnxOperatingState}->{oid} }; } sub check { @@ -51,14 +51,14 @@ sub check { $self->{output}->output_add(long_msg => "Checking operatings"); $self->{components}->{operating} = {name => 'operatings', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'operating')); + return if ($self->check_filter(section => 'operating')); foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_jnxOperatingEntry}})) { next if ($oid !~ /^$mapping->{jnxOperatingDescr}->{oid}\.(.*)$/); my $instance = $1; my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_jnxOperatingEntry}, instance => $instance); - next if ($self->check_exclude(section => 'operating', instance => $instance)); + next if ($self->check_filter(section => 'operating', instance => $instance)); $self->{components}->{operating}->{total}++; $self->{output}->output_add(long_msg => sprintf("Operating '%s' state is %s [instance: %s]", diff --git a/network/juniper/common/junos/mode/hardware.pm b/network/juniper/common/junos/mode/hardware.pm index 8f31b2469..3c3eadde5 100644 --- a/network/juniper/common/junos/mode/hardware.pm +++ b/network/juniper/common/junos/mode/hardware.pm @@ -20,34 +20,54 @@ package network::juniper::common::junos::mode::hardware; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::hardware); use strict; use warnings; -my $thresholds = { - fru => [ - ['unknown', 'UNKNOWN'], - ['present', 'OK'], - ['ready', 'OK'], - ['announce online', 'OK'], - ['online', 'OK'], - ['announce offline', 'WARNING'], - ['offline', 'CRITICAL'], - ['diagnostic', 'WARNING'], - ['standby', 'WARNING'], - ['empty', 'OK'], - ], - operating => [ - ['unknown', 'UNKNOWN'], - ['running', 'OK'], - ['ready', 'OK'], - ['reset', 'WARNING'], - ['runningAtFullSpeed', 'WARNING'], - ['down', 'CRITICAL'], - ['standby', 'OK'], - ], -}; +sub set_system { + my ($self, %options) = @_; + + $self->{regexp_threshold_overload_check_section_option} = '^(fru|operating)$'; + $self->{regexp_threshold_numeric_check_section_option} = '^(fru-temperature)$'; + + $self->{cb_hook1} = 'get_type'; + $self->{cb_hook2} = 'snmp_execute'; + + $self->{thresholds} = { + fru => [ + ['unknown', 'UNKNOWN'], + ['present', 'OK'], + ['ready', 'OK'], + ['announce online', 'OK'], + ['online', 'OK'], + ['announce offline', 'WARNING'], + ['offline', 'CRITICAL'], + ['diagnostic', 'WARNING'], + ['standby', 'WARNING'], + ['empty', 'OK'], + ], + operating => [ + ['unknown', 'UNKNOWN'], + ['running', 'OK'], + ['ready', 'OK'], + ['reset', 'WARNING'], + ['runningAtFullSpeed', 'WARNING'], + ['down', 'CRITICAL'], + ['standby', 'OK'], + ], + }; + + $self->{components_path} = 'network::juniper::common::junos::mode::components'; + $self->{components_module} = ['fru', 'operating']; +} + +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) = @_; @@ -56,220 +76,23 @@ sub new { $self->{version} = '1.0'; $options{options}->add_options(arguments => - { - "exclude:s" => { name => 'exclude' }, - "absent-problem:s" => { name => 'absent' }, - "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->{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 !~ /(fru-temperature)/) { - $self->{output}->add_option_msg(short_msg => "Wrong $option option '" . $val . "' (type must be: fru-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->get_type(); - - my $snmp_request = []; - my @components = ('fru', 'operating'); - foreach (@components) { - if (/$self->{option_results}->{component}/) { - my $mod_name = "network::juniper::common::junos::mode::components::$_"; - centreon::plugins::misc::mymodule_load(output => $self->{output}, module => $mod_name, - error_msg => "Cannot load module '$mod_name'."); - my $func = $mod_name->can('load'); - $func->(request => $snmp_request); - } - } - - if (scalar(@{$snmp_request}) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong option. Cannot find component '" . $self->{option_results}->{component} . "'."); - $self->{output}->option_exit(); - } - $self->{results} = $self->{snmp}->get_multiple_table(oids => $snmp_request); - - foreach (@components) { - if (/$self->{option_results}->{component}/) { - my $mod_name = "network::juniper::common::junos::mode::components::$_"; - my $func = $mod_name->can('check'); - $func->($self); - } - } - - my $total_components = 0; - my $display_by_component = ''; - my $display_by_component_append = ''; - foreach my $comp (sort(keys %{$self->{components}})) { - # Skipping short msg when no components - next if ($self->{components}->{$comp}->{total} == 0 && $self->{components}->{$comp}->{skip} == 0); - $total_components += $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip}; - my $count_by_components = $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip}; - $display_by_component .= $display_by_component_append . $self->{components}->{$comp}->{total} . '/' . $count_by_components . ' ' . $self->{components}->{$comp}->{name}; - $display_by_component_append = ', '; - } - - $self->{output}->output_add(severity => 'OK', - short_msg => sprintf("All %s components are ok [%s].", - $total_components, - $display_by_component) - ); - - if (defined($self->{option_results}->{no_component}) && $total_components == 0) { - $self->{output}->output_add(severity => $self->{no_components}, - short_msg => 'No components are checked.'); - } - - $self->{output}->display(); - $self->{output}->exit(); -} - sub get_type { - my ($self) = @_; + my ($self, %options) = @_; my $oid_jnxBoxDescr = ".1.3.6.1.4.1.2636.3.1.2.0"; - my $result = $self->{snmp}->get_leef(oids => [$oid_jnxBoxDescr]); + my $result = $options{snmp}->get_leef(oids => [$oid_jnxBoxDescr]); $self->{env_type} = defined($result->{$oid_jnxBoxDescr}) ? $result->{$oid_jnxBoxDescr} : 'unknown'; $self->{output}->output_add(long_msg => sprintf("Environment type: %s", $self->{env_type})); } - -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 }; - my $checked = 0; - - 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}); - $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) { - $status = $_->{status}; - return $status; - } - } - } - foreach (@{$thresholds->{$options{section}}}) { - if ($options{value} =~ /$$_[0]/i) { - $status = $$_[1]; - return $status; - } - } - - return $status; -} - 1; __END__ @@ -285,15 +108,15 @@ Check Hardware (mib-jnx-chassis) (frus, operating). Which component to check (Default: '.*'). Can be: 'fru', 'operating'. -=item B<--exclude> +=item B<--filter> -Exclude some parts (comma seperated list) (Example: --exclude=fru) -Can also exclude specific instance: --exclude=fru#7.3.0.0# +Exclude some parts (comma seperated list) (Example: --filter=fru) +Can also exclude specific instance: --filter=fru,7.3.0.0 =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=fru#7.1.0.0# +Can be specific or global: --absent-problem=fru,7.1.0.0 =item B<--no-component> @@ -302,18 +125,18 @@ 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='operating,CRITICAL,^(?!(running)$)' =item B<--warning> -Set warning threshold for fru temperatures (syntax: type,regexp,treshold) +Set warning threshold for fru temperatures (syntax: type,regexp,threshold) Example: --warning='fru-temperature,.*,30' =item B<--critical> -Set critical threshold for fru temperatures (syntax: type,regexp,treshold) +Set critical threshold for fru temperatures (syntax: type,regexp,threshold) Example: --critical='fru-temperature,.*,40' =back diff --git a/network/juniper/common/screenos/mode/components/fan.pm b/network/juniper/common/screenos/mode/components/fan.pm index 0007759ec..7da0b128f 100644 --- a/network/juniper/common/screenos/mode/components/fan.pm +++ b/network/juniper/common/screenos/mode/components/fan.pm @@ -34,9 +34,9 @@ my $mapping = { my $oid_nsFanEntry = '.1.3.6.1.4.1.3224.21.2.1'; sub load { - my (%options) = @_; + my ($self) = @_; - push @{$options{request}}, { oid => $oid_nsFanEntry }; + push @{$self->{request}}, { oid => $oid_nsFanEntry }; } sub check { diff --git a/network/juniper/common/screenos/mode/components/module.pm b/network/juniper/common/screenos/mode/components/module.pm index 568bc5011..a589fab14 100644 --- a/network/juniper/common/screenos/mode/components/module.pm +++ b/network/juniper/common/screenos/mode/components/module.pm @@ -35,9 +35,9 @@ my $mapping = { my $oid_nsSlotEntry = '.1.3.6.1.4.1.3224.21.5.1'; sub load { - my (%options) = @_; + my ($self) = @_; - push @{$options{request}}, { oid => $oid_nsSlotEntry }; + push @{$self->{request}}, { oid => $oid_nsSlotEntry }; } sub check { diff --git a/network/juniper/common/screenos/mode/components/psu.pm b/network/juniper/common/screenos/mode/components/psu.pm index be8f99471..4b88ae158 100644 --- a/network/juniper/common/screenos/mode/components/psu.pm +++ b/network/juniper/common/screenos/mode/components/psu.pm @@ -34,9 +34,9 @@ my $mapping = { my $oid_nsPowerEntry = '.1.3.6.1.4.1.3224.21.1.1'; sub load { - my (%options) = @_; + my ($self) = @_; - push @{$options{request}}, { oid => $oid_nsPowerEntry }; + push @{$self->{request}}, { oid => $oid_nsPowerEntry }; } sub check { diff --git a/network/juniper/common/screenos/mode/components/temperature.pm b/network/juniper/common/screenos/mode/components/temperature.pm index 05ec02119..047667e4f 100644 --- a/network/juniper/common/screenos/mode/components/temperature.pm +++ b/network/juniper/common/screenos/mode/components/temperature.pm @@ -30,9 +30,9 @@ my $mapping = { my $oid_nsTemperatureEntry = '.1.3.6.1.4.1.3224.21.4.1'; sub load { - my (%options) = @_; + my ($self) = @_; - push @{$options{request}}, { oid => $oid_nsTemperatureEntry }; + push @{$self->{request}}, { oid => $oid_nsTemperatureEntry }; } sub check { diff --git a/network/juniper/common/screenos/mode/hardware.pm b/network/juniper/common/screenos/mode/hardware.pm index 705f2c3b2..c4a808cb7 100644 --- a/network/juniper/common/screenos/mode/hardware.pm +++ b/network/juniper/common/screenos/mode/hardware.pm @@ -20,240 +20,58 @@ package network::juniper::common::screenos::mode::hardware; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::hardware); use strict; use warnings; -my $thresholds = { - fan => [ - ['active', 'OK'], - ['.*', 'CRITICAL'], - ], - module => [ - ['active', 'OK'], - ['.*', 'CRITICAL'], - ], - psu => [ - ['active', 'OK'], - ['.*', 'CRITICAL'], - ], -}; +sub set_system { + my ($self, %options) = @_; + + $self->{regexp_threshold_overload_check_section_option} = '^(psu|module|fan)$'; + $self->{regexp_threshold_numeric_check_section_option} = '^(temperature)$'; + + $self->{cb_hook2} = 'snmp_execute'; + + $self->{thresholds} = { + fan => [ + ['active', 'OK'], + ['.*', 'CRITICAL'], + ], + module => [ + ['active', 'OK'], + ['.*', 'CRITICAL'], + ], + psu => [ + ['active', 'OK'], + ['.*', 'CRITICAL'], + ], + }; + + $self->{components_path} = 'network::juniper::common::screenos::mode::components'; + $self->{components_module} = ['psu', 'fan', 'temperature', 'module']; +} + +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) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1); 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 ($section !~ /^temperature|psu|module|fan$/) { - $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload section '" . $val . "'."); - $self->{output}->option_exit(); - } - if ($self->{output}->is_litteral_status(status => $status) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload status '" . $val . "'."); - $self->{output}->option_exit(); - } - $self->{overload_th}->{$section} = [] if (!defined($self->{overload_th}->{$section})); - push @{$self->{overload_th}->{$section}}, {filter => $filter, status => $status, instance => $instance }; - } - - $self->{numeric_threshold} = {}; - foreach my $option (('warning', 'critical')) { - foreach my $val (@{$self->{option_results}->{$option}}) { - next if (!defined($val) || $val eq ''); - if ($val !~ /^(.*?),(.*?),(.*)$/) { - $self->{output}->add_option_msg(short_msg => "Wrong $option option '" . $val . "'."); - $self->{output}->option_exit(); - } - my ($section, $instance, $value) = ($1, $2, $3); - if ($section !~ /^sensor$/) { - $self->{output}->add_option_msg(short_msg => "Wrong $option option '" . $val . "'."); - $self->{output}->option_exit(); - } - my $position = 0; - if (defined($self->{numeric_threshold}->{$section})) { - $position = scalar(@{$self->{numeric_threshold}->{$section}}); - } - if (($self->{perfdata}->threshold_validate(label => $option . '-' . $section . '-' . $position, value => $value)) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong $option threshold '" . $value . "'."); - $self->{output}->option_exit(); - } - $self->{numeric_threshold}->{$section} = [] if (!defined($self->{numeric_threshold}->{$section})); - push @{$self->{numeric_threshold}->{$section}}, { label => $option . '-' . $section . '-' . $position, threshold => $option, instance => $instance }; - } - } -} - -sub run { - my ($self, %options) = @_; - $self->{snmp} = $options{snmp}; - - my $snmp_request = []; - my @components = ('psu', 'fan', 'temperature', 'module'); - foreach (@components) { - if (/$self->{option_results}->{component}/) { - my $mod_name = "network::juniper::common::screenos::mode::components::$_"; - centreon::plugins::misc::mymodule_load(output => $self->{output}, module => $mod_name, - error_msg => "Cannot load module '$mod_name'."); - my $func = $mod_name->can('load'); - $func->(request => $snmp_request); - } - } - - if (scalar(@{$snmp_request}) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong option. Cannot find component '" . $self->{option_results}->{component} . "'."); - $self->{output}->option_exit(); - } - $self->{results} = $self->{snmp}->get_multiple_table(oids => $snmp_request); - - foreach (@components) { - if (/$self->{option_results}->{component}/) { - my $mod_name = "network::juniper::common::screenos::mode::components::$_"; - my $func = $mod_name->can('check'); - $func->($self); - } - } - - my $total_components = 0; - my $display_by_component = ''; - my $display_by_component_append = ''; - foreach my $comp (sort(keys %{$self->{components}})) { - # Skipping short msg when no components - next if ($self->{components}->{$comp}->{total} == 0 && $self->{components}->{$comp}->{skip} == 0); - $total_components += $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip}; - my $count_by_components = $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip}; - $display_by_component .= $display_by_component_append . $self->{components}->{$comp}->{total} . '/' . $count_by_components . ' ' . $self->{components}->{$comp}->{name}; - $display_by_component_append = ', '; - } - - $self->{output}->output_add(severity => 'OK', - short_msg => sprintf("All %s components are ok [%s].", - $total_components, - $display_by_component) - ); - - if (defined($self->{option_results}->{no_component}) && $total_components == 0) { - $self->{output}->output_add(severity => $self->{no_components}, - short_msg => 'No components are checked.'); - } - - $self->{output}->display(); - $self->{output}->exit(); -} - - -sub 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__ diff --git a/network/redback/snmp/mode/components/disk.pm b/network/redback/snmp/mode/components/disk.pm index afee478a8..209063263 100644 --- a/network/redback/snmp/mode/components/disk.pm +++ b/network/redback/snmp/mode/components/disk.pm @@ -37,9 +37,9 @@ my $mapping = { my $oid_rbnSRStorageEntry = '.1.3.6.1.4.1.2352.2.24.1.2.1.1'; sub load { - my (%options) = @_; + my ($self) = @_; - push @{$options{request}}, { oid => $oid_rbnSRStorageEntry }; + push @{$self->{request}}, { oid => $oid_rbnSRStorageEntry }; } sub check { @@ -47,14 +47,14 @@ sub check { $self->{output}->output_add(long_msg => "Checking disks"); $self->{components}->{disk} = {name => 'disks', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'disk')); + return if ($self->check_filter(section => 'disk')); foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_rbnSRStorageEntry}})) { next if ($oid !~ /^$mapping->{rbnSRStorageStatus}->{oid}\.(.*)$/); my $instance = $1; my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_rbnSRStorageEntry}, instance => $instance); - next if ($self->check_exclude(section => 'disk', instance => $instance)); + next if ($self->check_filter(section => 'disk', instance => $instance)); $self->{components}->{disk}->{total}++; $self->{output}->output_add(long_msg => sprintf("Disk '%s' status is %s [instance: %s].", diff --git a/network/redback/snmp/mode/components/fan.pm b/network/redback/snmp/mode/components/fan.pm index de66c2a0b..dcfedab8c 100644 --- a/network/redback/snmp/mode/components/fan.pm +++ b/network/redback/snmp/mode/components/fan.pm @@ -38,9 +38,9 @@ my $mapping = { my $oid_rbnFanStatusEntry = '.1.3.6.1.4.1.2352.2.4.1.1.1'; sub load { - my (%options) = @_; + my ($self) = @_; - push @{$options{request}}, { oid => $oid_rbnFanStatusEntry }; + push @{$self->{request}}, { oid => $oid_rbnFanStatusEntry }; } sub check { @@ -48,14 +48,14 @@ sub check { $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')); foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_rbnFanStatusEntry}})) { next if ($oid !~ /^$mapping->{rbnFanStatus}->{oid}\.(.*)$/); my $instance = $1; my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_rbnFanStatusEntry}, instance => $instance); - next if ($self->check_exclude(section => 'fan', instance => $instance)); + next if ($self->check_filter(section => 'fan', instance => $instance)); next if ($result->{rbnFanStatus} =~ /absent/i && $self->absent_problem(section => 'fan', instance => $instance)); $self->{components}->{fan}->{total}++; diff --git a/network/redback/snmp/mode/components/psu.pm b/network/redback/snmp/mode/components/psu.pm index 0fcb8395d..6bea8f2d6 100644 --- a/network/redback/snmp/mode/components/psu.pm +++ b/network/redback/snmp/mode/components/psu.pm @@ -38,9 +38,9 @@ my $mapping = { my $oid_rbnPowerStatusEntry = '.1.3.6.1.4.1.2352.2.4.1.2.1'; sub load { - my (%options) = @_; + my ($self) = @_; - push @{$options{request}}, { oid => $oid_rbnPowerStatusEntry }; + push @{$self->{request}}, { oid => $oid_rbnPowerStatusEntry }; } sub check { @@ -48,14 +48,14 @@ sub check { $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')); foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_rbnPowerStatusEntry}})) { next if ($oid !~ /^$mapping->{rbnPowerStatus}->{oid}\.(.*)$/); my $instance = $1; my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_rbnPowerStatusEntry}, instance => $instance); - next if ($self->check_exclude(section => 'psu', instance => $instance)); + next if ($self->check_filter(section => 'psu', instance => $instance)); next if ($result->{rbnPowerStatus} =~ /absent/i && $self->absent_problem(section => 'psu', instance => $instance)); $self->{components}->{psu}->{total}++; diff --git a/network/redback/snmp/mode/components/temperature.pm b/network/redback/snmp/mode/components/temperature.pm index 8aa26b996..4d712a1b7 100644 --- a/network/redback/snmp/mode/components/temperature.pm +++ b/network/redback/snmp/mode/components/temperature.pm @@ -31,9 +31,9 @@ my $mapping = { my $oid_rbnEntityTempSensorEntry = '.1.3.6.1.4.1.2352.2.4.1.6.1'; sub load { - my (%options) = @_; + my ($self) = @_; - push @{$options{request}}, { oid => $oid_rbnEntityTempSensorEntry }; + push @{$self->{request}}, { oid => $oid_rbnEntityTempSensorEntry }; } sub check { @@ -41,14 +41,14 @@ sub check { $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')); foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_rbnEntityTempSensorEntry}})) { next if ($oid !~ /^$mapping->{rbnEntityTempCurrent}->{oid}\.(.*)$/); my $instance = $1; my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_rbnEntityTempSensorEntry}, instance => $instance); - next if ($self->check_exclude(section => 'temperature', instance => $instance)); + next if ($self->check_filter(section => 'temperature', instance => $instance)); $self->{components}->{temperature}->{total}++; $self->{output}->output_add(long_msg => sprintf("'%s' temperature is %dC [instance: %s].", diff --git a/network/redback/snmp/mode/components/voltage.pm b/network/redback/snmp/mode/components/voltage.pm index afdf75800..6ae69e7de 100644 --- a/network/redback/snmp/mode/components/voltage.pm +++ b/network/redback/snmp/mode/components/voltage.pm @@ -31,9 +31,9 @@ my $mapping = { my $oid_rbnVoltageSensorEntry = '.1.3.6.1.4.1.2352.2.4.1.3.1'; sub load { - my (%options) = @_; + my ($self) = @_; - push @{$options{request}}, { oid => $oid_rbnVoltageSensorEntry }; + push @{$self->{request}}, { oid => $oid_rbnVoltageSensorEntry }; } sub check { @@ -41,14 +41,14 @@ sub check { $self->{output}->output_add(long_msg => "Checking voltages"); $self->{components}->{voltage} = {name => 'voltages', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'voltage')); + return if ($self->check_filter(section => 'voltage')); foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_rbnVoltageSensorEntry}})) { next if ($oid !~ /^$mapping->{rbnVoltageCurrent}->{oid}\.(.*)$/); my $instance = $1; my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_rbnVoltageSensorEntry}, instance => $instance); - next if ($self->check_exclude(section => 'voltage', instance => $instance)); + next if ($self->check_filter(section => 'voltage', instance => $instance)); $self->{components}->{voltage}->{total}++; $self->{output}->output_add(long_msg => sprintf("'%s' voltage is %d mV [instance: %s].", diff --git a/network/redback/snmp/mode/hardware.pm b/network/redback/snmp/mode/hardware.pm index 0d0c8044c..586330438 100644 --- a/network/redback/snmp/mode/hardware.pm +++ b/network/redback/snmp/mode/hardware.pm @@ -20,30 +20,49 @@ package network::redback::snmp::mode::hardware; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::hardware); use strict; use warnings; -my $thresholds = { - fan => [ - ['unknown', 'UNKNOWN'], - ['normal', 'OK'], - ['failed', 'CRITICAL'], - ['absent', 'OK'], - ], - psu => [ - ['unknown', 'UNKNOWN'], - ['normal', 'OK'], - ['failed', 'CRITICAL'], - ['absent', 'OK'], - ], - disk => [ - ['operational', 'OK'], - ['failed', 'CRITICAL'], - ['degrading', 'WARNING'], - ], -}; +sub set_system { + my ($self, %options) = @_; + + $self->{regexp_threshold_overload_check_section_option} = '^(fan|psu|disk)$'; + $self->{regexp_threshold_numeric_check_section_option} = '^(temperature|voltage)$'; + + $self->{cb_hook2} = 'snmp_execute'; + + $self->{thresholds} = { + fan => [ + ['unknown', 'UNKNOWN'], + ['normal', 'OK'], + ['failed', 'CRITICAL'], + ['absent', 'OK'], + ], + psu => [ + ['unknown', 'UNKNOWN'], + ['normal', 'OK'], + ['failed', 'CRITICAL'], + ['absent', 'OK'], + ], + disk => [ + ['operational', 'OK'], + ['failed', 'CRITICAL'], + ['degrading', 'WARNING'], + ], + }; + + $self->{components_path} = 'network::redback::snmp::mode::components'; + $self->{components_module} = ['fan', 'psu', 'temperature', 'voltage', 'disk']; +} + +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) = @_; @@ -52,208 +71,12 @@ sub new { $self->{version} = '1.0'; $options{options}->add_options(arguments => - { - "exclude:s" => { name => 'exclude' }, - "absent-problem:s" => { name => 'absent' }, - "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->{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 !~ /(temperature|voltage)/) { - $self->{output}->add_option_msg(short_msg => "Wrong $option option '" . $val . "' (type must be: temperature or voltage)."); - $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}; - - my $snmp_request = []; - my @components = ('fan', 'psu', 'temperature', 'voltage', 'disk'); - foreach (@components) { - if (/$self->{option_results}->{component}/) { - my $mod_name = "network::redback::snmp::mode::components::$_"; - centreon::plugins::misc::mymodule_load(output => $self->{output}, module => $mod_name, - error_msg => "Cannot load module '$mod_name'."); - my $func = $mod_name->can('load'); - $func->(request => $snmp_request); - } - } - - if (scalar(@{$snmp_request}) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong option. Cannot find component '" . $self->{option_results}->{component} . "'."); - $self->{output}->option_exit(); - } - $self->{results} = $self->{snmp}->get_multiple_table(oids => $snmp_request); - - foreach (@components) { - if (/$self->{option_results}->{component}/) { - my $mod_name = "network::redback::snmp::mode::components::$_"; - my $func = $mod_name->can('check'); - $func->($self); - } - } - - my $total_components = 0; - my $display_by_component = ''; - my $display_by_component_append = ''; - foreach my $comp (sort(keys %{$self->{components}})) { - # Skipping short msg when no components - next if ($self->{components}->{$comp}->{total} == 0 && $self->{components}->{$comp}->{skip} == 0); - $total_components += $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip}; - my $count_by_components = $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip}; - $display_by_component .= $display_by_component_append . $self->{components}->{$comp}->{total} . '/' . $count_by_components . ' ' . $self->{components}->{$comp}->{name}; - $display_by_component_append = ', '; - } - - $self->{output}->output_add(severity => 'OK', - short_msg => sprintf("All %s components are ok [%s].", - $total_components, - $display_by_component) - ); - - if (defined($self->{option_results}->{no_component}) && $total_components == 0) { - $self->{output}->output_add(severity => $self->{no_components}, - short_msg => 'No components are checked.'); - } - - $self->{output}->display(); - $self->{output}->exit(); -} - -sub 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 }; - my $checked = 0; - - 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}); - $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) { - $status = $_->{status}; - return $status; - } - } - } - foreach (@{$thresholds->{$options{section}}}) { - if ($options{value} =~ /$$_[0]/i) { - $status = $$_[1]; - return $status; - } - } - - return $status; -} - 1; __END__ @@ -269,15 +92,15 @@ Check Hardware (Power Supplies, Fans, Temperatures, Voltages, Disks). Which component to check (Default: '.*'). Can be: 'fan', 'psu', 'temperature', 'voltage', 'disk'. -=item B<--exclude> +=item B<--filter> -Exclude some parts (comma seperated list) (Example: --exclude=fan) -Can also exclude specific instance: --exclude=fan#1#,psu#3# +Exclude some parts (comma seperated list) (Example: --filter=fan --filter=psu) +Can also exclude specific instance: --filter=fan,1 =item B<--absent-problem> Return an error if an entity is not 'present' (default is skipping) (comma seperated list) -Can be specific or global: --absent-problem=fan#1# +Can be specific or global: --absent-problem=fan,1 =item B<--no-component> @@ -286,7 +109,7 @@ 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,^(?!(normal)$)'