diff --git a/centreon-plugins/network/f5/bigip/mode/components/fan.pm b/centreon-plugins/network/f5/bigip/mode/components/fan.pm index 3218c2697..0ccbafbac 100644 --- a/centreon-plugins/network/f5/bigip/mode/components/fan.pm +++ b/centreon-plugins/network/f5/bigip/mode/components/fan.pm @@ -29,43 +29,59 @@ my %map_status = ( 2 => 'notPresent', ); +my $mapping = { + sysChassisFanStatus => { oid => '.1.3.6.1.4.1.3375.2.1.3.2.1.2.1.2', map => \%map_status }, + sysChassisFanSpeed => { oid => '.1.3.6.1.4.1.3375.2.1.3.2.1.2.1.3' }, +}; +my $oid_sysChassisFanEntry = '.1.3.6.1.4.1.3375.2.1.3.2.1.2.1'; + +sub load { + my (%options) = @_; + + push @{$options{request}}, { oid => $oid_sysChassisFanEntry }; +} + sub check { my ($self) = @_; - $self->{components}->{fan} = {name => 'fans', total => 0, skip => 0}; $self->{output}->output_add(long_msg => "Checking fans"); + $self->{components}->{fan} = {name => 'fans', total => 0, skip => 0}; return if ($self->check_exclude(section => 'fan')); - - my $oid_sysChassisFanEntry = '.1.3.6.1.4.1.3375.2.1.3.2.1.2.1'; - my $oid_sysChassisFanStatus = '.1.3.6.1.4.1.3375.2.1.3.2.1.2.1.2'; - my $oid_sysChassisFanSpeed = '.1.3.6.1.4.1.3375.2.1.3.2.1.2.1.3'; - - my $result = $self->{snmp}->get_table(oid => $oid_sysChassisFanEntry); - return if (scalar(keys %$result) <= 0); - foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) { - next if ($key !~ /^$oid_sysChassisFanStatus\.(\d+)$/); + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_sysChassisFanEntry}})) { + next if ($oid !~ /^$mapping->{sysChassisFanStatus}->{oid}\.(.*)$/); my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_sysChassisFanEntry}, instance => $instance); + next if ($result->{sysChassisFanStatus} =~ /notPresent/i && + $self->absent_problem(section => 'fan', instance => $instance)); next if ($self->check_exclude(section => 'fan', instance => $instance)); - - my $status = $result->{$oid_sysChassisFanStatus . '.' . $instance}; - my $speed = $result->{$oid_sysChassisFanSpeed . '.' . $instance}; - + $self->{components}->{fan}->{total}++; - $self->{output}->output_add(long_msg => sprintf("Fan '%s' status is %s.", - $instance, $map_status{$status})); - if ($status < 1) { - $self->{output}->output_add(severity => 'CRITICAL', - short_msg => sprintf("Fan '%s' status is %s", - $instance, $map_status{$status})); + + $self->{output}->output_add(long_msg => sprintf("fan '%s' status is '%s' [instance: %s, speed: %s].", + $instance, $result->{sysChassisFanStatus}, $instance, + defined($result->{sysChassisFanSpeed}) ? $result->{sysChassisFanSpeed} : '-')); + my $exit = $self->get_severity(section => 'fan', value => $result->{sysChassisFanStatus}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Fan '%s' status is '%s'", + $instance, $result->{sysChassisFanStatus})); } - - $self->{output}->perfdata_add(label => "fan_" . $instance, - value => $speed, - ); - } - + + if (defined($result->{sysChassisFanSpeed}) && $result->{sysChassisFanSpeed} =~ /[0-9]/) { + my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'fan', instance => $instance, value => $result->{sysChassisFanSpeed}); + if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit2, + short_msg => sprintf("fan speed '%s' is %s rpm", $instance, $result->{sysChassisFanSpeed})); + } + $self->{output}->perfdata_add(label => "fan_" . $instance, unit => 'rpm', + value => $result->{sysChassisFanSpeed}, + warning => $warn, + critical => $crit, + min => 0); + } + } } 1; diff --git a/centreon-plugins/network/f5/bigip/mode/components/psu.pm b/centreon-plugins/network/f5/bigip/mode/components/psu.pm index e43902701..7dfe8a9b3 100644 --- a/centreon-plugins/network/f5/bigip/mode/components/psu.pm +++ b/centreon-plugins/network/f5/bigip/mode/components/psu.pm @@ -29,33 +29,42 @@ my %map_status = ( 2 => 'notPresent', ); +my $mapping = { + sysChassisPowerSupplyStatus => { oid => '.1.3.6.1.4.1.3375.2.1.3.2.2.2.1.2', map => \%map_status }, +}; + +sub load { + my (%options) = @_; + + push @{$options{request}}, { oid => $mapping->{sysChassisPowerSupplyStatus}->{oid} }; +} + sub check { my ($self) = @_; - $self->{components}->{psu} = {name => 'psus', total => 0, skip => 0}; $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')); - - my $oid_sysChassisPowerSupplyEntry = '.1.3.6.1.4.1.3375.2.1.3.2.2.2.1'; - my $oid_sysChassisPowerSupplyStatus = '.1.3.6.1.4.1.3375.2.1.3.2.2.2.1.2'; - - my $result = $self->{snmp}->get_table(oid => $oid_sysChassisPowerSupplyEntry); - return if (scalar(keys %$result) <= 0); - foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) { - next if ($key !~ /^$oid_sysChassisPowerSupplyStatus\.(\d+)$/); + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$mapping->{sysChassisPowerSupplyStatus}->{oid}}})) { + $oid =~ /^$mapping->{sysChassisPowerSupplyStatus}->{oid}\.(.*)$/; my $instance = $1; - next if ($self->check_exclude(section => 'psu', instance => $instance)); + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$mapping->{sysChassisPowerSupplyStatus}->{oid}}, instance => $instance); - my $status = $result->{$oid_sysChassisPowerSupplyStatus . '.' . $instance}; - + next if ($result->{sysChassisPowerSupplyStatus} =~ /notPresent/i && + $self->absent_problem(section => 'psu', instance => $instance)); + next if ($self->check_exclude(section => 'psu', instance => $instance)); + $self->{components}->{psu}->{total}++; - $self->{output}->output_add(long_msg => sprintf("Power Supply '%s' status is %s.", - $instance, $map_status{$status})); - if ($status < 1) { - $self->{output}->output_add(severity => 'CRITICAL', - short_msg => sprintf("Power Supply '%s' status is %s", - $instance, $map_status{$status})); + + $self->{output}->output_add(long_msg => sprintf("power supply '%s' status is '%s' [instance: %s].", + $instance, $result->{sysChassisPowerSupplyStatus}, $instance + )); + my $exit = $self->get_severity(section => 'psu', value => $result->{sysChassisPowerSupplyStatus}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Power supply '%s' status is '%s'", + $instance, $result->{sysChassisPowerSupplyStatus})); } } } diff --git a/centreon-plugins/network/f5/bigip/mode/components/temperature.pm b/centreon-plugins/network/f5/bigip/mode/components/temperature.pm index db2840ee9..fd8b1b90b 100644 --- a/centreon-plugins/network/f5/bigip/mode/components/temperature.pm +++ b/centreon-plugins/network/f5/bigip/mode/components/temperature.pm @@ -23,37 +23,46 @@ package network::f5::bigip::mode::components::temperature; use strict; use warnings; +my $mapping = { + sysChassisTempTemperature => { oid => '.1.3.6.1.4.1.3375.2.1.3.2.3.2.1.2', map => \%map_status }, +}; + +sub load { + my (%options) = @_; + + push @{$options{request}}, { oid => $mapping->{sysChassisTempTemperature}->{oid} }; +} + sub check { my ($self) = @_; - + $self->{output}->output_add(long_msg => "Checking temperatures"); $self->{components}->{temperature} = {name => 'temperatures', total => 0, skip => 0}; return if ($self->check_exclude(section => 'temperature')); - my $oid_sysChassisTempEntry = '.1.3.6.1.4.1.3375.2.1.3.2.3.2.1'; - my $oid_sysChassisTempTemperature = '.1.3.6.1.4.1.3375.2.1.3.2.3.2.1.2'; - - my $result = $self->{snmp}->get_table(oid => $oid_sysChassisTempEntry); - return if (scalar(keys %$result) <= 0); - - foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) { - next if ($key !~ /^$oid_sysChassisTempTemperature\.(\d+)$/); + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$mapping->{sysChassisTempTemperature}->{oid}}})) { + $oid =~ /^$mapping->{sysChassisTempTemperature}->{oid}\.(.*)$/; my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$mapping->{sysChassisTempTemperature}->{oid}}, instance => $instance); + next if ($self->check_exclude(section => 'temperature', instance => $instance)); - my $exit_code = $self->{perfdata}->threshold_check(value => $result->{$oid_sysChassisTempTemperature . '.' . $instance}, - threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - - $self->{components}->{temperature}->{total}++; - $self->{output}->output_add(severity => $exit_code,long_msg => sprintf("temp_" . $instance . " is %.2f C", $result->{$oid_sysChassisTempTemperature . '.' . $instance})); - if (!$self->{output}->is_status(value => $exit_code, compare => 'ok', litteral => 1)) { - $self->{output}->output_add(severity => $exit_code,short_msg => sprintf("temp_" . $instance . " is %.2f C", $result->{$oid_sysChassisTempTemperature . '.' . $instance})); + $self->{components}->{temperature}->{total}++; + $self->{output}->output_add(long_msg => sprintf("temperature '%s' is %.2f C [instance: %s].", + $instance, $result->{sysChassisTempTemperature}, $instance + )); + + if (defined($result->{sysChassisTempTemperature}) && $result->{sysChassisTempTemperature} =~ /[0-9]/) { + my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, value => $result->{sysChassisTempTemperature}); + if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Temperature '%s' is %.2f C", $instance, $result->{sysChassisTempTemperature})); + } + $self->{output}->perfdata_add(label => "temp_" . $instance, unit => 'C', + value => sprintf("%.2f", $result->{sysChassisTempTemperature}), + warning => $warn, + critical => $crit); } - - $self->{output}->perfdata_add(label => "temp_" . $instance , unit => 'C', - value => sprintf("%.2f", $result->{$oid_sysChassisTempTemperature . '.' . $instance}), - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical')); } } diff --git a/centreon-plugins/network/f5/bigip/mode/hardware.pm b/centreon-plugins/network/f5/bigip/mode/hardware.pm index 09b0ce08a..631a02f5e 100644 --- a/centreon-plugins/network/f5/bigip/mode/hardware.pm +++ b/centreon-plugins/network/f5/bigip/mode/hardware.pm @@ -24,10 +24,15 @@ use base qw(centreon::plugins::mode); use strict; use warnings; +use centreon::plugins::misc; -use network::f5::bigip::mode::components::fan; -use network::f5::bigip::mode::components::psu; -use network::f5::bigip::mode::components::temperature; +my $thresholds = { + fan => [ + ['bad', 'CRITICAL'], + ['good', 'OK'], + ['notPresent', 'OK'], + ], +}; sub new { my ($class, %options) = @_; @@ -37,12 +42,16 @@ sub new { $self->{version} = '1.0'; $options{options}->add_options(arguments => { - "exclude:s" => { name => 'exclude' }, - "component:s" => { name => 'component', default => 'all' }, - "warning:s" => { name => 'warning' }, - "critical:s" => { name => 'critical' }, + "exclude:s" => { name => 'exclude' }, + "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; } @@ -50,43 +59,112 @@ sub check_options { my ($self, %options) = @_; $self->SUPER::init(%options); - if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'."); - $self->{output}->option_exit(); + if (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'; + } } - if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); - $self->{output}->option_exit(); + + $self->{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->{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 !~ /^(temperature|fan|psu)$/) { + $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 (!defined($thresholds->{$section})) { + $self->{output}->add_option_msg(short_msg => "Wrong $option option '" . $val . "'."); + $self->{output}->option_exit(); + } + my $position = 0; + if (defined($self->{numeric_threshold}->{$section})) { + $position = scalar(@{$self->{numeric_threshold}->{$section}}); + } + if (($self->{perfdata}->threshold_validate(label => $option . '-' . $section . '-' . $position, value => $value)) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong $option threshold '" . $value . "'."); + $self->{output}->option_exit(); + } + $self->{numeric_threshold}->{$section} = [] if (!defined($self->{numeric_threshold}->{$section})); + push @{$self->{numeric_threshold}->{$section}}, { label => $option . '-' . $section . '-' . $position, threshold => $option, instance => $instance }; + } } - -} - -sub global { - my ($self, %options) = @_; - - network::f5::bigip::mode::components::temperature::check($self); - network::f5::bigip::mode::components::fan::check($self); - network::f5::bigip::mode::components::psu::check($self); } 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::f5::bigip::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 ($self->{option_results}->{component} eq 'all') { - $self->global(); - } elsif ($self->{option_results}->{component} eq 'fan') { - network::f5::bigip::mode::components::fan::check($self); - } elsif ($self->{option_results}->{component} eq 'psu') { - network::f5::bigip::mode::components::psu::check($self); - } elsif ($self->{option_results}->{component} eq 'temperature') { - network::f5::bigip::mode::components::temperature::check($self); - } else { + 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::f5::bigip::mode::components::$_"; + my $func = $mod_name->can('check'); + $func->($self); + } + } + my $total_components = 0; my $display_by_component = ''; my $display_by_component_append = ''; @@ -94,17 +172,22 @@ sub run { # 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}; - $display_by_component .= $display_by_component_append . $self->{components}->{$comp}->{total} . '/' . $self->{components}->{$comp}->{skip} . ' ' . $self->{components}->{$comp}->{name}; + 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 [%s] are ok.", + short_msg => sprintf("All %s components are ok [%s].", $total_components, - $display_by_component - ) + $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(); } @@ -125,6 +208,70 @@ sub check_exclude { return 0; } +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 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; +} + +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); +} + 1; __END__ @@ -137,21 +284,34 @@ Check hardware (fans, temperatures, power supplies). =item B<--component> -Which component to check (Default: 'all'). +Which component to check (Default: '.*'). Can be: 'fan', 'psu', 'temperature'. =item B<--exclude> Exclude some parts (comma seperated list) (Example: --exclude=fan,psu) -Can also exclude specific instance: --exclude=fan#1#2#,psu +Can be specific or global: --exclude=fan#1#2#,psu + +=item B<--no-component> + +Return an error if no compenents are checked. +If total (with skipped) is 0. (Default: 'critical' returns). + +=item B<--threshold-overload> + +Set to overload default threshold values (syntax: section,[instance,]status,regexp) +It used before default thresholds (order stays). +Example: --threshold-overload='powerQuality,CRITICAL,^(?!(normal)$)' =item B<--warning> -Threshold warning in degree celsius. +Set warning threshold for temperatures, fan speed (syntax: type,instance,threshold) +Example: --warning='temperature,.*,30' =item B<--critical> -Threshold critical in degree celsius. +Set critical threshold for temperatures, fan speed (syntax: type,instance,threshold) +Example: --critical='temperature,.*,40' =back