diff --git a/hardware/server/hpproliant/mode/components/cpu.pm b/hardware/server/hpproliant/mode/components/cpu.pm index 29edbea17..5f0884643 100644 --- a/hardware/server/hpproliant/mode/components/cpu.pm +++ b/hardware/server/hpproliant/mode/components/cpu.pm @@ -59,7 +59,7 @@ sub check { my $oid_cpqSeCpuName = '.1.3.6.1.4.1.232.1.2.2.1.1.3'; my $oid_cpqSeCpuStatus = '.1.3.6.1.4.1.232.1.2.2.1.1.6'; my $oid_cpqSeCpuSocketNumber = '.1.3.6.1.4.1.232.1.2.2.1.1.9'; - + my $result = $self->{snmp}->get_table(oid => $oid_cpqSeCpuUnitIndex); return if (scalar(keys %$result) <= 0); diff --git a/network/juniper/common/screenos/mode/components/fan.pm b/network/juniper/common/screenos/mode/components/fan.pm index 422af6721..75f8782b4 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}; + $self->{components}->{fans} = {name => 'fans', total => 0, skip => 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 9ec423137..97ef5a02a 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}; + $self->{components}->{modules} = {name => 'modules', total => 0, skip => 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 d1c4985ec..766215e0d 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}; + $self->{components}->{psus} = {name => 'psus', total => 0, skip => 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 d9c5e501e..48e61e2b3 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}; + $self->{components}->{temperatures} = {name => 'temperatures', total => 0, skip => 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,12 +71,13 @@ 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/components/temperature.pm.save b/network/juniper/common/screenos/mode/components/temperature.pm.save deleted file mode 100644 index 4cd0b297b..000000000 --- a/network/juniper/common/screenos/mode/components/temperature.pm.save +++ /dev/null @@ -1,67 +0,0 @@ -################################################################################ -# Copyright 2005-2013 MERETHIS -# Centreon is developped by : Julien Mathis and Romain Le Merlus under -# GPL Licence 2.0. -# -# This program is free software; you can redistribute it and/or modify it under -# the terms of the GNU General Public License as published by the Free Software -# Foundation ; either version 2 of the License. -# -# This program is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A -# PARTICULAR PURPOSE. See the GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along with -# this program; if not, see . -# -# Linking this program statically or dynamically with other modules is making a -# combined work based on this program. Thus, the terms and conditions of the GNU -# General Public License cover the whole combination. -# -# As a special exception, the copyright holders of this program give MERETHIS -# permission to link this program with independent modules to produce an executable, -# regardless of the license terms of these independent modules, and to copy and -# distribute the resulting executable under terms of MERETHIS choice, provided that -# MERETHIS also meet, for each linked independent module, the terms and conditions -# of the license of that module. An independent module is a module which is not -# derived from this program. If you modify this program, you may extend this -# exception to your version of the program, but you are not obliged to do so. If you -# do not wish to do so, delete this exception statement from your version. -# -# For more information : contact@centreon.com -# Authors : Quentin Garnier -# -#################################################################################### - -package network::juniper::common::screenos::mode::components::temperature; - -use strict; -use warnings; - -sub check { - my ($self) = @_; - - $self->{output}->output_add(long_msg => "Checking temperatures"); - $self->{components}->{temperatures} = {name => 'temperatures', total => 0}; - return if ($self->check_exclude('temperatures')); - - my $oid_ssgTemperature = '.1.3.6.1.4.1.3224.21.4.1.3.1'; - - my $result = $self->{snmp}->get_leef(oids => [$oid_ssgTemperature], nothing_quit => 1); - - my $exit_code = $self->{perfdata}->threshold_check(value => $result->{$oid_ssgTemperature}, - threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - - $self->{components}->{temperatures}->{total}++; - - $self->{output}->output_add(severity => $exit_code,short_msg => sprintf("Temperature is %.2f C", $result->{$oid_ssgTemperature})); - - $self->{output}->perfdata_add(label => 'temperature', unit => 'C', value => sprintf("%.2f", $result->{$oid_ssgTemperature}), - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical')); - - #$self->{output}->display(); - #$self->{output}->exit(); -} - -1; diff --git a/network/juniper/common/screenos/mode/hardware.pm b/network/juniper/common/screenos/mode/hardware.pm index 963def039..afe36a89e 100644 --- a/network/juniper/common/screenos/mode/hardware.pm +++ b/network/juniper/common/screenos/mode/hardware.pm @@ -52,11 +52,13 @@ 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' }, - "warning:s" => { name => 'warning', default => '' }, - "critical:s" => { name => 'critical', default => '' }, + "no-component:s" => { name => 'no_component' }, + "warning:s" => { name => 'warning', }, + "critical:s" => { name => 'critical', }, }); $self->{components} = {}; return $self; @@ -74,7 +76,13 @@ 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 { @@ -106,15 +114,14 @@ 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); - $total_components += $self->{components}->{$comp}->{total}; - $display_by_component .= $display_by_component_append . $self->{components}->{$comp}->{total} . ' ' . $self->{components}->{$comp}->{name}; + 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}; $display_by_component_append = ', '; } @@ -125,20 +132,46 @@ 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, $section) = @_; + my ($self, %options) = @_; - if (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)$section(\s|,|$)/) { - $self->{output}->output_add(long_msg => sprintf("Skipping $section 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.")); 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__ @@ -159,6 +192,15 @@ 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.