Debian Codegraph @

src/hardware/server/fujitsu/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 hardware::server::fujitsu::snmp::mode::components::temperature;
22
23 use strict;
24 use warnings;
25
26 my $map_sc_temp_status = {
27 1 => 'unknown', 2 => 'sensor-disabled', 3 => 'ok', 4 => 'sensor-fail',
28 5 => 'warning-temp-warm', 6 => 'warning-temp-cold', 7 => 'critical-temp-warm',
29 8 => 'critical-temp-cold', 9 => 'damage-temp-warm', 10 => 'damage-temp-cold', 99 => 'not-available'
30 };
31 my $map_sc2_temp_status = {
32 1 => 'unknown', 2 => 'not-available', 3 => 'ok', 4 => 'sensor-failed', 5 => 'failed',
33 6 => 'temperature-warning-toohot', 7 => 'temperature-critical-toohot', 8 => 'temperature-normal',
34 9 => 'temperature-warning'
35 };
36
37 my $mapping = {
38 sc => {
39 tempSensorStatus => { oid => '.1.3.6.1.4.1.231.2.10.2.2.5.2.1.1.3', map => $map_sc_temp_status },
40 tempCurrentValue => { oid => '.1.3.6.1.4.1.231.2.10.2.2.5.2.1.1.11' },
41 tempSensorDesignation => { oid => '.1.3.6.1.4.1.231.2.10.2.2.5.2.1.1.13' }
42 },
43 sc2 => {
44 sc2tempSensorDesignation => { oid => '.1.3.6.1.4.1.231.2.10.2.2.10.5.1.1.3' },
45 sc2tempSensorStatus => { oid => '.1.3.6.1.4.1.231.2.10.2.2.10.5.1.1.5', map => $map_sc2_temp_status },
46 sc2tempCurrentTemperature => { oid => '.1.3.6.1.4.1.231.2.10.2.2.10.5.1.1.6' }
47 }
48 };
49 my $oid_sc2TemperatureSensors = '.1.3.6.1.4.1.231.2.10.2.2.10.5.1.1';
50 my $oid_temperatureSensors = '.1.3.6.1.4.1.231.2.10.2.2.5.2.1.1';
51
52 sub load {
53 my ($self) = @_;
54
55 push @{$self->{request}}, { oid => $oid_sc2TemperatureSensors, end => $mapping->{sc2}->{sc2tempCurrentTemperature} }, { oid => $oid_temperatureSensors };
56 }
57
58 sub check_temperature {
59 my ($self, %options) = @_;
60
61 my ($exit, $warn, $crit, $checked);
62 foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$options{entry}}})) {
63 next if ($oid !~ /^$options{mapping}->{$options{status}}->{oid}\.(.*)$/);
64 my $instance = $1;
65 my $result = $self->{snmp}->map_instance(mapping => $options{mapping}, results => $self->{results}->{$options{entry}}, instance => $instance);
66
67 next if ($self->check_filter(section => 'temperature', instance => $instance));
68 next if ($result->{$options{status}} =~ /not-present|not-available/i &&
69 $self->absent_problem(section => 'temperature', instance => $instance));
70 $self->{components}->{temperature}->{total}++;
71
72 $self->{output}->output_add(
73 long_msg => sprintf(
74 "temperature '%s' status is '%s' [instance: %s] [value: %s]",
75 $result->{$options{name}}, $result->{$options{status}}, $instance, $result->{$options{current}}
76 )
77 );
78
79 $exit = $self->get_severity(section => 'temperature', value => $result->{$options{status}});
80 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
81 $self->{output}->output_add(
82 severity => $exit,
83 short_msg => sprintf("Temperature '%s' status is '%s'", $result->{$options{name}}, $result->{$options{status}})
84 );
85 }
86
87 next if (!defined($result->{$options{current}}) || $result->{$options{current}} <= 0 || $result->{$options{current}} == 255);
88
89 ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, value => $result->{$options{current}});
90 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
91 $self->{output}->output_add(
92 severity => $exit,
93 short_msg => sprintf("Temperature '%s' is %s V", $result->{$options{name}}, $result->{$options{current}})
94 );
95 }
96 $self->{output}->perfdata_add(
97 nlabel => 'hardware.temperature.celsius',
98 unit => 'C',
99 instances => $result->{$options{name}},
100 value => $result->{$options{current}},
101 warning => $warn,
102 critical => $crit
103 );
104 }
105 }
106
107 sub check {
108 my ($self) = @_;
109
110 $self->{output}->output_add(long_msg => 'Checking temperatures');
111 $self->{components}->{temperature} = { name => 'temperatures', total => 0, skip => 0 };
112 return if ($self->check_filter(section => 'temperature'));
113
114 if (defined($self->{results}->{$oid_sc2TemperatureSensors}) && scalar(keys %{$self->{results}->{$oid_sc2TemperatureSensors}}) > 0) {
115 check_temperature(
116 $self, entry => $oid_sc2TemperatureSensors, mapping => $mapping->{sc2}, name => 'sc2tempSensorDesignation',
117 current => 'sc2tempCurrentTemperature', status => 'sc2tempSensorStatus'
118 );
119 } else {
120 check_temperature(
121 $self, entry => $oid_temperatureSensors, mapping => $mapping->{sc}, name => 'tempSensorDesignation',
122 current => 'tempCurrentValue', status => 'tempSensorStatus'
123 );
124 }
125 }
126
127 1;