summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 34a35d7)
raw | patch | inline | side by side (parent: 34a35d7)
author | Sebastian Harl <sh@tokkee.org> | |
Mon, 9 Feb 2009 18:20:13 +0000 (19:20 +0100) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Mon, 9 Feb 2009 21:23:05 +0000 (22:23 +0100) |
The conversion of the hash value to a notification_t object has been moved
into its own separate function.
into its own separate function.
src/perl.c | patch | blob | history |
diff --git a/src/perl.c b/src/perl.c
index c0326943298837d42741afb9acb65276081fa6b2..2d4cc867f1d355d59a2aacaa9343ba3aa649adea 100644 (file)
--- a/src/perl.c
+++ b/src/perl.c
return 0;
} /* static int av2data_set (pTHX_ AV *, data_set_t *) */
+/*
+ * notification:
+ * {
+ * severity => $severity,
+ * time => $time,
+ * message => $msg,
+ * host => $host,
+ * plugin => $plugin,
+ * type => $type,
+ * plugin_instance => $instance,
+ * type_instance => $type_instance
+ * }
+ */
+static int hv2notification (pTHX_ HV *hash, notification_t *n)
+{
+ SV **tmp = NULL;
+
+ if ((NULL == hash) || (NULL == n))
+ return -1;
+
+ if (NULL != (tmp = hv_fetch (hash, "severity", 8, 0)))
+ n->severity = SvIV (*tmp);
+ else
+ n->severity = NOTIF_FAILURE;
+
+ if (NULL != (tmp = hv_fetch (hash, "time", 4, 0)))
+ n->time = (time_t)SvIV (*tmp);
+ else
+ n->time = time (NULL);
+
+ if (NULL != (tmp = hv_fetch (hash, "message", 7, 0)))
+ sstrncpy (n->message, SvPV_nolen (*tmp), sizeof (n->message));
+
+ if (NULL != (tmp = hv_fetch (hash, "host", 4, 0)))
+ sstrncpy (n->host, SvPV_nolen (*tmp), sizeof (n->host));
+ else
+ sstrncpy (n->host, hostname_g, sizeof (n->host));
+
+ if (NULL != (tmp = hv_fetch (hash, "plugin", 6, 0)))
+ sstrncpy (n->plugin, SvPV_nolen (*tmp), sizeof (n->plugin));
+
+ if (NULL != (tmp = hv_fetch (hash, "plugin_instance", 15, 0)))
+ sstrncpy (n->plugin_instance, SvPV_nolen (*tmp),
+ sizeof (n->plugin_instance));
+
+ if (NULL != (tmp = hv_fetch (hash, "type", 4, 0)))
+ sstrncpy (n->type, SvPV_nolen (*tmp), sizeof (n->type));
+
+ if (NULL != (tmp = hv_fetch (hash, "type_instance", 13, 0)))
+ sstrncpy (n->type_instance, SvPV_nolen (*tmp),
+ sizeof (n->type_instance));
+ return 0;
+} /* static int hv2notification (pTHX_ HV *, notification_t *) */
+
static int data_set2av (pTHX_ data_set_t *ds, AV *array)
{
int i = 0;
/*
* 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)))
- sstrncpy (n.message, SvPV_nolen (*tmp), sizeof (n.message));
-
- if (NULL != (tmp = hv_fetch (notif, "host", 4, 0)))
- sstrncpy (n.host, SvPV_nolen (*tmp), sizeof (n.host));
- else
- sstrncpy (n.host, hostname_g, sizeof (n.host));
-
- if (NULL != (tmp = hv_fetch (notif, "plugin", 6, 0)))
- sstrncpy (n.plugin, SvPV_nolen (*tmp), sizeof (n.plugin));
-
- if (NULL != (tmp = hv_fetch (notif, "plugin_instance", 15, 0)))
- sstrncpy (n.plugin_instance, SvPV_nolen (*tmp),
- sizeof (n.plugin_instance));
-
- if (NULL != (tmp = hv_fetch (notif, "type", 4, 0)))
- sstrncpy (n.type, SvPV_nolen (*tmp), sizeof (n.type));
+ if (0 != hv2notification (aTHX_ notif, &n))
+ return -1;
- if (NULL != (tmp = hv_fetch (notif, "type_instance", 13, 0)))
- sstrncpy (n.type_instance, SvPV_nolen (*tmp), sizeof (n.type_instance));
return plugin_dispatch_notification (&n);
} /* static int pplugin_dispatch_notification (HV *) */