Debian Codegraph @

src/hardware/pdu/eaton/snmp/mode/environment.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::pdu::eaton::snmp::mode::environment;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27
28 use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc);
29
30 sub custom_status_output {
31 my ($self, %options) = @_;
32
33 my $msg = "status '" . $self->{result_values}->{status} . "'";
34 return $msg;
35 }
36
37 sub set_counters {
38 my ($self, %options) = @_;
39
40 $self->{maps_counters_type} = [
41 { name => 'pdu', type => 3, cb_prefix_output => 'prefix_pdu_output', cb_long_output => 'pdu_long_output', indent_long_output => ' ', message_multiple => 'All pdu sensors are ok',
42 group => [
43 { name => 'temperature', display_long => 1, cb_prefix_output => 'prefix_temperature_output', message_multiple => 'All temperature sensors are ok', type => 1, skipped_code => { -10 => 1 } },
44 { name => 'humidity', display_long => 1, cb_prefix_output => 'prefix_humidity_output', message_multiple => 'All humidity sensors are ok', type => 1, skipped_code => { -10 => 1 } },
45 ]
46 }
47 ];
48
49 $self->{maps_counters}->{temperature} = [
50 { label => 'temperature-status', threshold => 0, set => {
51 key_values => [ { name => 'status' }, { name => 'display' } ],
52 closure_custom_calc => \&catalog_status_calc,
53 closure_custom_output => $self->can('custom_status_output'),
54 closure_custom_perfdata => sub { return 0; },
55 closure_custom_threshold_check => \&catalog_status_threshold,
56 }
57 },
58 { label => 'temperature', nlabel => 'sensor.temperature.celsius', set => {
59 key_values => [ { name => 'value' }, { name => 'display' } ],
60 output_template => 'temperature %.1f C',
61 perfdatas => [
62 { value => 'value', template => '%.1f',
63 unit => 'C', label_extra_instance => 1 },
64 ],
65 }
66 },
67 ];
68
69 $self->{maps_counters}->{humidity} = [
70 { label => 'humidity-status', threshold => 0, set => {
71 key_values => [ { name => 'status' }, { name => 'display' } ],
72 closure_custom_calc => \&catalog_status_calc,
73 closure_custom_output => $self->can('custom_status_output'),
74 closure_custom_perfdata => sub { return 0; },
75 closure_custom_threshold_check => \&catalog_status_threshold,
76 }
77 },
78 { label => 'humidity', nlabel => 'sensor.humidity.percentage', set => {
79 key_values => [ { name => 'value' }, { name => 'display' } ],
80 output_template => 'humidity %.2f %%',
81 perfdatas => [
82 { value => 'value', template => '%.2f',
83 unit => '%', min => 0, max => 100, label_extra_instance => 1 },
84 ],
85 }
86 },
87 ];
88 }
89
90 sub new {
91 my ($class, %options) = @_;
92 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
93 bless $self, $class;
94
95 $options{options}->add_options(arguments => {
96 'unknown-temperature-status:s' => { name => 'unknown_temperature_status', default => '' },
97 'warning-temperature-status:s' => { name => 'warning_temperature_status', default => '' },
98 'critical-temperature-status:s' => { name => 'critical_temperature_status', default => '%{status} eq "bad"' },
99 'unknown-humidity-status:s' => { name => 'unknown_humidity_status', default => '' },
100 'warning-humidity-status:s' => { name => 'warning_humidity_status', default => '' },
101 'critical-humidity-status:s' => { name => 'critical_humidity_status', default => '%{status} eq "bad"' },
102 });
103
104 return $self;
105 }
106
107 sub check_options {
108 my ($self, %options) = @_;
109 $self->SUPER::check_options(%options);
110
111 $self->change_macros(
112 macros => [
113 'warning_temperature_status', 'critical_temperature_status', 'unknown_temperature_status',
114 'warning_humidity_status', 'critical_humidity_status', 'unknown_humidity_status',
115 ]
116 );
117 }
118
119 sub prefix_pdu_output {
120 my ($self, %options) = @_;
121
122 return "PDU '" . $options{instance_value}->{display} . "' : ";
123 }
124
125 sub pdu_long_output {
126 my ($self, %options) = @_;
127
128 return "checking pdu '" . $options{instance_value}->{display} . "'";
129 }
130
131 sub prefix_temperature_output {
132 my ($self, %options) = @_;
133
134 return "temperature '" . $options{instance_value}->{display} . "' ";
135 }
136
137 sub prefix_humidity_output {
138 my ($self, %options) = @_;
139
140 return "humidity '" . $options{instance_value}->{display} . "' ";
141 }
142
143 my $mapping_scale = { 0 => 'celsius', 1 => 'fahrenheit' };
144 my $mapping_probe = { -1 => 'bad', 0 => 'disconnected', 1 => 'connected' };
145
146 my $mapping = {
147 serialNumber => { oid => '.1.3.6.1.4.1.534.6.6.7.1.2.1.4' },
148 temperatureScale => { oid => '.1.3.6.1.4.1.534.6.6.7.1.2.1.9' },
149 };
150 my $mapping2 = {
151 temperatureName => { oid => '.1.3.6.1.4.1.534.6.6.7.7.1.1.2' },
152 temperatureProbeStatus => { oid => '.1.3.6.1.4.1.534.6.6.7.7.1.1.3', map => $mapping_probe },
153 temperatureValue => { oid => '.1.3.6.1.4.1.534.6.6.7.7.1.1.4' },
154 };
155 my $mapping3 = {
156 humidityName => { oid => '.1.3.6.1.4.1.534.6.6.7.7.2.1.2' },
157 humidityProbeStatus => { oid => '.1.3.6.1.4.1.534.6.6.7.7.2.1.3', map => $mapping_probe },
158 humidityValue => { oid => '.1.3.6.1.4.1.534.6.6.7.7.2.1.4' },
159 };
160 my $oid_unitEntry = '.1.3.6.1.4.1.534.6.6.7.1.2.1';
161 my $oid_temperatureEntry = '.1.3.6.1.4.1.534.6.6.7.7.1.1';
162 my $oid_humidityEntry = '.1.3.6.1.4.1.534.6.6.7.7.2.1';
163
164 sub manage_selection {
165 my ($self, %options) = @_;
166
167 my $snmp_result = $options{snmp}->get_multiple_table(
168 oids => [
169 { oid => $oid_unitEntry, start => $mapping->{serialNumber}->{oid}, end => $mapping->{temperatureScale}->{oid} },
170 { oid => $oid_temperatureEntry, start => $mapping2->{temperatureName}->{oid}, end => $mapping2->{temperatureValue}->{oid} },
171 { oid => $oid_humidityEntry, start => $mapping3->{humidityName}->{oid}, end => $mapping3->{humidityValue}->{oid} },
172 ],
173 nothing_quit => 1
174 );
175
176 $self->{pdu} = {};
177 foreach my $oid (keys %{$snmp_result->{$oid_unitEntry}}) {
178 next if ($oid !~ /^$mapping->{serialNumber}->{oid}\.(.*)$/);
179 my $strapping_index = $1;
180
181 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result->{$oid_unitEntry}, instance => $strapping_index);
182 my $temp_scale = $result->{temperatureScale};
183 my $pdu_serial = $result->{serialNumber};
184 $self->{pdu}->{$pdu_serial} = {
185 display => $pdu_serial,
186 temperature => {},
187 humidity => {},
188 };
189
190 foreach (keys %{$snmp_result->{$oid_temperatureEntry}}) {
191 next if (! /^$mapping2->{temperatureProbeStatus}->{oid}\.$strapping_index\.(.*)$/);
192 $result = $options{snmp}->map_instance(mapping => $mapping2, results => $snmp_result->{$oid_temperatureEntry}, instance => $strapping_index . '.' . $1);
193
194 my $name = defined($result->{temperatureName}) && $result->{temperatureName} ne '' ? $result->{temperatureName} : $1;
195 my $value = $result->{temperatureValue} / 10;
196 $value = centreon::plugins::misc::convert_fahrenheit(value => $value) if ($temp_scale eq 'fahrenheit');
197 $self->{pdu}->{$pdu_serial}->{temperature}->{$name} = {
198 display => $name,
199 status => $result->{temperatureProbeStatus},
200 value => $value,
201 };
202 }
203
204 foreach (keys %{$snmp_result->{$oid_humidityEntry}}) {
205 next if (! /^$mapping3->{humidityProbeStatus}->{oid}\.$strapping_index\.(.*)$/);
206 $result = $options{snmp}->map_instance(mapping => $mapping3, results => $snmp_result->{$oid_humidityEntry}, instance => $strapping_index . '.' . $1);
207
208 my $name = defined($result->{humidityName}) && $result->{humidityName} ne '' ? $result->{humidityName} : $1;
209 $self->{pdu}->{$pdu_serial}->{humidity}->{$name} = {
210 display => $name,
211 status => $result->{humidityProbeStatus},
212 value => $result->{humidityValue} / 10,
213 };
214 }
215 }
216
217 if (scalar(keys %{$self->{pdu}}) <= 0) {
218 $self->{output}->add_option_msg(short_msg => "No pdu found.");
219 $self->{output}->option_exit();
220 }
221 }
222
223 1;
224
225 __END__
226
227 =head1 MODE
228
229 Check pdu environmental sensors.
230
231 =over 8
232
233 =item B<--unknown-temperature-status>
234
235 Define the conditions to match for the status to be UNKNOWN (default: '').
236 You can use the following variables: %{status}, %{display}
237
238 =item B<--warning-temperature-status>
239
240 Define the conditions to match for the status to be WARNING (default: '').
241 You can use the following variables: %{status}, %{display}
242
243 =item B<--critical-temperature-status>
244
245 Define the conditions to match for the status to be CRITICAL (default: '%{status} eq "bad"').
246 You can use the following variables: %{status}, %{display}
247
248 =item B<--unknown-humidity-status>
249
250 Define the conditions to match for the status to be UNKNOWN (default: '').
251 You can use the following variables: %{status}, %{display}
252
253 =item B<--warning-humidity-status>
254
255 Define the conditions to match for the status to be WARNING (default: '').
256 You can use the following variables: %{status}, %{display}
257
258 =item B<--critical-humidity-status>
259
260 Define the conditions to match for the status to be CRITICAL (default: '%{status} eq "bad"').
261 You can use the following variables: %{status}, %{display}
262
263 =item B<--warning-*> B<--critical-*>
264
265 Thresholds.
266 Can be: 'humidity' (%), 'temperature' (C).
267
268 =back
269
270 =cut