Debian Codegraph @

src/storage/netgear/readynas/snmp/mode/components/temperature.pm

raw
1 #
2 # Copyright 2018 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 # Author : ArnoMLT
21 #
22
23 package storage::netgear::readynas::snmp::mode::components::temperature;
24
25 use strict;
26 use warnings;
27
28 my $mapping = {
29 v6 => {
30 temperatureValue => { oid => '.1.3.6.1.4.1.4526.22.5.1.2' },
31 temperatureType => { oid => '.1.3.6.1.4.1.4526.22.5.1.3' },
32 },
33 v4 => {
34 temperatureValue => { oid => '.1.3.6.1.4.1.4526.18.5.1.2' },
35 temperatureStatus => { oid => '.1.3.6.1.4.1.4526.18.5.1.3' }
36 }
37 };
38 my $oid_temperatureTable = {
39 v4 => '.1.3.6.1.4.1.4526.18.5',
40 v6 => '.1.3.6.1.4.1.4526.22.5'
41 };
42
43 sub load {
44 my ($self) = @_;
45
46 push @{$self->{request}}, {
47 oid => $oid_temperatureTable->{$self->{mib_ver}},
48 start => $mapping->{$self->{mib_ver}}->{temperatureValue}->{oid}
49 };
50 }
51
52 sub check {
53 my ($self) = @_;
54
55 $self->{output}->output_add(long_msg => "checking temperatures");
56 $self->{components}->{temperature} = { name => 'temperatures', total => 0, skip => 0 };
57 return if ($self->check_filter(section => 'temperature'));
58
59 foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{ $oid_temperatureTable->{$self->{mib_ver}} }})) {
60 next if ($oid !~ /^$mapping->{$self->{mib_ver}}->{temperatureValue}->{oid}\.(.*)$/);
61 my $instance = $1;
62 my $result = $self->{snmp}->map_instance(mapping => $mapping->{$self->{mib_ver}}, results => $self->{results}->{ $oid_temperatureTable->{$self->{mib_ver}} }, instance => $instance);
63 $instance .= "_" . $result->{temperatureType} if (defined($result->{temperatureType}));
64
65 next if ($self->check_filter(section => 'temperature', instance => $instance));
66 $self->{components}->{temperature}->{total}++;
67
68 my $temperature_unit = $self->{mib_ver} eq 'v6' ? 'C' : 'F';
69 my $temperature_status = defined($result->{temperatureStatus}) ? $result->{temperatureStatus} : 'n/a';
70
71 $self->{output}->output_add(
72 long_msg => sprintf(
73 "temperature '%s' status is %s [value = %s%s]",
74 $instance,
75 defined($result->{temperatureStatus}) ? $result->{temperatureStatus} : 'n/a',
76 $result->{temperatureValue},
77 $temperature_unit
78 )
79 );
80 my $exit = $self->get_severity(label => 'default', section => 'temperature', value => $temperature_status);
81 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
82 $self->{output}->output_add(
83 severity => $exit,
84 short_msg => sprintf("Temperature '%s' status is %s.", $instance, $temperature_status)
85 );
86 }
87
88 my ($exit2, $warn, $crit) = $self->get_severity_numeric(section => 'temperature', instance => $instance, value => $result->{temperatureValue});
89 if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) {
90 $self->{output}->output_add(
91 severity => $exit2,
92 short_msg => sprintf("Temperature '%s' is %s%s", $instance, $result->{temperatureValue}, $temperature_unit)
93 );
94 }
95 $self->{output}->perfdata_add(
96 label => 'temp', unit => $temperature_unit,
97 nlabel => 'hardware.temperature.' . (($temperature_unit eq 'C') ? 'celsius' : 'fahrenheit'),
98 instances => $instance,
99 value => $result->{temperatureValue},
100 warning => $warn,
101 critical => $crit
102 );
103 }
104 }
105
106 1;