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) = @_;
return sprintf(
"charge remaining: %s%% (%s minutes remaining)",
'charge remaining: %s%% (%s minutes remaining)',
$self->{result_values}->{charge_remain},
$self->{result_values}->{minute_remain}
);
@ -46,7 +46,7 @@ sub set_counters {
my ($self, %options) = @_;
$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} = [
@ -140,8 +140,10 @@ sub manage_selection {
nothing_quit => 1
);
$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}->{voltage} = (defined($self->{global}->{voltage}) && $self->{global}->{voltage} =~ /\d/) ? $self->{global}->{voltage} * 0.1 : 0;
$self->{global}->{current} = (defined($self->{global}->{current}) && $self->{global}->{current} =~ /\d/ && $self->{global}->{current} != -1 && $self->{global}->{current} != 65535) ?
$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}->{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;

View File

@ -110,7 +110,7 @@ sub manage_selection {
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance);
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;
}
@ -126,7 +126,7 @@ sub manage_selection {
}
$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;
}

View File

@ -133,10 +133,11 @@ sub manage_selection {
next if (defined($self->{oline}->{$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) {
delete $result->{$_} if ($result->{$_} == 0);
}
delete $result->{$_} if (
(defined($self->{option_results}->{ignore_zero_counters}) && $result->{$_} == 0) ||
($result->{$_} == -1 || $result->{$_} == 65535)
);
}
$result->{current} *= 0.1 if (defined($result->{current}));
$result->{voltage} *= 0.1 if (defined($result->{voltage}));