mirror of
https://github.com/centreon/centreon-plugins.git
synced 2025-07-26 23:24:27 +02:00
parent
43338cd1e8
commit
4347be5e75
@ -39,7 +39,6 @@ use base qw(centreon::plugins::mode);
|
|||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use hardware::server::sun::mgmt_cards::lib::telnet;
|
|
||||||
|
|
||||||
sub new {
|
sub new {
|
||||||
my ($class, %options) = @_;
|
my ($class, %options) = @_;
|
||||||
@ -54,6 +53,8 @@ sub new {
|
|||||||
"username:s" => { name => 'username' },
|
"username:s" => { name => 'username' },
|
||||||
"password:s" => { name => 'password' },
|
"password:s" => { name => 'password' },
|
||||||
"timeout:s" => { name => 'timeout', default => 30 },
|
"timeout:s" => { name => 'timeout', default => 30 },
|
||||||
|
"command-plink:s" => { name => 'command_plink', default => 'plink' },
|
||||||
|
"ssh" => { name => 'ssh' },
|
||||||
});
|
});
|
||||||
return $self;
|
return $self;
|
||||||
}
|
}
|
||||||
@ -74,24 +75,69 @@ sub check_options {
|
|||||||
$self->{output}->add_option_msg(short_msg => "Need to specify a password.");
|
$self->{output}->add_option_msg(short_msg => "Need to specify a password.");
|
||||||
$self->{output}->option_exit();
|
$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 {
|
sub run {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
my $output;
|
||||||
|
|
||||||
my $telnet_handle = hardware::server::sun::mgmt_cards::lib::telnet::connect(
|
if (defined($self->{option_results}->{ssh})) {
|
||||||
username => $self->{option_results}->{username},
|
$output = $self->ssh_command();
|
||||||
password => $self->{option_results}->{password},
|
} else {
|
||||||
hostname => $self->{option_results}->{hostname},
|
my $telnet_handle = hardware::server::sun::mgmt_cards::lib::telnet::connect(
|
||||||
port => $self->{option_results}->{port},
|
username => $self->{option_results}->{username},
|
||||||
timeout => $self->{option_results}->{timeout},
|
password => $self->{option_results}->{password},
|
||||||
output => $self->{output});
|
hostname => $self->{option_results}->{hostname},
|
||||||
my @lines = $telnet_handle->cmd("showenvironment");
|
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',
|
$self->{output}->output_add(severity => 'OK',
|
||||||
short_msg => "No problems detected.");
|
short_msg => "No problems detected.");
|
||||||
|
|
||||||
my ($output) = join("", @lines);
|
|
||||||
$output =~ s/\r//g;
|
$output =~ s/\r//g;
|
||||||
my $long_msg = $output;
|
my $long_msg = $output;
|
||||||
$long_msg =~ s/\|/~/mg;
|
$long_msg =~ s/\|/~/mg;
|
||||||
@ -254,6 +300,14 @@ telnet password.
|
|||||||
|
|
||||||
Timeout in seconds for the command (Default: 30).
|
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
|
=back
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
@ -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 'showfaults': ALOM4v (in T1xxx, T2xxx) (in ssh with 'plink' command) ;
|
||||||
- mode 'showstatus': XSCF (Mxxxx - M3000, M4000, M5000,...) (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 '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-v8xx': RSC cards (v890, v880) (in telnet with Net::Telnet) ;
|
||||||
- mode 'environment-v4xx': RSC cards (v480, v490) (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).
|
- mode 'environment-sf2xx': RSC cards (sf280) (in telnet with Net::Telnet).
|
||||||
|
Loading…
x
Reference in New Issue
Block a user