summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 994a59d)
raw | patch | inline | side by side (parent: 994a59d)
author | Sebastian Harl <sh@tokkee.org> | |
Mon, 28 Jan 2008 11:23:10 +0000 (12:23 +0100) | ||
committer | Florian Forster <octo@huhu.verplant.org> | |
Mon, 4 Feb 2008 16:40:23 +0000 (17:40 +0100) |
This adds the following function to collectd's Perl API:
Collectd::plugin_dispatch_notification:
submit a notification to collectd's notification mechanism
arguments:
notif - notification
A notification is a reference to a hash with the following members:
severity => $severity (default: NOTIF_FAILURE)
time => $time (default: time (NULL))
message => $msg
host => $host (default: hostname_g)
plugin => $plugin
type => $type
plugin_instance => $instance
type_instance => $type_instance
The severity should be any of the Collectd::NOTIF_* constants.
Signed-off-by: Sebastian Harl <sh@tokkee.org>
Signed-off-by: Florian Forster <octo@huhu.verplant.org>
Collectd::plugin_dispatch_notification:
submit a notification to collectd's notification mechanism
arguments:
notif - notification
A notification is a reference to a hash with the following members:
severity => $severity (default: NOTIF_FAILURE)
time => $time (default: time (NULL))
message => $msg
host => $host (default: hostname_g)
plugin => $plugin
type => $type
plugin_instance => $instance
type_instance => $type_instance
The severity should be any of the Collectd::NOTIF_* constants.
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 e0700f0a61df673d85230845148de30e2704381e..fc4a69dc8eb60c7810fa5a3d72ad30e98e73afbb 100644 (file)
plugin_register
plugin_unregister
plugin_dispatch_values
+ plugin_dispatch_notification
plugin_log
) ],
'types' => [ qw(
diff --git a/src/perl.c b/src/perl.c
index 4fca92aaaa2277973d8aa8791d325aaaafb290fd..346f9601f07dc4250a57b9f5e74520e3d0e358f2 100644 (file)
--- a/src/perl.c
+++ b/src/perl.c
static XS (Collectd_plugin_register_ds);
static XS (Collectd_plugin_unregister_ds);
static XS (Collectd_plugin_dispatch_values);
+static XS (Collectd_plugin_dispatch_notification);
static XS (Collectd_plugin_log);
static XS (Collectd_call_by_name);
{ "Collectd::plugin_register_data_set", Collectd_plugin_register_ds },
{ "Collectd::plugin_unregister_data_set", Collectd_plugin_unregister_ds },
{ "Collectd::plugin_dispatch_values", Collectd_plugin_dispatch_values },
+ { "Collectd::plugin_dispatch_notification",
+ Collectd_plugin_dispatch_notification },
{ "Collectd::plugin_log", Collectd_plugin_log },
{ "Collectd::call_by_name", Collectd_call_by_name },
{ "", NULL }
list.plugin[DATA_MAX_NAME_LEN - 1] = '\0';
}
- if (NULL != (tmp = hv_fetch (values,
- "plugin_instance", 15, 0))) {
+ if (NULL != (tmp = hv_fetch (values, "plugin_instance", 15, 0))) {
strncpy (list.plugin_instance, SvPV_nolen (*tmp), DATA_MAX_NAME_LEN);
list.plugin_instance[DATA_MAX_NAME_LEN - 1] = '\0';
}
return ret;
} /* static int pplugin_dispatch_values (char *, HV *) */
+/*
+ * Dispatch a notification.
+ *
+ * notification:
+ * {
+ * severity => $severity,
+ * time => $time,
+ * message => $msg,
+ * host => $host,
+ * plugin => $plugin,
+ * type => $type,
+ * plugin_instance => $instance,
+ * type_instance => $type_instance
+ * }
+ */
+static int pplugin_dispatch_notification (pTHX_ HV *notif)
+{
+ notification_t n;
+
+ SV **tmp = NULL;
+
+ if (NULL == notif)
+ return -1;
+
+ memset (&n, 0, sizeof (n));
+
+ if (NULL != (tmp = hv_fetch (notif, "severity", 8, 0)))
+ n.severity = SvIV (*tmp);
+ else
+ n.severity = NOTIF_FAILURE;
+
+ if (NULL != (tmp = hv_fetch (notif, "time", 4, 0)))
+ n.time = (time_t)SvIV (*tmp);
+ else
+ n.time = time (NULL);
+
+ if (NULL != (tmp = hv_fetch (notif, "message", 7, 0)))
+ strncpy (n.message, SvPV_nolen (*tmp), sizeof (n.message));
+ n.message[sizeof (n.message) - 1] = '\0';
+
+ if (NULL != (tmp = hv_fetch (notif, "host", 4, 0)))
+ strncpy (n.host, SvPV_nolen (*tmp), sizeof (n.host));
+ else
+ strncpy (n.host, hostname_g, sizeof (n.host));
+ n.host[sizeof (n.host) - 1] = '\0';
+
+ if (NULL != (tmp = hv_fetch (notif, "plugin", 6, 0)))
+ strncpy (n.plugin, SvPV_nolen (*tmp), sizeof (n.plugin));
+ n.plugin[sizeof (n.plugin) - 1] = '\0';
+
+ if (NULL != (tmp = hv_fetch (notif, "plugin_instance", 15, 0)))
+ strncpy (n.plugin_instance, SvPV_nolen (*tmp),
+ sizeof (n.plugin_instance));
+ n.plugin_instance[sizeof (n.plugin_instance) - 1] = '\0';
+
+ if (NULL != (tmp = hv_fetch (notif, "type", 4, 0)))
+ strncpy (n.type, SvPV_nolen (*tmp), sizeof (n.type));
+ n.type[sizeof (n.type) - 1] = '\0';
+
+ if (NULL != (tmp = hv_fetch (notif, "type_instance", 13, 0)))
+ strncpy (n.type_instance, SvPV_nolen (*tmp), sizeof (n.type_instance));
+ n.type_instance[sizeof (n.type_instance) - 1] = '\0';
+ return plugin_dispatch_notification (&n);
+} /* static int pplugin_dispatch_notification (HV *) */
+
/*
* Call all working functions of the given type.
*/
XSRETURN_EMPTY;
} /* static XS (Collectd_plugin_dispatch_values) */
+/*
+ * Collectd::plugin_dispatch_notification (notif).
+ *
+ * notif:
+ * notification to dispatch
+ */
+static XS (Collectd_plugin_dispatch_notification)
+{
+ SV *notif = NULL;
+
+ int ret = 0;
+
+ dXSARGS;
+
+ if (1 != items) {
+ log_err ("Usage: Collectd::plugin_dispatch_notification(notif)");
+ XSRETURN_EMPTY;
+ }
+
+ log_debug ("Collectd::plugin_dispatch_notification: notif = \"%s\"",
+ SvPV_nolen (ST (0)));
+
+ notif = ST (0);
+
+ if (! (SvROK (notif) && (SVt_PVHV == SvTYPE (SvRV (notif))))) {
+ log_err ("Collectd::plugin_dispatch_notification: Invalid notif.");
+ XSRETURN_EMPTY;
+ }
+
+ ret = pplugin_dispatch_notification (aTHX_ (HV *)SvRV (notif));
+
+ if (0 == ret)
+ XSRETURN_YES;
+ else
+ XSRETURN_EMPTY;
+} /* static XS (Collectd_plugin_dispatch_notification) */
+
/*
* Collectd::plugin_log (level, message).
*