[collectd] [PATCH 6/6] Collectd.pm: Improved error handling of failed callbacks.
Sebastian Harl
sh at tokkee.org
Sat Nov 17 18:45:58 CET 2007
If call_by_name() failed, it will be handled the same way as if the callback
returned "false". The $@ variable may now be used by plugins as well to
describe errors in greater detail.
Signed-off-by: Sebastian Harl <sh at tokkee.org>
---
bindings/perl/Collectd.pm | 27 ++++++++++++++++++---------
src/collectd-perl.pod | 3 +++
2 files changed, 21 insertions(+), 9 deletions(-)
diff --git a/bindings/perl/Collectd.pm b/bindings/perl/Collectd.pm
index 8c3159c..2de9885 100644
--- a/bindings/perl/Collectd.pm
+++ b/bindings/perl/Collectd.pm
@@ -143,12 +143,21 @@ sub plugin_call_all {
$cb_name = $p->{'cb_name'};
$status = call_by_name (@_);
- if (! defined $status) {
+ if (! $status) {
+ my $err = undef;
+
+ if ($@) {
+ $err = $@;
+ }
+ else {
+ $err = "callback returned false";
+ }
+
if (TYPE_LOG != $type) {
- ERROR ("Could not execute callback \"$cb_name\": $@");
+ ERROR ("Execution of callback \"$cb_name\" failed: $err");
}
- next;
+ $status = 0;
}
if ($status) {
@@ -156,23 +165,23 @@ sub plugin_call_all {
$p->{'wait_time'} = 10;
}
elsif (TYPE_READ == $type) {
+ WARNING ("${plugin}->read() failed with status $status. "
+ . "Will suspend it for $p->{'wait_left'} seconds.");
+
$p->{'wait_left'} = $p->{'wait_time'};
$p->{'wait_time'} *= 2;
if ($p->{'wait_time'} > 86400) {
$p->{'wait_time'} = 86400;
}
-
- WARNING ("${plugin}->read() failed with status $status. "
- . "Will suspend it for $p->{'wait_left'} seconds.");
}
elsif (TYPE_INIT == $type) {
+ ERROR ("${plugin}->init() failed with status $status. "
+ . "Plugin will be disabled.");
+
foreach my $type (keys %types) {
plugin_unregister ($type, $plugin);
}
-
- ERROR ("${plugin}->init() failed with status $status. "
- . "Plugin will be disabled.");
}
elsif (TYPE_LOG != $type) {
WARNING ("${plugin}->$types{$type}() failed with status $status.");
diff --git a/src/collectd-perl.pod b/src/collectd-perl.pod
index 2b77667..73bacc6 100644
--- a/src/collectd-perl.pod
+++ b/src/collectd-perl.pod
@@ -103,6 +103,9 @@ be used to clean up the plugin (e.g. close sockets, ...).
=back
+Any function may set the B<$@> variable to describe errors in more detail. The
+message will be passed on to the user using collectd's logging mechanism.
+
See the documentation of the B<plugin_register> method in the section
"METHODS" below for the number and types of arguments passed to each
B<callback function>. This section also explains how to register B<callback
--
1.5.3.4
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://mailman.verplant.org/pipermail/collectd/attachments/20071117/d1fe6549/attachment.pgp
More information about the collectd
mailing list