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>
29 #include <arpa/inet.h>
38 #include "configfile.h"
39 #include "utils_cache.h"
40 #include "riemann.pb-c.h"
41 #include "write_riemann_threshold.h"
43 #define RIEMANN_HOST "localhost"
44 #define RIEMANN_PORT "5555"
45 #define RIEMANN_TTL_FACTOR 2.0
46 #define RIEMANN_BATCH_MAX 8192
50 char *event_service_prefix;
51 #define F_CONNECT 0x01
56 _Bool check_thresholds;
58 _Bool always_append_ds;
70 static char **riemann_tags;
71 static size_t riemann_tags_num;
72 static char **riemann_attrs;
73 static size_t riemann_attrs_num;
75 static void riemann_event_protobuf_free (Event *event) /* {{{ */
83 sfree (event->service);
85 sfree (event->description);
87 strarray_free (event->tags, event->n_tags);
91 for (i = 0; i < event->n_attributes; i++)
93 sfree (event->attributes[i]->key);
94 sfree (event->attributes[i]->value);
95 sfree (event->attributes[i]);
97 sfree (event->attributes);
98 event->n_attributes = 0;
101 } /* }}} void riemann_event_protobuf_free */
103 static void riemann_msg_protobuf_free(Msg *msg) /* {{{ */
110 for (i = 0; i < msg->n_events; i++)
112 riemann_event_protobuf_free (msg->events[i]);
113 msg->events[i] = NULL;
120 } /* }}} void riemann_msg_protobuf_free */
122 /* host->lock must be held when calling this function. */
123 static int riemann_connect(struct riemann_host *host) /* {{{ */
126 struct addrinfo *ai, *res, hints;
130 if (host->flags & F_CONNECT)
133 memset(&hints, 0, sizeof(hints));
134 memset(&service, 0, sizeof(service));
135 hints.ai_family = AF_UNSPEC;
136 hints.ai_socktype = host->use_tcp ? SOCK_STREAM : SOCK_DGRAM;
138 hints.ai_flags |= AI_ADDRCONFIG;
141 node = (host->node != NULL) ? host->node : RIEMANN_HOST;
142 service = (host->service != NULL) ? host->service : RIEMANN_PORT;
144 if ((e = getaddrinfo(node, service, &hints, &res)) != 0) {
145 ERROR ("write_riemann plugin: Unable to resolve host \"%s\": %s",
146 node, gai_strerror(e));
151 for (ai = res; ai != NULL; ai = ai->ai_next) {
152 if ((host->s = socket(ai->ai_family,
154 ai->ai_protocol)) == -1) {
158 if (connect(host->s, ai->ai_addr, ai->ai_addrlen) != 0) {
164 host->flags |= F_CONNECT;
165 DEBUG("write_riemann plugin: got a successful connection for: %s:%s",
173 WARNING("write_riemann plugin: Unable to connect to Riemann at %s:%s",
178 } /* }}} int riemann_connect */
180 /* host->lock must be held when calling this function. */
181 static int riemann_disconnect (struct riemann_host *host) /* {{{ */
183 if ((host->flags & F_CONNECT) == 0)
188 host->flags &= ~F_CONNECT;
191 } /* }}} int riemann_disconnect */
193 static int riemann_send_msg (struct riemann_host *host, const Msg *msg) /* {{{ */
196 u_char *buffer = NULL;
199 status = riemann_connect (host);
203 buffer_len = msg__get_packed_size(msg);
208 buffer = malloc (buffer_len);
209 if (buffer == NULL) {
210 ERROR ("write_riemann plugin: malloc failed.");
213 memset (buffer, 0, buffer_len);
217 uint32_t length = htonl ((uint32_t) (buffer_len - 4));
218 memcpy (buffer, &length, 4);
219 msg__pack(msg, buffer + 4);
223 msg__pack(msg, buffer);
226 status = (int) swrite (host->s, buffer, buffer_len);
230 ERROR ("write_riemann plugin: Sending to Riemann at %s:%s failed: %s",
231 (host->node != NULL) ? host->node : RIEMANN_HOST,
232 (host->service != NULL) ? host->service : RIEMANN_PORT,
233 sstrerror (errno, errbuf, sizeof (errbuf)));
240 } /* }}} int riemann_send_msg */
242 static int riemann_recv_ack(struct riemann_host *host) /* {{{ */
248 status = (int) sread (host->s, &header, 4);
253 size_t size = ntohl(header);
255 // Buffer on the stack since acknowledges are typically small.
257 memset (buffer, 0, size);
259 status = (int) sread (host->s, buffer, size);
264 msg = msg__unpack (NULL, size, buffer);
271 ERROR ("write_riemann plugin: Sending to Riemann at %s:%s acknowledgement message reported error: %s",
272 (host->node != NULL) ? host->node : RIEMANN_HOST,
273 (host->service != NULL) ? host->service : RIEMANN_PORT,
276 msg__free_unpacked(msg, NULL);
280 msg__free_unpacked (msg, NULL);
282 } /* }}} int riemann_recv_ack */
285 * Function to send messages (Msg) to riemann.
287 * Acquires the host lock, disconnects on errors.
289 static int riemann_send(struct riemann_host *host, Msg const *msg) /* {{{ */
292 pthread_mutex_lock (&host->lock);
294 status = riemann_send_msg(host, msg);
296 riemann_disconnect (host);
297 pthread_mutex_unlock (&host->lock);
302 * For TCP we need to receive message acknowledgemenent.
306 status = riemann_recv_ack(host);
310 riemann_disconnect (host);
311 pthread_mutex_unlock (&host->lock);
316 pthread_mutex_unlock (&host->lock);
318 } /* }}} int riemann_send */
320 static int riemann_event_add_tag (Event *event, char const *tag) /* {{{ */
322 return (strarray_add (&event->tags, &event->n_tags, tag));
323 } /* }}} int riemann_event_add_tag */
325 static int riemann_event_add_attribute(Event *event, /* {{{ */
326 char const *key, char const *value)
328 Attribute **new_attributes;
331 new_attributes = realloc (event->attributes,
332 sizeof (*event->attributes) * (event->n_attributes + 1));
333 if (new_attributes == NULL)
335 ERROR ("write_riemann plugin: realloc failed.");
338 event->attributes = new_attributes;
340 a = malloc (sizeof (*a));
343 ERROR ("write_riemann plugin: malloc failed.");
348 a->key = strdup (key);
350 a->value = strdup (value);
352 event->attributes[event->n_attributes] = a;
353 event->n_attributes++;
356 } /* }}} int riemann_event_add_attribute */
358 static Msg *riemann_notification_to_protobuf(struct riemann_host *host, /* {{{ */
359 notification_t const *n)
363 char service_buffer[6 * DATA_MAX_NAME_LEN];
364 char const *severity;
365 notification_meta_t *meta;
368 msg = malloc (sizeof (*msg));
371 ERROR ("write_riemann plugin: malloc failed.");
374 memset (msg, 0, sizeof (*msg));
377 msg->events = malloc (sizeof (*msg->events));
378 if (msg->events == NULL)
380 ERROR ("write_riemann plugin: malloc failed.");
385 event = malloc (sizeof (*event));
388 ERROR ("write_riemann plugin: malloc failed.");
393 memset (event, 0, sizeof (*event));
396 msg->events[0] = event;
399 event->host = strdup (n->host);
400 event->time = CDTIME_T_TO_TIME_T (n->time);
405 case NOTIF_OKAY: severity = "ok"; break;
406 case NOTIF_WARNING: severity = "warning"; break;
407 case NOTIF_FAILURE: severity = "critical"; break;
408 default: severity = "unknown";
410 event->state = strdup (severity);
412 riemann_event_add_tag (event, "notification");
414 riemann_event_add_attribute (event, "host", n->host);
415 if (n->plugin[0] != 0)
416 riemann_event_add_attribute (event, "plugin", n->plugin);
417 if (n->plugin_instance[0] != 0)
418 riemann_event_add_attribute (event, "plugin_instance",
422 riemann_event_add_attribute (event, "type", n->type);
423 if (n->type_instance[0] != 0)
424 riemann_event_add_attribute (event, "type_instance",
427 for (i = 0; i < riemann_attrs_num; i += 2)
428 riemann_event_add_attribute(event,
430 riemann_attrs[i +1]);
432 for (i = 0; i < riemann_tags_num; i++)
433 riemann_event_add_tag (event, riemann_tags[i]);
435 format_name (service_buffer, sizeof (service_buffer),
436 /* host = */ "", n->plugin, n->plugin_instance,
437 n->type, n->type_instance);
438 event->service = strdup (&service_buffer[1]);
440 if (n->message[0] != 0)
441 riemann_event_add_attribute (event, "description", n->message);
443 /* Pull in values from threshold and add extra attributes */
444 for (meta = n->meta; meta != NULL; meta = meta->next)
446 if (strcasecmp ("CurrentValue", meta->name) == 0 && meta->type == NM_TYPE_DOUBLE)
448 event->metric_d = meta->nm_value.nm_double;
449 event->has_metric_d = 1;
453 if (meta->type == NM_TYPE_STRING) {
454 riemann_event_add_attribute (event, meta->name, meta->nm_value.nm_string);
459 DEBUG ("write_riemann plugin: Successfully created protobuf for notification: "
460 "host = \"%s\", service = \"%s\", state = \"%s\"",
461 event->host, event->service, event->state);
463 } /* }}} Msg *riemann_notification_to_protobuf */
465 static Event *riemann_value_to_protobuf(struct riemann_host const *host, /* {{{ */
466 data_set_t const *ds,
467 value_list_t const *vl, size_t index,
468 gauge_t const *rates,
472 char name_buffer[5 * DATA_MAX_NAME_LEN];
473 char service_buffer[6 * DATA_MAX_NAME_LEN];
477 event = malloc (sizeof (*event));
480 ERROR ("write_riemann plugin: malloc failed.");
483 memset (event, 0, sizeof (*event));
486 event->host = strdup (vl->host);
487 event->time = CDTIME_T_TO_TIME_T (vl->time);
490 if (host->check_thresholds) {
493 event->state = strdup("ok");
496 event->state = strdup("critical");
499 event->state = strdup("warning");
502 event->state = strdup("unknown");
507 ttl = CDTIME_T_TO_DOUBLE (vl->interval) * host->ttl_factor;
508 event->ttl = (float) ttl;
511 riemann_event_add_attribute (event, "plugin", vl->plugin);
512 if (vl->plugin_instance[0] != 0)
513 riemann_event_add_attribute (event, "plugin_instance",
514 vl->plugin_instance);
516 riemann_event_add_attribute (event, "type", vl->type);
517 if (vl->type_instance[0] != 0)
518 riemann_event_add_attribute (event, "type_instance",
521 if ((ds->ds[index].type != DS_TYPE_GAUGE) && (rates != NULL))
523 char ds_type[DATA_MAX_NAME_LEN];
525 ssnprintf (ds_type, sizeof (ds_type), "%s:rate",
526 DS_TYPE_TO_STRING(ds->ds[index].type));
527 riemann_event_add_attribute (event, "ds_type", ds_type);
531 riemann_event_add_attribute (event, "ds_type",
532 DS_TYPE_TO_STRING(ds->ds[index].type));
534 riemann_event_add_attribute (event, "ds_name", ds->ds[index].name);
536 char ds_index[DATA_MAX_NAME_LEN];
538 ssnprintf (ds_index, sizeof (ds_index), "%zu", index);
539 riemann_event_add_attribute (event, "ds_index", ds_index);
542 for (i = 0; i < riemann_attrs_num; i += 2)
543 riemann_event_add_attribute(event,
545 riemann_attrs[i +1]);
547 for (i = 0; i < riemann_tags_num; i++)
548 riemann_event_add_tag (event, riemann_tags[i]);
550 if (ds->ds[index].type == DS_TYPE_GAUGE)
552 event->has_metric_d = 1;
553 event->metric_d = (double) vl->values[index].gauge;
555 else if (rates != NULL)
557 event->has_metric_d = 1;
558 event->metric_d = (double) rates[index];
562 event->has_metric_sint64 = 1;
563 if (ds->ds[index].type == DS_TYPE_DERIVE)
564 event->metric_sint64 = (int64_t) vl->values[index].derive;
565 else if (ds->ds[index].type == DS_TYPE_ABSOLUTE)
566 event->metric_sint64 = (int64_t) vl->values[index].absolute;
568 event->metric_sint64 = (int64_t) vl->values[index].counter;
571 format_name (name_buffer, sizeof (name_buffer),
572 /* host = */ "", vl->plugin, vl->plugin_instance,
573 vl->type, vl->type_instance);
574 if (host->always_append_ds || (ds->ds_num > 1))
576 if (host->event_service_prefix == NULL)
577 ssnprintf (service_buffer, sizeof (service_buffer), "%s/%s",
578 &name_buffer[1], ds->ds[index].name);
580 ssnprintf (service_buffer, sizeof (service_buffer), "%s%s/%s",
581 host->event_service_prefix, &name_buffer[1], ds->ds[index].name);
585 if (host->event_service_prefix == NULL)
586 sstrncpy (service_buffer, &name_buffer[1], sizeof (service_buffer));
588 ssnprintf (service_buffer, sizeof (service_buffer), "%s%s",
589 host->event_service_prefix, &name_buffer[1]);
592 event->service = strdup (service_buffer);
594 DEBUG ("write_riemann plugin: Successfully created protobuf for metric: "
595 "host = \"%s\", service = \"%s\"",
596 event->host, event->service);
598 } /* }}} Event *riemann_value_to_protobuf */
600 static Msg *riemann_value_list_to_protobuf (struct riemann_host const *host, /* {{{ */
601 data_set_t const *ds,
602 value_list_t const *vl,
607 gauge_t *rates = NULL;
609 /* Initialize the Msg structure. */
610 msg = malloc (sizeof (*msg));
613 ERROR ("write_riemann plugin: malloc failed.");
616 memset (msg, 0, sizeof (*msg));
619 /* Set up events. First, the list of pointers. */
620 msg->n_events = vl->values_len;
621 msg->events = calloc (msg->n_events, sizeof (*msg->events));
622 if (msg->events == NULL)
624 ERROR ("write_riemann plugin: calloc failed.");
625 riemann_msg_protobuf_free (msg);
629 if (host->store_rates)
631 rates = uc_get_rate (ds, vl);
634 ERROR ("write_riemann plugin: uc_get_rate failed.");
635 riemann_msg_protobuf_free (msg);
640 for (i = 0; i < msg->n_events; i++)
642 msg->events[i] = riemann_value_to_protobuf (host, ds, vl,
643 (int) i, rates, statuses[i]);
644 if (msg->events[i] == NULL)
646 riemann_msg_protobuf_free (msg);
654 } /* }}} Msg *riemann_value_list_to_protobuf */
658 * Always call while holding host->lock !
660 static int riemann_batch_flush_nolock (cdtime_t timeout,
661 struct riemann_host *host)
668 if ((host->batch_init + timeout) > now)
671 riemann_send_msg(host, host->batch_msg);
672 riemann_msg_protobuf_free(host->batch_msg);
674 if (host->use_tcp && ((status = riemann_recv_ack(host)) != 0))
675 riemann_disconnect (host);
677 host->batch_init = cdtime();
678 host->batch_msg = NULL;
682 static int riemann_batch_flush (cdtime_t timeout,
683 const char *identifier __attribute__((unused)),
684 user_data_t *user_data)
686 struct riemann_host *host;
689 if (user_data == NULL)
692 host = user_data->data;
693 pthread_mutex_lock (&host->lock);
694 status = riemann_batch_flush_nolock (timeout, host);
696 ERROR ("write_riemann plugin: riemann_send failed with status %i",
699 pthread_mutex_unlock(&host->lock);
703 static int riemann_batch_add_value_list (struct riemann_host *host, /* {{{ */
704 data_set_t const *ds,
705 value_list_t const *vl,
714 msg = riemann_value_list_to_protobuf (host, ds, vl, statuses);
718 pthread_mutex_lock(&host->lock);
720 if (host->batch_msg == NULL) {
721 host->batch_msg = msg;
723 len = msg->n_events + host->batch_msg->n_events;
724 events = realloc(host->batch_msg->events,
725 (len * sizeof(*host->batch_msg->events)));
726 if (events == NULL) {
727 pthread_mutex_unlock(&host->lock);
728 ERROR ("write_riemann plugin: out of memory");
729 riemann_msg_protobuf_free (msg);
732 host->batch_msg->events = events;
734 for (i = host->batch_msg->n_events; i < len; i++)
735 host->batch_msg->events[i] = msg->events[i - host->batch_msg->n_events];
737 host->batch_msg->n_events = len;
743 len = msg__get_packed_size(host->batch_msg);
745 if ((host->batch_max < 0) || (((size_t) host->batch_max) <= len)) {
746 ret = riemann_batch_flush_nolock(0, host);
749 pthread_mutex_unlock(&host->lock);
751 } /* }}} Msg *riemann_batch_add_value_list */
753 static int riemann_notification(const notification_t *n, user_data_t *ud) /* {{{ */
756 struct riemann_host *host = ud->data;
759 if (!host->notifications)
763 * Never batch for notifications, send them ASAP
765 msg = riemann_notification_to_protobuf (host, n);
769 status = riemann_send (host, msg);
771 ERROR ("write_riemann plugin: riemann_send failed with status %i",
774 riemann_msg_protobuf_free (msg);
776 } /* }}} int riemann_notification */
778 static int riemann_write(const data_set_t *ds, /* {{{ */
779 const value_list_t *vl,
783 int statuses[vl->values_len];
784 struct riemann_host *host = ud->data;
786 if (host->check_thresholds) {
787 status = write_riemann_threshold_check(ds, vl, statuses);
791 memset (statuses, 0, sizeof (statuses));
794 if (host->use_tcp == 1 && host->batch_mode) {
795 riemann_batch_add_value_list (host, ds, vl, statuses);
797 Msg *msg = riemann_value_list_to_protobuf (host, ds, vl, statuses);
801 status = riemann_send (host, msg);
803 ERROR ("write_riemann plugin: riemann_send failed with status %i", status);
805 riemann_msg_protobuf_free (msg);
809 } /* }}} int riemann_write */
811 static void riemann_free(void *p) /* {{{ */
813 struct riemann_host *host = p;
818 pthread_mutex_lock (&host->lock);
820 host->reference_count--;
821 if (host->reference_count > 0)
823 pthread_mutex_unlock (&host->lock);
827 riemann_disconnect (host);
829 sfree(host->service);
830 pthread_mutex_destroy (&host->lock);
832 } /* }}} void riemann_free */
834 static int riemann_config_node(oconfig_item_t *ci) /* {{{ */
836 struct riemann_host *host = NULL;
839 oconfig_item_t *child;
840 char callback_name[DATA_MAX_NAME_LEN];
843 if ((host = calloc(1, sizeof (*host))) == NULL) {
844 ERROR ("write_riemann plugin: calloc failed.");
847 pthread_mutex_init (&host->lock, NULL);
848 host->reference_count = 1;
850 host->service = NULL;
851 host->notifications = 1;
852 host->check_thresholds = 0;
853 host->store_rates = 1;
854 host->always_append_ds = 0;
856 host->batch_mode = 1;
857 host->batch_max = RIEMANN_BATCH_MAX; /* typical MSS */
858 host->batch_init = cdtime();
859 host->ttl_factor = RIEMANN_TTL_FACTOR;
861 status = cf_util_get_string (ci, &host->name);
863 WARNING("write_riemann plugin: Required host name is missing.");
868 for (i = 0; i < ci->children_num; i++) {
870 * The code here could be simplified but makes room
871 * for easy adding of new options later on.
873 child = &ci->children[i];
876 if (strcasecmp ("Host", child->key) == 0) {
877 status = cf_util_get_string (child, &host->node);
880 } else if (strcasecmp ("Notifications", child->key) == 0) {
881 status = cf_util_get_boolean(child, &host->notifications);
884 } else if (strcasecmp ("EventServicePrefix", child->key) == 0) {
885 status = cf_util_get_string (child, &host->event_service_prefix);
888 } else if (strcasecmp ("CheckThresholds", child->key) == 0) {
889 status = cf_util_get_boolean(child, &host->check_thresholds);
892 } else if (strcasecmp ("Batch", child->key) == 0) {
893 status = cf_util_get_boolean(child, &host->batch_mode);
896 } else if (strcasecmp("BatchMaxSize", child->key) == 0) {
897 status = cf_util_get_int(child, &host->batch_max);
900 } else if (strcasecmp ("Port", child->key) == 0) {
901 status = cf_util_get_service (child, &host->service);
903 ERROR ("write_riemann plugin: Invalid argument "
904 "configured for the \"Port\" "
908 } else if (strcasecmp ("Protocol", child->key) == 0) {
910 status = cf_util_get_string_buffer (child,
914 ERROR ("write_riemann plugin: cf_util_get_"
915 "string_buffer failed with "
916 "status %i.", status);
920 if (strcasecmp ("UDP", tmp) == 0)
922 else if (strcasecmp ("TCP", tmp) == 0)
925 WARNING ("write_riemann plugin: The value "
926 "\"%s\" is not valid for the "
927 "\"Protocol\" option. Use "
928 "either \"UDP\" or \"TCP\".",
930 } else if (strcasecmp ("StoreRates", child->key) == 0) {
931 status = cf_util_get_boolean (child, &host->store_rates);
934 } else if (strcasecmp ("AlwaysAppendDS", child->key) == 0) {
935 status = cf_util_get_boolean (child,
936 &host->always_append_ds);
939 } else if (strcasecmp ("TTLFactor", child->key) == 0) {
941 status = cf_util_get_double (child, &tmp);
945 host->ttl_factor = tmp;
946 } else if (tmp >= 1.0) {
947 NOTICE ("write_riemann plugin: The configured "
948 "TTLFactor is very small "
949 "(%.1f). A value of 2.0 or "
950 "greater is recommended.",
952 host->ttl_factor = tmp;
953 } else if (tmp > 0.0) {
954 WARNING ("write_riemann plugin: The configured "
955 "TTLFactor is too small to be "
956 "useful (%.1f). I'll use it "
957 "since the user knows best, "
958 "but under protest.",
960 host->ttl_factor = tmp;
961 } else { /* zero, negative and NAN */
962 ERROR ("write_riemann plugin: The configured "
963 "TTLFactor is invalid (%.1f).",
967 WARNING("write_riemann plugin: ignoring unknown config "
968 "option: \"%s\"", child->key);
976 ssnprintf (callback_name, sizeof (callback_name), "write_riemann/%s",
979 ud.free_func = riemann_free;
981 pthread_mutex_lock (&host->lock);
983 status = plugin_register_write (callback_name, riemann_write, &ud);
985 if (host->use_tcp == 1 && host->batch_mode) {
987 plugin_register_flush(callback_name, riemann_batch_flush, &ud);
990 WARNING ("write_riemann plugin: plugin_register_write (\"%s\") "
991 "failed with status %i.",
992 callback_name, status);
994 host->reference_count++;
996 status = plugin_register_notification (callback_name,
997 riemann_notification, &ud);
999 WARNING ("write_riemann plugin: plugin_register_notification (\"%s\") "
1000 "failed with status %i.",
1001 callback_name, status);
1003 host->reference_count++;
1005 if (host->reference_count <= 1)
1007 /* Both callbacks failed => free memory.
1008 * We need to unlock here, because riemann_free() will lock.
1009 * This is not a race condition, because we're the only one
1010 * holding a reference. */
1011 pthread_mutex_unlock (&host->lock);
1012 riemann_free (host);
1016 host->reference_count--;
1017 pthread_mutex_unlock (&host->lock);
1020 } /* }}} int riemann_config_node */
1022 static int riemann_config(oconfig_item_t *ci) /* {{{ */
1025 oconfig_item_t *child;
1028 for (i = 0; i < ci->children_num; i++) {
1029 child = &ci->children[i];
1031 if (strcasecmp("Node", child->key) == 0) {
1032 riemann_config_node (child);
1033 } else if (strcasecmp(child->key, "attribute") == 0) {
1037 if (child->values_num != 2) {
1038 WARNING("riemann attributes need both a key and a value.");
1041 if (child->values[0].type != OCONFIG_TYPE_STRING ||
1042 child->values[1].type != OCONFIG_TYPE_STRING) {
1043 WARNING("riemann attribute needs string arguments.");
1046 if ((key = strdup(child->values[0].value.string)) == NULL) {
1047 WARNING("cannot allocate memory for attribute key.");
1050 if ((val = strdup(child->values[1].value.string)) == NULL) {
1051 WARNING("cannot allocate memory for attribute value.");
1055 strarray_add(&riemann_attrs, &riemann_attrs_num, key);
1056 strarray_add(&riemann_attrs, &riemann_attrs_num, val);
1057 DEBUG("write_riemann: got attr: %s => %s", key, val);
1060 } else if (strcasecmp(child->key, "tag") == 0) {
1062 status = cf_util_get_string(child, &tmp);
1066 strarray_add (&riemann_tags, &riemann_tags_num, tmp);
1067 DEBUG("write_riemann plugin: Got tag: %s", tmp);
1070 WARNING ("write_riemann plugin: Ignoring unknown "
1071 "configuration option \"%s\" at top level.",
1076 } /* }}} int riemann_config */
1078 void module_register(void)
1080 plugin_register_complex_config ("write_riemann", riemann_config);
1083 /* vim: set sw=8 sts=8 ts=8 noet : */