Debian Codegraph @

src/storage/quantum/scalar/snmp/mode/components/temperature.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::quantum::scalar::snmp::mode::components::temperature;
22
23 use strict;
24 use warnings;
25 use storage::quantum::scalar::snmp::mode::components::resources qw($map_sensor_status);
26
27 # In MIB 'QUANTUM-MIDRANGE-TAPE-LIBRARY-MIB'
28 my $mapping = {
29 libraryTemperatureSensorName => { oid => '.1.3.6.1.4.1.3697.1.10.15.5.120.2.2.1.2' },
30 libraryTemperatureSensorLocation => { oid => '.1.3.6.1.4.1.3697.1.10.15.5.120.2.2.1.3' },
31 libraryTemperatureSensorStatus => { oid => '.1.3.6.1.4.1.3697.1.10.15.5.120.2.2.1.4', map => $map_sensor_status },
32 libraryTemperatureSensorValue => { oid => '.1.3.6.1.4.1.3697.1.10.15.5.120.2.2.1.5' },
33 };
34 my $oid_libraryTemperatureSensorEntry = '.1.3.6.1.4.1.3697.1.10.15.5.120.2.2.1';
35
36 sub load {
37 my ($self) = @_;
38
39 push @{$self->{request}}, { oid => $oid_libraryTemperatureSensorEntry };
40 }
41
42 sub check {
43 my ($self) = @_;
44
45 $self->{output}->output_add(long_msg => "checking temperatures");
46 $self->{components}->{temperature} = {name => 'temperatures', total => 0, skip => 0};
47 return if ($self->check_filter(section => 'temperature'));
48
49 my ($exit, $warn, $crit, $checked);
50 foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_libraryTemperatureSensorEntry}})) {
51 next if ($oid !~ /^$mapping->{libraryTemperatureSensorStatus}->{oid}\.(.*)$/);
52 my $instance = $1;
53 my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_libraryTemperatureSensorEntry}, instance => $instance);
54
55 next if ($self->check_filter(section => 'temperature', instance => $instance));
56 $self->{components}->{temperature}->{total}++;
57
58 $self->{output}->output_add(long_msg => sprintf("temperature '%s' status is '%s' [instance = %s] [value = %s]",
59 $result->{libraryTemperatureSensorLocation}, $result->{libraryTemperatureSensorStatus}, $instance,
60 $result->{libraryTemperatureSensorValue}));
61
62 $exit = $self->get_severity(label => 'default', section => 'temperature', instance => $instance, value => $result->{libraryTemperatureSensorStatus});
63 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
64 $self->{output}->output_add(severity => $exit,
65 short_msg => sprintf("Temperature '%s' status is '%s'", $result->{libraryTemperatureSensorLocation}, $result->{libraryTemperatureSensorStatus}));
66 }
67
68 next if (!defined($result->{libraryTemperatureSensorValue}) || $result->{libraryTemperatureSensorValue} !~ /[0-9]/);
69
70 ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, value => $result->{libraryTemperatureSensorValue});
71 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
72 $self->{output}->output_add(
73 severity => $exit,
74 short_msg => sprintf("Temperature '%s' is %s degree centigrade", $result->{libraryTemperatureSensorLocation}, $result->{libraryTemperatureSensorValue})
75 );
76 }
77
78 $self->{output}->perfdata_add(
79 nlabel => 'hardware.sensor.temperature.celsius', unit => 'C',
80 instances => $result->{libraryTemperatureSensorLocation},
81 value => $result->{libraryTemperatureSensorValue},
82 warning => $warn,
83 critical => $crit,
84 );
85 }
86 }
87
88 1;