add filter name for pdu eaton

This commit is contained in:
garnier-quentin 2020-04-06 12:07:15 +02:00
parent 2099b7ccd9
commit 1b33f69e12
2 changed files with 38 additions and 14 deletions

View File

@ -27,9 +27,9 @@ 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 } },
{ name => 'group', type => 1, cb_prefix_output => 'prefix_group_output', message_multiple => 'All groups are ok', skipped_code => { -10 => 1 } }
];
$self->{maps_counters}->{group} = [
@ -38,8 +38,8 @@ sub set_counters {
output_template => 'Current : %.2f A',
perfdatas => [
{ value => 'groupCurrent_absolute', template => '%.2f',
min => 0, unit => 'A', label_extra_instance => 1, instance_use => 'display_absolute' },
],
min => 0, unit => 'A', label_extra_instance => 1, instance_use => 'display_absolute' }
]
}
},
{ label => 'voltage', nlabel => 'group.voltage.volt', set => {
@ -47,8 +47,8 @@ sub set_counters {
output_template => 'Voltage : %.2f V',
perfdatas => [
{ value => 'groupVoltage_absolute', template => '%.2f',
unit => 'V', label_extra_instance => 1, instance_use => 'display_absolute' },
],
unit => 'V', label_extra_instance => 1, instance_use => 'display_absolute' }
]
}
},
{ label => 'power', nlabel => 'group.power.watt', set => {
@ -56,10 +56,10 @@ sub set_counters {
output_template => 'Power : %.2f W',
perfdatas => [
{ value => 'groupWatts_absolute', template => '%.2f',
unit => 'W', label_extra_instance => 1, instance_use => 'display_absolute' },
],
unit => 'W', label_extra_instance => 1, instance_use => 'display_absolute' }
]
}
},
}
];
}
@ -69,6 +69,7 @@ sub new {
bless $self, $class;
$options{options}->add_options(arguments => {
'filter-name:s' => { name => 'filter_name' }
});
return $self;
@ -90,7 +91,6 @@ my $mapping = {
sub manage_selection {
my ($self, %options) = @_;
$self->{group} = {};
my $snmp_result = $options{snmp}->get_multiple_table(
oids => [
{ oid => $mapping->{groupName}->{oid} },
@ -101,11 +101,12 @@ sub manage_selection {
return_type => 1, nothing_quit => 1
);
$self->{group} = {};
foreach my $oid (keys %{$snmp_result}) {
$oid =~ /\.(\d+)\.(\d+)$/;
my ($strapping_index, $group_index) = ($1, $2);
next if (defined($self->{group}->{$strapping_index . '.' . $group_index}));
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $strapping_index . '.' . $group_index);
$result->{groupVoltage} *= 0.001 if (defined($result->{groupVoltage}));
$result->{groupCurrent} *= 0.001 if (defined($result->{groupCurrent}));
@ -113,6 +114,13 @@ sub manage_selection {
if (defined($result->{groupName}) && $result->{groupName} ne '') {
$display = $result->{groupName} . ' strapping ' . $strapping_index;
}
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;
}
$self->{group}->{$strapping_index . '.' . $group_index} = { display => $display, %$result };
}
@ -132,6 +140,10 @@ Check group metrics (voltage, current and power).
=over 8
=item B<--filter-name>
Filter group name (can be a regexp).
=item B<--warning-*>
Threshold warning.

View File

@ -69,6 +69,7 @@ sub new {
bless $self, $class;
$options{options}->add_options(arguments => {
'filter-name:s' => { name => 'filter_name' }
});
return $self;
@ -90,7 +91,6 @@ my $mapping = {
sub manage_selection {
my ($self, %options) = @_;
$self->{outlet} = {};
my $snmp_result = $options{snmp}->get_multiple_table(
oids => [
{ oid => $mapping->{outletName}->{oid} },
@ -101,12 +101,13 @@ sub manage_selection {
return_type => 1, nothing_quit => 1
);
$self->{outlet} = {};
foreach my $oid (keys %{$snmp_result}) {
$oid =~ /\.(\d+)\.(\d+)$/;
my ($strapping_index, $outlet_index) = ($1, $2);
next if (defined($self->{outlet}->{$strapping_index . '.' . $outlet_index}));
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $strapping_index . '.' . $outlet_index);
$result->{outletVoltage} *= 0.001 if (defined($result->{outletVoltage}));
$result->{outletCurrent} *= 0.001 if (defined($result->{outletCurrent}));
@ -114,6 +115,13 @@ sub manage_selection {
if (defined($result->{outletName}) && $result->{outletName} ne '') {
$display = $result->{outletName} . ' strapping ' . $strapping_index;
}
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;
}
$self->{outlet}->{$strapping_index . '.' . $outlet_index} = { display => $display, %$result };
}
@ -133,6 +141,10 @@ Check outlet metrics (voltage, current and power).
=over 8
=item B<--filter-name>
Filter outlet name (can be a regexp).
=item B<--warning-*>
Threshold warning.