| 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::cyberpower::snmp::mode::outlets; |
| 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 |
|
| 29 |
sub custom_status_output { |
| 30 |
my ($self, %options) = @_; |
| 31 |
|
| 32 |
return sprintf( |
| 33 |
"state: '%s' %s", |
| 34 |
$self->{result_values}->{state}, |
| 35 |
'[phase: ' . $self->{result_values}->{phase} . ']', |
| 36 |
); |
| 37 |
} |
| 38 |
|
| 39 |
sub device_long_output { |
| 40 |
my ($self, %options) = @_; |
| 41 |
|
| 42 |
return "checking device '" . $options{instance_value}->{display} . "'"; |
| 43 |
} |
| 44 |
|
| 45 |
sub prefix_device_output { |
| 46 |
my ($self, %options) = @_; |
| 47 |
|
| 48 |
return "Device '" . $options{instance_value}->{display} . "' "; |
| 49 |
} |
| 50 |
|
| 51 |
sub prefix_outlet_output { |
| 52 |
my ($self, %options) = @_; |
| 53 |
|
| 54 |
return "outlet '" . $options{instance_value}->{display} . "' "; |
| 55 |
} |
| 56 |
|
| 57 |
sub set_counters { |
| 58 |
my ($self, %options) = @_; |
| 59 |
|
| 60 |
$self->{maps_counters_type} = [ |
| 61 |
{ |
| 62 |
name => 'devices', type => 3, cb_prefix_output => 'prefix_device_output', cb_long_output => 'device_long_output', indent_long_output => ' ', message_multiple => 'All devices are ok', |
| 63 |
group => [ |
| 64 |
{ name => 'outlets', display_long => 1, cb_prefix_output => 'prefix_outlet_output', message_multiple => 'outlets are ok', type => 1, skipped_code => { -10 => 1 } } |
| 65 |
] |
| 66 |
} |
| 67 |
]; |
| 68 |
|
| 69 |
$self->{maps_counters}->{outlets} = [ |
| 70 |
{ label => 'status', type => 2, critical_default => '%{state} =~ /off/i', set => { |
| 71 |
key_values => [ { name => 'state' }, { name => 'bank' }, { name => 'phase' }, { name => 'display' } ], |
| 72 |
closure_custom_output => $self->can('custom_status_output'), |
| 73 |
closure_custom_perfdata => sub { return 0; }, |
| 74 |
closure_custom_threshold_check => \&catalog_status_threshold_ng |
| 75 |
} |
| 76 |
}, |
| 77 |
{ label => 'current', nlabel => 'outlet.current.ampere', set => { |
| 78 |
key_values => [ { name => 'current' }, { name => 'display' } ], |
| 79 |
output_template => 'current: %s A', |
| 80 |
perfdatas => [ |
| 81 |
{ template => '%s', unit => 'A', min => 0, label_extra_instance => 1 } |
| 82 |
] |
| 83 |
} |
| 84 |
} |
| 85 |
]; |
| 86 |
} |
| 87 |
|
| 88 |
sub new { |
| 89 |
my ($class, %options) = @_; |
| 90 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); |
| 91 |
bless $self, $class; |
| 92 |
|
| 93 |
$options{options}->add_options(arguments => {}); |
| 94 |
|
| 95 |
return $self; |
| 96 |
} |
| 97 |
|
| 98 |
my $map_pdu_status = { |
| 99 |
1 => 'on', 2 => 'off' |
| 100 |
}; |
| 101 |
my $map_pdu_phase = { |
| 102 |
1 => 'phase1', 2 => 'phase2', 3 => 'phase3', |
| 103 |
4 => 'phase1-2', 5 => 'phase2-3', 6 => 'phase3-1' |
| 104 |
}; |
| 105 |
|
| 106 |
sub check_pdu { |
| 107 |
my ($self, %options) = @_; |
| 108 |
|
| 109 |
return if (scalar(keys %{$self->{devices}}) > 0); |
| 110 |
|
| 111 |
$self->{devices}->{ $options{device} } = { |
| 112 |
display => $options{device}, |
| 113 |
outlets => {} |
| 114 |
}; |
| 115 |
|
| 116 |
my $mapping = { |
| 117 |
name => { oid => '.1.3.6.1.4.1.3808.1.1.3.3.5.1.1.2' }, # ePDUOutletStatusOutletName |
| 118 |
phase => { oid => '.1.3.6.1.4.1.3808.1.1.3.3.5.1.1.3', map => $map_pdu_phase }, # ePDUOutletStatusOutletPhase |
| 119 |
state => { oid => '.1.3.6.1.4.1.3808.1.1.3.3.5.1.1.4', map => $map_pdu_status }, # ePDUOutletStatusOutletState |
| 120 |
bank => { oid => '.1.3.6.1.4.1.3808.1.1.3.3.5.1.1.6' }, # ePDUOutletStatusOutletBank |
| 121 |
current => { oid => '.1.3.6.1.4.1.3808.1.1.3.3.5.1.1.7' } # ePDUOutletStatusLoad |
| 122 |
}; |
| 123 |
|
| 124 |
my $oid_ePDUOutletStatusEntry = '.1.3.6.1.4.1.3808.1.1.3.3.5.1.1'; |
| 125 |
my $snmp_result = $options{snmp}->get_table( |
| 126 |
oid => $oid_ePDUOutletStatusEntry, |
| 127 |
start => $mapping->{name}->{oid}, |
| 128 |
end => $mapping->{current}->{oid} |
| 129 |
); |
| 130 |
|
| 131 |
my $duplicated = {}; |
| 132 |
foreach my $oid (keys %$snmp_result) { |
| 133 |
next if ($oid !~ /^$mapping->{state}->{oid}\.(.*)$/); |
| 134 |
my $instance = $1; |
| 135 |
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); |
| 136 |
|
| 137 |
my $name = $result->{name} . ' bank ' . $result->{bank}; |
| 138 |
$name = $instance if (defined($duplicated->{$name})); |
| 139 |
if (defined($self->{devices}->{ $options{device} }->{outlets}->{$name})) { |
| 140 |
$duplicated->{$name} = 1; |
| 141 |
my $instance2 = $self->{devices}->{ $options{device} }->{outlets}->{$name}->{instance}; |
| 142 |
$self->{devices}->{ $options{device} }->{outlets}->{$instance2} = $self->{devices}->{ $options{device} }->{outlets}->{$name}; |
| 143 |
$self->{devices}->{ $options{device} }->{outlets}->{$instance2}->{display} = $instance2; |
| 144 |
delete $self->{devices}->{ $options{device} }->{outlets}->{$name}; |
| 145 |
$name = $instance; |
| 146 |
} |
| 147 |
|
| 148 |
$result->{current} /= 10; |
| 149 |
$self->{devices}->{ $options{device} }->{outlets}->{$name} = { |
| 150 |
instance => $instance, |
| 151 |
display => $name, |
| 152 |
%$result |
| 153 |
}; |
| 154 |
} |
| 155 |
} |
| 156 |
|
| 157 |
my $map_pdu2_status = { |
| 158 |
1 => 'on', |
| 159 |
2 => 'off', |
| 160 |
}; |
| 161 |
my $map_pdu2_phase = { |
| 162 |
1 => 'seqPhase1ToNeutral', 2 => 'seqPhase2ToNeutral', |
| 163 |
3 => 'seqPhase3ToNeutral', 4 => 'seqPhase1ToPhase2', |
| 164 |
5 => 'seqPhase2ToPhase3', 6 => 'seqPhase3ToPhase1', |
| 165 |
}; |
| 166 |
my $oid_ePDUIdentName = '.1.3.6.1.4.1.3808.1.1.3.1.1'; |
| 167 |
my $oid_ePDU2DeviceConfigName = '.1.3.6.1.4.1.3808.1.1.6.3.2.1.3'; |
| 168 |
|
| 169 |
sub check_pdu2 { |
| 170 |
my ($self, %options) = @_; |
| 171 |
|
| 172 |
my $mapping_switched = { |
| 173 |
bank => { oid => '.1.3.6.1.4.1.3808.1.1.6.6.1.3.1.6' }, # ePDU2OutletSwitchedInfoBank |
| 174 |
module => { oid => '.1.3.6.1.4.1.3808.1.1.6.6.1.4.1.2' }, # ePDU2OutletSwitchedStatusModuleIndex |
| 175 |
number => { oid => '.1.3.6.1.4.1.3808.1.1.6.6.1.4.1.3' }, # ePDU2OutletSwitchedStatusNumber |
| 176 |
name => { oid => '.1.3.6.1.4.1.3808.1.1.6.6.1.4.1.4' }, # ePDU2OutletSwitchedStatusName |
| 177 |
state => { oid => '.1.3.6.1.4.1.3808.1.1.6.6.1.4.1.5', map => $map_pdu2_status } # ePDU2OutletSwitchedStatusState |
| 178 |
}; |
| 179 |
|
| 180 |
my $mapping_metered = { |
| 181 |
module => { oid => '.1.3.6.1.4.1.3808.1.1.6.6.2.3.1.2' }, # ePDU2OutletMeteredInfoModuleIndex |
| 182 |
number => { oid => '.1.3.6.1.4.1.3808.1.1.6.6.2.3.1.3' }, # ePDU2OutletMeteredInfoNumber |
| 183 |
name => { oid => '.1.3.6.1.4.1.3808.1.1.6.6.2.3.1.4' }, # ePDU2OutletMeteredInfoName |
| 184 |
phase => { oid => '.1.3.6.1.4.1.3808.1.1.6.6.2.3.1.5', map => $map_pdu2_phase }, # ePDU2OutletMeteredInfoLayout |
| 185 |
bank => { oid => '.1.3.6.1.4.1.3808.1.1.6.6.2.3.1.7' }, # ePDU2OutletMeteredInfoBank |
| 186 |
current => { oid => '.1.3.6.1.4.1.3808.1.1.6.6.2.4.1.6' } # ePDU2OutletMeteredStatusLoad |
| 187 |
}; |
| 188 |
|
| 189 |
my $oid_ePDU2OutletSwitchedStatusEntry = '.1.3.6.1.4.1.3808.1.1.6.6.1.4.1'; |
| 190 |
my $snmp_result_switched = $options{snmp}->get_multiple_table( |
| 191 |
oids => [ |
| 192 |
{ oid => $mapping_switched->{bank}->{oid} }, |
| 193 |
{ oid => $oid_ePDU2OutletSwitchedStatusEntry, start => $mapping_switched->{module}->{oid}, end => $mapping_switched->{state}->{oid} } |
| 194 |
], |
| 195 |
return_type => 1, |
| 196 |
); |
| 197 |
|
| 198 |
my $oid_ePDU2OutletMeteredInfoEntry = '.1.3.6.1.4.1.3808.1.1.6.6.2.3.1'; |
| 199 |
my $oid_ePDU2OutletMeteredStatusEntry = '.1.3.6.1.4.1.3808.1.1.6.6.2.4.1'; |
| 200 |
my $snmp_result_metered = $options{snmp}->get_multiple_table( |
| 201 |
oids => [ |
| 202 |
{ oid => $oid_ePDU2OutletMeteredInfoEntry, start => $mapping_metered->{module}->{oid}, end => $mapping_metered->{bank}->{oid} }, |
| 203 |
{ oid => $oid_ePDU2OutletMeteredStatusEntry, start => $mapping_metered->{current}->{oid}, end => $mapping_metered->{current}->{oid} } |
| 204 |
], |
| 205 |
return_type => 1, |
| 206 |
); |
| 207 |
|
| 208 |
my $result_metered = {}; |
| 209 |
foreach (keys %$snmp_result_metered) { |
| 210 |
next if (! /^$mapping_metered->{module}->{oid}\.(.*)$/); |
| 211 |
|
| 212 |
my $result = $options{snmp}->map_instance(mapping => $mapping_metered, results => $snmp_result_metered, instance => $1); |
| 213 |
|
| 214 |
$result_metered->{ $result->{module} . ':' . $result->{bank} . ':' . $result->{number} } = $result; |
| 215 |
} |
| 216 |
|
| 217 |
my $duplicated = {}; |
| 218 |
foreach (keys %$snmp_result_switched) { |
| 219 |
next if (! /^$mapping_switched->{state}->{oid}\.(.*)$/); |
| 220 |
my $result = $options{snmp}->map_instance(mapping => $mapping_switched, results => $snmp_result_switched, instance => $1); |
| 221 |
|
| 222 |
my $device_name = $options{devices}->{ $oid_ePDU2DeviceConfigName . '.' . $result->{module} }; |
| 223 |
if (!defined($self->{devices}->{$device_name})) { |
| 224 |
$self->{devices}->{$device_name} = { |
| 225 |
display => $device_name, |
| 226 |
outlets => {} |
| 227 |
}; |
| 228 |
} |
| 229 |
|
| 230 |
my $instance = $result->{bank} . ':' . $result->{number}; |
| 231 |
my $name = $result->{name} . ' bank ' . $result->{bank}; |
| 232 |
$name = $instance if (defined($duplicated->{$name})); |
| 233 |
if (defined($self->{devices}->{$device_name}->{outlets}->{$name})) { |
| 234 |
$duplicated->{$name} = 1; |
| 235 |
my $instance2 = $self->{devices}->{$device_name}->{outlets}->{$name}->{instance}; |
| 236 |
$self->{devices}->{$device_name}->{outlets}->{$instance2} = $self->{devices}->{$device_name}->{outlets}->{$name}; |
| 237 |
$self->{devices}->{$device_name}->{outlets}->{$instance2}->{display} = $instance2; |
| 238 |
delete $self->{devices}->{$device_name}->{outlets}->{$name}; |
| 239 |
$name = $instance; |
| 240 |
} |
| 241 |
|
| 242 |
$result_metered->{ $result->{module} . ':' . $result->{bank} . ':' . $result->{number} }->{current} /= 10 |
| 243 |
if (defined($result_metered->{ $result->{module} . ':' . $result->{bank} . ':' . $result->{number} }->{current})); |
| 244 |
$self->{devices}->{$device_name}->{outlets}->{$name} = { |
| 245 |
instance => $instance, |
| 246 |
display => $name, |
| 247 |
bank => $result->{bank}, |
| 248 |
state => $result->{state}, |
| 249 |
current => $result_metered->{ $result->{module} . ':' . $result->{bank} . ':' . $result->{number} }->{current}, |
| 250 |
phase => defined($result_metered->{ $result->{module} . ':' . $result->{bank} . ':' . $result->{number} }->{phase}) ? |
| 251 |
$result_metered->{ $result->{module} . ':' . $result->{bank} . ':' . $result->{number} }->{phase} : '-' |
| 252 |
}; |
| 253 |
} |
| 254 |
} |
| 255 |
|
| 256 |
sub manage_selection { |
| 257 |
my ($self, %options) = @_; |
| 258 |
|
| 259 |
my $snmp_result = $options{snmp}->get_multiple_table( |
| 260 |
oids => [ |
| 261 |
{ oid => $oid_ePDUIdentName }, |
| 262 |
{ oid => $oid_ePDU2DeviceConfigName } |
| 263 |
], |
| 264 |
nothing_quit => 1 |
| 265 |
); |
| 266 |
|
| 267 |
$self->{devices} = {}; |
| 268 |
$self->check_pdu2(snmp => $options{snmp}, devices => $snmp_result->{$oid_ePDU2DeviceConfigName}); |
| 269 |
$self->check_pdu( |
| 270 |
snmp => $options{snmp}, |
| 271 |
device => defined($snmp_result->{$oid_ePDUIdentName}->{$oid_ePDUIdentName . '.0'}) ? $snmp_result->{$oid_ePDUIdentName}->{$oid_ePDUIdentName . '.0'} : 'unknown' |
| 272 |
); |
| 273 |
} |
| 274 |
|
| 275 |
1; |
| 276 |
|
| 277 |
__END__ |
| 278 |
|
| 279 |
=head1 MODE |
| 280 |
|
| 281 |
Check outlets. |
| 282 |
|
| 283 |
=over 8 |
| 284 |
|
| 285 |
=item B<--unknown-status> |
| 286 |
|
| 287 |
Define the conditions to match for the status to be UNKNOWN. |
| 288 |
You can use the following variables: %%{state}, %{phase}, %{bank}, %{display} |
| 289 |
|
| 290 |
=item B<--warning-status> |
| 291 |
|
| 292 |
Define the conditions to match for the status to be WARNING. |
| 293 |
You can use the following variables: %{state}, %{phase}, %{bank}, %{display} |
| 294 |
|
| 295 |
=item B<--critical-status> |
| 296 |
|
| 297 |
Define the conditions to match for the status to be CRITICAL (default: '%{state} =~ /off/'). |
| 298 |
You can use the following variables: %{state}, %{phase}, %{bank}, %{display} |
| 299 |
|
| 300 |
=item B<--warning-*> B<--critical-*> |
| 301 |
|
| 302 |
Thresholds. |
| 303 |
Can be: 'current'. |
| 304 |
|
| 305 |
=back |
| 306 |
|
| 307 |
=cut |