Debian Codegraph @

src/storage/hp/3par/ssh/mode/components/sensor.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::hp::3par::ssh::mode::components::sensor;
22
23 use strict;
24 use warnings;
25 use centreon::plugins::misc;
26
27 sub load {
28 my ($self) = @_;
29
30 #Node 0
31 #---------
32 #
33 #------Measurement------ -Reading- -Lo_Limit- -Hi_Limit- -----Status-----
34 # Ambient 21 C 5 C 40 C Within Tolerance
35 # Midplane 23 C 10 C 50 C Within Tolerance
36 # PCM 0 inlet 27 C 10 C 50 C Within Tolerance
37 # SBB Canister 1 memory 42 C 5 C 82 C Within Tolerance
38 # PCM 0 (5V) 5.19 V --- --- Within Tolerance
39 # PCM 0 (40A Max) 2.77 A --- --- Within Tolerance
40 # PS0 Fan0 4380 RPM 1540 RPM 7140 RPM Within Tolerance
41 # PS0 Fan1 4080 RPM 1540 RPM 7140 RPM Within Tolerance
42
43 #
44 #Node 1
45 #---------
46 #
47 #------Measurement------ -Reading- -Lo_Limit- -Hi_Limit- -----Status-----
48 # Ambient 21 C 5 C 40 C Within Tolerance
49 # Midplane 23 C 10 C 50 C Within Tolerance
50 # PCM 0 inlet 27 C 10 C 50 C Within Tolerance
51 # PCM 0 hotspot 21 C 10 C 65 C Within Tolerance
52 # Node Input PWR 87.6 W 0.0 W 264.0 W Within Tolerance
53 # DDR40 VDDQ A 1.20 V 1.14 V 1.26 V Within Tolerance
54 # DDR40 VPP A 2.48 V 2.37 V 2.75 V Within Tolerance
55 # DDR40 VDDQ B 1.20 V 1.14 V 1.26 V Within Tolerance
56 # DDR40 VPP B 2.48 V 2.37 V 2.75 V Within Tolerance
57
58 push @{$self->{commands}}, 'echo "===shownodeenv==="', 'shownodeenv';
59 }
60
61 sub check {
62 my ($self) = @_;
63
64 $self->{output}->output_add(long_msg => "Checking sensors");
65 $self->{components}->{sensor} = { name => 'sensors', total => 0, skip => 0 };
66 return if ($self->check_filter(section => 'sensor'));
67
68 return if ($self->{results} !~ /===shownodeenv===.*?\n(.*?)(===|\Z)/msi);
69 my $content = $1;
70 my $unit_new_perf = { A => 'current.ampere', V => 'voltage.volt', W => 'power.watt', C => 'temperature.celsius', R => 'current.speed' };
71
72 while ($content =~ /^Node\s+(\d+)(.*?)(?=\nNode|\Z$)/msg) {
73 my ($node_id, $measures) = ($1, $2);
74
75 my @lines = split /\n/, $measures;
76 foreach (@lines) {
77 next if (!/^(.*?)\s+([\d.]+)\s+([CWAVR])P?M?\s+([\d.]+\s+[CWAVR]|---)P?M?\s+([\d.]+\s+[CWAVR]|---)P?M?\s+/);
78 my ($name, $reading, $unit, $lo_limit, $hi_limit) = (centreon::plugins::misc::trim($1), $2, $3, $4, $5);
79 my $instance = 'node' . $node_id . '.' . $name;
80
81 next if ($self->check_filter(section => 'sensor', instance => $instance, name => $name));
82 $self->{components}->{sensor}->{total}++;
83
84 $self->{output}->output_add(
85 long_msg => sprintf(
86 "sensor '%s' on node '%s' is %s %s [instance: %s]",
87 $name, $node_id, $reading, $unit, $instance
88 )
89 );
90
91 my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'sensor', instance => $instance, name => $name, value => $reading);
92 $lo_limit = ($lo_limit =~ s/.*?(\d+(\.\d+)?).*/$1/) ? $lo_limit : undef;
93 $hi_limit = ($hi_limit =~ s/.*?(\d+(\.\d+)?).*/$1/) ? $hi_limit : undef;
94 if ($checked == 0 && (defined($lo_limit) || defined($hi_limit))) {
95 my $warn_th = '';
96 my $crit_th = (defined($lo_limit) ? $lo_limit : '~') . ':' . (defined($hi_limit) ? $hi_limit : '~');
97 $self->{perfdata}->threshold_validate(label => 'warning-sensor-instance-' . $instance, value => $warn_th);
98 $self->{perfdata}->threshold_validate(label => 'critical-sensor-instance-' . $instance, value => $crit_th);
99
100 $exit = $self->{perfdata}->threshold_check(
101 value => $reading,
102 threshold => [
103 { label => 'critical-sensor-instance-' . $instance, exit_litteral => 'critical' },
104 { label => 'warning-sensor-instance-' . $instance, exit_litteral => 'warning' }
105 ]
106 );
107 $warn = $self->{perfdata}->get_perfdata_for_output(label => 'warning-sensor-instance-' . $instance);
108 $crit = $self->{perfdata}->get_perfdata_for_output(label => 'critical-sensor-instance-' . $instance);
109 }
110
111 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
112 $self->{output}->output_add(
113 severity => $exit,
114 short_msg => sprintf("Sensor '%s' on node '%s' is %s %s ", $name, $node_id, $reading, $unit)
115 );
116 }
117
118 $self->{output}->perfdata_add(
119 nlabel => 'hardware.sensor.' . $unit_new_perf->{$unit},
120 unit => $unit,
121 instances => ['node' . $node_id, $name],
122 value => $reading,
123 warning => $warn,
124 critical => $crit,
125 );
126 }
127 }
128 }
129
130 1;