Fix some errors and some better errors management
This commit is contained in:
qgarnier 2014-04-10 20:27:14 +02:00
parent e4d7387913
commit e214d22c63
11 changed files with 58 additions and 29 deletions

View File

@ -40,7 +40,7 @@ use base qw(centreon::plugins::mode);
use strict;
use warnings;
use centreon::plugins::misc;
use hardware::server::sun::mgmtcards::lib::telnet;
use hardware::server::sun::mgmt_cards::lib::telnet;
sub new {
my ($class, %options) = @_;
@ -80,11 +80,12 @@ sub check_options {
sub run {
my ($self, %options) = @_;
my $telnet_handle = hardware::server::sun::mgmtcards::lib::telnet::connect(
my $telnet_handle = hardware::server::sun::mgmt_cards::lib::telnet::connect(
username => $self->{option_results}->{username},
password => $self->{option_results}->{password},
hostname => $self->{option_results}->{hostname},
port => $self->{option_results}->{port},
timeout => $self->{option_results}->{timeout},
output => $self->{output});
my @lines = $telnet_handle->cmd("showenvironment");

View File

@ -40,7 +40,7 @@ use base qw(centreon::plugins::mode);
use strict;
use warnings;
use centreon::plugins::misc;
use hardware::server::sun::mgmtcards::lib::telnet;
use hardware::server::sun::mgmt_cards::lib::telnet;
sub new {
my ($class, %options) = @_;
@ -80,11 +80,12 @@ sub check_options {
sub run {
my ($self, %options) = @_;
my $telnet_handle = hardware::server::sun::mgmtcards::lib::telnet::connect(
my $telnet_handle = hardware::server::sun::mgmt_cards::lib::telnet::connect(
username => $self->{option_results}->{username},
password => $self->{option_results}->{password},
hostname => $self->{option_results}->{hostname},
port => $self->{option_results}->{port},
timeout => $self->{option_results}->{timeout},
output => $self->{output});
my @lines = $telnet_handle->cmd("showenvironment");

View File

@ -40,7 +40,7 @@ use base qw(centreon::plugins::mode);
use strict;
use warnings;
use centreon::plugins::misc;
use hardware::server::sun::mgmtcards::lib::telnet;
use hardware::server::sun::mgmt_cards::lib::telnet;
sub new {
my ($class, %options) = @_;
@ -80,11 +80,12 @@ sub check_options {
sub run {
my ($self, %options) = @_;
my $telnet_handle = hardware::server::sun::mgmtcards::lib::telnet::connect(
my $telnet_handle = hardware::server::sun::mgmt_cards::lib::telnet::connect(
username => $self->{option_results}->{username},
password => $self->{option_results}->{password},
hostname => $self->{option_results}->{hostname},
port => $self->{option_results}->{port},
timeout => $self->{option_results}->{timeout},
output => $self->{output});
my @lines = $telnet_handle->cmd("showenvironment");

View File

@ -39,7 +39,7 @@ use base qw(centreon::plugins::mode);
use strict;
use warnings;
use hardware::server::sun::mgmtcards::lib::telnet;
use hardware::server::sun::mgmt_cards::lib::telnet;
use centreon::plugins::statefile;
sub new {
@ -102,11 +102,12 @@ sub telnet_shell_plateform {
sub run {
my ($self, %options) = @_;
my $telnet_handle = hardware::server::sun::mgmtcards::lib::telnet::connect(
my $telnet_handle = hardware::server::sun::mgmt_cards::lib::telnet::connect(
username => $self->{option_results}->{username},
password => $self->{option_results}->{password},
hostname => $self->{option_results}->{hostname},
port => $self->{option_results}->{port},
timeout => $self->{option_results}->{timeout},
output => $self->{output},
closure => \&telnet_shell_plateform);
my @lines = $telnet_handle->cmd("showboards");

View File

@ -39,7 +39,7 @@ use base qw(centreon::plugins::mode);
use strict;
use warnings;
use hardware::server::sun::mgmtcards::lib::telnet;
use hardware::server::sun::mgmt_cards::lib::telnet;
sub new {
my ($class, %options) = @_;
@ -79,11 +79,12 @@ sub check_options {
sub run {
my ($self, %options) = @_;
my $telnet_handle = hardware::server::sun::mgmtcards::lib::telnet::connect(
my $telnet_handle = hardware::server::sun::mgmt_cards::lib::telnet::connect(
username => $self->{option_results}->{username},
password => $self->{option_results}->{password},
hostname => $self->{option_results}->{hostname},
port => $self->{option_results}->{port},
timeout => $self->{option_results}->{timeout},
output => $self->{output});
my @lines = $telnet_handle->cmd("showenvironment");
@ -94,7 +95,7 @@ sub run {
$output =~ s/\r//g;
my $long_msg = $output;
$long_msg =~ s/\|/~/mg;
output_add(long_msg => $long_msg);
$self->{output}->output_add(long_msg => $long_msg);
if ($output =~ /^System Temperatures.*?\n.*?\n.*?\n.*?\n(.*?)\n\n/ims && defined($1)) {
#Sensor Status Temp LowHard LowSoft LowWarn HighWarn HighSoft HighHard

View File

@ -81,7 +81,7 @@ sub run {
######
# Command execution
######
my $cmd = "echo 'showfaults' | " . $self->{option_results}->{command_plink} . " -T -l '" . $self->{option_results}->{username} . "' -batch -pw '" . $self->{option_results}->{password} . "' " . $self->{option_results}->{password} . " 2>&1";
my $cmd = "echo -e '" . $self->{option_results}->{username} . "\n" . $self->{option_results}->{password} . "\nshowfaults\nlogout\n' | " . $self->{option_results}->{command_plink} . ' -T -batch ' . $self->{option_results}->{hostname} . " 2>&1";
my ($lerror, $stdout, $exit_code) = centreon::plugins::misc::backtick(
command => $cmd,
timeout => $self->{option_results}->{timeout},
@ -106,13 +106,17 @@ sub run {
# Command treatment
######
my ($otp1, $otp2) = split(/showfaults\n/, $stdout);
$self->{output}->output_add(long_msg => $otp2);
if ($otp2 !~ /ID.*?FRU.*?Fault/mi) {
my $long_msg = $otp2;
$long_msg =~ s/\|/~/mg;
if (!defined($otp2) || $otp2 !~ /(No failures|ID.*?FRU.*?Fault)/mi) {
$self->{output}->output_add(long_msg => $stdout);
$self->{output}->output_add(severity => 'UNKNOWN',
short_msg => "Command 'showfaults' problems (see additional info).");
return ;
$self->{output}->display();
$self->{output}->exit();
}
$self->{output}->output_add(long_msg => $long_msg);
$self->{output}->output_add(severity => 'OK',
short_msg => "No Problems on system.");
# Check showfaults
@ -134,7 +138,7 @@ __END__
=head1 MODE
Check Sun 'T1xxx', 'T2xxx' ans 'T5xxx' Hardware (through ALOM4v).
Check Sun 'T1xxx', 'T2xxx' Hardware (through ALOM4v).
=over 8

View File

@ -117,14 +117,16 @@ sub run {
my ($otp1, $otp2) = split(/\Q$cmd_in\E\n/, $stdout);
my $long_msg = $otp2;
$long_msg =~ s/\|/~/mg;
$self->{output}->output_add(long_msg => $long_msg);
if ($otp2 !~ /Target.*?Property.*?Value/mi) {
if (!defined($otp2) || $otp2 !~ /Target.*?Property.*?Value/mi) {
$self->{output}->output_add(long_msg => $stdout);
$self->{output}->output_add(severity => 'UNKNOWN',
short_msg => "Command '$cmd_in' problems (see additional info).");
$self->{output}->display();
$self->{output}->exit();
}
$self->{output}->output_add(long_msg => $long_msg);
if (defined($self->{option_results}->{memory})) {
$self->{statefile_cache}->read(statefile => 'cache_sun_mgmtcards_' . $self->{option_results}->{hostname} . '_' . $self->{mode});
$self->{output}->output_add(severity => 'OK',

View File

@ -50,10 +50,10 @@ sub new {
'show-faulty' => 'hardware::server::sun::mgmt_cards::mode::showfaulty',
'showfaults' => 'hardware::server::sun::mgmt_cards::mode::showfaults',
'showboards' => 'hardware::server::sun::mgmt_cards::mode::showboards',
'showenvironment' => 'hardware::server::sun::mgmt_cards::mode::showenvironment',
'environment-v8xx' => 'hardware::server::sun::mgmt_cards::mode::environmentv8xx',
'environment-v4xx' => 'hardware::server::sun::mgmt_cards::mode::environmentv4xx',
'environment-sf2xx' => 'hardware::server::sun::mgmt_cards::mode::environmentsf2xx',
'showenvironment' => 'hardware::server::sun::mgmt_cards::mode::showenvironment',
'environment-v8xx' => 'hardware::server::sun::mgmt_cards::mode::environmentv8xx',
'environment-v4xx' => 'hardware::server::sun::mgmt_cards::mode::environmentv4xx',
'environment-sf2xx' => 'hardware::server::sun::mgmt_cards::mode::environmentsf2xx',
);
return $self;
@ -67,7 +67,7 @@ __END__
Check a variety of Sun Hardware through management cards:
- mode 'show-faulty': ILOM (T3-x, T4-x, T5xxx) (in ssh with 'plink' command) ;
- mode 'showfaults': ALOM4v (in T1xxx, T2xxx, T5xxx) (in ssh with 'plink' command) ;
- mode 'showfaults': ALOM4v (in T1xxx, T2xxx) (in ssh with 'plink' command) ;
- mode 'showboards': ScApp (SFxxxx - sf6900, sf6800, sf3800,...) (in telnet with Net::Telnet) ;
- mode 'showenvironment': ALOM (v240, v440, v245,...) (in telnet with Net::Telnet) ;
- mode 'environment-v8xx': RSC cards (v890, v880) (in telnet with Net::Telnet) ;

View File

@ -82,11 +82,17 @@ sub run {
command => $self->{option_results}->{command_pasv},
command_path => $self->{option_results}->{command_path_pasv},
command_options => $self->{option_results}->{command_options_pasv});
if ($stdout !~ /MAIN/i) {
if ($stdout =~ /SPARE/i) {
$self->{output}->output_add(severity => 'OK',
short_msg => "System Controller is in spare mode.");
$self->{output}->display();
$self->{output}->exit();
} elsif ($stdout !~ /MAIN/i) {
$self->{output}->output_add(long_msg => $stdout);
$self->{output}->output_add(severity => 'UNKNOWN',
short_msg => "Command problems (see additional info).");
$self->{output}->display();
$self->{output}->exit();
}
$stdout = centreon::plugins::misc::execute(output => $self->{output},
@ -144,7 +150,7 @@ Hostname to query (need --remote).
=item B<--ssh-option>
Specify multiple options like the user (example: --ssh-option='-l=centreon-engine" --ssh-option='-p=52").
Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
=item B<--ssh-path>

View File

@ -82,11 +82,17 @@ sub run {
command => $self->{option_results}->{command_pasv},
command_path => $self->{option_results}->{command_path_pasv},
command_options => $self->{option_results}->{command_options_pasv});
if ($stdout !~ /MAIN/i) {
if ($stdout =~ /SPARE/i) {
$self->{output}->output_add(severity => 'OK',
short_msg => "System Controller is in spare mode.");
$self->{output}->display();
$self->{output}->exit();
} elsif ($stdout !~ /MAIN/i) {
$self->{output}->output_add(long_msg => $stdout);
$self->{output}->output_add(severity => 'UNKNOWN',
short_msg => "Command problems (see additional info).");
$self->{output}->display();
$self->{output}->exit();
}
$stdout = centreon::plugins::misc::execute(output => $self->{output},
@ -227,7 +233,7 @@ Hostname to query (need --remote).
=item B<--ssh-option>
Specify multiple options like the user (example: --ssh-option='-l=centreon-engine" --ssh-option='-p=52").
Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
=item B<--ssh-path>

View File

@ -82,11 +82,17 @@ sub run {
command => $self->{option_results}->{command_pasv},
command_path => $self->{option_results}->{command_path_pasv},
command_options => $self->{option_results}->{command_options_pasv});
if ($stdout !~ /MAIN/i) {
if ($stdout =~ /SPARE/i) {
$self->{output}->output_add(severity => 'OK',
short_msg => "System Controller is in spare mode.");
$self->{output}->display();
$self->{output}->exit();
} elsif ($stdout !~ /MAIN/i) {
$self->{output}->output_add(long_msg => $stdout);
$self->{output}->output_add(severity => 'UNKNOWN',
short_msg => "Command problems (see additional info).");
$self->{output}->display();
$self->{output}->exit();
}
$stdout = centreon::plugins::misc::execute(output => $self->{output},
@ -133,7 +139,7 @@ Hostname to query (need --remote).
=item B<--ssh-option>
Specify multiple options like the user (example: --ssh-option='-l=centreon-engine" --ssh-option='-p=52").
Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
=item B<--ssh-path>