This commit is contained in:
garnier-quentin 2021-01-28 09:33:29 +01:00
parent fd565f2f70
commit cf199cbdba
3 changed files with 15 additions and 12 deletions

View File

@ -36,7 +36,7 @@ sub custom_load_output {
my ($self, %options) = @_; my ($self, %options) = @_;
return sprintf( return sprintf(
"charge remaining: %s%% (%s minutes remaining)", 'charge remaining: %s%% (%s minutes remaining)',
$self->{result_values}->{charge_remain}, $self->{result_values}->{charge_remain},
$self->{result_values}->{minute_remain} $self->{result_values}->{minute_remain}
); );
@ -46,7 +46,7 @@ sub set_counters {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{maps_counters_type} = [ $self->{maps_counters_type} = [
{ name => 'global', type => 0, message_separator => ' - ', skipped_code => { -10 => 1 } }, { name => 'global', type => 0, message_separator => ' - ', skipped_code => { -10 => 1 } }
]; ];
$self->{maps_counters}->{global} = [ $self->{maps_counters}->{global} = [
@ -129,7 +129,7 @@ my $mapping = {
charge_remain => { oid => '.1.3.6.1.4.1.4555.1.1.7.1.2.4' }, # upsEstimatedChargeRemaining charge_remain => { oid => '.1.3.6.1.4.1.4555.1.1.7.1.2.4' }, # upsEstimatedChargeRemaining
voltage => { oid => '.1.3.6.1.4.1.4555.1.1.7.1.2.5' }, # upsBatteryVoltage (dV) voltage => { oid => '.1.3.6.1.4.1.4555.1.1.7.1.2.5' }, # upsBatteryVoltage (dV)
temperature => { oid => '.1.3.6.1.4.1.4555.1.1.7.1.2.6' }, # upsBatteryTemperature (degrees Centigrade) temperature => { oid => '.1.3.6.1.4.1.4555.1.1.7.1.2.6' }, # upsBatteryTemperature (degrees Centigrade)
current => { oid => '.1.3.6.1.4.1.4555.1.1.7.1.2.8' } # upsBatteryCurrent (dA) current => { oid => '.1.3.6.1.4.1.4555.1.1.7.1.2.8' } # upsBatteryCurrent (dA)
}; };
sub manage_selection { sub manage_selection {
@ -140,8 +140,10 @@ sub manage_selection {
nothing_quit => 1 nothing_quit => 1
); );
$self->{global} = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => 0); $self->{global} = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => 0);
$self->{global}->{current} = (defined($self->{global}->{current}) && $self->{global}->{current} =~ /\d/) ? $self->{global}->{current} * 0.1 : 0; $self->{global}->{current} = (defined($self->{global}->{current}) && $self->{global}->{current} =~ /\d/ && $self->{global}->{current} != -1 && $self->{global}->{current} != 65535) ?
$self->{global}->{voltage} = (defined($self->{global}->{voltage}) && $self->{global}->{voltage} =~ /\d/) ? $self->{global}->{voltage} * 0.1 : 0; $self->{global}->{current} * 0.1 : 0;
$self->{global}->{voltage} = (defined($self->{global}->{voltage}) && $self->{global}->{voltage} =~ /\d/ && $self->{global}->{voltage} != -1 && $self->{global}->{voltage} != 65535) ?
$self->{global}->{voltage} * 0.1 : 0;
$self->{global}->{temperature} = (defined($self->{global}->{temperature}) && $self->{global}->{temperature} =~ /\d/) ? $self->{global}->{temperature} * 0.1 : 0; $self->{global}->{temperature} = (defined($self->{global}->{temperature}) && $self->{global}->{temperature} =~ /\d/) ? $self->{global}->{temperature} * 0.1 : 0;
$self->{global}->{minute_remain} = (defined($self->{global}->{minute_remain}) && $self->{global}->{minute_remain} =~ /\d/) ? $self->{global}->{minute_remain} : 'unknown'; $self->{global}->{minute_remain} = (defined($self->{global}->{minute_remain}) && $self->{global}->{minute_remain} =~ /\d/) ? $self->{global}->{minute_remain} : 'unknown';
$self->{global}->{charge_remain} = (defined($self->{global}->{charge_remain}) && $self->{global}->{charge_remain} =~ /\d/) ? $self->{global}->{charge_remain} : undef; $self->{global}->{charge_remain} = (defined($self->{global}->{charge_remain}) && $self->{global}->{charge_remain} =~ /\d/) ? $self->{global}->{charge_remain} : undef;

View File

@ -110,7 +110,7 @@ sub manage_selection {
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance);
foreach (('current', 'voltage')) { foreach (('current', 'voltage')) {
$result->{$_} = 0 if (defined($result->{$_}) && ($result->{$_} eq '' || $result->{$_} == -1 || $result->{$_} == -65535)); $result->{$_} = 0 if (defined($result->{$_}) && ($result->{$_} eq '' || $result->{$_} == -1 || $result->{$_} == 65535));
$result->{$_} *= 0.1; $result->{$_} *= 0.1;
} }
@ -126,7 +126,7 @@ sub manage_selection {
} }
$self->{global} = $options{snmp}->map_instance(mapping => $mapping2, results => $snmp_result, instance => 0); $self->{global} = $options{snmp}->map_instance(mapping => $mapping2, results => $snmp_result, instance => 0);
$self->{global}->{frequency} = defined($self->{global}->{frequency}) && $self->{global}->{frequency} != -1 && $self->{global}->{frequency} != -65535 $self->{global}->{frequency} = defined($self->{global}->{frequency}) && $self->{global}->{frequency} != -1 && $self->{global}->{frequency} != 65535
? ($self->{global}->{frequency} * 0.1) : 0; ? ($self->{global}->{frequency} * 0.1) : 0;
} }

