-
Notifications
You must be signed in to change notification settings - Fork 175
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
base: master
Are you sure you want to change the base?
Conversation
Allow custom_query checks with multiple rows of output to populate the second returned column as the perfdata variable name. Pass the result value as the perfdata value. Helpful for count(*) GROUP BY queries.
Addresses concern raised in [Issue bucardo#69](bucardo#69)
## 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. |
There was a problem hiding this comment.
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; | ||
my $grandtotal = @{$db->{slurp}}; |
There was a problem hiding this comment.
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
$perfdata = sprintf ' %s=%s;%s;%s', | ||
perfname($r->{$perfname}), $result, $warning, $critical; | ||
if ($perfdata ne $db->{perf}){ | ||
$db->{perf} .= $perfdata; |
There was a problem hiding this comment.
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.
Build test are failing for
|
Fixes error ` Use of uninitialized value in string ne`
my $perfdata = ''; | ||
if (! defined $db->{perf}){ | ||
$db->{perf} = ''; | ||
} |
There was a problem hiding this comment.
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
if (! defined $db->{perf}){ | ||
$db->{perf} = ''; | ||
} | ||
my $grandtotal = @{$db->{slurp}}; |
There was a problem hiding this comment.
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
Any chance someone can review this and see about merging it? Without it, custom queries are pretty much useless if you need to use perfdata. |
Please merge this fix as we require these changes also. |
Allow
custom_query
checks with multiple rows of output to populate the second returned column as the perfdata variable name. Pass the result value as the perfdata value. Helpful forcount(*) GROUP BY
queries.Example: alert when the count of any fruit is below 5. Output performance data for each fruit.
Current output without this change is not very useful: repeats the name of the 2nd column as the perfdata variable name, provides the name of each fruit as the perfdata value, but not the count. Repeats the threshold as the value.
With the change, trends in fruit counts can now be tracked over time in the performance data: