2 * collectd - src/write_riemann.c
3 * Copyright (C) 2012,2013 Pierre-Yves Ritschard
4 * Copyright (C) 2013 Florian octo Forster
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
25 * Pierre-Yves Ritschard <pyr at spootnik.org>
26 * Florian octo Forster <octo at collectd.org>
32 #include "configfile.h"
33 #include "utils_cache.h"
34 #include "riemann.pb-c.h"
36 #include <arpa/inet.h>
42 #define RIEMANN_HOST "localhost"
43 #define RIEMANN_PORT "5555"
44 #define RIEMANN_TTL_FACTOR 2.0
45 #define RIEMANN_BATCH_MAX 8192
47 int write_riemann_threshold_check(const data_set_t *, const value_list_t *, int *);
51 char *event_service_prefix;
52 #define F_CONNECT 0x01
57 _Bool check_thresholds;
59 _Bool always_append_ds;
71 static char **riemann_tags;
72 static size_t riemann_tags_num;
73 static char **riemann_attrs;
74 static size_t riemann_attrs_num;
76 static void riemann_event_protobuf_free (Event *event) /* {{{ */
84 sfree (event->service);
86 sfree (event->description);
88 strarray_free (event->tags, event->n_tags);
92 for (i = 0; i < event->n_attributes; i++)
94 sfree (event->attributes[i]->key);
95 sfree (event->attributes[i]->value);
96 sfree (event->attributes[i]);
98 sfree (event->attributes);
99 event->n_attributes = 0;
102 } /* }}} void riemann_event_protobuf_free */
104 static void riemann_msg_protobuf_free(Msg *msg) /* {{{ */
111 for (i = 0; i < msg->n_events; i++)
113 riemann_event_protobuf_free (msg->events[i]);
114 msg->events[i] = NULL;
121 } /* }}} void riemann_msg_protobuf_free */
123 /* host->lock must be held when calling this function. */
124 static int riemann_connect(struct riemann_host *host) /* {{{ */
127 struct addrinfo *ai, *res, hints;
131 if (host->flags & F_CONNECT)
134 memset(&hints, 0, sizeof(hints));
135 memset(&service, 0, sizeof(service));
136 hints.ai_family = AF_UNSPEC;
137 hints.ai_socktype = host->use_tcp ? SOCK_STREAM : SOCK_DGRAM;
139 hints.ai_flags |= AI_ADDRCONFIG;
142 node = (host->node != NULL) ? host->node : RIEMANN_HOST;
143 service = (host->service != NULL) ? host->service : RIEMANN_PORT;
145 if ((e = getaddrinfo(node, service, &hints, &res)) != 0) {
146 ERROR ("write_riemann plugin: Unable to resolve host \"%s\": %s",
147 node, gai_strerror(e));
152 for (ai = res; ai != NULL; ai = ai->ai_next) {
153 if ((host->s = socket(ai->ai_family,
155 ai->ai_protocol)) == -1) {
159 if (connect(host->s, ai->ai_addr, ai->ai_addrlen) != 0) {
165 host->flags |= F_CONNECT;
166 DEBUG("write_riemann plugin: got a successful connection for: %s:%s",
174 WARNING("write_riemann plugin: Unable to connect to Riemann at %s:%s",
179 } /* }}} int riemann_connect */
181 /* host->lock must be held when calling this function. */
182 static int riemann_disconnect (struct riemann_host *host) /* {{{ */
184 if ((host->flags & F_CONNECT) == 0)
189 host->flags &= ~F_CONNECT;
192 } /* }}} int riemann_disconnect */
194 static int riemann_send_msg (struct riemann_host *host, const Msg *msg) /* {{{ */
197 u_char *buffer = NULL;
200 status = riemann_connect (host);
204 buffer_len = msg__get_packed_size(msg);
209 buffer = malloc (buffer_len);
210 if (buffer == NULL) {
211 ERROR ("write_riemann plugin: malloc failed.");
214 memset (buffer, 0, buffer_len);
218 uint32_t length = htonl ((uint32_t) (buffer_len - 4));
219 memcpy (buffer, &length, 4);
220 msg__pack(msg, buffer + 4);
224 msg__pack(msg, buffer);
227 status = (int) swrite (host->s, buffer, buffer_len);
231 ERROR ("write_riemann plugin: Sending to Riemann at %s:%s failed: %s",
232 (host->node != NULL) ? host->node : RIEMANN_HOST,
233 (host->service != NULL) ? host->service : RIEMANN_PORT,
234 sstrerror (errno, errbuf, sizeof (errbuf)));
241 } /* }}} int riemann_send_msg */
243 static int riemann_recv_ack(struct riemann_host *host) /* {{{ */
249 status = (int) sread (host->s, &header, 4);
254 size_t size = ntohl(header);
256 // Buffer on the stack since acknowledges are typically small.
258 memset (buffer, 0, size);
260 status = (int) sread (host->s, buffer, size);
265 msg = msg__unpack (NULL, size, buffer);
272 ERROR ("write_riemann plugin: Sending to Riemann at %s:%s acknowledgement message reported error: %s",
273 (host->node != NULL) ? host->node : RIEMANN_HOST,
274 (host->service != NULL) ? host->service : RIEMANN_PORT,
277 msg__free_unpacked(msg, NULL);
281 msg__free_unpacked (msg, NULL);
283 } /* }}} int riemann_recv_ack */
286 * Function to send messages (Msg) to riemann.
288 * Acquires the host lock, disconnects on errors.
290 static int riemann_send(struct riemann_host *host, Msg const *msg) /* {{{ */
293 pthread_mutex_lock (&host->lock);
295 status = riemann_send_msg(host, msg);
297 riemann_disconnect (host);
298 pthread_mutex_unlock (&host->lock);
303 * For TCP we need to receive message acknowledgemenent.
307 status = riemann_recv_ack(host);
311 riemann_disconnect (host);
312 pthread_mutex_unlock (&host->lock);
317 pthread_mutex_unlock (&host->lock);
319 } /* }}} int riemann_send */
321 static int riemann_event_add_tag (Event *event, char const *tag) /* {{{ */
323 return (strarray_add (&event->tags, &event->n_tags, tag));
324 } /* }}} int riemann_event_add_tag */
326 static int riemann_event_add_attribute(Event *event, /* {{{ */
327 char const *key, char const *value)
329 Attribute **new_attributes;
332 new_attributes = realloc (event->attributes,
333 sizeof (*event->attributes) * (event->n_attributes + 1));
334 if (new_attributes == NULL)
336 ERROR ("write_riemann plugin: realloc failed.");
339 event->attributes = new_attributes;
341 a = malloc (sizeof (*a));
344 ERROR ("write_riemann plugin: malloc failed.");
349 a->key = strdup (key);
351 a->value = strdup (value);
353 event->attributes[event->n_attributes] = a;
354 event->n_attributes++;
357 } /* }}} int riemann_event_add_attribute */
359 static Msg *riemann_notification_to_protobuf(struct riemann_host *host, /* {{{ */
360 notification_t const *n)
364 char service_buffer[6 * DATA_MAX_NAME_LEN];
365 char const *severity;
366 notification_meta_t *meta;
369 msg = malloc (sizeof (*msg));
372 ERROR ("write_riemann plugin: malloc failed.");
375 memset (msg, 0, sizeof (*msg));
378 msg->events = malloc (sizeof (*msg->events));
379 if (msg->events == NULL)
381 ERROR ("write_riemann plugin: malloc failed.");
386 event = malloc (sizeof (*event));
389 ERROR ("write_riemann plugin: malloc failed.");
394 memset (event, 0, sizeof (*event));
397 msg->events[0] = event;
400 event->host = strdup (n->host);
401 event->time = CDTIME_T_TO_TIME_T (n->time);
406 case NOTIF_OKAY: severity = "ok"; break;
407 case NOTIF_WARNING: severity = "warning"; break;
408 case NOTIF_FAILURE: severity = "critical"; break;
409 default: severity = "unknown";
411 event->state = strdup (severity);
413 riemann_event_add_tag (event, "notification");
415 riemann_event_add_attribute (event, "host", n->host);
416 if (n->plugin[0] != 0)
417 riemann_event_add_attribute (event, "plugin", n->plugin);
418 if (n->plugin_instance[0] != 0)
419 riemann_event_add_attribute (event, "plugin_instance",
423 riemann_event_add_attribute (event, "type", n->type);
424 if (n->type_instance[0] != 0)
425 riemann_event_add_attribute (event, "type_instance",
428 for (i = 0; i < riemann_attrs_num; i += 2)
429 riemann_event_add_attribute(event,
431 riemann_attrs[i +1]);
433 for (i = 0; i < riemann_tags_num; i++)
434 riemann_event_add_tag (event, riemann_tags[i]);
436 format_name (service_buffer, sizeof (service_buffer),
437 /* host = */ "", n->plugin, n->plugin_instance,
438 n->type, n->type_instance);
439 event->service = strdup (&service_buffer[1]);
441 if (n->message[0] != 0)
442 riemann_event_add_attribute (event, "description", n->message);
444 /* Pull in values from threshold and add extra attributes */
445 for (meta = n->meta; meta != NULL; meta = meta->next)
447 if (strcasecmp ("CurrentValue", meta->name) == 0 && meta->type == NM_TYPE_DOUBLE)
449 event->metric_d = meta->nm_value.nm_double;
450 event->has_metric_d = 1;
454 if (meta->type == NM_TYPE_STRING) {
455 riemann_event_add_attribute (event, meta->name, meta->nm_value.nm_string);
460 DEBUG ("write_riemann plugin: Successfully created protobuf for notification: "
461 "host = \"%s\", service = \"%s\", state = \"%s\"",
462 event->host, event->service, event->state);
464 } /* }}} Msg *riemann_notification_to_protobuf */
466 static Event *riemann_value_to_protobuf(struct riemann_host const *host, /* {{{ */
467 data_set_t const *ds,
468 value_list_t const *vl, size_t index,
469 gauge_t const *rates,
473 char name_buffer[5 * DATA_MAX_NAME_LEN];
474 char service_buffer[6 * DATA_MAX_NAME_LEN];
478 event = malloc (sizeof (*event));
481 ERROR ("write_riemann plugin: malloc failed.");
484 memset (event, 0, sizeof (*event));
487 event->host = strdup (vl->host);
488 event->time = CDTIME_T_TO_TIME_T (vl->time);
491 if (host->check_thresholds) {
494 event->state = strdup("ok");
497 event->state = strdup("critical");
500 event->state = strdup("warning");
503 event->state = strdup("unknown");
508 ttl = CDTIME_T_TO_DOUBLE (vl->interval) * host->ttl_factor;
509 event->ttl = (float) ttl;
512 riemann_event_add_attribute (event, "plugin", vl->plugin);
513 if (vl->plugin_instance[0] != 0)
514 riemann_event_add_attribute (event, "plugin_instance",
515 vl->plugin_instance);
517 riemann_event_add_attribute (event, "type", vl->type);
518 if (vl->type_instance[0] != 0)
519 riemann_event_add_attribute (event, "type_instance",
522 if ((ds->ds[index].type != DS_TYPE_GAUGE) && (rates != NULL))
524 char ds_type[DATA_MAX_NAME_LEN];
526 ssnprintf (ds_type, sizeof (ds_type), "%s:rate",
527 DS_TYPE_TO_STRING(ds->ds[index].type));
528 riemann_event_add_attribute (event, "ds_type", ds_type);
532 riemann_event_add_attribute (event, "ds_type",
533 DS_TYPE_TO_STRING(ds->ds[index].type));
535 riemann_event_add_attribute (event, "ds_name", ds->ds[index].name);
537 char ds_index[DATA_MAX_NAME_LEN];
539 ssnprintf (ds_index, sizeof (ds_index), "%zu", index);
540 riemann_event_add_attribute (event, "ds_index", ds_index);
543 for (i = 0; i < riemann_attrs_num; i += 2)
544 riemann_event_add_attribute(event,
546 riemann_attrs[i +1]);
548 for (i = 0; i < riemann_tags_num; i++)
549 riemann_event_add_tag (event, riemann_tags[i]);
551 if (ds->ds[index].type == DS_TYPE_GAUGE)
553 event->has_metric_d = 1;
554 event->metric_d = (double) vl->values[index].gauge;
556 else if (rates != NULL)
558 event->has_metric_d = 1;
559 event->metric_d = (double) rates[index];
563 event->has_metric_sint64 = 1;
564 if (ds->ds[index].type == DS_TYPE_DERIVE)
565 event->metric_sint64 = (int64_t) vl->values[index].derive;
566 else if (ds->ds[index].type == DS_TYPE_ABSOLUTE)
567 event->metric_sint64 = (int64_t) vl->values[index].absolute;
569 event->metric_sint64 = (int64_t) vl->values[index].counter;
572 format_name (name_buffer, sizeof (name_buffer),
573 /* host = */ "", vl->plugin, vl->plugin_instance,
574 vl->type, vl->type_instance);
575 if (host->always_append_ds || (ds->ds_num > 1))
577 if (host->event_service_prefix == NULL)
578 ssnprintf (service_buffer, sizeof (service_buffer), "%s/%s",
579 &name_buffer[1], ds->ds[index].name);
581 ssnprintf (service_buffer, sizeof (service_buffer), "%s%s/%s",
582 host->event_service_prefix, &name_buffer[1], ds->ds[index].name);
586 if (host->event_service_prefix == NULL)
587 sstrncpy (service_buffer, &name_buffer[1], sizeof (service_buffer));
589 ssnprintf (service_buffer, sizeof (service_buffer), "%s%s",
590 host->event_service_prefix, &name_buffer[1]);
593 event->service = strdup (service_buffer);
595 DEBUG ("write_riemann plugin: Successfully created protobuf for metric: "
596 "host = \"%s\", service = \"%s\"",
597 event->host, event->service);
599 } /* }}} Event *riemann_value_to_protobuf */
601 static Msg *riemann_value_list_to_protobuf (struct riemann_host const *host, /* {{{ */
602 data_set_t const *ds,
603 value_list_t const *vl,
608 gauge_t *rates = NULL;
610 /* Initialize the Msg structure. */
611 msg = malloc (sizeof (*msg));
614 ERROR ("write_riemann plugin: malloc failed.");
617 memset (msg, 0, sizeof (*msg));
620 /* Set up events. First, the list of pointers. */
621 msg->n_events = vl->values_len;
622 msg->events = calloc (msg->n_events, sizeof (*msg->events));
623 if (msg->events == NULL)
625 ERROR ("write_riemann plugin: calloc failed.");
626 riemann_msg_protobuf_free (msg);
630 if (host->store_rates)
632 rates = uc_get_rate (ds, vl);
635 ERROR ("write_riemann plugin: uc_get_rate failed.");
636 riemann_msg_protobuf_free (msg);
641 for (i = 0; i < msg->n_events; i++)
643 msg->events[i] = riemann_value_to_protobuf (host, ds, vl,
644 (int) i, rates, statuses[i]);
645 if (msg->events[i] == NULL)
647 riemann_msg_protobuf_free (msg);
655 } /* }}} Msg *riemann_value_list_to_protobuf */
659 * Always call while holding host->lock !
661 static int riemann_batch_flush_nolock (cdtime_t timeout,
662 struct riemann_host *host)
669 if ((host->batch_init + timeout) > now)
672 riemann_send_msg(host, host->batch_msg);
673 riemann_msg_protobuf_free(host->batch_msg);
675 if (host->use_tcp && ((status = riemann_recv_ack(host)) != 0))
676 riemann_disconnect (host);
678 host->batch_init = cdtime();
679 host->batch_msg = NULL;
683 static int riemann_batch_flush (cdtime_t timeout,
684 const char *identifier __attribute__((unused)),
685 user_data_t *user_data)
687 struct riemann_host *host;
690 if (user_data == NULL)
693 host = user_data->data;
694 pthread_mutex_lock (&host->lock);
695 status = riemann_batch_flush_nolock (timeout, host);
697 ERROR ("write_riemann plugin: riemann_send failed with status %i",
700 pthread_mutex_unlock(&host->lock);
704 static int riemann_batch_add_value_list (struct riemann_host *host, /* {{{ */
705 data_set_t const *ds,
706 value_list_t const *vl,
715 msg = riemann_value_list_to_protobuf (host, ds, vl, statuses);
719 pthread_mutex_lock(&host->lock);
721 if (host->batch_msg == NULL) {
722 host->batch_msg = msg;
724 len = msg->n_events + host->batch_msg->n_events;
725 events = realloc(host->batch_msg->events,
726 (len * sizeof(*host->batch_msg->events)));
727 if (events == NULL) {
728 pthread_mutex_unlock(&host->lock);
729 ERROR ("write_riemann plugin: out of memory");
730 riemann_msg_protobuf_free (msg);
733 host->batch_msg->events = events;
735 for (i = host->batch_msg->n_events; i < len; i++)
736 host->batch_msg->events[i] = msg->events[i - host->batch_msg->n_events];
738 host->batch_msg->n_events = len;
744 len = msg__get_packed_size(host->batch_msg);
746 if ((host->batch_max < 0) || (((size_t) host->batch_max) <= len)) {
747 ret = riemann_batch_flush_nolock(0, host);
750 pthread_mutex_unlock(&host->lock);
752 } /* }}} Msg *riemann_batch_add_value_list */
754 static int riemann_notification(const notification_t *n, user_data_t *ud) /* {{{ */
757 struct riemann_host *host = ud->data;
760 if (!host->notifications)
764 * Never batch for notifications, send them ASAP
766 msg = riemann_notification_to_protobuf (host, n);
770 status = riemann_send (host, msg);
772 ERROR ("write_riemann plugin: riemann_send failed with status %i",
775 riemann_msg_protobuf_free (msg);
777 } /* }}} int riemann_notification */
779 static int riemann_write(const data_set_t *ds, /* {{{ */
780 const value_list_t *vl,
784 int statuses[vl->values_len];
785 struct riemann_host *host = ud->data;
787 if (host->check_thresholds) {
788 status = write_riemann_threshold_check(ds, vl, statuses);
792 memset (statuses, 0, sizeof (statuses));
795 if (host->use_tcp == 1 && host->batch_mode) {
796 riemann_batch_add_value_list (host, ds, vl, statuses);
798 Msg *msg = riemann_value_list_to_protobuf (host, ds, vl, statuses);
802 status = riemann_send (host, msg);
804 ERROR ("write_riemann plugin: riemann_send failed with status %i", status);
806 riemann_msg_protobuf_free (msg);
810 } /* }}} int riemann_write */
812 static void riemann_free(void *p) /* {{{ */
814 struct riemann_host *host = p;
819 pthread_mutex_lock (&host->lock);
821 host->reference_count--;
822 if (host->reference_count > 0)
824 pthread_mutex_unlock (&host->lock);
828 riemann_disconnect (host);
830 sfree(host->service);
831 pthread_mutex_destroy (&host->lock);
833 } /* }}} void riemann_free */
835 static int riemann_config_node(oconfig_item_t *ci) /* {{{ */
837 struct riemann_host *host = NULL;
840 oconfig_item_t *child;
841 char callback_name[DATA_MAX_NAME_LEN];
844 if ((host = calloc(1, sizeof (*host))) == NULL) {
845 ERROR ("write_riemann plugin: calloc failed.");
848 pthread_mutex_init (&host->lock, NULL);
849 host->reference_count = 1;
851 host->service = NULL;
852 host->notifications = 1;
853 host->check_thresholds = 0;
854 host->store_rates = 1;
855 host->always_append_ds = 0;
857 host->batch_mode = 1;
858 host->batch_max = RIEMANN_BATCH_MAX; /* typical MSS */
859 host->batch_init = cdtime();
860 host->ttl_factor = RIEMANN_TTL_FACTOR;
862 status = cf_util_get_string (ci, &host->name);
864 WARNING("write_riemann plugin: Required host name is missing.");
869 for (i = 0; i < ci->children_num; i++) {
871 * The code here could be simplified but makes room
872 * for easy adding of new options later on.
874 child = &ci->children[i];
877 if (strcasecmp ("Host", child->key) == 0) {
878 status = cf_util_get_string (child, &host->node);
881 } else if (strcasecmp ("Notifications", child->key) == 0) {
882 status = cf_util_get_boolean(child, &host->notifications);
885 } else if (strcasecmp ("EventServicePrefix", child->key) == 0) {
886 status = cf_util_get_string (child, &host->event_service_prefix);
889 } else if (strcasecmp ("CheckThresholds", child->key) == 0) {
890 status = cf_util_get_boolean(child, &host->check_thresholds);
893 } else if (strcasecmp ("Batch", child->key) == 0) {
894 status = cf_util_get_boolean(child, &host->batch_mode);
897 } else if (strcasecmp("BatchMaxSize", child->key) == 0) {
898 status = cf_util_get_int(child, &host->batch_max);
901 } else if (strcasecmp ("Port", child->key) == 0) {
902 status = cf_util_get_service (child, &host->service);
904 ERROR ("write_riemann plugin: Invalid argument "
905 "configured for the \"Port\" "
909 } else if (strcasecmp ("Protocol", child->key) == 0) {
911 status = cf_util_get_string_buffer (child,
915 ERROR ("write_riemann plugin: cf_util_get_"
916 "string_buffer failed with "
917 "status %i.", status);
921 if (strcasecmp ("UDP", tmp) == 0)
923 else if (strcasecmp ("TCP", tmp) == 0)
926 WARNING ("write_riemann plugin: The value "
927 "\"%s\" is not valid for the "
928 "\"Protocol\" option. Use "
929 "either \"UDP\" or \"TCP\".",
931 } else if (strcasecmp ("StoreRates", child->key) == 0) {
932 status = cf_util_get_boolean (child, &host->store_rates);
935 } else if (strcasecmp ("AlwaysAppendDS", child->key) == 0) {
936 status = cf_util_get_boolean (child,
937 &host->always_append_ds);
940 } else if (strcasecmp ("TTLFactor", child->key) == 0) {
942 status = cf_util_get_double (child, &tmp);
946 host->ttl_factor = tmp;
947 } else if (tmp >= 1.0) {
948 NOTICE ("write_riemann plugin: The configured "
949 "TTLFactor is very small "
950 "(%.1f). A value of 2.0 or "
951 "greater is recommended.",
953 host->ttl_factor = tmp;
954 } else if (tmp > 0.0) {
955 WARNING ("write_riemann plugin: The configured "
956 "TTLFactor is too small to be "
957 "useful (%.1f). I'll use it "
958 "since the user knows best, "
959 "but under protest.",
961 host->ttl_factor = tmp;
962 } else { /* zero, negative and NAN */
963 ERROR ("write_riemann plugin: The configured "
964 "TTLFactor is invalid (%.1f).",
968 WARNING("write_riemann plugin: ignoring unknown config "
969 "option: \"%s\"", child->key);
977 ssnprintf (callback_name, sizeof (callback_name), "write_riemann/%s",
980 ud.free_func = riemann_free;
982 pthread_mutex_lock (&host->lock);
984 status = plugin_register_write (callback_name, riemann_write, &ud);
986 if (host->use_tcp == 1 && host->batch_mode) {
988 plugin_register_flush(callback_name, riemann_batch_flush, &ud);
991 WARNING ("write_riemann plugin: plugin_register_write (\"%s\") "
992 "failed with status %i.",
993 callback_name, status);
995 host->reference_count++;
997 status = plugin_register_notification (callback_name,
998 riemann_notification, &ud);
1000 WARNING ("write_riemann plugin: plugin_register_notification (\"%s\") "
1001 "failed with status %i.",
1002 callback_name, status);
1004 host->reference_count++;
1006 if (host->reference_count <= 1)
1008 /* Both callbacks failed => free memory.
1009 * We need to unlock here, because riemann_free() will lock.
1010 * This is not a race condition, because we're the only one
1011 * holding a reference. */
1012 pthread_mutex_unlock (&host->lock);
1013 riemann_free (host);
1017 host->reference_count--;
1018 pthread_mutex_unlock (&host->lock);
1021 } /* }}} int riemann_config_node */
1023 static int riemann_config(oconfig_item_t *ci) /* {{{ */
1026 oconfig_item_t *child;
1029 for (i = 0; i < ci->children_num; i++) {
1030 child = &ci->children[i];
1032 if (strcasecmp("Node", child->key) == 0) {
1033 riemann_config_node (child);
1034 } else if (strcasecmp(child->key, "attribute") == 0) {
1038 if (child->values_num != 2) {
1039 WARNING("riemann attributes need both a key and a value.");
1042 if (child->values[0].type != OCONFIG_TYPE_STRING ||
1043 child->values[1].type != OCONFIG_TYPE_STRING) {
1044 WARNING("riemann attribute needs string arguments.");
1047 if ((key = strdup(child->values[0].value.string)) == NULL) {
1048 WARNING("cannot allocate memory for attribute key.");
1051 if ((val = strdup(child->values[1].value.string)) == NULL) {
1052 WARNING("cannot allocate memory for attribute value.");
1056 strarray_add(&riemann_attrs, &riemann_attrs_num, key);
1057 strarray_add(&riemann_attrs, &riemann_attrs_num, val);
1058 DEBUG("write_riemann: got attr: %s => %s", key, val);
1061 } else if (strcasecmp(child->key, "tag") == 0) {
1063 status = cf_util_get_string(child, &tmp);
1067 strarray_add (&riemann_tags, &riemann_tags_num, tmp);
1068 DEBUG("write_riemann plugin: Got tag: %s", tmp);
1071 WARNING ("write_riemann plugin: Ignoring unknown "
1072 "configuration option \"%s\" at top level.",
1077 } /* }}} int riemann_config */
1079 void module_register(void)
1081 plugin_register_complex_config ("write_riemann", riemann_config);
1084 /* vim: set sw=8 sts=8 ts=8 noet : */