View File

@ -109,7 +109,7 @@ my $map_status = {
my $mapping = { my $mapping = {
voltage => { oid => '.1.3.6.1.4.1.4555.1.1.7.1.4.4.1.2' }, # upsOutputVoltage (Volt) voltage => { oid => '.1.3.6.1.4.1.4555.1.1.7.1.4.4.1.2' }, # upsOutputVoltage (Volt)
current => { oid => '.1.3.6.1.4.1.4555.1.1.7.1.4.4.1.3' }, # upsOutputCurrent (dA) current => { oid => '.1.3.6.1.4.1.4555.1.1.7.1.4.4.1.3' }, # upsOutputCurrent (dA)
percent_load => { oid => '.1.3.6.1.4.1.4555.1.1.7.1.4.4.1.4' } # upsOutputPercentLoad percent_load => { oid => '.1.3.6.1.4.1.4555.1.1.7.1.4.4.1.4' } # upsOutputPercentLoad
}; };
my $mapping2 = { my $mapping2 = {
status => { oid => '.1.3.6.1.4.1.4555.1.1.7.1.4.1', map => $map_status } # upsOutputSource status => { oid => '.1.3.6.1.4.1.4555.1.1.7.1.4.1', map => $map_status } # upsOutputSource
@ -133,10 +133,11 @@ sub manage_selection {
next if (defined($self->{oline}->{$instance})); next if (defined($self->{oline}->{$instance}));
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance);
if (defined($self->{option_results}->{ignore_zero_counters})) { foreach (keys %$result) {
foreach (keys %$result) { delete $result->{$_} if (
delete $result->{$_} if ($result->{$_} == 0); (defined($self->{option_results}->{ignore_zero_counters}) && $result->{$_} == 0) ||
} ($result->{$_} == -1 || $result->{$_} == 65535)
);
} }
$result->{current} *= 0.1 if (defined($result->{current})); $result->{current} *= 0.1 if (defined($result->{current}));
$result->{voltage} *= 0.1 if (defined($result->{voltage})); $result->{voltage} *= 0.1 if (defined($result->{voltage}));