Debian Codegraph @

src/hardware/pdu/gude/epc/snmp/mode/sppowerchannels.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::gude::epc::snmp::mode::sppowerchannels;
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 use hardware::pdu::gude::epc::snmp::mode::resources;
29
30 sub prefix_sp_output {
31 my ($self, %options) = @_;
32
33 return "Single port power channel interface '" . $options{instance} . "' ";
34 }
35
36 sub set_counters {
37 my ($self, %options) = @_;
38
39 $self->{maps_counters_type} = [
40 { name => 'global', type => 0 },
41 { name => 'sp', type => 1, cb_prefix_output => 'prefix_sp_output', message_multiple => 'All single port power channel interfaces are ok', skipped_code => { -10 => 1 } }
42 ];
43
44 $self->{maps_counters}->{global} = [
45 { label => 'total-singleports', nlabel => 'pdu.singleport_power_channels.total.count', set => {
46 key_values => [ { name => 'total' } ],
47 output_template => '%s single port(s)',
48 perfdatas => [
49 { template => '%s', min => 0 }
50 ]
51 }
52 }
53 ];
54
55 $self->{maps_counters}->{sp} = [
56 { label => 'state', type => 2, set => {
57 key_values => [ { name => 'state' }, { name => 'name' } ],
58 output_template => 'state: %s',
59 closure_custom_perfdata => sub { return 0; },
60 closure_custom_threshold_check => \&catalog_status_threshold_ng
61 }
62 },
63 { label => 'status', type => 2, set => {
64 key_values => [ { name => 'status' }, { name => 'name' } ],
65 output_template => 'status: %s',
66 closure_custom_perfdata => sub { return 0; },
67 closure_custom_threshold_check => \&catalog_status_threshold_ng
68 }
69 },
70 { label => 'current', nlabel => 'pdu.interface.singleport_power_channel.current.ampere', set => {
71 key_values => [ { name => 'current', no_value => 0 } ],
72 output_template => 'current: %.2f A',
73 perfdatas => [
74 { template => '%.2f', min => 0, unit => 'A', label_extra_instance => 1 }
75 ]
76 }
77 },
78 { label => 'energy', nlabel => 'pdu.interface.singleport_power_channel.energy.active.kilowatthour', set => {
79 key_values => [ { name => 'abs_energy_active', no_value => 0 } ],
80 output_template => 'absolute energy active: %.2f kWh',
81 perfdatas => [
82 { template => '%.2f', min => 0, unit => 'kWh', label_extra_instance => 1 }
83 ]
84 }
85 },
86 { label => 'frequency', nlabel => 'pdu.interface.singleport_power_channel.frequency.hertz', set => {
87 key_values => [ { name => 'frequency', no_value => 0 } ],
88 output_template => 'frequency: %.2f Hz',
89 perfdatas => [
90 { template => '%.2f', min => 0, unit => 'Hz', label_extra_instance => 1 }
91 ]
92 }
93 },
94 { label => 'phase-angle', nlabel => 'pdu.interface.singleport_power_channel.phase.angle.degree', set => {
95 key_values => [ { name => 'phase_angle', no_value => 0 } ],
96 output_template => 'phase angle: %.2f°',
97 perfdatas => [
98 { template => '%.2f', min => 0, label_extra_instance => 1 }
99 ]
100 }
101 },
102 { label => 'power-active', nlabel => 'pdu.power_channel.active.watt', set => {
103 key_values => [ { name => 'power_active', no_value => 0 } ],
104 output_template => 'active power: %.2f W',
105 perfdatas => [
106 { template => '%.2f', unit => 'W', label_extra_instance => 1 }
107 ]
108 }
109 },
110 { label => 'power-apparent', nlabel => 'pdu.interface.singleport_power_channel.power.apparent.voltampere', set => {
111 key_values => [ { name => 'power_apparent', no_value => 0 } ],
112 output_template => 'apparent power: %.2f VA',
113 perfdatas => [
114 { template => '%.2f', unit => 'VA', label_extra_instance => 1 }
115 ]
116 }
117 },
118 { label => 'power-factor', nlabel => 'pdu.interface.singleport_power_channel.power.factor.count', set => {
119 key_values => [ { name => 'power_factor', no_value => 0 } ],
120 output_template => 'power factor: %.2f',
121 perfdatas => [
122 { template => '%.2f', min => 0, unit => '', label_extra_instance => 1 }
123 ]
124 }
125 },
126 { label => 'power-reactive', nlabel => 'pdu.interface.singleport_power_channel.power.reactive.voltampere', set => {
127 key_values => [ { name => 'power_reactive', no_value => 0 } ],
128 output_template => 'reactive power: %.2f Var',
129 perfdatas => [
130 { template => '%.2f', unit => 'Var', label_extra_instance => 1 }
131 ]
132 }
133 },
134 { label => 'voltage', nlabel => 'pdu.interface.singleport_power_channel.voltage.volt', set => {
135 key_values => [ { name => 'voltage', no_value => 0 } ],
136 output_template => 'voltage: %.2f V',
137 perfdatas => [
138 { template => '%.2f', min => 0, unit => 'V', label_extra_instance => 1 }
139 ]
140 }
141 }
142 ];
143 }
144
145 sub new {
146 my ($class, %options) = @_;
147 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
148 bless $self, $class;
149
150 $options{options}->add_options(arguments => {
151 'filter-name:s' => { name => 'filter_name' },
152 'skip-poweredoff' => { name => 'skip_poweredoff' }
153 });
154
155 return $self;
156 }
157
158 sub manage_selection {
159 my ($self, %options) = @_;
160
161 my $branch = hardware::pdu::gude::epc::snmp::mode::resources::find_gude_branch($self, snmp => $options{snmp});
162
163 my $sp_state_mapping = {
164 0 => 'off',
165 1 => 'on'
166 };
167 my $sp_status_mapping = {
168 0 => 'not active',
169 1 => 'valid'
170 };
171
172 my $mapping = {
173 state => { oid => $branch .'.1.3.1.2.1.3', map => $sp_state_mapping },
174 status => { oid => $branch .'.1.5.5.2.1.2', map => $sp_status_mapping },
175 abs_energy_active => { oid => $branch .'.1.5.5.2.1.3' },
176 power_active => { oid => $branch .'.1.5.5.2.1.4' },
177 current => { oid => $branch .'.1.5.5.2.1.5' },
178 voltage => { oid => $branch .'.1.5.5.2.1.6' },
179 frequency => { oid => $branch .'.1.5.5.2.1.7' },
180 power_factor => { oid => $branch .'.1.5.5.2.1.8' },
181 phase_angle => { oid => $branch .'.1.5.5.2.1.9' },
182 power_apparent => { oid => $branch .'.1.5.5.2.1.10' },
183 power_reactive => { oid => $branch .'.1.5.5.2.1.11' }
184 };
185
186 my $oid_name = $branch . '.1.3.1.2.1.2';
187 my $snmp_result = $options{snmp}->get_table(oid => $oid_name, nothing_quit => 1);
188
189 $self->{global} = { total => 0 };
190 $self->{sp} = {};
191 my $duplicated = {};
192 foreach (keys %$snmp_result) {
193 /^$oid_name\.(.*)$/;
194 my $id = $1;
195 my $name = $snmp_result->{$_};
196 $name = $snmp_result->{$_} . ':' . $id if (defined($duplicated->{$name}));
197 if (defined($self->{sp}->{$name})) {
198 $duplicated->{$name} = 1;
199 my $instance = $self->{sp}->{$name}->{name} . ':' . $self->{sp}->{$name}->{instance};
200 $self->{sp}->{$instance} = delete $self->{sp}->{$name};
201 $name = $snmp_result->{$_} . ':' . $id;
202 }
203 next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
204 $name !~ /$self->{option_results}->{filter_name}/);
205 $self->{global}->{total}++;
206 $self->{sp}->{$name} = { name => $name, instance => $id };
207 }
208
209 return if (scalar(keys %{$self->{sp}}) <= 0);
210
211 $options{snmp}->load(
212 oids => [ map($_->{oid}, values(%$mapping)) ],
213 instances => [ map($_->{instance}, values %{$self->{sp}}) ],
214 instance_regexp => '^(.*)$'
215 );
216 $snmp_result = $options{snmp}->get_leef();
217
218 foreach (keys %{$self->{sp}}) {
219 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $self->{sp}->{$_}->{instance});
220 if (defined($self->{option_results}->{skip_poweredoff}) && $result->{state} eq 'off') {
221 $self->{global}->{total}--;
222 delete $self->{sp}->{$_};
223 next;
224 }
225 $result->{current} *= 0.001 if (defined($result->{current}));
226 $result->{power_factor} *= 0.001 if (defined($result->{power_factor}));
227 $result->{frequency} *= 0.01 if (defined($result->{frequency}));
228 $result->{abs_energy_active} *= 0.01 if (defined($result->{abs_energy_active}));
229 $self->{sp}->{$_} = { %$result, %{$self->{sp}->{$_}} };
230 }
231 }
232
233 1;
234
235 __END__
236
237 =head1 MODE
238
239 Check single port power channels.
240
241 =over 8
242
243 =item B<--filter-name>
244
245 Filter single port power channels by name (can be a regexp).
246
247 =item B<--skip-poweredoff>
248
249 Exclude the single ports that have been powered off.
250
251 =item B<--warning-state>
252
253 Warning threshold for single port state.
254
255 =item B<--critical-state>
256
257 Critical threshold for single port state.
258
259 =item B<--warning-status>
260
261 Warning threshold for for single port status.
262
263 =item B<--critical-status>
264
265 Critical threshold for for single port status.
266
267 =item B<--warning-*>
268
269 Warning threshold.
270 Can be: 'active-channels', 'current', 'energy', 'frequency', 'phase-angle', 'power-active',
271 'power-apparent', 'power-factor', 'power-reactive', 'voltage'
272
273 =item B<--critical-*>
274
275 Can be: 'active-channels', 'current', 'energy', 'frequency', 'phase-angle', 'power-active',
276 'power-apparent', 'power-factor', 'power-reactive', 'voltage'
277
278 =back
279
280 =cut