Debian Codegraph @

src/hardware/server/sun/mgmt_cards/mode/environmentv4xx.pm

raw
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::environmentv4xx;
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 {
37 "hostname:s" => { name => 'hostname' },
38 "port:s" => { name => 'port', default => 23 },
39 "username:s" => { name => 'username' },
40 "password:s" => { name => 'password' },
41 "timeout:s" => { name => 'timeout', default => 30 },
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: LOCATOR FAULT POWER
87 # [OFF] [OFF] [ ON]
88
89 my $genfault_status = $2;
90 $genfault_status = centreon::plugins::misc::trim($genfault_status);
91
92 if (defined($genfault_status) && $genfault_status !~ /^(OFF)$/i) {
93 $self->{output}->output_add(severity => 'CRITICAL',
94 short_msg => "Gen Fault status is '" . $genfault_status . "'");
95 }
96 }
97
98 if ($output =~ /^Disk LED Status:(.*?)=======/ims) {
99 #Disk LED Status: OK = GREEN ERROR = YELLOW
100 # DISK 1: [EMPTY]
101 # DISK 0: [OK]
102 my $content = $1;
103 while (($content =~ /DISK\s+([0-9]+)\s*:\s+\[([^\]]+?)\]/imsg)) {
104 my $disknum = $1;
105 my $disk_status = $2;
106 $disk_status = centreon::plugins::misc::trim($disk_status);
107
108 if (defined($disk_status) && $disk_status !~ /^(OK|EMPTY)$/i) {
109 $self->{output}->output_add(severity => 'CRITICAL',
110 short_msg => "Disk $disknum status is '" . $disk_status . "'");
111 }
112 }
113 }
114
115 if ($output =~ /^Fan Tray :(.*?)=======/ims) {
116 #Fan Tray :
117 #----------
118 #
119 #Tray Speed Status
120 #---- ----- ------
121 #FAN TRAY0 CPU FAN0 5555 [OK]
122 #FAN TRAY0 CPU FAN1 4000 [OK]
123 #FAN TRAY0 CPU FAN2 3846 [OK]
124 #FAN TRAY1 IO FAN0 4000 [OK]
125 #FAN TRAY1 IO FAN1 4166 [OK]
126 #FAN TRAY1 IO FAN2 0 [UNKNOWN]
127 #
128 # Can be [FAILED], [OK], [UNKNOWN]
129 # If system is poweroff, nothing displayed.
130 my $content = $1;
131 while (($content =~ /\n([^\n]*?)(\s+[0-9]+\s+|\s+)\[(.*?)\]$/imsg)) {
132 my $fan_name = $1;
133 my $fan_status = $3;
134 $fan_name = centreon::plugins::misc::trim($fan_name);
135 $fan_status = centreon::plugins::misc::trim($fan_status);
136
137 if (defined($fan_status) && $fan_status !~ /^(OK)$/i) {
138 $self->{output}->output_add(severity => 'CRITICAL',
139 short_msg => "Fan '" . $fan_name . "' status is '" . $fan_status . "'");
140 }
141 }
142 }
143
144 if ($output =~ /^Power Supplies(.*?)=======/ims) {
145 # Power Supplies:
146 #---------------
147 #
148 #Supply Status PS Fault Fan Fault Temp Fault
149 #------ ------------ -------- --------- ----------
150 # 0 OK OFF OFF OFF
151 # 1 OK OFF OFF OFF
152 my $content = $1;
153 while (($content =~ /^\s*?([0-9]+)\s+(.*?)(\n|\s{2})/imsg)) {
154 my $supplynum = $1;
155 my $supply_status = $2;
156 $supply_status = centreon::plugins::misc::trim($supply_status);
157
158 if (defined($supply_status) && $supply_status !~ /^(OK)$/i) {
159 $self->{output}->output_add(severity => 'CRITICAL',
160 short_msg => "Supply '" . $supplynum . "' status is '" . $supply_status . "'");
161 }
162 }
163 }
164
165 $self->{output}->display();
166 $self->{output}->exit();
167 }
168
169 1;
170
171 __END__
172
173 =head1 MODE
174
175 Check Sun 'v480' and 'v490' Hardware (through RSC card).
176
177 =over 8
178
179 =item B<--hostname>
180
181 Hostname to query.
182
183 =item B<--port>
184
185 telnet port (default: 23).
186
187 =item B<--username>
188
189 telnet username.
190
191 =item B<--password>
192
193 telnet password.
194
195 =item B<--timeout>
196
197 Timeout in seconds for the command (default: 30).
198
199 =back
200
201 =cut