| 1 |
# |
| 2 |
# Copyright 2024 Centreon (http://www.centreon.com/) |
| 3 |
# |
| 4 |
# Centreon is a full-fledged industry-strength solution that meets |
| 5 |
# the needs in IT infrastructure and application monitoring for |
| 6 |
# service performance. |
| 7 |
# |
| 8 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
| 9 |
# you may not use this file except in compliance with the License. |
| 10 |
# You may obtain a copy of the License at |
| 11 |
# |
| 12 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 13 |
# |
| 14 |
# Unless required by applicable law or agreed to in writing, software |
| 15 |
# distributed under the License is distributed on an "AS IS" BASIS, |
| 16 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 |
# See the License for the specific language governing permissions and |
| 18 |
# limitations under the License. |
| 19 |
# |
| 20 |
|
| 21 |
package hardware::server::sun::mgmt_cards::mode::environmentsf2xx; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::mode); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
use centreon::plugins::misc; |
| 28 |
use hardware::server::sun::mgmt_cards::lib::telnet; |
| 29 |
|
| 30 |
sub new { |
| 31 |
my ($class, %options) = @_; |
| 32 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options); |
| 33 |
bless $self, $class; |
| 34 |
|
| 35 |
$options{options}->add_options(arguments => { |
| 36 |
"hostname:s" => { name => 'hostname' }, |
| 37 |
"port:s" => { name => 'port', default => 23 }, |
| 38 |
"username:s" => { name => 'username' }, |
| 39 |
"password:s" => { name => 'password' }, |
| 40 |
"timeout:s" => { name => 'timeout', default => 30 } |
| 41 |
}); |
| 42 |
|
| 43 |
return $self; |
| 44 |
} |
| 45 |
|
| 46 |
sub check_options { |
| 47 |
my ($self, %options) = @_; |
| 48 |
$self->SUPER::init(%options); |
| 49 |
|
| 50 |
if (!defined($self->{option_results}->{hostname})) { |
| 51 |
$self->{output}->add_option_msg(short_msg => "Need to specify a hostname."); |
| 52 |
$self->{output}->option_exit(); |
| 53 |
} |
| 54 |
if (!defined($self->{option_results}->{username})) { |
| 55 |
$self->{output}->add_option_msg(short_msg => "Need to specify a username."); |
| 56 |
$self->{output}->option_exit(); |
| 57 |
} |
| 58 |
if (!defined($self->{option_results}->{password})) { |
| 59 |
$self->{output}->add_option_msg(short_msg => "Need to specify a password."); |
| 60 |
$self->{output}->option_exit(); |
| 61 |
} |
| 62 |
} |
| 63 |
|
| 64 |
sub run { |
| 65 |
my ($self, %options) = @_; |
| 66 |
|
| 67 |
my $telnet_handle = hardware::server::sun::mgmt_cards::lib::telnet::connect( |
| 68 |
username => $self->{option_results}->{username}, |
| 69 |
password => $self->{option_results}->{password}, |
| 70 |
hostname => $self->{option_results}->{hostname}, |
| 71 |
port => $self->{option_results}->{port}, |
| 72 |
timeout => $self->{option_results}->{timeout}, |
| 73 |
output => $self->{output}); |
| 74 |
my @lines = $telnet_handle->cmd("showenvironment"); |
| 75 |
|
| 76 |
$self->{output}->output_add(severity => 'OK', |
| 77 |
short_msg => "No problems detected."); |
| 78 |
|
| 79 |
my ($output) = join("", @lines); |
| 80 |
$output =~ s/\r//g; |
| 81 |
my $long_msg = $output; |
| 82 |
$long_msg =~ s/\|/~/mg; |
| 83 |
$self->{output}->output_add(long_msg => $long_msg); |
| 84 |
|
| 85 |
if ($output =~ /^System LED Status:[^\[]+?\[([^\]]+?)][^\[]+?\[([^\]]+?)]/ims && defined($1)) { |
| 86 |
#System LED Status: GENERAL ERROR POWER |
| 87 |
# [OFF] [ ON] |
| 88 |
|
| 89 |
my $genfault_status = $1; |
| 90 |
$genfault_status = centreon::plugins::misc::trim($genfault_status); |
| 91 |
if (defined($genfault_status) && $genfault_status !~ /^(OFF)$/i) { |
| 92 |
$self->{output}->output_add(severity => 'CRITICAL', |
| 93 |
short_msg => "Gen Fault status is '" . $genfault_status . "'"); |
| 94 |
} |
| 95 |
} |
| 96 |
|
| 97 |
if ($output =~ /^Disk LED Status:(.*?)=======/ims) { |
| 98 |
#Disk LED Status: OK = GREEN ERROR = YELLOW |
| 99 |
# DISK 1: [EMPTY] |
| 100 |
# DISK 0: [OK] |
| 101 |
my $content = $1; |
| 102 |
while (($content =~ /DISK\s+([0-9]+)\s*:\s+\[([^\]]+?)\]/imsg)) { |
| 103 |
my $disknum = $1; |
| 104 |
my $disk_status = $2; |
| 105 |
$disk_status = centreon::plugins::misc::trim($disk_status); |
| 106 |
|
| 107 |
if (defined($disk_status) && $disk_status !~ /^(OK|EMPTY)$/i) { |
| 108 |
$self->{output}->output_add(severity => 'CRITICAL', |
| 109 |
short_msg => "Disk $disknum status is '" . $disk_status . "'"); |
| 110 |
} |
| 111 |
} |
| 112 |
} |
| 113 |
|
| 114 |
if ($output =~ /^Fan Bank :(.*?)=======/ims) { |
| 115 |
#Fan Bank : |
| 116 |
#---------- |
| 117 |
# |
| 118 |
#Bank Speed Status |
| 119 |
# (0-255) |
| 120 |
#---- ----- ------ |
| 121 |
# SYS 255 OK |
| 122 |
my $content = $1; |
| 123 |
while (($content =~ /\n\s+([^\n]*?)(\s+[0-9]+\s+)(.*?)\n/imsg)) { |
| 124 |
my $fan_name = $1; |
| 125 |
my $fan_status = $3; |
| 126 |
$fan_name = centreon::plugins::misc::trim($fan_name); |
| 127 |
$fan_status = centreon::plugins::misc::trim($fan_status); |
| 128 |
|
| 129 |
if (defined($fan_status) && $fan_status !~ /^(OK)$/i) { |
| 130 |
$self->{output}->output_add(severity => 'CRITICAL', |
| 131 |
short_msg => "Fan Bank '" . $fan_name . "' status is '" . $fan_status . "'"); |
| 132 |
} |
| 133 |
} |
| 134 |
} |
| 135 |
|
| 136 |
if ($output =~ /^Power Supplies(.*?)=======/ims) { |
| 137 |
#Power Supplies: |
| 138 |
#--------------- |
| 139 |
# |
| 140 |
#Supply Status |
| 141 |
#------ ------ |
| 142 |
# 1 OK: 560w |
| 143 |
my $content = $1; |
| 144 |
while (($content =~ /^\s*?([0-9]+)\s+(.*?)(\n|\s{2}|:)/imsg)) { |
| 145 |
my $supplynum = $1; |
| 146 |
my $supply_status = $2; |
| 147 |
$supply_status = centreon::plugins::misc::trim($supply_status); |
| 148 |
|
| 149 |
if (defined($supply_status) && $supply_status !~ /^(OK)$/i) { |
| 150 |
$self->{output}->output_add(severity => 'CRITICAL', |
| 151 |
short_msg => "Supply '" . $supplynum . "' status is '" . $supply_status . "'"); |
| 152 |
} |
| 153 |
} |
| 154 |
} |
| 155 |
|
| 156 |
$self->{output}->display(); |
| 157 |
$self->{output}->exit(); |
| 158 |
} |
| 159 |
|
| 160 |
1; |
| 161 |
|
| 162 |
__END__ |
| 163 |
|
| 164 |
=head1 MODE |
| 165 |
|
| 166 |
Check Sun 'sf280' Hardware (through RSC card). |
| 167 |
|
| 168 |
=over 8 |
| 169 |
|
| 170 |
=item B<--hostname> |
| 171 |
|
| 172 |
Hostname to query. |
| 173 |
|
| 174 |
=item B<--port> |
| 175 |
|
| 176 |
telnet port (default: 23). |
| 177 |
|
| 178 |
=item B<--username> |
| 179 |
|
| 180 |
telnet username. |
| 181 |
|
| 182 |
=item B<--password> |
| 183 |
|
| 184 |
telnet password. |
| 185 |
|
| 186 |
=item B<--timeout> |
| 187 |
|
| 188 |
Timeout in seconds for the command (default: 30). |
| 189 |
|
| 190 |
=back |
| 191 |
|
| 192 |
=cut |