centreon-plugins/hardware/pdu/eaton/snmp/mode/group.pm

148 lines
4.9 KiB
Perl
Raw Normal View History

2019-05-28 15:06:32 +02:00
#
2020-01-06 15:19:23 +01:00
# Copyright 2020 Centreon (http://www.centreon.com/)
2019-05-28 15:06:32 +02:00
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package hardware::pdu::eaton::snmp::mode::group;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'group', type => 1, cb_prefix_output => 'prefix_group_output', message_multiple => 'All groups are ok', skipped_code => { -10 => 1 } },
];
$self->{maps_counters}->{group} = [
{ label => 'current', nlabel => 'group.current.ampere', set => {
2019-09-25 11:42:12 +02:00
key_values => [ { name => 'groupCurrent', no_value => 0 }, { name => 'display' } ],
2019-05-28 15:06:32 +02:00
output_template => 'Current : %.2f A',
perfdatas => [
{ value => 'groupCurrent_absolute', template => '%.2f',
2019-09-25 11:42:12 +02:00
min => 0, unit => 'A', label_extra_instance => 1, instance_use => 'display_absolute' },
2019-05-28 15:06:32 +02:00
],
}
},
{ label => 'voltage', nlabel => 'group.voltage.volt', set => {
2019-09-25 11:42:12 +02:00
key_values => [ { name => 'groupVoltage', no_value => 0 }, { name => 'display' } ],
2019-05-28 15:06:32 +02:00
output_template => 'Voltage : %.2f V',
perfdatas => [
{ value => 'groupVoltage_absolute', template => '%.2f',
2019-09-25 11:42:12 +02:00
unit => 'V', label_extra_instance => 1, instance_use => 'display_absolute' },
2019-05-28 15:06:32 +02:00
],
}
},
{ label => 'power', nlabel => 'group.power.watt', set => {
2019-09-25 11:42:12 +02:00
key_values => [ { name => 'groupWatts', no_value => 0 }, { name => 'display' } ],
2019-05-28 15:06:32 +02:00
output_template => 'Power : %.2f W',
perfdatas => [
{ value => 'groupWatts_absolute', template => '%.2f',
2019-09-25 11:42:12 +02:00
unit => 'W', label_extra_instance => 1, instance_use => 'display_absolute' },
2019-05-28 15:06:32 +02:00
],
}
},
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
});
return $self;
}
sub prefix_group_output {
my ($self, %options) = @_;
return "Group '" . $options{instance_value}->{display} . "' ";
}
my $mapping = {
2019-05-28 22:00:20 +02:00
groupName => { oid => '.1.3.6.1.4.1.534.6.6.7.5.1.1.3' },
2019-05-28 15:06:32 +02:00
groupVoltage => { oid => '.1.3.6.1.4.1.534.6.6.7.5.3.1.3' }, # in mVolt
groupCurrent => { oid => '.1.3.6.1.4.1.534.6.6.7.5.4.1.3' }, # in mA
groupWatts => { oid => '.1.3.6.1.4.1.534.6.6.7.5.5.1.3' }, # in Watt
};
sub manage_selection {
my ($self, %options) = @_;
$self->{group} = {};
my $snmp_result = $options{snmp}->get_multiple_table(
oids => [
2019-05-28 22:00:20 +02:00
{ oid => $mapping->{groupName}->{oid} },
2019-05-28 15:06:32 +02:00
{ oid => $mapping->{groupVoltage}->{oid} },
{ oid => $mapping->{groupCurrent}->{oid} },
{ oid => $mapping->{groupWatts}->{oid} },
],
return_type => 1, nothing_quit => 1
);
foreach my $oid (keys %{$snmp_result}) {
2019-09-25 11:42:12 +02:00
$oid =~ /\.(\d+)\.(\d+)$/;
my ($strapping_index, $group_index) = ($1, $2);
next if (defined($self->{group}->{$strapping_index . '.' . $group_index}));
2019-05-28 15:06:32 +02:00
2019-09-25 11:42:12 +02:00
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $strapping_index . '.' . $group_index);
2019-05-28 15:06:32 +02:00
$result->{groupVoltage} *= 0.001 if (defined($result->{groupVoltage}));
$result->{groupCurrent} *= 0.001 if (defined($result->{groupCurrent}));
2019-09-25 11:42:12 +02:00
my $display = $strapping_index . '.' . $group_index;
if (defined($result->{groupName}) && $result->{groupName} ne '') {
$display = $result->{groupName} . ' strapping ' . $strapping_index;
}
$self->{group}->{$strapping_index . '.' . $group_index} = { display => $display, %$result };
2019-05-28 15:06:32 +02:00
}
if (scalar(keys %{$self->{group}}) <= 0) {
$self->{output}->add_option_msg(short_msg => "No group found.");
$self->{output}->option_exit();
}
}
1;
__END__
=head1 MODE
Check group metrics (voltage, current and power).
=over 8
=item B<--warning-*>
Threshold warning.
Can be: 'voltage', 'current', 'power'.
=item B<--critical-*>
Threshold critical.
Can be: 'voltage', 'current', 'power'.
=back
=cut