[Nagiosplug-devel] check_qmailq
Paul L. Allen
pla at softflare.com
Thu Jan 8 04:57:05 CET 2004
I tried the check_qmailq plugin from the contrib directory and found it
somewhat lacking because the critical and warning limits are hard-wired.
So I ended up rewriting it.
In the course of writing it I found it useful to make some changes to
utils.pm to avoid the necessity to duplicate code. For example, the
current usage routine exits with an unknown status, meaning that if you
want to print the usage in the help text you essentially have to do the
same thing a different way. With the following change, calling
usage in void context results in the current behavior but calling it
in scalar or array context (such as print usage("Whatever\n");) results
in it printing the usage without exiting. It could be more efficient,
but not without breaking the existing usage.
sub usage {
return(sprintf(shift(@_), @_)) if (defined(wantarray));
printf(@_);
exit $ERRORS{UNKNOWN};
}
Another thing I found useful in avoiding inconsistencies between exit
status and textual response was:
%ERROR_FLAGS = reverse(%ERRORS);
Most perl plugins seem to determine the status code then use if statements
to work out what to print at the start of the textual response. With
%ERROR_FLAGS this can be simplified to:
print "$ERROR_FLAGS{$status} - $queue messages in queue...\n"
I also wrote a check_range routine that (I hope) accepts a metric and
a numeric or percentage range in all possible forms and returns true
if the metric is OK. It takes an optional parameter for use in
constructing error messages about malformed ranges. It's a bit long
to paste here, but I'm happy to mail it if you want.
So the question is, do you want my check_qmailq? If so, will you
incorporate the changes in utils.pm or should I pull them out of my
local utils.pm and stick them directly into my check_qmailq where they
benefit me but not others?
--
Paul Allen
Softflare Support
More information about the Devel
mailing list