Debian Codegraph @

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