Debian Codegraph @

src/storage/hp/lefthand/snmp/mode/components/device.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::hp::lefthand::snmp::mode::components::device;
22
23 use strict;
24 use warnings;
25 use storage::hp::lefthand::snmp::mode::components::resources qw($map_status);
26
27 my $mapping = {
28 storageDeviceSerialNumber => { oid => '.1.3.6.1.4.1.9804.3.1.1.2.4.2.1.7' },
29 storageDeviceTemperature => { oid => '.1.3.6.1.4.1.9804.3.1.1.2.4.2.1.9' },
30 storageDeviceTemperatureCritical => { oid => '.1.3.6.1.4.1.9804.3.1.1.2.4.2.1.10' },
31 storageDeviceTemperatureLimit => { oid => '.1.3.6.1.4.1.9804.3.1.1.2.4.2.1.11' },
32 storageDeviceTemperatureStatus => { oid => '.1.3.6.1.4.1.9804.3.1.1.2.4.2.1.12', map => $map_status },
33 storageDeviceName => { oid => '.1.3.6.1.4.1.9804.3.1.1.2.4.2.1.14' },
34 storageDeviceSmartHealth => { oid => '.1.3.6.1.4.1.9804.3.1.1.2.4.2.1.17' }, # normal, marginal, faulty
35 storageDeviceState => { oid => '.1.3.6.1.4.1.9804.3.1.1.2.4.2.1.90' },
36 storageDeviceStatus => { oid => '.1.3.6.1.4.1.9804.3.1.1.2.4.2.1.91', map => $map_status },
37 };
38 my $oid_storageDeviceEntry = '.1.3.6.1.4.1.9804.3.1.1.2.4.2.1';
39
40 sub load {
41 my ($self) = @_;
42
43 push @{$self->{request}}, { oid => $oid_storageDeviceEntry };
44 }
45
46 sub check {
47 my ($self) = @_;
48
49 $self->{output}->output_add(long_msg => "Checking devices");
50 $self->{components}->{device} = {name => 'devices', total => 0, skip => 0};
51 return if ($self->check_filter(section => 'device'));
52
53 foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_storageDeviceEntry}})) {
54 next if ($oid !~ /^$mapping->{storageDeviceStatus}->{oid}\.(.*)$/);
55 my $instance = $1;
56 my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_storageDeviceEntry}, instance => $instance);
57
58 if ($result->{storageDeviceState} =~ /off_and_secured|off_or_removed/i) {
59 $self->absent_problem(section => 'device', instance => $instance);
60 next;
61 }
62 next if ($self->check_filter(section => 'device', instance => $instance));
63
64 $self->{components}->{device}->{total}++;
65 $self->{output}->output_add(long_msg => sprintf("storage device '%s' status is '%s' [instance = %s, state = %s, serial = %s, smart health = %s]",
66 $result->{storageDeviceName}, $result->{storageDeviceStatus}, $instance, $result->{storageDeviceState},
67 $result->{storageDeviceSerialNumber}, $result->{storageDeviceSmartHealth}));
68
69 my $exit = $self->get_severity(label => 'default', section => 'device', value => $result->{storageDeviceStatus});
70 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
71 $self->{output}->output_add(severity => $exit,
72 short_msg => sprintf("storage device '%s' state is '%s'", $result->{storageDeviceName}, $result->{storageDeviceState}));
73 }
74
75 $exit = $self->get_severity(label => 'smart', section => 'device.smart', value => $result->{storageDeviceSmartHealth});
76 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
77 $self->{output}->output_add(severity => $exit,
78 short_msg => sprintf("storage device '%s' smart health state is '%s'", $result->{storageDeviceName}, $result->{storageDeviceSmartHealth}));
79 }
80
81 my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'device.temperature', instance => $instance, value => $result->{storageDeviceTemperature});
82 if ($checked == 0) {
83 my $warn_th = '';
84 my $crit_th = defined($result->{storageDeviceTemperatureCritical}) ? $result->{storageDeviceTemperatureCritical} : '';
85 $self->{perfdata}->threshold_validate(label => 'warning-device.temperature-instance-' . $instance, value => $warn_th);
86 $self->{perfdata}->threshold_validate(label => 'critical-device.temperature-instance-' . $instance, value => $crit_th);
87
88 $exit = $self->{perfdata}->threshold_check(
89 value => $result->{storageDeviceTemperature},
90 threshold => [ { label => 'critical-device.temperature-instance-' . $instance, exit_litteral => 'critical' },
91 { label => 'warning-device.temperature-instance-' . $instance, exit_litteral => 'warning' } ]);
92 $warn = $self->{perfdata}->get_perfdata_for_output(label => 'warning-device.temperature-instance-' . $instance);
93 $crit = $self->{perfdata}->get_perfdata_for_output(label => 'critical-device.temperature-instance-' . $instance)
94 }
95
96 if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) {
97 $self->{output}->output_add(severity => $exit2,
98 short_msg => sprintf("storage device '%s' temperature is %s C", $result->{storageDeviceName}, $result->{storageDeviceTemperature}));
99 }
100 $self->{output}->perfdata_add(
101 label => 'temp', unit => 'C',
102 nlabel => 'hardware.device.temperature.celsius',
103 instances => $result->{storageDeviceName},
104 value => $result->{storageDeviceTemperature},
105 warning => $warn,
106 critical => $crit,
107 max => $result->{storageDeviceTemperatureLimit},
108 );
109 }
110 }
111
112 1;