Debian Codegraph @

src/storage/hitachi/hcp/snmp/mode/nodes.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::hitachi::hcp::snmp::mode::nodes;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27 use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
28
29 sub custom_node_status_output {
30 my ($self, %options) = @_;
31
32 return sprintf(
33 "node status: %s",
34 $self->{result_values}->{node_status}
35 );
36 }
37
38 sub custom_nic_status_output {
39 my ($self, %options) = @_;
40
41 return sprintf(
42 "nic status: %s",
43 $self->{result_values}->{nic_status}
44 );
45 }
46
47 sub custom_san_path_status_output {
48 my ($self, %options) = @_;
49
50 return sprintf(
51 "san path status: %s",
52 $self->{result_values}->{san_path_status}
53 );
54 }
55
56 sub custom_bbu_status_output {
57 my ($self, %options) = @_;
58
59 return sprintf(
60 "battery backup unit status: %s",
61 $self->{result_values}->{bbu_status}
62 );
63 }
64
65 sub custom_space_usage_output {
66 my ($self, %options) = @_;
67
68 my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total});
69 my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used});
70 my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free});
71 return sprintf(
72 "space usage total: %s used: %s (%.2f%%) free: %s (%.2f%%)",
73 $total_size_value . " " . $total_size_unit,
74 $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used},
75 $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}
76 );
77 }
78
79 sub node_long_output {
80 my ($self, %options) = @_;
81
82 return sprintf(
83 "checking node '%s' [ip address: %s]",
84 $options{instance_value}->{node_id},
85 $options{instance_value}->{ip_address}
86 );
87 }
88
89 sub prefix_node_output {
90 my ($self, %options) = @_;
91
92 return sprintf(
93 "node '%s' [ip address: %s] ",
94 $options{instance_value}->{node_id},
95 $options{instance_value}->{ip_address}
96 );
97 }
98
99 sub prefix_temperature_output {
100 my ($self, %options) = @_;
101
102 return "temperature '" . $options{instance_value}->{name} . "' ";
103 }
104
105 sub prefix_fan_output {
106 my ($self, %options) = @_;
107
108 return "fan '" . $options{instance_value}->{name} . "' ";
109 }
110
111 sub prefix_voltage_output {
112 my ($self, %options) = @_;
113
114 return "voltage '" . $options{instance_value}->{name} . "' ";
115 }
116
117 sub set_counters {
118 my ($self, %options) = @_;
119
120 $self->{maps_counters_type} = [
121 { name => 'nodes', type => 3, cb_prefix_output => 'prefix_node_output', cb_long_output => 'node_long_output',
122 indent_long_output => ' ', message_multiple => 'All nodes are ok',
123 group => [
124 { name => 'status', type => 0, skipped_code => { -10 => 1 } },
125 { name => 'space', type => 0, skipped_code => { -10 => 1 } },
126 { name => 'temperatures', type => 1, cb_prefix_output => 'prefix_temperature_output', skipped_code => { -10 => 1 } },
127 { name => 'fans', type => 1, cb_prefix_output => 'prefix_fan_output', skipped_code => { -10 => 1 } },
128 { name => 'voltages', type => 1, cb_prefix_output => 'prefix_voltage_output', skipped_code => { -10 => 1 } }
129 ]
130 }
131 ];
132
133 $self->{maps_counters}->{status} = [
134 { label => 'node-status', type => 2, critical_default => '%{node_status} eq "unavailable"', set => {
135 key_values => [
136 { name => 'node_status' }, { name => 'node_id' }
137 ],
138 closure_custom_output => $self->can('custom_node_status_output'),
139 closure_custom_perfdata => sub { return 0; },
140 closure_custom_threshold_check => \&catalog_status_threshold_ng
141 }
142 },
143 { label => 'nic-status', type => 2, critical_default => '%{nic_status} eq "failed"', set => {
144 key_values => [
145 { name => 'nic_status' }, { name => 'node_id' }
146 ],
147 closure_custom_output => $self->can('custom_nic_status_output'),
148 closure_custom_perfdata => sub { return 0; },
149 closure_custom_threshold_check => \&catalog_status_threshold_ng
150 }
151 },
152 { label => 'san-path-status', type => 2, critical_default => '%{san_path_status} eq "error"', set => {
153 key_values => [
154 { name => 'san_path_status' }, { name => 'node_id' }
155 ],
156 closure_custom_output => $self->can('custom_san_path_status_output'),
157 closure_custom_perfdata => sub { return 0; },
158 closure_custom_threshold_check => \&catalog_status_threshold_ng
159 }
160 },
161 { label => 'bbu-status', type => 2, critical_default => '%{bbu_status} !~ /healthy/i', set => {
162 key_values => [
163 { name => 'bbu_status' }, { name => 'node_id' }
164 ],
165 closure_custom_output => $self->can('custom_bbu_status_output'),
166 closure_custom_perfdata => sub { return 0; },
167 closure_custom_threshold_check => \&catalog_status_threshold_ng
168 }
169 }
170 ];
171
172 $self->{maps_counters}->{space} = [
173 { label => 'space-usage', nlabel => 'node.space.usage.bytes', set => {
174 key_values => [ { name => 'used' }, { name => 'free' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ],
175 closure_custom_output => $self->can('custom_space_usage_output'),
176 perfdatas => [
177 { template => '%d', min => 0, max => 'total', unit => 'B', cast_int => 1, label_extra_instance => 1 }
178 ]
179 }
180 },
181 { label => 'space-usage-free', display_ok => 0, nlabel => 'node.space.free.bytes', set => {
182 key_values => [ { name => 'free' }, { name => 'used' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ],
183 closure_custom_output => $self->can('custom_space_usage_output'),
184 perfdatas => [
185 { template => '%d', min => 0, max => 'total', unit => 'B', cast_int => 1, label_extra_instance => 1 }
186 ]
187 }
188 },
189 { label => 'space-usage-prct', display_ok => 0, nlabel => 'node.space.usage.percentage', set => {
190 key_values => [ { name => 'prct_used' }, { name => 'used' }, { name => 'free' }, { name => 'prct_free' }, { name => 'total' } ],
191 closure_custom_output => $self->can('custom_space_usage_output'),
192 perfdatas => [
193 { template => '%.2f', min => 0, max => 100, unit => '%', label_extra_instance => 1 }
194 ]
195 }
196 }
197 ];
198
199 $self->{maps_counters}->{temperatures} = [
200 { label => 'sensor-temperature', nlabel => 'node.sensor.temperature.celsius', display_ok => 0, set => {
201 key_values => [ { name => 'value' } ],
202 output_template => 'is %s C',
203 perfdatas => [
204 { template => '%s', unit => 'C', label_extra_instance => 1 }
205 ]
206 }
207 }
208 ];
209
210 $self->{maps_counters}->{fans} = [
211 { label => 'sensor-fan-speed', nlabel => 'node.sensor.fan.speed.rpm', display_ok => 0, set => {
212 key_values => [ { name => 'value' } ],
213 output_template => 'is %s rpm',
214 perfdatas => [
215 { template => '%s', min => 0, unit => 'rpm', label_extra_instance => 1 }
216 ]
217 }
218 }
219 ];
220
221 $self->{maps_counters}->{voltages} = [
222 { label => 'sensor-voltage', nlabel => 'node.sensor.voltage.volt', display_ok => 0, set => {
223 key_values => [ { name => 'value' } ],
224 output_template => 'is %s V',
225 perfdatas => [
226 { template => '%s', unit => 'V', label_extra_instance => 1 }
227 ]
228 }
229 }
230 ];
231 }
232
233 sub new {
234 my ($class, %options) = @_;
235 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
236 bless $self, $class;
237
238 $options{options}->add_options(arguments => {
239 'filter-node-id:s' => { name => 'filter_node_id' }
240 });
241
242 return $self;
243 }
244
245 my $map_node_status = {
246 0 => 'unavailable', 4 => 'available'
247 };
248 my $map_nic_failure = {
249 1 => 'error', # yes
250 2 => 'ok' # no
251 };
252 my $map_san_path_status = {
253 0 => 'error', 1 => 'rain', 2 => 'sanWithoutMultipath', 3 => 'sanGood', 4 => 'sanDegradedToOne'
254 };
255 my $mapping = {
256 space_free => { oid => '.1.3.6.1.4.1.116.5.46.1.1.1.4' }, # nodeAvailability
257 space_total => { oid => '.1.3.6.1.4.1.116.5.46.1.1.1.5' }, # nodeCapacity
258 node_status => { oid => '.1.3.6.1.4.1.116.5.46.1.1.1.7', map => $map_node_status }, # nodeStatus
259 nic_status => { oid => '.1.3.6.1.4.1.116.5.46.1.1.1.11', map => $map_nic_failure }, # nodeNicFailure
260 san_path_status => { oid => '.1.3.6.1.4.1.116.5.46.1.1.1.12', map => $map_san_path_status }, # nodeSANStatus
261 bbu_status => { oid => '.1.3.6.1.4.1.116.5.46.1.7.1.1' } # bbuBroken
262 };
263 my $mapping_temperature = {
264 name => { oid => '.1.3.6.1.4.1.116.5.46.1.2.1.1' }, # ipmiTemperatureName
265 value => { oid => '.1.3.6.1.4.1.116.5.46.1.2.1.2' } # ipmiTemperatureDetailedStatus (example: "25.0C (77.0F); (range 0.0-43.0C)")
266 };
267 my $oid_temperature_entry = '.1.3.6.1.4.1.116.5.46.1.2.1'; # hcpIpmiTemperatureNodeTableEntry
268
269 my $mapping_fan = {
270 name => { oid => '.1.3.6.1.4.1.116.5.46.1.4.1.1' }, # ipmiFanName
271 value => { oid => '.1.3.6.1.4.1.116.5.46.1.4.1.2' } # ipmiFanDetailedStatus (example: "5100.0 RPM")
272 };
273 my $oid_fan_entry = '.1.3.6.1.4.1.116.5.46.1.4.1'; # hcpIpmiFanNodeTableEntry
274
275 my $mapping_voltage = {
276 name => { oid => '.1.3.6.1.4.1.116.5.46.1.6.1.1' }, # ipmiVoltageName
277 value => { oid => '.1.3.6.1.4.1.116.5.46.1.6.1.2' } # ipmiVoltageDetailedStatus (example: "1.22 Volts (1.08-1.32 Volts)")
278 };
279 my $oid_voltage_entry = '.1.3.6.1.4.1.116.5.46.1.6.1'; # hcpIpmiVoltageNodeTableEntry
280
281 sub add_temperatures {
282 my ($self, %options) = @_;
283
284 my $snmp_result = $options{snmp}->get_table(oid => $oid_temperature_entry);
285 foreach (keys %$snmp_result) {
286 next if (! /$mapping_temperature->{value}->{oid}\.(\d+)\.(\d+)$/);
287 my ($number, $index) = ($1, $2);
288 next if (!defined($self->{nodes}->{$number}));
289
290 my $result = $options{snmp}->map_instance(mapping => $mapping_temperature, results => $snmp_result, instance => $number . '.' . $index);
291 my $value;
292 $value = $1 if ($result->{value} =~ /^\s*([0-9\.]+)\s*C/);
293 $self->{nodes}->{$number}->{temperatures}->{ $result->{name} } = {
294 name => $result->{name},
295 value => $value
296 };
297 }
298 }
299
300 sub add_fans {
301 my ($self, %options) = @_;
302
303 my $snmp_result = $options{snmp}->get_table(oid => $oid_fan_entry);
304 foreach (keys %$snmp_result) {
305 next if (! /$mapping_fan->{value}->{oid}\.(\d+)\.(\d+)$/);
306 my ($number, $index) = ($1, $2);
307 next if (!defined($self->{nodes}->{$number}));
308
309 my $result = $options{snmp}->map_instance(mapping => $mapping_fan, results => $snmp_result, instance => $number . '.' . $index);
310 my $value;
311 $value = $1 if ($result->{value} =~ /^\s*([0-9]+)/);
312 $self->{nodes}->{$number}->{fans}->{ $result->{name} } = {
313 name => $result->{name},
314 value => $value
315 };
316 }
317 }
318
319 sub add_voltages {
320 my ($self, %options) = @_;
321
322 my $snmp_result = $options{snmp}->get_table(oid => $oid_voltage_entry);
323 foreach (keys %$snmp_result) {
324 next if (! /$mapping_voltage->{value}->{oid}\.(\d+)\.(\d+)$/);
325 my ($number, $index) = ($1, $2);
326 next if (!defined($self->{nodes}->{$number}));
327
328 my $result = $options{snmp}->map_instance(mapping => $mapping_voltage, results => $snmp_result, instance => $number . '.' . $index);
329 my $value;
330 $value = $1 if ($result->{value} =~ /^\s*([0-9\.]+)/);
331 $self->{nodes}->{$number}->{voltages}->{ $result->{name} } = {
332 name => $result->{name},
333 value => $value
334 };
335 }
336 }
337
338 sub manage_selection {
339 my ($self, %options) = @_;
340
341 my $oid_nodeIP = '.1.3.6.1.4.1.116.5.46.1.1.1.2';
342 my $snmp_result = $options{snmp}->get_table(
343 oid => $oid_nodeIP,
344 nothing_quit => 1
345 );
346
347 $self->{nodes} = {};
348 foreach (keys %$snmp_result) {
349 /\.(\d+)$/;
350 my $number = $1;
351
352 if (defined($self->{option_results}->{filter_node_id}) && $self->{option_results}->{filter_node_id} ne '' &&
353 $number !~ /$self->{option_results}->{filter_node_id}/) {
354 $self->{output}->output_add(long_msg => "skipping node '" . $number . "'.", debug => 1);
355 next;
356 }
357
358 $self->{nodes}->{$number} = {
359 node_id => $number,
360 ip_address => $snmp_result->{$_},
361 status => { node_id => $number },
362 space => {},
363 temperatures => {},
364 fans => {}
365 };
366 }
367
368 return if (scalar(keys %{$self->{nodes}}) <= 0);
369
370 $options{snmp}->load(
371 oids => [ map($_->{oid}, values(%$mapping)) ],
372 instances => [ keys %{$self->{nodes}} ],
373 instance_regexp => '^(.*)$'
374 );
375 $snmp_result = $options{snmp}->get_leef();
376 foreach (keys %{$self->{nodes}}) {
377 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $_);
378
379 $self->{nodes}->{$_}->{status}->{node_status} = $result->{node_status};
380 $self->{nodes}->{$_}->{status}->{nic_status} = $result->{nic_status};
381 $self->{nodes}->{$_}->{status}->{san_path_status} = $result->{san_path_status};
382 $self->{nodes}->{$_}->{status}->{bbu_status} = $result->{bbu_status};
383
384 next if (!defined($result->{space_total}));
385
386 $self->{nodes}->{$_}->{space}->{total} = $result->{space_total};
387 $self->{nodes}->{$_}->{space}->{free} = $result->{space_free};
388 $self->{nodes}->{$_}->{space}->{used} = $result->{space_total} - $result->{space_free};
389 $self->{nodes}->{$_}->{space}->{prct_free} = $result->{space_free} * 100 / $result->{space_total};
390 $self->{nodes}->{$_}->{space}->{prct_used} = 100 - $self->{nodes}->{$_}->{space}->{prct_free};
391 }
392
393 $self->add_temperatures(snmp => $options{snmp});
394 $self->add_fans(snmp => $options{snmp});
395 $self->add_voltages(snmp => $options{snmp});
396 }
397
398 1;
399
400 __END__
401
402 =head1 MODE
403
404 Check nodes.
405
406 =over 8
407
408 =item B<--filter-node-id>
409
410 Filter nodes by ID (can be a regexp).
411
412 =item B<--unknown-node-status>
413
414 Define the conditions to match for the status to be UNKNOWN.
415 You can use the following variables: %{node_status}, %{node_id}
416
417 =item B<--warning-node-status>
418
419 Define the conditions to match for the status to be WARNING.
420 You can use the following variables: %{node_status}, %{node_id}
421
422 =item B<--critical-node-status>
423
424 Define the conditions to match for the status to be CRITICAL (default: '%{node_status} eq "unavailable"').
425 You can use the following variables: %{node_status}, %{node_id}
426
427 =item B<--unknown-nic-status>
428
429 Define the conditions to match for the status to be UNKNOWN.
430 You can use the following variables: %{nic_status}, %{node_id}
431
432 =item B<--warning-nic-status>
433
434 Define the conditions to match for the status to be WARNING.
435 You can use the following variables: %{nic_status}, %{node_id}
436
437 =item B<--critical-nic-status>
438
439 Define the conditions to match for the status to be CRITICAL (default: '%{nic_status} eq "failed"').
440 You can use the following variables: %{nic_status}, %{node_id}
441
442 =item B<--unknown-san-path-status>
443
444 Define the conditions to match for the status to be UNKNOWN.
445 You can use the following variables: %{san_path_status}, %{node_id}
446
447 =item B<--warning-san-path-status>
448
449 Define the conditions to match for the status to be WARNING.
450 You can use the following variables: %{san_path_status}, %{node_id}
451
452 =item B<--critical-san-path-status>
453
454 Define the conditions to match for the status to be CRITICAL (default: '%{san_path_status} eq "error"').
455 You can use the following variables: %{san_path_status}, %{node_id}
456
457 =item B<--unknown-bbu-status>
458
459 Define the conditions to match for the status to be UNKNOWN.
460 You can use the following variables: %{bbu_status}, %{node_id}
461
462 =item B<--warning-bbu-status>
463
464 Define the conditions to match for the status to be WARNING.
465 You can use the following variables: %{bbu_status}, %{node_id}
466
467 =item B<--critical-bbu-status>
468
469 Define the conditions to match for the status to be CRITICAL (default: '%{bbu_status} !~ /healthy/i').
470 You can use the following variables: %{bbu_status}, %{node_id}
471
472 =item B<--warning-*> B<--critical-*>
473
474 Thresholds.
475 Can be: 'space-usage-prct', 'space-usage', 'space-usage-free',
476 'sensor-voltage' (V), 'sensor-temperature' (C), 'sensor-fan-speed' (rpm).
477
478 =back
479
480 =cut