Debian Codegraph @

src/storage/qnap/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::qnap::snmp::mode::components::temperature;
22
23 use strict;
24 use warnings;
25
26 my $mapping = {
27 legacy => {
28 cpu_temp => { oid => '.1.3.6.1.4.1.24681.1.2.5' }, # cpu-Temperature
29 system_temp => { oid => '.1.3.6.1.4.1.24681.1.2.6' } # systemTemperature
30 },
31 qts => {
32 cpu_temp => { oid => '.1.3.6.1.4.1.55062.1.12.10' }, # cpuTemperature
33 system_temp => { oid => '.1.3.6.1.4.1.55062.1.12.11' } # systemTemperature
34 },
35 ex => {
36 cpu_temp => { oid => '.1.3.6.1.4.1.24681.1.3.5' }, # cpu-TemperatureEX
37 system_temp => { oid => '.1.3.6.1.4.1.24681.1.3.6' } # systemTemperatureEX
38 },
39 es => {
40 cpu_temp => { oid => '.1.3.6.1.4.1.24681.2.2.5' }, # es-CPU-Temperature
41 system_temp => { oid => '.1.3.6.1.4.1.24681.2.2.6' } # es-SystemTemperature1
42 }
43 };
44
45 sub load {}
46
47 sub check_temp_result {
48 my ($self, %options) = @_;
49
50 $options{result}->{cpu_temp} = defined($options{result}->{cpu_temp}) ? $options{result}->{cpu_temp} : 'unknown';
51 if ($options{result}->{cpu_temp} =~ /([0-9]+)\s*C?/ && !$self->check_filter(section => 'temperature', instance => 'cpu')) {
52 my $value = $1;
53 $self->{components}->{temperature}->{total}++;
54 $self->{output}->output_add(
55 long_msg => sprintf(
56 "cpu temperature is '%s' degree centigrade",
57 $value
58 )
59 );
60 my ($exit, $warn, $crit) = $self->get_severity_numeric(section => 'temperature', instance => 'cpu', value => $value);
61 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
62 $self->{output}->output_add(
63 severity => $exit,
64 short_msg => sprintf(
65 "CPU temperature is '%s' degree centigrade", $value
66 )
67 );
68 }
69 $self->{output}->perfdata_add(
70 nlabel => 'hardware.temperature.celsius',
71 unit => 'C',
72 instances => 'cpu',
73 value => $value
74 );
75 }
76
77 $options{result}->{system_temp} = defined($options{result}->{system_temp}) ? $options{result}->{system_temp} : 'unknown';
78 if ($options{result}->{system_temp} =~ /([0-9]+)\s*C?/ && !$self->check_filter(section => 'temperature', instance => 'system')) {
79 my $value = $1;
80 $self->{components}->{temperature}->{total}++;
81 $self->{output}->output_add(
82 long_msg => sprintf(
83 "system temperature is '%s' degree centigrade",
84 $value
85 )
86 );
87 my ($exit, $warn, $crit) = $self->get_severity_numeric(section => 'temperature', instance => 'system', value => $value);
88 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
89 $self->{output}->output_add(
90 severity => $exit,
91 short_msg => sprintf(
92 "System temperature is '%s' degree centigrade", $value
93 )
94 );
95 }
96 $self->{output}->perfdata_add(
97 nlabel => 'hardware.temperature.celsius',
98 unit => 'C',
99 instances => 'system',
100 value => $value
101 );
102 }
103 }
104
105 sub check_temp_qts {
106 my ($self, %options) = @_;
107
108 my $snmp_result = $self->{snmp}->get_leef(
109 oids => [ map($_->{oid} . '.0', values(%{$mapping->{qts}})) ]
110 );
111 my $result = $self->{snmp}->map_instance(mapping => $mapping->{qts}, results => $snmp_result, instance => 0);
112 check_temp_result($self, result => $result);
113 }
114
115 sub check_temp_es {
116 my ($self, %options) = @_;
117
118 my $snmp_result = $self->{snmp}->get_leef(
119 oids => [ map($_->{oid} . '.0', values(%{$mapping->{es}})) ]
120 );
121 my $result = $self->{snmp}->map_instance(mapping => $mapping->{es}, results => $snmp_result, instance => 0);
122 check_temp_result($self, result => $result);
123 }
124
125 sub check_temp {
126 my ($self, %options) = @_;
127
128 my $snmp_result = $self->{snmp}->get_leef(
129 oids => [ map($_->{oid} . '.0', values(%{$mapping->{ex}}), values(%{$mapping->{legacy}})) ],
130 );
131 my $result = $self->{snmp}->map_instance(mapping => $mapping->{ex}, results => $snmp_result, instance => 0);
132 if (defined($result->{cpu_temp})) {
133 check_temp_result($self, result => $result);
134 } else {
135 $result = $self->{snmp}->map_instance(mapping => $mapping->{legacy}, results => $snmp_result, instance => 0);
136 check_temp_result($self, result => $result);
137 }
138 }
139
140 sub check {
141 my ($self) = @_;
142
143 $self->{output}->output_add(long_msg => "Checking temperatures");
144 $self->{components}->{temperature} = { name => 'temperatures', total => 0, skip => 0 };
145 return if ($self->check_filter(section => 'temperature'));
146
147 if ($self->{is_qts} == 1) {
148 check_temp_qts($self);
149 } elsif ($self->{is_es} == 1) {
150 check_temp_es($self);
151 } else {
152 check_temp($self);
153 }
154 }
155
156 1;