summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: e5c14a8)
raw | patch | inline | side by side (parent: e5c14a8)
author | Sebastian Harl <sh@tokkee.org> | |
Mon, 28 Jan 2008 11:20:29 +0000 (12:20 +0100) | ||
committer | Florian Forster <octo@huhu.verplant.org> | |
Mon, 4 Feb 2008 16:40:23 +0000 (17:40 +0100) |
Perl plugin may now register a callback of type Collectd::TYPE_NOTIF which
accepts a single hash argument with the following members:
severity
time
message
host
plugin
plugin_instance
type
type_instance
Severity may be any of the following values (exported by the "notif" tag):
Collectd::NOTIF_FAILURE
Collectd::NOTIF_WARNING
Collectd::NOTIF_OKAY
Signed-off-by: Sebastian Harl <sh@tokkee.org>
Signed-off-by: Florian Forster <octo@huhu.verplant.org>
accepts a single hash argument with the following members:
severity
time
message
host
plugin
plugin_instance
type
type_instance
Severity may be any of the following values (exported by the "notif" tag):
Collectd::NOTIF_FAILURE
Collectd::NOTIF_WARNING
Collectd::NOTIF_OKAY
Signed-off-by: Sebastian Harl <sh@tokkee.org>
Signed-off-by: Florian Forster <octo@huhu.verplant.org>
bindings/perl/Collectd.pm | patch | blob | history | |
src/perl.c | patch | blob | history |
index 95a8a0a1b8b4a23a24a38fecb6f641eaed8b64c4..e0700f0a61df673d85230845148de30e2704381e 100644 (file)
TYPE_WRITE
TYPE_SHUTDOWN
TYPE_LOG
+ TYPE_NOTIF
TYPE_DATASET
) ],
'ds_types' => [ qw(
LOG_INFO
LOG_DEBUG
) ],
+ 'notif' => [ qw(
+ NOTIF_FAILURE
+ NOTIF_WARNING
+ NOTIF_OKAY
+ ) ],
'globals' => [ qw(
$hostname_g
$interval_g
TYPE_READ, "read",
TYPE_WRITE, "write",
TYPE_SHUTDOWN, "shutdown",
- TYPE_LOG, "log"
+ TYPE_LOG, "log",
+ TYPE_NOTIF, "notify"
);
foreach my $type (keys %types) {
diff --git a/src/perl.c b/src/perl.c
index b87d6b7e4b98c075f3fd25dd88c29af3320e00a3..4fca92aaaa2277973d8aa8791d325aaaafb290fd 100644 (file)
--- a/src/perl.c
+++ b/src/perl.c
#define PLUGIN_WRITE 2
#define PLUGIN_SHUTDOWN 3
#define PLUGIN_LOG 4
+#define PLUGIN_NOTIF 5
-#define PLUGIN_TYPES 5
+#define PLUGIN_TYPES 6
#define PLUGIN_DATASET 255
{ "Collectd::TYPE_WRITE", PLUGIN_WRITE },
{ "Collectd::TYPE_SHUTDOWN", PLUGIN_SHUTDOWN },
{ "Collectd::TYPE_LOG", PLUGIN_LOG },
+ { "Collectd::TYPE_NOTIF", PLUGIN_NOTIF },
{ "Collectd::TYPE_DATASET", PLUGIN_DATASET },
{ "Collectd::DS_TYPE_COUNTER", DS_TYPE_COUNTER },
{ "Collectd::DS_TYPE_GAUGE", DS_TYPE_GAUGE },
{ "Collectd::LOG_NOTICE", LOG_NOTICE },
{ "Collectd::LOG_INFO", LOG_INFO },
{ "Collectd::LOG_DEBUG", LOG_DEBUG },
+ { "Collectd::NOTIF_FAILURE", NOTIF_FAILURE },
+ { "Collectd::NOTIF_WARNING", NOTIF_WARNING },
+ { "Collectd::NOTIF_OKAY", NOTIF_OKAY },
{ "", 0 }
};
return 0;
} /* static int value2av (value_list_t *, data_set_t *, HV *) */
+static int notification2hv (pTHX_ notification_t *n, HV *hash)
+{
+ if (NULL == hv_store (hash, "severity", 8, newSViv (n->severity), 0))
+ return -1;
+
+ if (0 != n->time)
+ if (NULL == hv_store (hash, "time", 4, newSViv (n->time), 0))
+ return -1;
+
+ if ('\0' != *n->message)
+ if (NULL == hv_store (hash, "message", 7, newSVpv (n->message, 0), 0))
+ return -1;
+
+ if ('\0' != *n->host)
+ if (NULL == hv_store (hash, "host", 4, newSVpv (n->host, 0), 0))
+ return -1;
+
+ if ('\0' != *n->plugin)
+ if (NULL == hv_store (hash, "plugin", 6, newSVpv (n->plugin, 0), 0))
+ return -1;
+
+ if ('\0' != *n->plugin_instance)
+ if (NULL == hv_store (hash, "plugin_instance", 15,
+ newSVpv (n->plugin_instance, 0), 0))
+ return -1;
+
+ if ('\0' != *n->type)
+ if (NULL == hv_store (hash, "type", 4, newSVpv (n->type, 0), 0))
+ return -1;
+
+ if ('\0' != *n->type_instance)
+ if (NULL == hv_store (hash, "type_instance", 13,
+ newSVpv (n->type_instance, 0), 0))
+ return -1;
+ return 0;
+} /* static int notification2hv (notification_t *, HV *) */
+
/*
* Internal functions.
*/
XPUSHs (sv_2mortal (newSViv (va_arg (ap, int))));
XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0)));
}
+ else if (PLUGIN_NOTIF == type) {
+ /*
+ * $_[0] =
+ * {
+ * severity => $severity,
+ * time => $time,
+ * message => $msg,
+ * host => $host,
+ * plugin => $plugin,
+ * type => $type,
+ * plugin_instance => $instance,
+ * type_instance => $type_instance
+ * };
+ */
+ notification_t *n;
+ HV *notif = newHV ();
+
+ n = va_arg (ap, notification_t *);
+
+ if (-1 == notification2hv (aTHX_ n, notif))
+ return -1;
+
+ XPUSHs (sv_2mortal (newRV_noinc ((SV *)notif)));
+ }
PUTBACK;
return;
} /* static void perl_log (int, const char *) */
+static int perl_notify (const notification_t *notif)
+{
+ dTHX;
+
+ if (NULL == perl_threads)
+ return 0;
+
+ if (NULL == aTHX) {
+ c_ithread_t *t = NULL;
+
+ pthread_mutex_lock (&perl_threads->mutex);
+ t = c_ithread_create (perl_threads->head->interp);
+ pthread_mutex_unlock (&perl_threads->mutex);
+
+ aTHX = t->interp;
+ }
+ return pplugin_call_all (aTHX_ PLUGIN_NOTIF, notif);
+} /* static int perl_notify (const notification_t *) */
+
static int perl_shutdown (void)
{
c_ithread_t *t = NULL;
perl_run (aTHX);
plugin_register_log ("perl", perl_log);
+ plugin_register_notification ("perl", perl_notify);
plugin_register_init ("perl", perl_init);
plugin_register_read ("perl", perl_read);