Debian Codegraph @

src/hardware/sensors/comet/p8000/snmp/mode/sensors.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::sensors::comet::p8000::snmp::mode::sensors;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27
28 sub custom_temperature_perfdata {
29 my ($self, %options) = @_;
30
31 my ($extra_label, $unit) = ('', 'C');
32 if (!defined($options{extra_instance}) || $options{extra_instance} != 0) {
33 $extra_label .= '_' . $self->{result_values}->{display};
34 }
35 $self->{output}->perfdata_add(
36 label => $self->{label} . $extra_label, unit => $unit,
37 value => $self->{result_values}->{$self->{label} },
38 warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label} . '_' . $self->{result_values}->{display}),
39 critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label} . '_' . $self->{result_values}->{display}),
40 );
41 }
42
43 sub custom_humidity_perfdata {
44 my ($self, %options) = @_;
45
46 my ($extra_label, $unit) = ('', '%');
47 if (!defined($options{extra_instance}) || $options{extra_instance} != 0) {
48 $extra_label .= '_' . $self->{result_values}->{display};
49 }
50 $self->{output}->perfdata_add(
51 label => $self->{label} . $extra_label, unit => $unit,
52 value => $self->{result_values}->{$self->{label} },
53 warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label} . '_' . $self->{result_values}->{display}),
54 critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label} . '_' . $self->{result_values}->{display}),
55 min => 0, max => 100,
56 );
57 }
58
59 sub custom_sensor_threshold {
60 my ($self, %options) = @_;
61
62 my $warn_limit;
63 if (defined($self->{instance_mode}->{option_results}->{'warning-' . $self->{label}}) && $self->{instance_mode}->{option_results}->{'warning-' . $self->{label}} ne '') {
64 $warn_limit = $self->{instance_mode}->{option_results}->{'warning-' . $self->{label}};
65 }
66 $self->{perfdata}->threshold_validate(label => 'warning-' . $self->{label} . '_' . $self->{result_values}->{display}, value => $warn_limit);
67
68 my $crit_limit = $self->{result_values}->{limit_lo} . ':' . $self->{result_values}->{limit_hi};
69 if (defined($self->{instance_mode}->{option_results}->{'critical-' . $self->{label}}) && $self->{instance_mode}->{option_results}->{'critical-' . $self->{label}} ne '') {
70 $crit_limit = $self->{instance_mode}->{option_results}->{'critical-' . $self->{label}};
71 }
72 $self->{perfdata}->threshold_validate(label => 'critical-' . $self->{label} . '_' . $self->{result_values}->{display}, value => $crit_limit);
73
74 my $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{$self->{label} },
75 threshold => [ { label => 'critical-' . $self->{label} . '_' . $self->{result_values}->{display}, exit_litteral => 'critical' },
76 { label => 'warning-' . $self->{label} . '_' . $self->{result_values}->{display}, exit_litteral => 'warning' } ]);
77 return $exit;
78 }
79
80 sub set_counters {
81 my ($self, %options) = @_;
82
83 $self->{maps_counters_type} = [
84 { name => 'channel', type => 1, cb_prefix_output => 'prefix_channel_output', message_multiple => 'All channels are ok', skipped_code => { -10 => 1 } },
85 ];
86
87 $self->{maps_counters}->{channel} = [
88 { label => 'temperature', set => {
89 key_values => [ { name => 'temperature' }, { name => 'limit_hi' }, { name => 'limit_lo' }, { name => 'display' } ],
90 output_template => 'Temperature: %.2f C',
91 closure_custom_perfdata => $self->can('custom_temperature_perfdata'),
92 closure_custom_threshold_check => $self->can('custom_sensor_threshold'),
93 }
94 },
95 { label => 'humidity', set => {
96 key_values => [ { name => 'humidity' }, { name => 'limit_hi' }, { name => 'limit_lo' }, { name => 'display' } ],
97 output_template => 'Humidity: %.2f %%',
98 closure_custom_perfdata => $self->can('custom_humidity_perfdata'),
99 closure_custom_threshold_check => $self->can('custom_sensor_threshold'),
100 }
101 },
102 ];
103 }
104
105 sub new {
106 my ($class, %options) = @_;
107 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
108 bless $self, $class;
109
110 $options{options}->add_options(arguments => {
111 });
112
113 return $self;
114 }
115
116 sub prefix_channel_output {
117 my ($self, %options) = @_;
118
119 return "Channel '" . $options{instance_value}->{display} . "' ";
120 }
121
122 sub manage_selection {
123 my ($self, %options) = @_;
124
125 my $oid_channels = '.1.3.6.1.4.1.22626.1.5.2';
126 my $chName_suffix = '1.0';
127 my $chVal_suffix = '2.0';
128 my $chLimHi_suffix = '5.0';
129 my $chLimLo_suffix = '6.0';
130 my $chUnit_suffix = '9.0';
131
132 my $snmp_result = $options{snmp}->get_table(oid => $oid_channels, nothing_quit => 1);
133 $self->{channel} = {};
134 for my $channel ((1, 2, 3, 4)) {
135 next if (!defined($snmp_result->{$oid_channels . '.' . $channel . '.' . $chName_suffix}));
136
137 my $value = $snmp_result->{$oid_channels . '.' . $channel . '.' . $chVal_suffix};
138 # sensor not configured (n/a)
139 next if ($value !~ /[0-9\.]/);
140
141 my $name = $snmp_result->{$oid_channels . '.' . $channel . '.' . $chName_suffix};
142 my $unit = $snmp_result->{$oid_channels . '.' . $channel . '.' . $chUnit_suffix};
143 my $limit_hi = $snmp_result->{$oid_channels . '.' . $channel . '.' . $chLimHi_suffix};
144 my $limit_lo = $snmp_result->{$oid_channels . '.' . $channel . '.' . $chLimLo_suffix};
145
146 $limit_hi /= 10;
147 $limit_lo /= 10;
148 if ($unit =~ /F/i) {
149 $value = sprintf("%.2f", ($value - 32) / 1.8);
150 $limit_hi = sprintf("%.2f", ($limit_hi - 32) / 1.8);
151 $limit_lo = sprintf("%.2f", ($limit_lo - 32) / 1.8);
152 }
153
154 $self->{channel}->{$channel} = {
155 display => $name,
156 humidity => ($unit =~ /RH/) ? $value : undef,
157 temperature => ($unit =~ /F|C/) ? $value : undef,
158 limit_hi => $limit_hi,
159 limit_lo => $limit_lo,
160 };
161 }
162 }
163
164 1;
165
166 __END__
167
168 =head1 MODE
169
170 Check environment channels.
171
172 =over 8
173
174 =item B<--warning-*>
175
176 Warning threshold.
177 Can be: 'temperature', 'humidity'.
178
179 =item B<--critical-*>
180
181 Critical threshold.
182 Can be: 'temperature', 'humidity'.
183
184 =back
185
186 =cut