Debian Codegraph @

src/hardware/server/sun/mgmt_cards/mode/showfaults.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::showfaults;
22
23 use base qw(centreon::plugins::mode);
24
25 use strict;
26 use warnings;
27 use centreon::plugins::misc;
28
29 sub new {
30 my ($class, %options) = @_;
31 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
32 bless $self, $class;
33
34 $options{options}->add_options(arguments => {
35 "hostname:s" => { name => 'hostname' },
36 "username:s" => { name => 'username' },
37 "password:s" => { name => 'password' },
38 "timeout:s" => { name => 'timeout', default => 30 },
39 "command-plink:s" => { name => 'command_plink' }
40 });
41
42 return $self;
43 }
44
45 sub check_options {
46 my ($self, %options) = @_;
47 $self->SUPER::init(%options);
48
49 if (!defined($self->{option_results}->{hostname})) {
50 $self->{output}->add_option_msg(short_msg => "Need to specify a hostname.");
51 $self->{output}->option_exit();
52 }
53 if (!defined($self->{option_results}->{username})) {
54 $self->{output}->add_option_msg(short_msg => "Need to specify a username.");
55 $self->{output}->option_exit();
56 }
57 if (!defined($self->{option_results}->{password})) {
58 $self->{output}->add_option_msg(short_msg => "Need to specify a password.");
59 $self->{output}->option_exit();
60 }
61
62 centreon::plugins::misc::check_security_command(
63 output => $self->{output},
64 command => $self->{option_results}->{command_plink}
65 );
66
67 $self->{option_results}->{command_plink} = 'plink'
68 if (!defined($self->{option_results}->{command_plink}) || $self->{option_results}->{command_plink} eq '');
69 }
70
71 sub run {
72 my ($self, %options) = @_;
73
74 ######
75 # Command execution
76 ######
77 my $cmd = "echo -e '" . $self->{option_results}->{username} . "\n" . $self->{option_results}->{password} . "\nshowfaults\nlogout\n' | " . $self->{option_results}->{command_plink} . ' -T -batch ' . $self->{option_results}->{hostname} . " 2>&1";
78 my ($lerror, $stdout, $exit_code) = centreon::plugins::misc::backtick(
79 command => $cmd,
80 timeout => $self->{option_results}->{timeout},
81 wait_exit => 1
82 );
83
84 $stdout =~ s/\r//g;
85 if ($lerror <= -1000) {
86 $self->{output}->output_add(severity => 'UNKNOWN',
87 short_msg => $stdout);
88 $self->{output}->display();
89 $self->{output}->exit();
90 }
91 if ($exit_code != 0) {
92 $stdout =~ s/\n/ - /g;
93 $self->{output}->output_add(severity => 'UNKNOWN',
94 short_msg => "Command error: $stdout");
95 $self->{output}->display();
96 $self->{output}->exit();
97 }
98
99 ######
100 # Command treatment
101 ######
102 my ($otp1, $otp2) = split(/showfaults\n/, $stdout);
103 my $long_msg = $otp2;
104 $long_msg =~ s/\|/~/mg;
105 if (!defined($otp2) || $otp2 !~ /(No failures|ID.*?FRU.*?Fault)/mi) {
106 $self->{output}->output_add(long_msg => $stdout);
107 $self->{output}->output_add(severity => 'UNKNOWN',
108 short_msg => "Command 'showfaults' problems (see additional info).");
109 $self->{output}->display();
110 $self->{output}->exit();
111 }
112
113 $self->{output}->output_add(long_msg => $long_msg);
114 $self->{output}->output_add(severity => 'OK',
115 short_msg => "No Problems on system.");
116 # Check showfaults
117 # Format:
118 # ID FRU Fault
119 # 1 /SYS SP detected fault: Input power unavailable for PSU at PS1
120 while ($otp2 =~ m/^\s+([0-9]+?)\s+([^\s]+?)\s+(.*)$/mg) {
121 $self->{output}->output_add(severity => 'CRITICAL',
122 short_msg => "[$1][$2] $3.");
123 }
124
125 $self->{output}->display();
126 $self->{output}->exit();
127 }
128
129 1;
130
131 __END__
132
133 =head1 MODE
134
135 Check Sun C<T1xxx>, C<T2xxx> management cards hardware (using C<ALOM4v>).
136
137 =over 8
138
139 =item B<--hostname>
140
141 Define the hostname to query.
142
143 =item B<--username>
144
145 Define the ssh username.
146
147 =item B<--password>
148
149 Define the ssh password.
150
151 =item B<--command-plink>
152
153 Define the C<plink> command (default: C<plink>).
154
155 =item B<--timeout>
156
157 Timeout in seconds for the command (default: 30).
158
159 =back
160
161 =cut