From a7ace615bf5590244b41bc8f1f237e9e1e88a723 Mon Sep 17 00:00:00 2001 From: Quentin Garnier Date: Thu, 12 Jun 2014 14:51:51 +0200 Subject: [PATCH] Refs #5077 --- .../server/sun/mgmt_cards/mode/showboards.pm | 81 ++++++++++++++++--- hardware/server/sun/mgmt_cards/plugin.pm | 2 +- os/solaris/local/conf/prtdiag.conf | 81 +++++++++++++++---- 3 files changed, 137 insertions(+), 27 deletions(-) diff --git a/hardware/server/sun/mgmt_cards/mode/showboards.pm b/hardware/server/sun/mgmt_cards/mode/showboards.pm index d50fc9f94..3ae24ecad 100644 --- a/hardware/server/sun/mgmt_cards/mode/showboards.pm +++ b/hardware/server/sun/mgmt_cards/mode/showboards.pm @@ -56,6 +56,8 @@ sub new { "password:s" => { name => 'password' }, "timeout:s" => { name => 'timeout', default => 30 }, "memory" => { name => 'memory' }, + "command-plink:s" => { name => 'command_plink', default => 'plink' }, + "ssh" => { name => 'ssh' }, }); $self->{statefile_cache} = centreon::plugins::statefile->new(%options); return $self; @@ -81,6 +83,10 @@ sub check_options { if (defined($self->{option_results}->{memory})) { $self->{statefile_cache}->check_options(%options); } + + if (!defined($self->{option_results}->{ssh})) { + require hardware::server::sun::mgmt_cards::lib::telnet; + } } sub telnet_shell_plateform { @@ -99,18 +105,65 @@ sub telnet_shell_plateform { $telnet_handle->print("0"); } +sub ssh_command { + my ($self, %options) = @_; + my $username = ''; + + if (defined($self->{option_results}->{username}) && $self->{option_results}->{username} ne '') { + $username = $self->{option_results}->{username} . '\n'; + } + + my $cmd_in = "0" . $username . $self->{option_results}->{password} . '\nshowboards\ndisconnect\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 !~ /Slot/mi) { + $self->{output}->output_add(long_msg => $stdout); + $self->{output}->output_add(severity => 'UNKNOWN', + short_msg => "Command 'showboards' 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}, - closure => \&telnet_shell_plateform); - my @lines = $telnet_handle->cmd("showboards"); + my ($output, @lines); + + if (defined($self->{option_results}->{ssh})) { + $output = $self->ssh_command(); + @lines = split /\n/, $output; + } 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}, + closure => \&telnet_shell_plateform); + @lines = $telnet_handle->cmd("showboards"); + } if (defined($self->{option_results}->{memory})) { $self->{statefile_cache}->read(statefile => 'cache_sun_mgmtcards_' . $self->{option_results}->{hostname} . '_' . $self->{mode}); @@ -196,6 +249,14 @@ Returns new errors (retention file is used by the following option). 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 diff --git a/hardware/server/sun/mgmt_cards/plugin.pm b/hardware/server/sun/mgmt_cards/plugin.pm index cb0f83924..d4e966d96 100644 --- a/hardware/server/sun/mgmt_cards/plugin.pm +++ b/hardware/server/sun/mgmt_cards/plugin.pm @@ -70,7 +70,7 @@ 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) (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 or in ssh with 'plink' command) ; - 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) ; diff --git a/os/solaris/local/conf/prtdiag.conf b/os/solaris/local/conf/prtdiag.conf index 02e0c4b29..c5acdac4e 100644 --- a/os/solaris/local/conf/prtdiag.conf +++ b/os/solaris/local/conf/prtdiag.conf @@ -100,7 +100,7 @@ checks.FRU.output_string = FRU '%Location%' operationnal status is '%Status%' [SunFire 280R] system.match = ^System Configuration:.*Sun Fire 280R -system.checks = Leds,Fans,Disks,PSU +system.checks = Leds,Fans,Disks,PSU,IO checks.Leds.description = system leds status checks.Leds.begin_match = ^System LED Status:\s+ @@ -132,10 +132,9 @@ checks.PSU.begin_match = ^Power Supplies: checks.PSU.end_match = ^= checks.PSU.data_match = ^(.*?\d+)\s+\[\s*(\S+)\s*\] checks.PSU.data_labels = Supply,Status -checks.PSU.ok_condition = "%Status%" eq "OK" +checks.PSU.ok_condition = "%Status%" =~ m/^OK|NO_FAULT$/ checks.PSU.output_string = Power supply '%Supply%' status is '%Status%' - [Enterprise 150] system.match = ^System Configuration:.*Sun Ultra 1 SBus system.checks = Boards @@ -343,7 +342,7 @@ checks.Boards.data_labels = Diagnosis checks.Boards.ok_condition = "%Diagnosis%" =~ m/^No / checks.Boards.output_string = System diagnosis for IO cards is '%Diagnosis%' - +# OK Merethis [SunFire V240] system.match = ^System Configuration:.*Sun Fire V240 system.checks = Fans,Leds,Temperatures,Voltages,Current,FRU @@ -403,7 +402,15 @@ checks.FRU.output_string = FRU '%Location%' status is '%Status%' # OK Merethis [SunFire V440] system.match = ^System Configuration:.*Sun Fire V440 -system.checks = Fans,Leds,Temperatures,Voltages,Current,FRU +system.checks = CPU,Fans,Leds,Temperatures,Voltages,Current,FRU + +checks.CPU.description = CPU status +checks.CPU.begin_match = ^=+ CPUs = +checks.CPU.end_match = ^$ +checks.CPU.data_match = ^\s*(\d+)\s+(?:.*?)\s+(\S+)\s+(\S+)\s*$ +checks.CPU.data_labels = CPU,Status,Location +checks.CPU.ok_condition = "%Status%" =~ m/^on-line|online$/ +checks.CPU.output_string = CPU%CPU% ('%Location%') status is '%Status%' checks.Fans.description = fans status checks.Fans.begin_match = ^Fan Speeds: @@ -457,7 +464,7 @@ checks.FRU.data_labels = Location,Status checks.FRU.ok_condition = "%Status%" =~ m/present|okay/ checks.FRU.output_string = FRU '%Location%' status is '%Status%' - +# Ok Merethis [SunFire V490] system.match = ^System Configuration:.*Sun Fire V490 system.checks = Temperatures,Leds,Disks,Fans,PSU @@ -473,13 +480,11 @@ checks.Temperatures.output_string = Temperature sensor '%Sensor%' status is '%St checks.Leds.description = system leds status checks.Leds.begin_match = ^System LED Status: -checks.Leds.end_match = ^= -checks.Leds.fetch_mode = linear -checks.Leds.skip_match = ^-+ -checks.Leds.data_match = ((?:\S+\s)*\S+),\[\s*(.*?)\s*\] -checks.Leds.data_labels = Location,Status -checks.Leds.ok_condition = not( ( "%Location%" eq "FAULT" ) and ("%Status%" eq "ON") ) -checks.Leds.output_string = System LED '%Location%' status is '%Status%' +checks.Leds.end_match = :$ +checks.Leds.data_match = ^\s+\[\s*(.*?)\s*\]\s+\[\s*(.*?)\s*\]\s+\[\s*(.*?)\s*\] +checks.Leds.data_labels = Location,Failure,Running +checks.Leds.ok_condition = "%Failure%" ne "ON" +checks.Leds.output_string = System failure led status is '%Failure%' checks.Disks.description = disks status checks.Disks.begin_match = ^Disk Status: @@ -505,7 +510,53 @@ checks.PSU.data_labels = Supply,Status checks.PSU.ok_condition = "%Status%" eq "NO_FAULT" checks.PSU.output_string = Power supply '%Supply%' status is '%Status%' +# Ok Merethis +[SunFire 480] +system.match = ^System Configuration:.*Sun Fire 480 +system.checks = Temperatures,Leds,Disks,Fans,PSU +checks.Temperatures.description = temperature sensors +checks.Temperatures.begin_match = ^System Temperatures.*: +checks.Temperatures.end_match = ^$ +checks.Temperatures.skip_match = ^Device +checks.Temperatures.data_match = ^(\S+)\s+(\S+)\s+(\S+)$ +checks.Temperatures.data_labels = Sensor,Temperature,Status +checks.Temperatures.ok_condition = ( "%Status%" eq "OK" ) +checks.Temperatures.output_string = Temperature sensor '%Sensor%' status is '%Status%' (temp.: %Temperature% deg.) + +checks.Leds.description = system leds status +checks.Leds.begin_match = ^System LED Status: +checks.Leds.end_match = :$ +checks.Leds.data_match = ^\s+\[\s*(.*?)\s*\]\s+\[\s*(.*?)\s*\]\s+\[\s*(.*?)\s*\] +checks.Leds.data_labels = Location,Failure,Running +checks.Leds.ok_condition = "%Failure%" ne "ON" +checks.Leds.output_string = System failure led status is '%Failure%' + +checks.Disks.description = disks status +checks.Disks.begin_match = ^Disk Status: +checks.Disks.end_match = ^$ +checks.Disks.data_match = ^(.*?\d+)(?:.*?)\[\s*(\S+)\s*\]\s*$ +checks.Disks.data_labels = Disk,Status +checks.Disks.ok_condition = "%Status%" eq "NO_FAULT" +checks.Disks.output_string = Disk '%Disk%' status is '%Status%' + +checks.Fans.description = fans status +checks.Fans.begin_match = ^Fan Status: +checks.Fans.end_match = ^= +checks.Fans.data_match = ^(\S+)\s+(\S+)\s+(.*?)\s+\[\s*(\S+)\s*\] +checks.Fans.data_labels = Tray,Fan,Speed,Status +checks.Fans.ok_condition = "%Status%" eq "NO_FAULT" +checks.Fans.output_string = Fan '%Tray%/%Fan%' status is '%Status%' (speed: %Speed% rpm) + +checks.PSU.description = power supplies status +checks.PSU.begin_match = ^Power Supplies: +checks.PSU.end_match = ^= +checks.PSU.data_match = ^(.*?)\s+\[\s*(\S+)\s*\] +checks.PSU.data_labels = Supply,Status +checks.PSU.ok_condition = "%Status%" eq "NO_FAULT" +checks.PSU.output_string = Power supply '%Supply%' status is '%Status%' + +# OK Merethis [SunFire 880] system.match = ^System Configuration:.*Sun Fire 880 system.checks = Boards,Temperatures,Leds,Disks,Fans,PSU @@ -534,7 +585,7 @@ checks.Leds.skip_match = ^$ checks.Leds.fetch_mode = linear checks.Leds.data_match = ((?:\S+\s)*\S+),\[\s*(.*?)\s*\] checks.Leds.data_labels = Location,Status -checks.Leds.ok_condition = not( ( "%Location%" eq "FAULT" ) and ("%Status%" eq "ON") ) +checks.Leds.ok_condition = not( ( "%Location%" =~ /FAULT/ ) and ("%Status%" eq "ON") ) checks.Leds.output_string = System LED '%Location%' status is '%Status%' checks.Disks.description = disks status @@ -626,5 +677,3 @@ checks.FRU.data_match = ^(\S+)\s+(\S+) checks.FRU.data_labels = Location,Status checks.FRU.ok_condition = "%Status%" =~ m/present|okay/ checks.FRU.output_string = FRU '%Location%' status is '%Status%' - -