Debian Codegraph @

src/storage/fujitsu/eternus/dx/ssh/mode/physicaldisk.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 storage::fujitsu::eternus::dx::ssh::mode::physicaldisk;
22
23 use base qw(centreon::plugins::mode);
24
25 use strict;
26 use warnings;
27
28 my $thresholds = {
29 disk => [
30 ['Available', 'OK'],
31 ['Spare', 'OK'],
32 ['Readying', 'OK'],
33 ['Redundant Copy', 'OK'],
34 ['Rebuild/Copyback', 'WARNING'],
35 ['Available (Predictive Failure)', 'WARNING'],
36 ['Present', 'OK'],
37 ['Failed Usable', 'WARNING'],
38 ['Formatting', 'WARNING'],
39 ['Not Format', 'WARNING'],
40 ['Not Supported', 'CRITICAL'],
41 ['Not Available', 'CRITICAL'],
42 ['Broken', 'CRITICAL'],
43 ['Not Exist', 'CRITICAL'],
44 ['Unknown', 'UNKNOWN']
45 ]
46 };
47
48 sub new {
49 my ($class, %options) = @_;
50 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
51 bless $self, $class;
52
53 $options{options}->add_options(arguments => {
54 'filter:s@' => { name => 'filter' },
55 'threshold-overload:s@' => { name => 'threshold_overload' },
56 'no-component:s' => { name => 'no_component' }
57 });
58
59 $self->{no_components} = undef;
60 return $self;
61 }
62
63 sub check_options {
64 my ($self, %options) = @_;
65 $self->SUPER::init(%options);
66
67 $self->{filter} = [];
68 foreach my $val (@{$self->{option_results}->{filter}}) {
69 next if (!defined($val) || $val eq '');
70 my @values = split (/,/, $val);
71 push @{$self->{filter}}, { filter => $values[0], instance => $values[1] };
72 }
73
74 $self->{overload_th} = {};
75 foreach my $val (@{$self->{option_results}->{threshold_overload}}) {
76 if ($val !~ /^(.*?),(.*?),(.*)$/) {
77 $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload option '" . $val . "'.");
78 $self->{output}->option_exit();
79 }
80 my ($section, $status, $filter) = ($1, $2, $3);
81 if ($self->{output}->is_litteral_status(status => $status) == 0) {
82 $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload status '" . $val . "'.");
83 $self->{output}->option_exit();
84 }
85 $self->{overload_th}->{$section} = [] if (!defined($self->{overload_th}->{$section}));
86 push @{$self->{overload_th}->{$section}}, {filter => $filter, status => $status};
87 }
88
89 if (defined($self->{option_results}->{no_component})) {
90 if ($self->{option_results}->{no_component} ne '') {
91 $self->{no_components} = $self->{option_results}->{no_component};
92 } else {
93 $self->{no_components} = 'critical';
94 }
95 }
96 }
97
98 sub run {
99 my ($self, %options) = @_;
100
101 my ($stdout) = $options{custom}->execute_command(
102 command => 'show',
103 command_options => "disks\n",
104 ssh_pipe => 1
105 );
106
107 #Location Status Size Type Speed(rpm) Usage Health(%)
108 #------------- ----------------------------- ------- ------------------- ---------- ------------------- ---------
109 #CE-Disk#0 Available 4TB 3.5 SSD-H 7200 System 100
110 #CE-Disk#1 Available 4TB 3.5 SSD-M 7200 System 0
111 #CE-Disk#2 Available 4TB 3.5 SSD-L 7200 System 0
112 #CE-Disk#3 Available 4TB 3.5 Nearline SED 7200 System 0
113
114 my $total_components = 0;
115 while ($stdout =~ /^(\S+)\s+(\S+)/msg) {
116 my ($disk_name, $disk_status) = ($1, $2);
117 next if ($disk_name =~ /Location|---/);
118 next if ($disk_name !~ /Disk/i);
119
120 next if ($self->check_filter(section => 'disk', instance => $disk_name));
121
122 $total_components++;
123 $self->{output}->output_add(long_msg => sprintf("Physical Disk '%s' status is '%s'", $disk_name, $disk_status));
124 my $exit = $self->get_severity(section => 'disk', value => $disk_status);
125 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
126 $self->{output}->output_add(
127 severity => $exit,
128 short_msg => sprintf("Physical Disk '%s' status is '%s'.", $disk_name, $disk_status)
129 );
130 }
131 }
132
133 $self->{output}->output_add(
134 severity => 'OK',
135 short_msg => sprintf("All %d physical disks are ok.", $total_components)
136 );
137
138 if (defined($self->{option_results}->{no_component}) && $total_components == 0) {
139 $self->{output}->output_add(
140 severity => $self->{no_components},
141 short_msg => 'No components are checked.'
142 );
143 }
144
145 $self->{output}->display();
146 $self->{output}->exit();
147 }
148
149 sub check_filter {
150 my ($self, %options) = @_;
151
152 foreach (@{$self->{filter}}) {
153 if ($options{section} =~ /$_->{filter}/) {
154 if (!defined($options{instance}) && !defined($_->{instance})) {
155 $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section."));
156 return 1;
157 } elsif (defined($options{instance}) && $options{instance} =~ /$_->{instance}/) {
158 $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance."));
159 return 1;
160 }
161 }
162 }
163
164 return 0;
165 }
166
167 sub get_severity {
168 my ($self, %options) = @_;
169 my $status = 'UNKNOWN'; # default
170
171 if (defined($self->{overload_th}->{$options{section}})) {
172 foreach (@{$self->{overload_th}->{$options{section}}}) {
173 if ($options{value} =~ /$_->{filter}/i) {
174 $status = $_->{status};
175 return $status;
176 }
177 }
178 }
179 foreach (@{$thresholds->{$options{section}}}) {
180 if ($options{value} =~ /$$_[0]/i) {
181 $status = $$_[1];
182 return $status;
183 }
184 }
185
186 return $status;
187 }
188
189 1;
190
191 __END__
192
193 =head1 MODE
194
195 Check Physical disks.
196
197 Command used: show disks
198
199 =over 8
200
201 =item B<--filter>
202
203 Exclude some parts (comma separated list)
204 You can also exclude items from specific instances: --filter=disk,CE-Disk#0
205
206 =item B<--threshold-overload>
207
208 Use this option to override the status returned by the plugin when the status label matches a regular expression (syntax: section,status,regexp).
209 Example: --threshold-overload='disk,CRITICAL,^(?!(Available|Spare)$)'
210
211 =item B<--no-component>
212
213 Define the expected status if no components are found (default: critical).
214
215 =back
216
217 =cut