Debian Codegraph @

src/storage/netapp/ontap/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::netapp::ontap::snmp::mode::components::temperature;
22
23 use strict;
24 use warnings;
25
26 my %map_hum_status = (
27 1 => 'noStatus',
28 2 => 'normal',
29 3 => 'highWarning',
30 4 => 'highCritical',
31 5 => 'lowWarning',
32 6 => 'lowCritical',
33 7 => 'sensorError',
34 );
35 my %map_hum_online = (
36 1 => 'online',
37 2 => 'offline',
38 );
39
40 my $mapping = {
41 enclTempSensorsPresent => { oid => '.1.3.6.1.4.1.789.1.21.1.2.1.20' },
42 enclTempSensorsOverTempFail => { oid => '.1.3.6.1.4.1.789.1.21.1.2.1.21' },
43 enclTempSensorsOverTempWarn => { oid => '.1.3.6.1.4.1.789.1.21.1.2.1.22' },
44 enclTempSensorsUnderTempFail => { oid => '.1.3.6.1.4.1.789.1.21.1.2.1.23' },
45 enclTempSensorsUnderTempWarn => { oid => '.1.3.6.1.4.1.789.1.21.1.2.1.24' },
46 enclTempSensorsCurrentTemp => { oid => '.1.3.6.1.4.1.789.1.21.1.2.1.25' },
47 enclTempSensorsOverTempFailThr => { oid => '.1.3.6.1.4.1.789.1.21.1.2.1.26' },
48 enclTempSensorsOverTempWarnThr => { oid => '.1.3.6.1.4.1.789.1.21.1.2.1.27' },
49 enclTempSensorsUnderTempFailThr => { oid => '.1.3.6.1.4.1.789.1.21.1.2.1.28' },
50 enclTempSensorsUnderTempWarnThr => { oid => '.1.3.6.1.4.1.789.1.21.1.2.1.29' },
51 };
52 my $oid_enclChannelShelfAddr = '.1.3.6.1.4.1.789.1.21.1.2.1.3';
53 my $oid_enclEntry = '.1.3.6.1.4.1.789.1.21.1.2.1';
54
55 sub load {
56 my ($self) = @_;
57
58 push @{$self->{request}}, { oid => $oid_enclEntry, start => $mapping->{enclTempSensorsPresent}->{oid}, end => $mapping->{enclTempSensorsUnderTempWarnThr}->{oid} };
59 }
60
61 sub check {
62 my ($self) = @_;
63
64 $self->{output}->output_add(long_msg => "Checking temperatures");
65 $self->{components}->{temperature} = {name => 'temperatures', total => 0, skip => 0};
66 return if ($self->check_filter(section => 'temperature'));
67
68 for (my $i = 1; $i <= $self->{number_shelf}; $i++) {
69 my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_enclEntry}, instance => $i);
70 my $shelf_addr = $self->{shelf_addr}->{$oid_enclChannelShelfAddr . '.' . $i};
71 my @current_temp = split /,/, $result->{enclTempSensorsCurrentTemp};
72
73 my @warn_under_thr = split /,/, $result->{enclTempSensorsUnderTempWarnThr};
74 my @crit_under_thr = split /,/, $result->{enclTempSensorsUnderTempFailThr};
75 my @warn_over_thr = split /,/, $result->{enclTempSensorsOverTempWarnThr};
76 my @crit_over_thr = split /,/, $result->{enclTempSensorsOverTempFailThr};
77
78 foreach my $num (split /,/, $result->{enclTempSensorsPresent}) {
79 $num = centreon::plugins::misc::trim($num);
80 next if ($num !~ /[0-9]/ || !defined($current_temp[$num - 1]));
81
82 next if ($self->check_filter(section => 'temperature', instance => $shelf_addr . '.' . $num));
83
84 $warn_under_thr[$num - 1] =~ /(-*[0-9]+)C/;
85 my $wu_thr = $1;
86 $crit_under_thr[$num - 1] =~ /(-*[0-9]+)C/;
87 my $cu_thr = $1;
88 $warn_over_thr[$num - 1] =~ /(-*[0-9]+)C/;
89 my $wo_thr = $1;
90 $crit_over_thr[$num - 1] =~ /(-*[0-9]+)C/;
91 my $co_thr = $1;
92 $current_temp[$num - 1] =~ /(-*[0-9]+)C/;
93 my $current_value = $1;
94
95 $self->{components}->{temperature}->{total}++;
96
97 my $status = 'ok';
98 if ($result->{enclTempSensorsUnderTempFailThr} =~ /(^|,|\s)$num(,|\s|$)/) {
99 $status = 'under critical threshold';
100 } elsif ($result->{enclTempSensorsUnderTempWarnThr} =~ /(^|,|\s)$num(,|\s|$)/) {
101 $status = 'under warning threshold';
102 } elsif ($result->{enclTempSensorsOverTempFailThr} =~ /(^|,|\s)$num(,|\s|$)/) {
103 $status = 'over critical threshold';
104 } elsif ($result->{enclTempSensorsOverTempWarnThr} =~ /(^|,|\s)$num(,|\s|$)/) {
105 $status = 'over warning threshold';
106 }
107
108 $self->{output}->output_add(long_msg => sprintf("Shelve '%s' temperature sensor '%s' is %s [current = %s]",
109 $shelf_addr, $num, $status, $current_value));
110 my $exit = $self->get_severity(section => 'temperature', value => $status);
111 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
112 $self->{output}->output_add(severity => $exit,
113 short_msg => sprintf("Shelve '%s' temperature sensor '%s' is %s",
114 $shelf_addr, $num, $status));
115 }
116
117 my $warn = $wu_thr . ':' . $wo_thr;
118 my $crit = $cu_thr . ':' . $co_thr;
119 my ($exit2, $warn2, $crit2, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $shelf_addr . '.' . $num, value => $current_value);
120 if ($checked == 1) {
121 ($warn, $crit) = ($warn2, $crit2);
122 }
123
124 if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) {
125 $self->{output}->output_add(severity => $exit2,
126 short_msg => sprintf("Shelve '%s' temperature sensor '%s' is %s degree centigrade",
127 $shelf_addr, $num, $current_value));
128 }
129
130 $self->{output}->perfdata_add(
131 label => "temp", unit => 'C',
132 nlabel => 'hardware.temperature.celsius',
133 instances => [$shelf_addr, $num],
134 value => $current_value,
135 warning => $warn,
136 critical => $crit
137 );
138 }
139 }
140 }
141
142 1;