Add mode ssh from a mgmt card
This commit is contained in:
Quentin Garnier 2014-06-06 16:46:35 +02:00
parent 786ca87ba4
commit 267ec14b21
2 changed files with 66 additions and 12 deletions

View File

@ -39,7 +39,6 @@ use base qw(centreon::plugins::mode);
use strict;
use warnings;
use hardware::server::sun::mgmt_cards::lib::telnet;
sub new {
my ($class, %options) = @_;
@ -54,6 +53,8 @@ sub new {
"username:s" => { name => 'username' },
"password:s" => { name => 'password' },
"timeout:s" => { name => 'timeout', default => 30 },
"command-plink:s" => { name => 'command_plink', default => 'plink' },
"ssh" => { name => 'ssh' },
});
return $self;
}
@ -74,24 +75,69 @@ sub check_options {
$self->{output}->add_option_msg(short_msg => "Need to specify a password.");
$self->{output}->option_exit();
}
if (!defined($self->{option_results}->{ssh})) {
require hardware::server::sun::mgmt_cards::lib::telnet;
}
}
sub ssh_command {
my ($self, %options) = @_;
my $cmd_in = $self->{option_results}->{username} . '\n' . $self->{option_results}->{password} . '\nshowenvironment\nlogout\n';
my $cmd = "echo -e '$cmd_in' | " . $self->{option_results}->{command_plink} . " -batch " . $self->{option_results}->{hostname} . " 2>&1";
my ($lerror, $stdout, $exit_code) = centreon::plugins::misc::backtick(
command => $cmd,
timeout => $self->{option_results}->{timeout},
wait_exit => 1
);
$stdout =~ s/\r//g;
if ($lerror <= -1000) {
$self->{output}->output_add(severity => 'UNKNOWN',
short_msg => $stdout);
$self->{output}->display();
$self->{output}->exit();
}
if ($exit_code != 0) {
$stdout =~ s/\n/ - /g;
$self->{output}->output_add(severity => 'UNKNOWN',
short_msg => "Command error: $stdout");
$self->{output}->display();
$self->{output}->exit();
}
if ($stdout !~ /Environmental Status/mi) {
$self->{output}->output_add(long_msg => $stdout);
$self->{output}->output_add(severity => 'UNKNOWN',
short_msg => "Command 'showenvironment' problems (see additional info).");
$self->{output}->display();
$self->{output}->exit();
}
return $stdout;
}
sub run {
my ($self, %options) = @_;
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");
my $output;
if (defined($self->{option_results}->{ssh})) {
$output = $self->ssh_command();
} else {
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");
$output = join("", @lines);
}
$self->{output}->output_add(severity => 'OK',
short_msg => "No problems detected.");
my ($output) = join("", @lines);
$output =~ s/\r//g;
my $long_msg = $output;
$long_msg =~ s/\|/~/mg;
@ -254,6 +300,14 @@ telnet password.
Timeout in seconds for the command (Default: 30).
=item B<--command-plink>
Plink command (default: plink). Use to set a path.
=item B<--ssh>
Use ssh (with plink) instead of telnet.
=back
=cut

View File

@ -71,7 +71,7 @@ Check a variety of Sun Hardware through management cards:
- mode 'showfaults': ALOM4v (in T1xxx, T2xxx) (in ssh with 'plink' command) ;
- mode 'showstatus': XSCF (Mxxxx - M3000, M4000, M5000,...) (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 'showenvironment': ALOM (v240, v440, v245,...) (in telnet with Net::Telnet or in ssh with 'plink' command) ;
- mode 'environment-v8xx': RSC cards (v890, v880) (in telnet with Net::Telnet) ;
- mode 'environment-v4xx': RSC cards (v480, v490) (in telnet with Net::Telnet) ;
- mode 'environment-sf2xx': RSC cards (sf280) (in telnet with Net::Telnet).