Debian Codegraph @

src/storage/qnap/snmp/mode/components/disk.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::qnap::snmp::mode::components::disk;
22
23 use strict;
24 use warnings;
25
26 my $map_status_disk = {
27 0 => 'ready',
28 '-5' => 'noDisk',
29 '-6' => 'invalid',
30 '-9' => 'rwError',
31 '-4' => 'unknown'
32 };
33 my $map_smartinfo = {
34 2 => 'abnormal',
35 1 => 'warning',
36 0 => 'good',
37 -1 => 'error'
38 };
39
40 my $mapping = {
41 legacy => {
42 description => { oid => '.1.3.6.1.4.1.24681.1.2.11.1.2' }, # hdDescr
43 temperature => { oid => '.1.3.6.1.4.1.24681.1.2.11.1.3' }, # hdTemperature ("40 C/104 F")
44 status => { oid => '.1.3.6.1.4.1.24681.1.2.11.1.4', map => $map_status_disk }, # HdStatus
45 smartinfo => { oid => '.1.3.6.1.4.1.24681.1.2.11.1.7' } # HdSmartInfo
46 },
47 qts => {
48 description => { oid => '.1.3.6.1.4.1.55062.1.10.2.1.2' }, # diskID
49 status => { oid => '.1.3.6.1.4.1.55062.1.10.2.1.7' }, # diskStatus
50 temperature => { oid => '.1.3.6.1.4.1.55062.1.10.2.1.8' } # diskTemperature
51 },
52 ex => {
53 description => { oid => '.1.3.6.1.4.1.24681.1.4.1.1.1.1.5.2.1.2' }, # diskID
54 status => { oid => '.1.3.6.1.4.1.24681.1.4.1.1.1.1.5.2.1.5', map => $map_smartinfo }, # diskSmartInfo
55 temperature => { oid => '.1.3.6.1.4.1.24681.1.4.1.1.1.1.5.2.1.6' } # diskTemperture
56 },
57 es => {
58 description => { oid => '.1.3.6.1.4.1.24681.2.2.11.1.2' }, # es-HdDescr
59 temperature => { oid => '.1.3.6.1.4.1.24681.2.2.11.1.3' }, # es-HdTemperature ("26 C/78.8 F")
60 status => { oid => '.1.3.6.1.4.1.24681.2.2.11.1.4' }, # es-HdStatus
61 smartinfo => { oid => '.1.3.6.1.4.1.24681.2.2.11.1.7' } # es-HdSmartInfo
62 }
63 };
64
65 sub load {}
66
67 sub check_disk_legacy {
68 my ($self, %options) = @_;
69
70 return if (defined($self->{disk_checked}));
71
72 my $snmp_result = $self->{snmp}->get_table(
73 oid => '.1.3.6.1.4.1.24681.1.2.11', # systemHdTable
74 start => $mapping->{description}->{oid}
75 );
76
77 foreach my $oid ($self->{snmp}->oid_lex_sort(keys %$snmp_result)) {
78 next if ($oid !~ /^$mapping->{legacy}->{description}->{oid}\.(\d+)$/);
79 my $instance = $1;
80 my $result = $self->{snmp}->map_instance(mapping => $mapping->{legacy}, results => $snmp_result, instance => $instance);
81
82 next if ($self->check_filter(section => 'disk', instance => $instance));
83 next if (
84 $result->{status} eq 'noDisk' &&
85 $self->absent_problem(section => 'disk', instance => $instance)
86 );
87
88 $self->{components}->{disk}->{total}++;
89 $self->{output}->output_add(
90 long_msg => sprintf(
91 "disk '%s' status is %s [instance: %s, temperature: %s, smart status: %s]",
92 $result->{description},
93 $result->{status},
94 $instance,
95 $result->{temperature},
96 defined($result->{smartinfo}) ? $result->{smartinfo} : '-',
97 )
98 );
99 my $exit = $self->get_severity(section => 'disk', instance => $instance, value => $result->{status});
100 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
101 $self->{output}->output_add(
102 severity => $exit,
103 short_msg => sprintf(
104 "Disk '%s' status is %s.", $result->{description}, $result->{status}
105 )
106 );
107 }
108
109 if (defined($result->{smartinfo})) {
110 $exit = $self->get_severity(section => 'smartdisk', value => $result->{smartinfo});
111 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
112 $self->{output}->output_add(
113 severity => $exit,
114 short_msg => sprintf(
115 "Disk '%s' smart status is %s.", $result->{description}, $result->{smartinfo}
116 )
117 );
118 }
119 }
120
121 next if ($result->{temperature} !~ /([0-9]+)/);
122
123 my $disk_temp = $1;
124 my ($exit2, $warn, $crit) = $self->get_severity_numeric(section => 'disk', instance => $instance, value => $disk_temp);
125 if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) {
126 $self->{output}->output_add(
127 severity => $exit2,
128 short_msg => sprintf(
129 "Disk '%s' temperature is %s degree centigrade", $result->{description}, $disk_temp
130 )
131 );
132 }
133 $self->{output}->perfdata_add(
134 nlabel => 'hardware.disk.temperature.celsius',
135 unit => 'C',
136 instances => $instance,
137 value => $disk_temp
138 );
139 }
140 }
141
142 sub check_disk_qts {
143 my ($self, %options) = @_;
144
145 my $snmp_result = $self->{snmp}->get_table(
146 oid => '.1.3.6.1.4.1.55062.1.10.2', # diskTable
147 start => $mapping->{qts}->{description}->{oid},
148 end => $mapping->{qts}->{temperature}->{oid}
149 );
150 foreach my $oid ($self->{snmp}->oid_lex_sort(keys %$snmp_result)) {
151 next if ($oid !~ /^$mapping->{qts}->{description}->{oid}\.(\d+)$/);
152 my $instance = $1;
153 $self->{disk_checked} = 1;
154
155 my $result = $self->{snmp}->map_instance(mapping => $mapping->{qts}, results => $snmp_result, instance => $instance);
156
157 next if ($self->check_filter(section => 'disk', instance => $instance));
158
159 $self->{components}->{disk}->{total}++;
160 $self->{output}->output_add(
161 long_msg => sprintf(
162 "disk '%s' status is %s [instance: %s, temperature: %s]",
163 $result->{description},
164 $result->{status},
165 $instance,
166 $result->{temperature}
167 )
168 );
169 my $exit = $self->get_severity(section => 'disk', instance => $instance, value => $result->{status});
170 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
171 $self->{output}->output_add(
172 severity => $exit,
173 short_msg => sprintf(
174 "Disk '%s' status is %s.", $result->{description}, $result->{status}
175 )
176 );
177 }
178
179 next if ($result->{temperature} !~ /([0-9]+)/);
180
181 my $disk_temp = $1;
182 my ($exit2, $warn, $crit) = $self->get_severity_numeric(section => 'disk', instance => $instance, value => $disk_temp);
183 if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) {
184 $self->{output}->output_add(
185 severity => $exit2,
186 short_msg => sprintf(
187 "Disk '%s' temperature is %s degree centigrade", $result->{description}, $disk_temp
188 )
189 );
190 }
191 $self->{output}->perfdata_add(
192 nlabel => 'hardware.disk.temperature.celsius',
193 unit => 'C',
194 instances => $instance,
195 value => $disk_temp
196 );
197 }
198 }
199
200 sub check_disk_ex {
201 my ($self, %options) = @_;
202
203 my $snmp_result = $self->{snmp}->get_table(
204 oid => '.1.3.6.1.4.1.24681.1.4.1.1.1.1.5.2', # diskTable
205 start => $mapping->{ex}->{description}->{oid},
206 end => $mapping->{ex}->{temperature}->{oid}
207 );
208 foreach my $oid ($self->{snmp}->oid_lex_sort(keys %$snmp_result)) {
209 next if ($oid !~ /^$mapping->{ex}->{description}->{oid}\.(\d+)$/);
210 my $instance = $1;
211 $self->{disk_checked} = 1;
212
213 my $result = $self->{snmp}->map_instance(mapping => $mapping->{ex}, results => $snmp_result, instance => $instance);
214
215 next if ($self->check_filter(section => 'disk', instance => $instance));
216
217 $self->{components}->{disk}->{total}++;
218 $self->{output}->output_add(
219 long_msg => sprintf(
220 "disk '%s' status is %s [instance: %s, temperature: %s]",
221 $result->{description},
222 $result->{status},
223 $instance,
224 $result->{temperature}
225 )
226 );
227 my $exit = $self->get_severity(section => 'disk', instance => $instance, value => $result->{status});
228 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
229 $self->{output}->output_add(
230 severity => $exit,
231 short_msg => sprintf(
232 "Disk '%s' status is %s.", $result->{description}, $result->{status}
233 )
234 );
235 }
236
237 next if ($result->{temperature} !~ /([0-9]+)/);
238
239 my $disk_temp = $1;
240 my ($exit2, $warn, $crit) = $self->get_severity_numeric(section => 'disk', instance => $instance, value => $disk_temp);
241 if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) {
242 $self->{output}->output_add(
243 severity => $exit2,
244 short_msg => sprintf(
245 "Disk '%s' temperature is %s degree centigrade", $result->{description}, $disk_temp
246 )
247 );
248 }
249 $self->{output}->perfdata_add(
250 nlabel => 'hardware.disk.temperature.celsius',
251 unit => 'C',
252 instances => $instance,
253 value => $disk_temp
254 );
255 }
256 }
257
258 sub check_disk_es {
259 my ($self, %options) = @_;
260
261 my $snmp_result = $self->{snmp}->get_table(oid => '.1.3.6.1.4.1.24681.2.2.11'); # es-SystemHdTable
262 foreach my $oid ($self->{snmp}->oid_lex_sort(keys %$snmp_result)) {
263 next if ($oid !~ /^$mapping->{es}->{description}->{oid}\.(\d+)$/);
264 my $instance = $1;
265 my $result = $self->{snmp}->map_instance(mapping => $mapping->{es}, results => $snmp_result, instance => $instance);
266
267 next if ($self->check_filter(section => 'disk', instance => $instance));
268
269 $self->{components}->{disk}->{total}++;
270 $self->{output}->output_add(
271 long_msg => sprintf(
272 "disk '%s' status is %s [instance: %s, temperature: %s, smart status: %s]",
273 $result->{description},
274 $result->{status},
275 $instance,
276 $result->{temperature},
277 defined($result->{smartinfo}) ? $result->{smartinfo} : '-',
278 )
279 );
280 my $exit = $self->get_severity(section => 'disk', instance => $instance, value => $result->{status});
281 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
282 $self->{output}->output_add(
283 severity => $exit,
284 short_msg => sprintf(
285 "Disk '%s' status is %s.", $result->{description}, $result->{status}
286 )
287 );
288 }
289
290 if (defined($result->{smartinfo})) {
291 $exit = $self->get_severity(section => 'smartdisk', value => $result->{smartinfo});
292 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
293 $self->{output}->output_add(
294 severity => $exit,
295 short_msg => sprintf(
296 "Disk '%s' smart status is %s.", $result->{description}, $result->{smartinfo}
297 )
298 );
299 }
300 }
301
302 next if ($result->{temperature} !~ /([0-9]+)/);
303
304 my $disk_temp = $1;
305 my ($exit2, $warn, $crit) = $self->get_severity_numeric(section => 'disk', instance => $instance, value => $disk_temp);
306 if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) {
307 $self->{output}->output_add(
308 severity => $exit2,
309 short_msg => sprintf(
310 "Disk '%s' temperature is %s degree centigrade", $result->{description}, $disk_temp
311 )
312 );
313 }
314 $self->{output}->perfdata_add(
315 nlabel => 'hardware.disk.temperature.celsius',
316 unit => 'C',
317 instances => $instance,
318 value => $disk_temp
319 );
320 }
321 }
322
323 sub check {
324 my ($self) = @_;
325
326 $self->{output}->output_add(long_msg => 'Checking disks');
327 $self->{components}->{disk} = { name => 'disks', total => 0, skip => 0 };
328 return if ($self->check_filter(section => 'disk'));
329
330 if ($self->{is_qts} == 1) {
331 check_disk_qts($self);
332 } elsif ($self->{is_es} == 1) {
333 check_disk_es($self);
334 } else {
335 check_disk_ex($self);
336 check_disk_legacy($self);
337 }
338 }
339
340 1;