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

160 lines
5.3 KiB
Perl
Raw Normal View History

2019-05-28 15:06:32 +02:00
#
2021-02-08 09:55:50 +01:00
# Copyright 2021 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) = @_;
2020-04-06 12:07:15 +02:00
2019-05-28 15:06:32 +02:00
$self->{maps_counters_type} = [
2020-04-06 12:07:15 +02:00
{ name => 'group', type => 1, cb_prefix_output => 'prefix_group_output', message_multiple => 'All groups are ok', skipped_code => { -10 => 1 } }
2019-05-28 15:06:32 +02:00
];
$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 => [
2020-05-13 14:18:28 +02:00
{ value => 'groupCurrent', template => '%.2f',
min => 0, unit => 'A', label_extra_instance => 1, instance_use => 'display' }
2020-04-06 12:07:15 +02:00
]
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 => [
2020-05-13 14:18:28 +02:00
{ value => 'groupVoltage', template => '%.2f',
unit => 'V', label_extra_instance => 1, instance_use => 'display' }
2020-04-06 12:07:15 +02:00
]
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 => [
2020-05-13 14:18:28 +02:00
{ value => 'groupWatts', template => '%.2f',
unit => 'W', label_extra_instance => 1, instance_use => 'display' }
2020-04-06 12:07:15 +02:00
]
2019-05-28 15:06:32 +02:00
}
2020-04-06 12:07:15 +02:00
}
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 => {
2020-04-06 12:07:15 +02:00
'filter-name:s' => { name => 'filter_name' }
2019-05-28 15:06:32 +02:00
});
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) = @_;
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
);
2020-04-06 12:07:15 +02:00
$self->{group} = {};
2019-05-28 15:06:32 +02:00
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}));
2020-04-06 12:07:15 +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;
}
2020-04-06 12:07:15 +02:00
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
$display !~ /$self->{option_results}->{filter_name}/) {
$self->{output}->output_add(long_msg => "skipping '" . $display . "': no matching filter.", debug => 1);
next;
}
2019-09-25 11:42:12 +02:00
$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
2020-04-06 12:07:15 +02:00
=item B<--filter-name>
Filter group name (can be a regexp).
2019-05-28 15:06:32 +02:00
=item B<--warning-*>
Threshold warning.
Can be: 'voltage', 'current', 'power'.
=item B<--critical-*>
Threshold critical.
Can be: 'voltage', 'current', 'power'.
=back
=cut