From: Sebastian Harl Date: Tue, 10 Apr 2007 22:27:54 +0000 (+0200) Subject: perl plugin: Exported plugin_log() to Perl. X-Git-Tag: collectd-4.0.0-rc4~2 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=21ebca2d467304ebd3dc187d3ecdda6e5aff9d52;p=collectd.git perl plugin: Exported plugin_log() to Perl. This adds the following function to collectd's Perl API: Collectd::plugin_log: pass a message to collectd's logging mechanism arguments: level - log level message - log message The log level should be any of the Collectd::LOG_* constants. Signed-off-by: Sebastian Harl --- diff --git a/src/collectd.pod b/src/collectd.pod index 08524901..6d298049 100644 --- a/src/collectd.pod +++ b/src/collectd.pod @@ -76,6 +76,10 @@ NFS utilization (I, Linux only) =item +Embedded Perl interpreter (I) + +=item + Network latency (I) =item @@ -269,10 +273,10 @@ I<5.2.4. Server Status Variables> for an explanation of these values. =head2 perl The C includes a Perl-interpreter in collectd and provides -Perl-equvalents of the plugin-functions. This makes it possible to write +Perl-equivalents of the plugin-functions. This makes it possible to write plugins in Perl. -There are two more comlex types you need to know about: +There are two more complex types you need to know about: =over 4 @@ -345,7 +349,7 @@ array-reference which points to an array of hashes. Each hash describes one data-source. For the exact layout see B above. If the I argument is any of the other types (B, B, -...) when I is expected to be a funtion reference. These functions are +...) then I is expected to be a function reference. These functions are called in the various stages of the daemon and are passed the following arguments: @@ -388,7 +392,8 @@ registered with the daemon. =item B (I, I) -TODO. +Submits a I of level I to collectd's logging mechanism. +The message is passed to all log-callbacks that are registered with collectd. =back diff --git a/src/perl.c b/src/perl.c index 0c5e8829..294f69a2 100644 --- a/src/perl.c +++ b/src/perl.c @@ -56,6 +56,7 @@ void boot_DynaLoader (PerlInterpreter *, CV *); static XS (Collectd_plugin_register); static XS (Collectd_plugin_unregister); static XS (Collectd_plugin_dispatch_values); +static XS (Collectd_plugin_log); /* @@ -101,6 +102,7 @@ static struct { { "Collectd::plugin_register", Collectd_plugin_register }, { "Collectd::plugin_unregister", Collectd_plugin_unregister }, { "Collectd::plugin_dispatch_values", Collectd_plugin_dispatch_values }, + { "Collectd::plugin_log", Collectd_plugin_log }, { "", NULL } }; @@ -825,7 +827,6 @@ static XS (Collectd_plugin_dispatch_values) dXSARGS; - items = 2; if (2 != items) { log_err ("Usage: Collectd::plugin_dispatch_values(name, values)"); XSRETURN_EMPTY; @@ -853,6 +854,30 @@ static XS (Collectd_plugin_dispatch_values) XSRETURN_EMPTY; } /* static XS (Collectd_plugin_dispatch_values) */ +/* + * Collectd::plugin_log (level, message). + * + * level: + * log level (LOG_DEBUG, ... LOG_ERR) + * + * message: + * log message + */ +static XS (Collectd_plugin_log) +{ + dXSARGS; + + if (2 != items) { + log_err ("Usage: Collectd::plugin_log(level, message)"); + XSRETURN_EMPTY; + } + + log_debug ("Collectd::plugin_log: level = %i, message = \"%s\"", + SvIV (ST (0)), SvPV_nolen (ST (1))); + plugin_log (SvIV (ST (0)), SvPV_nolen (ST (1))); + XSRETURN_YES; +} /* static XS (Collectd_plugin_log) */ + /* * Collectd::bootstrap (). */