diff --git a/network/juniper/common/screenos/mode/components/fan.pm b/network/juniper/common/screenos/mode/components/fan.pm index 75f8782b4..422af6721 100644 --- a/network/juniper/common/screenos/mode/components/fan.pm +++ b/network/juniper/common/screenos/mode/components/fan.pm @@ -46,7 +46,7 @@ my %map_status = ( sub check { my ($self) = @_; - $self->{components}->{fans} = {name => 'fans', total => 0, skip => 0}; + $self->{components}->{fans} = {name => 'fans', total => 0}; $self->{output}->output_add(long_msg => "Checking fans"); return if ($self->check_exclude(section => 'fans')); diff --git a/network/juniper/common/screenos/mode/components/module.pm b/network/juniper/common/screenos/mode/components/module.pm index 97ef5a02a..9ec423137 100644 --- a/network/juniper/common/screenos/mode/components/module.pm +++ b/network/juniper/common/screenos/mode/components/module.pm @@ -46,7 +46,7 @@ my %map_status = ( sub check { my ($self) = @_; - $self->{components}->{modules} = {name => 'modules', total => 0, skip => 0}; + $self->{components}->{modules} = {name => 'modules', total => 0}; $self->{output}->output_add(long_msg => "Checking modules"); return if ($self->check_exclude(section => 'modules')); @@ -62,11 +62,11 @@ sub check { my $instance = $1; next if ($self->check_exclude(section => 'modules', instance => $instance)); - $self->{components}->{modules}->{total}++; my $type = $result->{$oid_nsSlotType . '.' . $instance}; my $status = $result->{$oid_nsSlotStatus . '.' . $instance}; - + + $self->{components}->{modules}->{total}++; $self->{output}->output_add(long_msg => sprintf("Module '%s' status is %s [instance: %s].", $type, $map_status{$status}, $instance)); if ($status != 1) { diff --git a/network/juniper/common/screenos/mode/components/psu.pm b/network/juniper/common/screenos/mode/components/psu.pm index 766215e0d..d1c4985ec 100644 --- a/network/juniper/common/screenos/mode/components/psu.pm +++ b/network/juniper/common/screenos/mode/components/psu.pm @@ -46,7 +46,7 @@ my %map_status = ( sub check { my ($self) = @_; - $self->{components}->{psus} = {name => 'psus', total => 0, skip => 0}; + $self->{components}->{psus} = {name => 'psus', total => 0}; $self->{output}->output_add(long_msg => "Checking power supplies"); return if ($self->check_exclude(section => 'psus')); diff --git a/network/juniper/common/screenos/mode/components/temperature.pm b/network/juniper/common/screenos/mode/components/temperature.pm index 48e61e2b3..d9c5e501e 100644 --- a/network/juniper/common/screenos/mode/components/temperature.pm +++ b/network/juniper/common/screenos/mode/components/temperature.pm @@ -42,7 +42,7 @@ sub check { my ($self) = @_; $self->{output}->output_add(long_msg => "Checking temperatures"); - $self->{components}->{temperatures} = {name => 'temperatures', total => 0, skip => 0}; + $self->{components}->{temperatures} = {name => 'temperatures', total => 0}; return if ($self->check_exclude('temperatures')); my $oid_nsTemperatureEntry = '.1.3.6.1.4.1.3224.21.4.1'; @@ -58,10 +58,10 @@ sub check { next if ($self->check_exclude(section => 'temperatures', instance => $instance)); - my $temperature_name = $result->{$oid_nsTemperatureDesc . '.' . $instance}; + my $temperature_name = $result->{$oid_nsTemperatureDesc . '.' . $instance}; - my $exit_code = $self->{perfdata}->threshold_check(value => $result->{$oid_nsTemperatureCur . '.' . $instance}, - threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + my $exit_code = $self->{perfdata}->threshold_check(value => $result->{$oid_nsTemperatureCur . '.' . $instance}, + threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); $self->{components}->{temperatures}->{total}++; @@ -71,13 +71,12 @@ sub check { $self->{output}->output_add(severity => $exit_code,short_msg => sprintf($temperature_name . " is %.2f C", $result->{$oid_nsTemperatureCur . '.' . $instance})); } - $temperature_name =~ s/\ /_/g; - $self->{output}->perfdata_add(label => $temperature_name, unit => 'C', - value => sprintf("%.2f", $result->{$oid_nsTemperatureCur . '.' . $instance}), - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical')); + $temperature_name =~ s/\ /_/g; + $self->{output}->perfdata_add(label => $temperature_name , unit => 'C', value => sprintf("%.2f", $result->{$oid_nsTemperatureCur . '.' . $instance}), + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical')); + } } -} 1; diff --git a/network/juniper/common/screenos/mode/hardware.pm b/network/juniper/common/screenos/mode/hardware.pm index afe36a89e..963def039 100644 --- a/network/juniper/common/screenos/mode/hardware.pm +++ b/network/juniper/common/screenos/mode/hardware.pm @@ -52,13 +52,11 @@ 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 => 'all' }, - "no-component:s" => { name => 'no_component' }, - "warning:s" => { name => 'warning', }, - "critical:s" => { name => 'critical', }, + "warning:s" => { name => 'warning', default => '' }, + "critical:s" => { name => 'critical', default => '' }, }); $self->{components} = {}; return $self; @@ -76,13 +74,7 @@ sub check_options { $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); $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'; - } - } + } sub global { @@ -114,14 +106,15 @@ sub run { $self->{output}->option_exit(); } + my $total_components = 0; my $display_by_component = ''; my $display_by_component_append = ''; foreach my $comp (sort(keys %{$self->{components}})) { # Skipping short msg when no components - next if ($self->{components}->{$comp}->{total} == 0 && $self->{components}->{$comp}->{skip} == 0); - $total_components += $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip}; - $display_by_component .= $display_by_component_append . $self->{components}->{$comp}->{total} . '/' . $self->{components}->{$comp}->{skip} . ' ' . $self->{components}->{$comp}->{name}; + next if ($self->{components}->{$comp}->{total} == 0); + $total_components += $self->{components}->{$comp}->{total}; + $display_by_component .= $display_by_component_append . $self->{components}->{$comp}->{total} . ' ' . $self->{components}->{$comp}->{name}; $display_by_component_append = ', '; } @@ -132,46 +125,20 @@ sub run { ) ); - 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) = @_; + my ($self, $section) = @_; - 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.")); + if (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)$section(\s|,|$)/) { + $self->{output}->output_add(long_msg => sprintf("Skipping $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; -} - 1; __END__ @@ -192,15 +159,6 @@ Can be: 'fan', 'psu', 'module'. Exclude some parts (comma seperated list) (Example: --exclude=fans,modules) Can also exclude specific instance: --exclude=fans#1#2#,modules#1#,psus -=item B<--absent-problem> - -N/A for following equipment. Not needed. - -=item B<--no-component> - -Return an error if no compenents are checked. -If total (with skipped) is 0. (Default: 'critical' returns). - =item B<--warning> Threshold warning in degree celsius.