Debian Codegraph @

src/hardware/server/sun/mgmt_cards/mode/environmentv8xx.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::environmentv8xx;
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 =~ /^\s+POWER\s+GEN FAULT[^\[]+?\[([^\]]+?)][^\[]+?\[([^\]]+?)]/ims && defined($1)) {
86 # POWER GEN FAULT
87 # [ ON] [OFF]
88
89 my $power_status = $1;
90 my $genfault_status = $2;
91 $genfault_status = centreon::plugins::misc::trim($genfault_status);
92
93 if (defined($genfault_status) && $genfault_status !~ /^(OFF)$/i) {
94 $self->{output}->output_add(severity => 'CRITICAL',
95 short_msg => "Gen Fault status is '" . $genfault_status . "'");
96 }
97 }
98
99 if ($output =~ /^\s+REMOVE\s+DISK FAULT[^\[]+?\[([^\]]+?)][^\[]+?\[([^\]]+?)]/ims && defined($1)) {
100 # REMOVE DISK FAULT
101 # [OFF] [OFF]
102
103 my $remove_status = $1;
104 my $diskfault_status = $2;
105 $diskfault_status = centreon::plugins::misc::trim($diskfault_status);
106
107 if (defined($diskfault_status) && $diskfault_status !~ /^(OFF)$/i) {
108 $self->{output}->output_add(severity => 'CRITICAL',
109 short_msg => "Disk Fault status is '" . $diskfault_status . "'");
110 }
111 }
112
113 if ($output =~ /^\s+POWER FAULT\s+LEFT THERMAL FAULT[^\[]+?\[([^\]]+?)][^\[]+?\[([^\]]+?)]/ims && defined($1)) {
114 # POWER FAULT LEFT THERMAL FAULT
115 # [OFF] [OFF]
116
117 my $powerfault_status = $1;
118 my $leftthermalfault_status = $2;
119 $powerfault_status = centreon::plugins::misc::trim($powerfault_status);
120 $leftthermalfault_status = centreon::plugins::misc::trim($leftthermalfault_status);
121
122 if (defined($powerfault_status) && $powerfault_status !~ /^(OFF)$/i) {
123 $self->{output}->output_add(severity => 'CRITICAL',
124 short_msg => "Power Fault status is '" . $powerfault_status . "'");
125 }
126 if (defined($leftthermalfault_status) && $leftthermalfault_status !~ /^(OFF)$/i) {
127 $self->{output}->output_add(severity => 'CRITICAL',
128 short_msg => "Left Thermal Fault status is '" . $leftthermalfault_status . "'");
129 }
130 }
131
132 if ($output =~ /^\s+RIGHT THERMAL FAULT\s+LEFT DOOR[^\[]+?\[([^\]]+?)][^\[]+?\[([^\]]+?)]/ims && defined($1)) {
133 # RIGHT THERMAL FAULT LEFT DOOR
134 # [OFF] [OFF]
135
136 my $rightthermalfault_status = $1;
137 $rightthermalfault_status = centreon::plugins::misc::trim($rightthermalfault_status);
138
139 if (defined($rightthermalfault_status) && $rightthermalfault_status !~ /^(OFF)$/i) {
140 $self->{output}->output_add(severity => 'CRITICAL',
141 short_msg => "Right Thermal Fault status is '" . $rightthermalfault_status . "'");
142 }
143 }
144
145 while (($output =~ /^DISK\s+([0-9]+):\s+\[PRESENT\]\s+\[([^\]]+)\]/imsg)) {
146 # Presence Fault LED
147 # -------- ---------
148 #DISK 0: [PRESENT] [OFF]
149 #DISK 1: [EMPTY]
150
151 my $disknum = $1;
152 my $diskfault_status = $2;
153 $diskfault_status = centreon::plugins::misc::trim($diskfault_status);
154
155 if (defined($diskfault_status) && $diskfault_status !~ /^(OFF)$/i) {
156 $self->{output}->output_add(severity => 'CRITICAL',
157 short_msg => "Disk $disknum status is '" . $diskfault_status . "'");
158 }
159 }
160
161 if ($output =~ /^Fan Bank(.*?)=======/ims) {
162 #Bank Presence ON State Status
163 #---- -------- -------- ------
164 #CPU0_PRIM_FAN [PRESENT] [ON] [OK]
165 #CPU1_PRIM_FAN [PRESENT] [ON] [OK]
166
167 my $content = $1;
168 while (($content =~ /^([^\s]+)\s+\[PRESENT\]\s+\[([^\]]+)\]\s+\[([^\]]+)\]/imsg)) {
169 my $fanbank_name = $1;
170 my $fanbank_status = $3;
171 $fanbank_status = centreon::plugins::misc::trim($fanbank_status);
172
173 if (defined($fanbank_status) && $fanbank_status !~ /^(OK)$/i) {
174 $self->{output}->output_add(severity => 'CRITICAL',
175 short_msg => "Fan Bank '" . $fanbank_name . "' status is '" . $fanbank_status . "'");
176 }
177 }
178 }
179
180 if ($output =~ /^Power Supplies(.*?)=======/ims) {
181 #Power Supplies:
182 #---------------
183 #
184 #Supply Status Fan Fail Temp Fail CS Fail
185 #------ ------------ -------- --------- -------
186 #1 NO AC POWER
187 #2 OK
188 my $content = $1;
189 while (($content =~ /^\s*?([0-9]+)\s+(.*?)(\n|\s{2})/imsg)) {
190 my $supplynum = $1;
191 my $supply_status = $2;
192 $supply_status = centreon::plugins::misc::trim($supply_status);
193
194 if (defined($supply_status) && $supply_status !~ /^(OK)$/i) {
195 $self->{output}->output_add(severity => 'CRITICAL',
196 short_msg => "Supply '" . $supplynum . "' status is '" . $supply_status . "'");
197 }
198 }
199 }
200
201 $self->{output}->display();
202 $self->{output}->exit();
203 }
204
205 1;
206
207 __END__
208
209 =head1 MODE
210
211 Check Sun v890 and v880 Hardware (through RSC card).
212
213 =over 8
214
215 =item B<--hostname>
216
217 Hostname to query.
218
219 =item B<--port>
220
221 telnet port (default: 23).
222
223 =item B<--username>
224
225 telnet username.
226
227 =item B<--password>
228
229 telnet password.
230
231 =item B<--timeout>
232
233 Timeout in seconds for the command (default: 30).
234
235 =back
236
237 =cut