Merge branch 'master' of https://github.com/centreon/centreon-plugins
This commit is contained in:
commit
797f0e8996
|
@ -0,0 +1,155 @@
|
|||
#
|
||||
# Copyright 2019 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# 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::devices::abb::cms700::snmp::mode::listsensors;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$options{options}->add_options(arguments => {});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
}
|
||||
|
||||
my $oid_GroupName = '.1.3.6.1.4.1.51055.1.20';
|
||||
my $oid_BranchNamesens = '.1.3.6.1.4.1.51055.1.19';
|
||||
my $mapping = {
|
||||
Phasesens => { oid => '.1.3.6.1.4.1.51055.1.21' },
|
||||
Groupsens => { oid => '.1.3.6.1.4.1.51055.1.22' },
|
||||
};
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my %groups;
|
||||
my $snmp_result = $options{snmp}->get_table(oid => $oid_GroupName);
|
||||
foreach my $oid (keys %$snmp_result) {
|
||||
next if ($oid !~ /^$oid_GroupName\.(.*)/);
|
||||
next if ($snmp_result->{$oid} eq '');
|
||||
$groups{$1} = $snmp_result->{$oid};
|
||||
}
|
||||
|
||||
my %sensors;
|
||||
$snmp_result = $options{snmp}->get_table(oid => $oid_BranchNamesens);
|
||||
foreach my $oid (keys %$snmp_result) {
|
||||
next if ($oid !~ /^$oid_BranchNamesens\.(.*)/);
|
||||
next if ($snmp_result->{$oid} eq '');
|
||||
my $instance = $1;
|
||||
|
||||
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
|
||||
$snmp_result->{$oid} !~ /$self->{option_results}->{filter_name}/) {
|
||||
$self->{output}->output_add(long_msg => "skipping sensor '" . $snmp_result->{$oid} . "'.", debug => 1);
|
||||
next;
|
||||
}
|
||||
|
||||
$sensors{$instance} = $snmp_result->{$oid};
|
||||
}
|
||||
|
||||
$options{snmp}->load(
|
||||
oids => [
|
||||
$mapping->{Phasesens}->{oid},
|
||||
$mapping->{Groupsens}->{oid},
|
||||
],
|
||||
instances => [ keys %sensors ],
|
||||
instance_regexp => '^(.*)$'
|
||||
);
|
||||
my $snmp_result_data = $options{snmp}->get_leef(nothing_quit => 1);
|
||||
|
||||
foreach my $oid (keys %$snmp_result_data) {
|
||||
next if ($oid !~ /^$mapping->{Phasesens}->{oid}\.(.*)/);
|
||||
my $instance = $1;
|
||||
my $result = $options{snmp}->map_instance(
|
||||
mapping => $mapping,
|
||||
results => $snmp_result_data,
|
||||
instance => $instance
|
||||
);
|
||||
|
||||
$self->{sensors}->{$instance}->{name} = $sensors{$instance};
|
||||
$self->{sensors}->{$instance}->{phase} = ($result->{Phasesens} != 0) ? $result->{Phasesens} : '-';
|
||||
$self->{sensors}->{$instance}->{group} =
|
||||
(defined($groups{$result->{Groupsens}})) ? $groups{$result->{Groupsens}} : '-';
|
||||
}
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->manage_selection(%options);
|
||||
foreach my $instance (sort keys %{$self->{sensors}}) {
|
||||
$self->{output}->output_add(
|
||||
long_msg => sprintf("[name = %s] [group = %s] [phase = %s]",
|
||||
$self->{sensors}->{$instance}->{name},
|
||||
$self->{sensors}->{$instance}->{group},
|
||||
$self->{sensors}->{$instance}->{phase})
|
||||
);
|
||||
}
|
||||
|
||||
$self->{output}->output_add(
|
||||
severity => 'OK',
|
||||
short_msg => 'List sensors:'
|
||||
);
|
||||
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
sub disco_format {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{output}->add_disco_format(elements => ['name', 'group', 'phase']);
|
||||
}
|
||||
|
||||
sub disco_show {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->manage_selection(%options);
|
||||
foreach my $instance (sort keys %{$self->{sensors}}) {
|
||||
$self->{output}->add_disco_entry(
|
||||
name => $self->{sensors}->{$instance}->{name},
|
||||
group => $self->{sensors}->{$instance}->{group},
|
||||
phase => $self->{sensors}->{$instance}->{phase},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
List sensors.
|
||||
|
||||
=over 8
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -35,7 +35,7 @@ sub set_counters {
|
|||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'global', type => 0 },
|
||||
{ name => 'global', type => 0, cb_init => 'skip_global' },
|
||||
{ name => 'phases', type => 1, cb_prefix_output => 'prefix_output',
|
||||
message_multiple => 'All mains phases are ok', skipped_code => { -10 => 1 } },
|
||||
];
|
||||
|
@ -179,12 +179,20 @@ sub set_counters {
|
|||
];
|
||||
}
|
||||
|
||||
sub skip_global {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
scalar(keys %{$self->{phases}}) > 1 ? return(0) : return(1);
|
||||
}
|
||||
|
||||
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 => {});
|
||||
$options{options}->add_options(arguments => {
|
||||
"filter-phase:s" => { name => 'filter_phase' },
|
||||
});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
@ -224,6 +232,12 @@ sub manage_selection {
|
|||
my $instance = $1;
|
||||
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance);
|
||||
|
||||
if (defined($self->{option_results}->{filter_phase}) && $self->{option_results}->{filter_phase} ne '' &&
|
||||
$instance !~ /$self->{option_results}->{filter_phase}/) {
|
||||
$self->{output}->output_add(long_msg => "skipping sensor '" . $snmp_result->{$oid} . "'.", debug => 1);
|
||||
next;
|
||||
}
|
||||
|
||||
$self->{phases}->{$instance}->{display} = 'L' . $instance;
|
||||
$self->{phases}->{$instance}->{uL} = $result->{uL} / 100;
|
||||
$self->{phases}->{$instance}->{iL} = $result->{iL} / 100;
|
||||
|
@ -259,6 +273,10 @@ Check mains phases measurements.
|
|||
|
||||
=over 8
|
||||
|
||||
=item B<--filter-phase>
|
||||
|
||||
Filter by phase (can be a regexp).
|
||||
|
||||
=item B<--filter-counters>
|
||||
|
||||
Only display some counters (regexp can be used).
|
||||
|
|
|
@ -75,7 +75,7 @@ sub set_counters {
|
|||
},
|
||||
{ label => 'power-active', nlabel => 'sensor.power.active.watt', set => {
|
||||
key_values => [ { name => 'Psens' }, { name => 'display' } ],
|
||||
output_template => 'Active Power: %.2f',
|
||||
output_template => 'Active Power: %.2f W',
|
||||
perfdatas => [
|
||||
{ value => 'Psens_absolute', template => '%.2f', unit => 'W', min => 0,
|
||||
label_extra_instance => 1, instance_use => 'display_absolute' },
|
||||
|
@ -84,7 +84,7 @@ sub set_counters {
|
|||
},
|
||||
{ label => 'energy-active', nlabel => 'sensor.energy.active.watthours', set => {
|
||||
key_values => [ { name => 'Whsens' }, { name => 'display' } ],
|
||||
output_template => 'Active Energy: %.2f',
|
||||
output_template => 'Active Energy: %.2f Wh',
|
||||
perfdatas => [
|
||||
{ value => 'Whsens_absolute', template => '%.2f', unit => 'Wh', min => 0,
|
||||
label_extra_instance => 1, instance_use => 'display_absolute' },
|
||||
|
@ -136,7 +136,6 @@ my $mapping = {
|
|||
Groupsens => { oid => '.1.3.6.1.4.1.51055.1.22' },
|
||||
PowerFactorsens => { oid => '.1.3.6.1.4.1.51055.1.23' },
|
||||
};
|
||||
my $oid_main = '.1.3.6.1.4.1.51055.1';
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
@ -182,6 +181,7 @@ sub manage_selection {
|
|||
);
|
||||
my $snmp_result_data = $options{snmp}->get_leef(nothing_quit => 1);
|
||||
|
||||
$self->{sensors} = {};
|
||||
foreach my $oid (keys %$snmp_result_data) {
|
||||
next if ($oid !~ /^$mapping->{TRMSsens}->{oid}\.(.*)/);
|
||||
my $instance = $1;
|
||||
|
@ -192,7 +192,8 @@ sub manage_selection {
|
|||
);
|
||||
|
||||
if (defined($self->{option_results}->{filter_group}) && $self->{option_results}->{filter_group} ne '' &&
|
||||
(!defined($groups{$result->{Groupsens}}) || ($groups{$result->{Groupsens}} !~ /$self->{option_results}->{filter_group}/))) {
|
||||
(!defined($groups{$result->{Groupsens}}) ||
|
||||
($groups{$result->{Groupsens}} !~ /$self->{option_results}->{filter_group}/))) {
|
||||
$self->{output}->output_add(long_msg => "skipping sensor '" . $sensors{$instance} . "'.", debug => 1);
|
||||
next;
|
||||
}
|
||||
|
@ -212,7 +213,8 @@ sub manage_selection {
|
|||
$self->{sensors}->{$instance}->{PowerFactorsens} = $result->{PowerFactorsens} / 100;
|
||||
|
||||
$self->{sensors}->{$instance}->{Phasesens} = $result->{Phasesens};
|
||||
$self->{sensors}->{$instance}->{Groupsens} = (defined($groups{$result->{Groupsens}})) ? $groups{$result->{Groupsens}} : '-';
|
||||
$self->{sensors}->{$instance}->{Groupsens} =
|
||||
(defined($groups{$result->{Groupsens}})) ? $groups{$result->{Groupsens}} : '-';
|
||||
}
|
||||
|
||||
if (scalar(keys %{$self->{sensors}}) <= 0) {
|
||||
|
|
Loading…
Reference in New Issue