Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

custom_query perfdata multi-row output improvements #122

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions check_postgres.pl
Original file line number Diff line number Diff line change
Expand Up @@ -4398,9 +4398,17 @@ sub check_custom_query {

my $goodrow = 0;

## The other column tells it the name to use as the perfdata value
## If there is a single row and at least 2 columns,
## the other column tells it the name to use as the perfdata value
## If there are multiple rows and at least 2 columns,
## use the second column value as the perfdata name,
## use the result value as the perfdata value.
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added comments to explain exactly how the query results are processed into performance data

my $perfname;

my $perfdata = '';
if (! defined $db->{perf}){
$db->{perf} = '';
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initialize perfdata variables before they are compared

my $grandtotal = @{$db->{slurp}};
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check the number of rows returned by the custom query

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Get the returned custom query row count

for my $r (@{$db->{slurp}}) {
my $result = $r->{result};
if (! defined $perfname) {
Expand All @@ -4413,8 +4421,16 @@ sub check_custom_query {
}
$goodrow++;
if ($perfname) {
$db->{perf} .= sprintf ' %s=%s;%s;%s',
perfname($perfname), $r->{$perfname}, $warning, $critical;
if ($grandtotal > 1) {
$perfdata = sprintf ' %s=%s;%s;%s',
perfname($r->{$perfname}), $result, $warning, $critical;
if ($perfdata ne $db->{perf}){
$db->{perf} .= $perfdata;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If more than one row is returned, store the perfdata to a temporary variable and check if it has already been appended to the output.

}
} else {
$db->{perf} .= sprintf ' %s=%s;%s;%s',
perfname($perfname), $r->{$perfname}, $warning, $critical;
}
}
my $gotmatch = 0;
if (! defined $result) {
Expand Down