Debian Codegraph @

src/hardware/pdu/emerson/snmp/mode/receptacles.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::emerson::snmp::mode::receptacles;
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 catalog_status_calc);
28 use Digest::MD5 qw(md5_hex);
29
30 sub custom_rcp_status_output {
31 my ($self, %options) = @_;
32
33 my $msg = sprintf(
34 "operational state '%s' [power state: %s]",
35 $self->{result_values}->{oper_state},
36 $self->{result_values}->{power_state}
37 );
38 return $msg;
39 }
40
41 sub set_counters {
42 my ($self, %options) = @_;
43
44 $self->{maps_counters_type} = [
45 { name => 'rb', type => 3, cb_prefix_output => 'prefix_rb_output', cb_long_output => 'rb_long_output', indent_long_output => ' ', message_multiple => 'All receptacle branches are ok',
46 group => [
47 { name => 'global', type => 0, skipped_code => { -10 => 1 } },
48 { name => 'rcp', display_long => 1, cb_prefix_output => 'prefix_rcp_output', message_multiple => 'All receptacles are ok', type => 1, skipped_code => { -10 => 1 } },
49 ]
50 }
51 ];
52
53 $self->{maps_counters}->{global} = [
54 { label => 'total-accumulated-energy', nlabel => 'receptaclebranch.total.accumulated.energy.kilowatthour', set => {
55 key_values => [ { name => 'lgpPduRbEntryEnergyAccum', diff => 1 } ],
56 output_template => 'total input power : %s kWh',
57 perfdatas => [
58 { template => '%s', value => 'lgpPduRbEntryEnergyAccum',
59 unit => 'kWh', min => 0, label_extra_instance => 1 },
60 ],
61 }
62 },
63 { label => 'line2neutral-real-power', nlabel => 'receptaclebranch.line2neutral.real.power.watt', set => {
64 key_values => [ { name => 'lgpPduRbEntryPwr' } ],
65 output_template => 'line-to-neutral real power : %s W',
66 perfdatas => [
67 { template => '%s', value => 'lgpPduRbEntryPwr',
68 unit => 'W', min => 0, label_extra_instance => 1 },
69 ],
70 }
71 },
72 { label => 'line2neutral-apparent-power', nlabel => 'receptaclebranch.line2neutral.apparent.power.voltampere', set => {
73 key_values => [ { name => 'lgpPduRbEntryAp' } ],
74 output_template => 'line-to-neutral apparent power : %s VA',
75 perfdatas => [
76 { template => '%s', value => 'lgpPduRbEntryAp',
77 unit => 'VA', min => 0, label_extra_instance => 1 },
78 ],
79 }
80 },
81 { label => 'current-neutral', nlabel => 'receptaclebranch.line2neutral.current.ampacrms', set => {
82 key_values => [ { name => 'lgpPduRbEntryEcHundredths' } ],
83 output_template => 'line-to-neutral current : %s Amp AC RMS',
84 perfdatas => [
85 { value => 'lgpPduRbEntryEcHundredths', template => '%s',
86 unit => 'AmpAcRMS', min => 0, label_extra_instance => 1 },
87 ],
88 }
89 },
90 { label => 'potential-neutral', nlabel => 'receptaclebranch.line2neutral.potential.voltrms', set => {
91 key_values => [ { name => 'lgpPduRbEntryEpLNTenths' } ],
92 output_template => 'line-to-neutral potential : %s VoltRMS',
93 perfdatas => [
94 { value => 'lgpPduRbEntryEpLNTenths', template => '%s',
95 unit => 'VoltRMS', min => 0, label_extra_instance => 1 },
96 ],
97 }
98 },
99 ];
100
101 $self->{maps_counters}->{rcp} = [
102 { label => 'rcp-status', threshold => 0, set => {
103 key_values => [ { name => 'oper_state' }, { name => 'power_state' }, { name => 'display' } ],
104 closure_custom_calc => \&catalog_status_calc,
105 closure_custom_output => $self->can('custom_rcp_status_output'),
106 closure_custom_perfdata => sub { return 0; },
107 closure_custom_threshold_check => \&catalog_status_threshold,
108 }
109 },
110 ];
111 }
112
113 sub prefix_rb_output {
114 my ($self, %options) = @_;
115
116 return "Receptacle branch '" . $options{instance_value}->{display} . "' : ";
117 }
118
119 sub rb_long_output {
120 my ($self, %options) = @_;
121
122 return "checking receptacle branch '" . $options{instance_value}->{display} . "'";
123 }
124
125 sub prefix_rcp_output {
126 my ($self, %options) = @_;
127
128 return "receptacle '" . $options{instance_value}->{display} . "' ";
129 }
130
131 sub new {
132 my ($class, %options) = @_;
133 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1, statefile => 1);
134 bless $self, $class;
135
136 $options{options}->add_options(arguments => {
137 'filter-rb:s' => { name => 'filter_rb' },
138 'unknown-rcp-status:s' => { name => 'unknown_rcp_status', default => '' },
139 'warning-rcp-status:s' => { name => 'warning_rcp_status', default => '%{oper_state} =~ /warning|alarm/' },
140 'critical-rcp-status:s' => { name => 'critical_rcp_status', default => '%{oper_state} =~ /abnormal/' },
141 });
142
143 return $self;
144 }
145
146 sub check_options {
147 my ($self, %options) = @_;
148 $self->SUPER::check_options(%options);
149
150 $self->change_macros(macros => ['unknown_rcp_status', 'warning_rcp_status', 'critical_rcp_status']);
151 }
152
153 my $rcp_power_state = { 0 => 'unknown', 1 => 'off', 2 => 'on', 3 => 'off-pending-on-delay' };
154 my $rcp_oper = { 1 => 'normal', 2 => 'warning', 3 => 'alarm', 4 => 'abnormal' };
155
156 sub manage_selection {
157 my ($self, %options) = @_;
158
159 my $mapping = {
160 lgpPduEntryUsrLabel => { oid => '.1.3.6.1.4.1.476.1.42.3.8.20.1.10' },
161 lgpPduEntrySysAssignLabel => { oid => '.1.3.6.1.4.1.476.1.42.3.8.20.1.15' },
162 };
163 my $mapping2 = {
164 lgpPduRbEntryUsrLabel => { oid => '.1.3.6.1.4.1.476.1.42.3.8.40.20.1.8' },
165 lgpPduRbEntrySysAssignLabel => { oid => '.1.3.6.1.4.1.476.1.42.3.8.40.20.1.20' },
166 lgpPduRbEntryEnergyAccum => { oid => '.1.3.6.1.4.1.476.1.42.3.8.40.20.1.85' }, # 0.1 Kilowatt-Hour
167 lgpPduRbEntryEpLNTenths => { oid => '.1.3.6.1.4.1.476.1.42.3.8.40.20.1.100' },
168 lgpPduRbEntryPwr => { oid => '.1.3.6.1.4.1.476.1.42.3.8.40.20.1.115' }, # Watt
169 lgpPduRbEntryAp => { oid => '.1.3.6.1.4.1.476.1.42.3.8.40.20.1.120' }, # VA
170 lgpPduRbEntryEcHundredths => { oid => '.1.3.6.1.4.1.476.1.42.3.8.40.20.1.130' },
171 };
172 my $mapping3 = {
173 lgpPduRcpEntryUsrLabel => { oid => '.1.3.6.1.4.1.476.1.42.3.8.50.20.1.10' },
174 lgpPduRcpEntrySysAssignLabel => { oid => '.1.3.6.1.4.1.476.1.42.3.8.50.20.1.25' },
175 lgpPduRcpEntryPwrState => { oid => '.1.3.6.1.4.1.476.1.42.3.8.50.20.1.95', map => $rcp_power_state },
176 lgpPduRcpEntryOperationCondition => { oid => '.1.3.6.1.4.1.476.1.42.3.8.50.20.1.210', map => $rcp_oper },
177 };
178
179 my $oid_lgpPduEntry = '.1.3.6.1.4.1.476.1.42.3.8.20.1';
180 my $oid_lgpPduRbEntry = '.1.3.6.1.4.1.476.1.42.3.8.40.20.1';
181 my $oid_lgpPduRcpEntry = '.1.3.6.1.4.1.476.1.42.3.8.50.20.1';
182 my $snmp_result = $options{snmp}->get_multiple_table(
183 oids => [
184 { oid => $oid_lgpPduEntry, start => $mapping->{lgpPduEntryUsrLabel}->{oid}, end => $mapping->{lgpPduEntrySysAssignLabel}->{oid} },
185 { oid => $oid_lgpPduRbEntry, start => $mapping2->{lgpPduRbEntryUsrLabel}->{oid}, end => $mapping2->{lgpPduRbEntryEcHundredths}->{oid} },
186 { oid => $oid_lgpPduRcpEntry, start => $mapping3->{lgpPduRcpEntryUsrLabel}->{oid}, end => $mapping3->{lgpPduRcpEntryOperationCondition}->{oid} },
187 ],
188 nothing_quit => 1,
189 );
190
191 $self->{rb} = {};
192 foreach my $oid (keys %{$snmp_result->{$oid_lgpPduRbEntry}}) {
193 next if ($oid !~ /^$mapping2->{lgpPduRbEntrySysAssignLabel}->{oid}\.(.*?)\.(.*)$/);
194 my ($pdu_index, $rb_index) = ($1, $2);
195
196 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result->{$oid_lgpPduEntry}, instance => $pdu_index);
197 my $result2 = $options{snmp}->map_instance(mapping => $mapping2, results => $snmp_result->{$oid_lgpPduRbEntry}, instance => $pdu_index . '.' . $rb_index);
198
199 my $name = (defined($result->{lgpPduEntryUsrLabel}) && $result->{lgpPduEntryUsrLabel} ne '' ? $result->{lgpPduEntryUsrLabel} : $result->{lgpPduEntrySysAssignLabel});
200 $name .= '~' . (defined($result2->{lgpPduRbEntryUsrLabel}) && $result2->{lgpPduRbEntryUsrLabel} ne '' ? $result2->{lgpPduRbEntryUsrLabel} : $result2->{lgpPduRbEntrySysAssignLabel});
201
202 if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
203 $name !~ /$self->{option_results}->{filter_name}/) {
204 $self->{output}->output_add(long_msg => "skipping receptacle branch '" . $name . "'.", debug => 1);
205 next;
206 }
207
208 $result2->{lgpPduRbEntryEnergyAccum} /= 10;
209 $result2->{lgpPduRbEntryEcHundredths} *= 0.01 if (defined($result2->{lgpPduRbEntryEcHundredths}));
210 $result2->{lgpPduRbEntryEpLNTenths} *= 0.1 if (defined($result2->{lgpPduRbEntryEpLNTenths}));
211 $self->{rb}->{$name} = {
212 display => $name,
213 global => { %$result2 },
214 rcp => {},
215 };
216
217 foreach (keys %{$snmp_result->{$oid_lgpPduRcpEntry}}) {
218 next if (!/^$mapping3->{lgpPduRcpEntrySysAssignLabel}->{oid}\.$pdu_index\.$rb_index\.(.*)$/);
219 my $rcp_index = $1;
220 my $result3 = $options{snmp}->map_instance(mapping => $mapping3, results => $snmp_result->{$oid_lgpPduRcpEntry}, instance => $pdu_index . '.' . $rb_index . '.' . $rcp_index);
221
222 my $rcp_name = (defined($result3->{lgpPduRcpEntryUsrLabel}) && $result3->{lgpPduRcpEntryUsrLabel} ne '' ? $result3->{lgpPduRcpEntryUsrLabel} : $result3->{lgpPduRcpEntrySysAssignLabel});
223 $self->{rb}->{$name}->{rcp}->{$rcp_name} = {
224 display => $rcp_name,
225 power_state => $result3->{lgpPduRcpEntryPwrState},
226 oper_state => $result3->{lgpPduRcpEntryOperationCondition},
227 };
228 }
229 }
230
231 if (scalar(keys %{$self->{rb}}) <= 0) {
232 $self->{output}->add_option_msg(short_msg => "No receptacle branch found.");
233 $self->{output}->option_exit();
234 }
235
236 $self->{cache_name} = "pdu_liebert_" . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' .
237 (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' .
238 (defined($self->{option_results}->{filter_rb}) ? md5_hex($self->{option_results}->{filter_rb}) : md5_hex('all'));
239 }
240
241 1;
242
243 __END__
244
245 =head1 MODE
246
247 Check receptacles.
248
249 =over 8
250
251 =item B<--filter-rb>
252
253 Filter receptable branch name (can be a regexp).
254
255 =item B<--unknown-rcp-status>
256
257 Define the conditions to match for the status to be WARNING (default: '').
258 You can use the following variables: %{oper_state}, %{power_state}, %{display}
259
260 =item B<--warning-rcp-status>
261
262 Define the conditions to match for the status to be WARNING (default: '%{oper_state} =~ /warning|alarm/').
263 You can use the following variables: %{oper_state}, %{power_state}, %{display}
264
265 =item B<--critical-rcp-status>
266
267 Define the conditions to match for the status to be CRITICAL (default: '%{oper_state} =~ /abnormal/').
268 You can use the following variables: %{oper_state}, %{power_state}, %{display}
269
270 =item B<--warning-*> B<--critical-*>
271
272 Thresholds.
273 Can be: 'total-accumulated-energy', 'line2neutral-real-power', 'line2neutral-apparent-power'.
274
275 =back
276
277 =cut