Merge pull request #1453 from CPbN/perfdata

Add new perfdata only if value is set
This commit is contained in:
qgarnier 2019-03-27 15:54:42 +01:00 committed by GitHub
commit 7c19408a63
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 6 deletions

View File

@ -999,14 +999,16 @@ sub apply_pfdata_sum {
my $pattern_pf; my $pattern_pf;
eval "\$pattern_pf = \"$options{args}->{pattern_pf}\""; eval "\$pattern_pf = \"$options{args}->{pattern_pf}\"";
my $sum = 0; my ($sum, $num) = (0, 0);
for (my $i = 0; $i < scalar(@{$self->{perfdatas}}); $i++) { for (my $i = 0; $i < scalar(@{$self->{perfdatas}}); $i++) {
next if ($self->{perfdatas}->[$i]->{label} !~ /$pattern_pf/); next if ($self->{perfdatas}->[$i]->{label} !~ /$pattern_pf/);
next if ($self->{perfdatas}->[$i]->{value} !~ /\d+/); next if ($self->{perfdatas}->[$i]->{value} !~ /\d+/);
$sum += $self->{perfdatas}->[$i]->{value}; $sum += $self->{perfdatas}->[$i]->{value};
$num++;
} }
${$options{perf}}->{value} = $sum; ${$options{perf}}->{value} = $sum
if ($num > 0);
} }
sub apply_pfdata_average { sub apply_pfdata_average {
@ -1022,7 +1024,8 @@ sub apply_pfdata_average {
$num++; $num++;
} }
${$options{perf}}->{value} = ($num > 0) ? sprintf("%.2f", ($sum / $num)) : 0; ${$options{perf}}->{value} = sprintf("%.2f", ($sum / $num))
if ($num > 0);
} }
sub load_perfdata_extend_args { sub load_perfdata_extend_args {
@ -1114,7 +1117,9 @@ sub apply_perfdata_extend {
$func->($self, perf => \$new_perf, args => $extend->{method_args}); $func->($self, perf => \$new_perf, args => $extend->{method_args});
} }
push @{$self->{perfdatas}}, $new_perf; if (length($new_perf->{value})) {
push @{$self->{perfdatas}}, $new_perf;
}
next; next;
} }
@ -1145,8 +1150,10 @@ sub apply_perfdata_extend {
push @$new_pfdata, $new_perf; push @$new_pfdata, $new_perf;
} }
} }
push @{$self->{perfdatas}}, @$new_pfdata; if (length($new_pfdata->{value})) {
push @{$self->{perfdatas}}, @$new_pfdata;
}
} }
} }