(plugin) hardware::ups::powerware::snmp - mode input-lines fix wrong threshold (#3962)

This commit is contained in:
qgarnier 2022-10-06 09:31:07 +02:00 committed by GitHub
parent 67e668cdf8
commit 70b1de5e13
3 changed files with 46 additions and 51 deletions

View File

@ -46,41 +46,41 @@ sub set_counters {
closure_custom_calc => \&catalog_status_calc, closure_custom_calc => \&catalog_status_calc,
closure_custom_output => $self->can('custom_status_output'), closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; }, closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold, closure_custom_threshold_check => \&catalog_status_threshold
} }
}, },
{ label => 'charge-remaining', , nlabel => 'battery.charge.remaining.percent', set => { { label => 'charge-remaining', , nlabel => 'battery.charge.remaining.percent', set => {
key_values => [ { name => 'xupsBatCapacity' } ], key_values => [ { name => 'xupsBatCapacity' } ],
output_template => 'remaining capacity: %s %%', output_template => 'remaining capacity: %s %%',
perfdatas => [ perfdatas => [
{ value => 'xupsBatCapacity', template => '%s', min => 0, max => 100, unit => '%' }, { template => '%s', min => 0, max => 100, unit => '%' }
], ]
} }
}, },
{ label => 'charge-remaining-minutes', nlabel => 'battery.charge.remaining.minutes', display_ok => 0, set => { { label => 'charge-remaining-minutes', nlabel => 'battery.charge.remaining.minutes', display_ok => 0, set => {
key_values => [ { name => 'xupsBatTimeRemaining' } ], key_values => [ { name => 'xupsBatTimeRemaining' } ],
output_template => 'remaining time: %s minutes', output_template => 'remaining time: %s minutes',
perfdatas => [ perfdatas => [
{ value => 'xupsBatTimeRemaining', template => '%s', min => 0, unit => 'm' }, { template => '%s', min => 0, unit => 'm' }
], ]
} }
}, },
{ label => 'current', nlabel => 'battery.current.ampere', display_ok => 0, set => { { label => 'current', nlabel => 'battery.current.ampere', display_ok => 0, set => {
key_values => [ { name => 'xupsBatCurrent', no_value => 0 } ], key_values => [ { name => 'xupsBatCurrent', no_value => 0 } ],
output_template => 'current: %s A', output_template => 'current: %s A',
perfdatas => [ perfdatas => [
{ value => 'xupsBatCurrent', template => '%s', unit => 'A' }, { template => '%s', unit => 'A' }
], ]
} }
}, },
{ label => 'voltage', nlabel => 'battery.voltage.volt', display_ok => 0, set => { { label => 'voltage', nlabel => 'battery.voltage.volt', display_ok => 0, set => {
key_values => [ { name => 'xupsBatVoltage', no_value => 0 } ], key_values => [ { name => 'xupsBatVoltage', no_value => 0 } ],
output_template => 'voltage: %s V', output_template => 'voltage: %s V',
perfdatas => [ perfdatas => [
{ value => 'xupsBatVoltage', template => '%s', unit => 'V' }, { template => '%s', unit => 'V' }
], ]
}
} }
},
]; ];
} }
@ -92,7 +92,7 @@ sub new {
$options{options}->add_options(arguments => { $options{options}->add_options(arguments => {
'unknown-status:s' => { name => 'unknown_status', default => '%{status} =~ /unknown/i' }, 'unknown-status:s' => { name => 'unknown_status', default => '%{status} =~ /unknown/i' },
'warning-status:s' => { name => 'warning_status', default => '%{status} =~ /batteryDischarging/i' }, 'warning-status:s' => { name => 'warning_status', default => '%{status} =~ /batteryDischarging/i' },
'critical-status:s' => { name => 'critical_status', default => '' }, 'critical-status:s' => { name => 'critical_status', default => '' }
}); });
return $self; return $self;
@ -108,7 +108,7 @@ sub check_options {
my $map_battery_status = { my $map_battery_status = {
1 => 'batteryCharging', 2 => 'batteryDischarging', 1 => 'batteryCharging', 2 => 'batteryDischarging',
3 => 'batteryFloating', 4 => 'batteryResting', 3 => 'batteryFloating', 4 => 'batteryResting',
5 => 'unknown', 5 => 'unknown'
}; };
my $mapping = { my $mapping = {
@ -116,7 +116,7 @@ my $mapping = {
xupsBatVoltage => { oid => '.1.3.6.1.4.1.534.1.2.2' }, # in V xupsBatVoltage => { oid => '.1.3.6.1.4.1.534.1.2.2' }, # in V
xupsBatCurrent => { oid => '.1.3.6.1.4.1.534.1.2.3' }, # in dA xupsBatCurrent => { oid => '.1.3.6.1.4.1.534.1.2.3' }, # in dA
xupsBatCapacity => { oid => '.1.3.6.1.4.1.534.1.2.4' }, xupsBatCapacity => { oid => '.1.3.6.1.4.1.534.1.2.4' },
xupsBatteryAbmStatus => { oid => '.1.3.6.1.4.1.534.1.2.5', map => $map_battery_status }, xupsBatteryAbmStatus => { oid => '.1.3.6.1.4.1.534.1.2.5', map => $map_battery_status }
}; };
sub manage_selection { sub manage_selection {

View File

@ -25,6 +25,12 @@ use base qw(centreon::plugins::templates::counter);
use strict; use strict;
use warnings; use warnings;
sub prefix_iline_output {
my ($self, %options) = @_;
return "Input Line '" . $options{instance_value}->{display} . "' ";
}
sub set_counters { sub set_counters {
my ($self, %options) = @_; my ($self, %options) = @_;
@ -84,12 +90,6 @@ sub new {
return $self; return $self;
} }
sub prefix_iline_output {
my ($self, %options) = @_;
return "Input Line '" . $options{instance_value}->{display} . "' ";
}
my $mapping = { my $mapping = {
xupsInputVoltage => { oid => '.1.3.6.1.4.1.534.1.3.4.1.2' }, # in V xupsInputVoltage => { oid => '.1.3.6.1.4.1.534.1.3.4.1.2' }, # in V
xupsInputCurrent => { oid => '.1.3.6.1.4.1.534.1.3.4.1.3' }, # in A xupsInputCurrent => { oid => '.1.3.6.1.4.1.534.1.3.4.1.3' }, # in A
@ -145,15 +145,15 @@ sub manage_selection {
my $result = $options{snmp}->map_instance(mapping => $mapping2, results => $snmp_result, instance => '0'); my $result = $options{snmp}->map_instance(mapping => $mapping2, results => $snmp_result, instance => '0');
$result->{xupsInputFrequency} = defined($result->{xupsInputFrequency}) ? ($result->{xupsInputFrequency} * 0.1) : 0; $result->{xupsInputFrequency} = defined($result->{xupsInputFrequency}) ? ($result->{xupsInputFrequency} * 0.1) : 0;
$self->{global} = { %$result }; $self->{global} = $result;
$result = $options{snmp}->map_instance(mapping => $mapping3, results => $snmp_result, instance => '0'); $result = $options{snmp}->map_instance(mapping => $mapping3, results => $snmp_result, instance => '0');
if ((!defined($self->{option_results}->{'warning-voltage'}) || $self->{option_results}->{'warning-voltage'} eq '') && if ((!defined($self->{option_results}->{'warning-voltage'}) || $self->{option_results}->{'warning-voltage'} eq '') &&
(!defined($self->{option_results}->{'critical-voltage'}) || $self->{option_results}->{'critical-voltage'} eq '') (!defined($self->{option_results}->{'critical-voltage'}) || $self->{option_results}->{'critical-voltage'} eq '')
) { ) {
my $th = ''; my $th = '';
$th .= $result->{upsConfigHighVoltageTransferPoint} if (defined($result->{upsConfigHighVoltageTransferPoint}) && $result->{upsConfigHighVoltageTransferPoint} =~ /\d+/); $th .= $result->{upsConfigHighVoltageTransferPoint} if (defined($result->{upsConfigHighVoltageTransferPoint}) && $result->{upsConfigHighVoltageTransferPoint} =~ /\d+/ && $result->{upsConfigHighVoltageTransferPoint} != 0);
$th = $result->{upsConfigLowVoltageTransferPoint} . ':' . $th if (defined($result->{upsConfigLowVoltageTransferPoint}) && $result->{upsConfigLowVoltageTransferPoint} =~ /\d+/); $th = $result->{upsConfigLowVoltageTransferPoint} . ':' . $th if (defined($result->{upsConfigLowVoltageTransferPoint}) && $result->{upsConfigLowVoltageTransferPoint} =~ /\d+/ && $result->{upsConfigLowVoltageTransferPoint} != 0);
$self->{perfdata}->threshold_validate(label => 'critical-voltage', value => $th) if ($th ne ''); $self->{perfdata}->threshold_validate(label => 'critical-voltage', value => $th) if ($th ne '');
} }
} }

View File

@ -25,6 +25,12 @@ use base qw(centreon::plugins::templates::counter);
use strict; use strict;
use warnings; use warnings;
sub prefix_oline_output {
my ($self, %options) = @_;
return "Output Line '" . $options{instance_value}->{display} . "' ";
}
sub set_counters { sub set_counters {
my ($self, %options) = @_; my ($self, %options) = @_;
@ -38,20 +44,18 @@ sub set_counters {
key_values => [ { name => 'xupsOutputLoad', no_value => -1 } ], key_values => [ { name => 'xupsOutputLoad', no_value => -1 } ],
output_template => 'Load : %.2f %%', output_template => 'Load : %.2f %%',
perfdatas => [ perfdatas => [
{ value => 'xupsOutputLoad', template => '%.2f', { template => '%.2f', min => 0, max => 100 }
min => 0, max => 100 }, ]
],
} }
}, },
{ label => 'frequence', nlabel => 'lines.output.frequence.hertz', set => { { label => 'frequence', nlabel => 'lines.output.frequence.hertz', set => {
key_values => [ { name => 'xupsOutputFrequency', no_value => 0 } ], key_values => [ { name => 'xupsOutputFrequency', no_value => 0 } ],
output_template => 'Frequence : %.2f Hz', output_template => 'Frequence : %.2f Hz',
perfdatas => [ perfdatas => [
{ value => 'xupsOutputFrequency', template => '%.2f', { template => '%.2f', unit => 'Hz' }
unit => 'Hz' }, ]
], }
} }
},
]; ];
$self->{maps_counters}->{oline} = [ $self->{maps_counters}->{oline} = [
@ -59,29 +63,26 @@ sub set_counters {
key_values => [ { name => 'xupsOutputCurrent', no_value => 0 } ], key_values => [ { name => 'xupsOutputCurrent', no_value => 0 } ],
output_template => 'Current : %.2f A', output_template => 'Current : %.2f A',
perfdatas => [ perfdatas => [
{ value => 'xupsOutputCurrent', template => '%.2f', { template => '%.2f', min => 0, unit => 'A', label_extra_instance => 1 }
min => 0, unit => 'A', label_extra_instance => 1 }, ]
],
} }
}, },
{ label => 'voltage', nlabel => 'line.output.voltage.volt', set => { { label => 'voltage', nlabel => 'line.output.voltage.volt', set => {
key_values => [ { name => 'xupsOutputVoltage', no_value => 0 } ], key_values => [ { name => 'xupsOutputVoltage', no_value => 0 } ],
output_template => 'Voltage : %.2f V', output_template => 'Voltage : %.2f V',
perfdatas => [ perfdatas => [
{ value => 'xupsOutputVoltage', template => '%.2f', { template => '%.2f', unit => 'V', label_extra_instance => 1 }
unit => 'V', label_extra_instance => 1 }, ]
],
} }
}, },
{ label => 'power', nlabel => 'line.output.power.watt', set => { { label => 'power', nlabel => 'line.output.power.watt', set => {
key_values => [ { name => 'xupsOutputWatts', no_value => 0 } ], key_values => [ { name => 'xupsOutputWatts', no_value => 0 } ],
output_template => 'Power: %.2f W', output_template => 'Power: %.2f W',
perfdatas => [ perfdatas => [
{ value => 'xupsOutputWatts', template => '%.2f', { template => '%.2f', unit => 'W', label_extra_instance => 1 }
unit => 'W', label_extra_instance => 1 }, ]
], }
} }
},
]; ];
} }
@ -96,20 +97,14 @@ sub new {
return $self; return $self;
} }
sub prefix_oline_output {
my ($self, %options) = @_;
return "Output Line '" . $options{instance_value}->{display} . "' ";
}
my $mapping = { my $mapping = {
xupsOutputVoltage => { oid => '.1.3.6.1.4.1.534.1.4.4.1.2' }, # in V xupsOutputVoltage => { oid => '.1.3.6.1.4.1.534.1.4.4.1.2' }, # in V
xupsOutputCurrent => { oid => '.1.3.6.1.4.1.534.1.4.4.1.3' }, # in A xupsOutputCurrent => { oid => '.1.3.6.1.4.1.534.1.4.4.1.3' }, # in A
xupsOutputWatts => { oid => '.1.3.6.1.4.1.534.1.4.4.1.4' }, # in W xupsOutputWatts => { oid => '.1.3.6.1.4.1.534.1.4.4.1.4' } # in W
}; };
my $mapping2 = { my $mapping2 = {
xupsOutputLoad => { oid => '.1.3.6.1.4.1.534.1.4.1' }, # in % xupsOutputLoad => { oid => '.1.3.6.1.4.1.534.1.4.1' }, # in %
xupsOutputFrequency => { oid => '.1.3.6.1.4.1.534.1.4.2' }, # in dHZ xupsOutputFrequency => { oid => '.1.3.6.1.4.1.534.1.4.2' } # in dHZ
}; };
my $oid_xupsOutput = '.1.3.6.1.4.1.534.1.4'; my $oid_xupsOutput = '.1.3.6.1.4.1.534.1.4';