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>
33 #include "configfile.h"
34 #include "utils_cache.h"
35 #include "riemann.pb-c.h"
36 #include "write_riemann_threshold.h"
38 #include <sys/socket.h>
39 #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
49 char *event_service_prefix;
50 #define F_CONNECT 0x01
55 _Bool check_thresholds;
57 _Bool always_append_ds;
69 static char **riemann_tags;
70 static size_t riemann_tags_num;
71 static char **riemann_attrs;
72 static size_t riemann_attrs_num;
74 static void riemann_event_protobuf_free (Event *event) /* {{{ */
82 sfree (event->service);
84 sfree (event->description);
86 strarray_free (event->tags, event->n_tags);
90 for (i = 0; i < event->n_attributes; i++)
92 sfree (event->attributes[i]->key);
93 sfree (event->attributes[i]->value);
94 sfree (event->attributes[i]);
96 sfree (event->attributes);
97 event->n_attributes = 0;
100 } /* }}} void riemann_event_protobuf_free */
102 static void riemann_msg_protobuf_free(Msg *msg) /* {{{ */
109 for (i = 0; i < msg->n_events; i++)
111 riemann_event_protobuf_free (msg->events[i]);
112 msg->events[i] = NULL;
119 } /* }}} void riemann_msg_protobuf_free */
121 /* host->lock must be held when calling this function. */
122 static int riemann_connect(struct riemann_host *host) /* {{{ */
125 struct addrinfo *ai, *res, hints;
129 if (host->flags & F_CONNECT)
132 memset(&hints, 0, sizeof(hints));
133 memset(&service, 0, sizeof(service));
134 hints.ai_family = AF_UNSPEC;
135 hints.ai_socktype = host->use_tcp ? SOCK_STREAM : SOCK_DGRAM;
137 hints.ai_flags |= AI_ADDRCONFIG;
140 node = (host->node != NULL) ? host->node : RIEMANN_HOST;
141 service = (host->service != NULL) ? host->service : RIEMANN_PORT;
143 if ((e = getaddrinfo(node, service, &hints, &res)) != 0) {
144 ERROR ("write_riemann plugin: Unable to resolve host \"%s\": %s",
145 node, gai_strerror(e));
150 for (ai = res; ai != NULL; ai = ai->ai_next) {
151 if ((host->s = socket(ai->ai_family,
153 ai->ai_protocol)) == -1) {
157 if (connect(host->s, ai->ai_addr, ai->ai_addrlen) != 0) {
163 host->flags |= F_CONNECT;
164 DEBUG("write_riemann plugin: got a successful connection for: %s:%s",
172 WARNING("write_riemann plugin: Unable to connect to Riemann at %s:%s",
177 } /* }}} int riemann_connect */
179 /* host->lock must be held when calling this function. */
180 static int riemann_disconnect (struct riemann_host *host) /* {{{ */
182 if ((host->flags & F_CONNECT) == 0)
187 host->flags &= ~F_CONNECT;
190 } /* }}} int riemann_disconnect */
192 static int riemann_send_msg (struct riemann_host *host, const Msg *msg) /* {{{ */
195 u_char *buffer = NULL;
198 status = riemann_connect (host);
202 buffer_len = msg__get_packed_size(msg);
207 buffer = malloc (buffer_len);
208 if (buffer == NULL) {
209 ERROR ("write_riemann plugin: malloc failed.");
212 memset (buffer, 0, buffer_len);
216 uint32_t length = htonl ((uint32_t) (buffer_len - 4));
217 memcpy (buffer, &length, 4);
218 msg__pack(msg, buffer + 4);
222 msg__pack(msg, buffer);
225 status = (int) swrite (host->s, buffer, buffer_len);
229 ERROR ("write_riemann plugin: Sending to Riemann at %s:%s failed: %s",
230 (host->node != NULL) ? host->node : RIEMANN_HOST,
231 (host->service != NULL) ? host->service : RIEMANN_PORT,
232 sstrerror (errno, errbuf, sizeof (errbuf)));
239 } /* }}} int riemann_send_msg */
241 static int riemann_recv_ack(struct riemann_host *host) /* {{{ */
247 status = (int) sread (host->s, &header, 4);
252 size_t size = ntohl(header);
254 // Buffer on the stack since acknowledges are typically small.
256 memset (buffer, 0, size);
258 status = (int) sread (host->s, buffer, size);
263 msg = msg__unpack (NULL, size, buffer);
270 ERROR ("write_riemann plugin: Sending to Riemann at %s:%s acknowledgement message reported error: %s",
271 (host->node != NULL) ? host->node : RIEMANN_HOST,
272 (host->service != NULL) ? host->service : RIEMANN_PORT,
275 msg__free_unpacked(msg, NULL);
279 msg__free_unpacked (msg, NULL);
281 } /* }}} int riemann_recv_ack */
284 * Function to send messages (Msg) to riemann.
286 * Acquires the host lock, disconnects on errors.
288 static int riemann_send(struct riemann_host *host, Msg const *msg) /* {{{ */
291 pthread_mutex_lock (&host->lock);
293 status = riemann_send_msg(host, msg);
295 riemann_disconnect (host);
296 pthread_mutex_unlock (&host->lock);
301 * For TCP we need to receive message acknowledgemenent.
305 status = riemann_recv_ack(host);
309 riemann_disconnect (host);
310 pthread_mutex_unlock (&host->lock);
315 pthread_mutex_unlock (&host->lock);
317 } /* }}} int riemann_send */
319 static int riemann_event_add_tag (Event *event, char const *tag) /* {{{ */
321 return (strarray_add (&event->tags, &event->n_tags, tag));
322 } /* }}} int riemann_event_add_tag */
324 static int riemann_event_add_attribute(Event *event, /* {{{ */
325 char const *key, char const *value)
327 Attribute **new_attributes;
330 new_attributes = realloc (event->attributes,
331 sizeof (*event->attributes) * (event->n_attributes + 1));
332 if (new_attributes == NULL)
334 ERROR ("write_riemann plugin: realloc failed.");
337 event->attributes = new_attributes;
339 a = malloc (sizeof (*a));
342 ERROR ("write_riemann plugin: malloc failed.");
347 a->key = strdup (key);
349 a->value = strdup (value);
351 event->attributes[event->n_attributes] = a;
352 event->n_attributes++;
355 } /* }}} int riemann_event_add_attribute */
357 static Msg *riemann_notification_to_protobuf(struct riemann_host *host, /* {{{ */
358 notification_t const *n)
362 char service_buffer[6 * DATA_MAX_NAME_LEN];
363 char const *severity;
364 notification_meta_t *meta;
367 msg = malloc (sizeof (*msg));
370 ERROR ("write_riemann plugin: malloc failed.");
373 memset (msg, 0, sizeof (*msg));
376 msg->events = malloc (sizeof (*msg->events));
377 if (msg->events == NULL)
379 ERROR ("write_riemann plugin: malloc failed.");
384 event = malloc (sizeof (*event));
387 ERROR ("write_riemann plugin: malloc failed.");
392 memset (event, 0, sizeof (*event));
395 msg->events[0] = event;
398 event->host = strdup (n->host);
399 event->time = CDTIME_T_TO_TIME_T (n->time);
404 case NOTIF_OKAY: severity = "ok"; break;
405 case NOTIF_WARNING: severity = "warning"; break;
406 case NOTIF_FAILURE: severity = "critical"; break;
407 default: severity = "unknown";
409 event->state = strdup (severity);
411 riemann_event_add_tag (event, "notification");
413 riemann_event_add_attribute (event, "host", n->host);
414 if (n->plugin[0] != 0)
415 riemann_event_add_attribute (event, "plugin", n->plugin);
416 if (n->plugin_instance[0] != 0)
417 riemann_event_add_attribute (event, "plugin_instance",
421 riemann_event_add_attribute (event, "type", n->type);
422 if (n->type_instance[0] != 0)
423 riemann_event_add_attribute (event, "type_instance",
426 for (i = 0; i < riemann_attrs_num; i += 2)
427 riemann_event_add_attribute(event,
429 riemann_attrs[i +1]);
431 for (i = 0; i < riemann_tags_num; i++)
432 riemann_event_add_tag (event, riemann_tags[i]);
434 format_name (service_buffer, sizeof (service_buffer),
435 /* host = */ "", n->plugin, n->plugin_instance,
436 n->type, n->type_instance);
437 event->service = strdup (&service_buffer[1]);
439 if (n->message[0] != 0)
440 riemann_event_add_attribute (event, "description", n->message);
442 /* Pull in values from threshold and add extra attributes */
443 for (meta = n->meta; meta != NULL; meta = meta->next)
445 if (strcasecmp ("CurrentValue", meta->name) == 0 && meta->type == NM_TYPE_DOUBLE)
447 event->metric_d = meta->nm_value.nm_double;
448 event->has_metric_d = 1;
452 if (meta->type == NM_TYPE_STRING) {
453 riemann_event_add_attribute (event, meta->name, meta->nm_value.nm_string);
458 DEBUG ("write_riemann plugin: Successfully created protobuf for notification: "
459 "host = \"%s\", service = \"%s\", state = \"%s\"",
460 event->host, event->service, event->state);
462 } /* }}} Msg *riemann_notification_to_protobuf */
464 static Event *riemann_value_to_protobuf(struct riemann_host const *host, /* {{{ */
465 data_set_t const *ds,
466 value_list_t const *vl, size_t index,
467 gauge_t const *rates,
471 char name_buffer[5 * DATA_MAX_NAME_LEN];
472 char service_buffer[6 * DATA_MAX_NAME_LEN];
476 event = malloc (sizeof (*event));
479 ERROR ("write_riemann plugin: malloc failed.");
482 memset (event, 0, sizeof (*event));
485 event->host = strdup (vl->host);
486 event->time = CDTIME_T_TO_TIME_T (vl->time);
489 if (host->check_thresholds) {
492 event->state = strdup("ok");
495 event->state = strdup("critical");
498 event->state = strdup("warning");
501 event->state = strdup("unknown");
506 ttl = CDTIME_T_TO_DOUBLE (vl->interval) * host->ttl_factor;
507 event->ttl = (float) ttl;
510 riemann_event_add_attribute (event, "plugin", vl->plugin);
511 if (vl->plugin_instance[0] != 0)
512 riemann_event_add_attribute (event, "plugin_instance",
513 vl->plugin_instance);
515 riemann_event_add_attribute (event, "type", vl->type);
516 if (vl->type_instance[0] != 0)
517 riemann_event_add_attribute (event, "type_instance",
520 if ((ds->ds[index].type != DS_TYPE_GAUGE) && (rates != NULL))
522 char ds_type[DATA_MAX_NAME_LEN];
524 ssnprintf (ds_type, sizeof (ds_type), "%s:rate",
525 DS_TYPE_TO_STRING(ds->ds[index].type));
526 riemann_event_add_attribute (event, "ds_type", ds_type);
530 riemann_event_add_attribute (event, "ds_type",
531 DS_TYPE_TO_STRING(ds->ds[index].type));
533 riemann_event_add_attribute (event, "ds_name", ds->ds[index].name);
535 char ds_index[DATA_MAX_NAME_LEN];
537 ssnprintf (ds_index, sizeof (ds_index), "%zu", index);
538 riemann_event_add_attribute (event, "ds_index", ds_index);
541 for (i = 0; i < riemann_attrs_num; i += 2)
542 riemann_event_add_attribute(event,
544 riemann_attrs[i +1]);
546 for (i = 0; i < riemann_tags_num; i++)
547 riemann_event_add_tag (event, riemann_tags[i]);
549 if (ds->ds[index].type == DS_TYPE_GAUGE)
551 event->has_metric_d = 1;
552 event->metric_d = (double) vl->values[index].gauge;
554 else if (rates != NULL)
556 event->has_metric_d = 1;
557 event->metric_d = (double) rates[index];
561 event->has_metric_sint64 = 1;
562 if (ds->ds[index].type == DS_TYPE_DERIVE)
563 event->metric_sint64 = (int64_t) vl->values[index].derive;
564 else if (ds->ds[index].type == DS_TYPE_ABSOLUTE)
565 event->metric_sint64 = (int64_t) vl->values[index].absolute;
567 event->metric_sint64 = (int64_t) vl->values[index].counter;
570 format_name (name_buffer, sizeof (name_buffer),
571 /* host = */ "", vl->plugin, vl->plugin_instance,
572 vl->type, vl->type_instance);
573 if (host->always_append_ds || (ds->ds_num > 1))
575 if (host->event_service_prefix == NULL)
576 ssnprintf (service_buffer, sizeof (service_buffer), "%s/%s",
577 &name_buffer[1], ds->ds[index].name);
579 ssnprintf (service_buffer, sizeof (service_buffer), "%s%s/%s",
580 host->event_service_prefix, &name_buffer[1], ds->ds[index].name);
584 if (host->event_service_prefix == NULL)
585 sstrncpy (service_buffer, &name_buffer[1], sizeof (service_buffer));
587 ssnprintf (service_buffer, sizeof (service_buffer), "%s%s",
588 host->event_service_prefix, &name_buffer[1]);
591 event->service = strdup (service_buffer);
593 DEBUG ("write_riemann plugin: Successfully created protobuf for metric: "
594 "host = \"%s\", service = \"%s\"",
595 event->host, event->service);
597 } /* }}} Event *riemann_value_to_protobuf */
599 static Msg *riemann_value_list_to_protobuf (struct riemann_host const *host, /* {{{ */
600 data_set_t const *ds,
601 value_list_t const *vl,
606 gauge_t *rates = NULL;
608 /* Initialize the Msg structure. */
609 msg = malloc (sizeof (*msg));
612 ERROR ("write_riemann plugin: malloc failed.");
615 memset (msg, 0, sizeof (*msg));
618 /* Set up events. First, the list of pointers. */
619 msg->n_events = (size_t) vl->values_len;
620 msg->events = calloc (msg->n_events, sizeof (*msg->events));
621 if (msg->events == NULL)
623 ERROR ("write_riemann plugin: calloc failed.");
624 riemann_msg_protobuf_free (msg);
628 if (host->store_rates)
630 rates = uc_get_rate (ds, vl);
633 ERROR ("write_riemann plugin: uc_get_rate failed.");
634 riemann_msg_protobuf_free (msg);
639 for (i = 0; i < msg->n_events; i++)
641 msg->events[i] = riemann_value_to_protobuf (host, ds, vl,
642 (int) i, rates, statuses[i]);
643 if (msg->events[i] == NULL)
645 riemann_msg_protobuf_free (msg);
653 } /* }}} Msg *riemann_value_list_to_protobuf */
657 * Always call while holding host->lock !
659 static int riemann_batch_flush_nolock (cdtime_t timeout,
660 struct riemann_host *host)
667 if ((host->batch_init + timeout) > now)
670 riemann_send_msg(host, host->batch_msg);
671 riemann_msg_protobuf_free(host->batch_msg);
673 if (host->use_tcp && ((status = riemann_recv_ack(host)) != 0))
674 riemann_disconnect (host);
676 host->batch_init = cdtime();
677 host->batch_msg = NULL;
681 static int riemann_batch_flush (cdtime_t timeout,
682 const char *identifier __attribute__((unused)),
683 user_data_t *user_data)
685 struct riemann_host *host;
688 if (user_data == NULL)
691 host = user_data->data;
692 pthread_mutex_lock (&host->lock);
693 status = riemann_batch_flush_nolock (timeout, host);
695 ERROR ("write_riemann plugin: riemann_send failed with status %i",
698 pthread_mutex_unlock(&host->lock);
702 static int riemann_batch_add_value_list (struct riemann_host *host, /* {{{ */
703 data_set_t const *ds,
704 value_list_t const *vl,
713 msg = riemann_value_list_to_protobuf (host, ds, vl, statuses);
717 pthread_mutex_lock(&host->lock);
719 if (host->batch_msg == NULL) {
720 host->batch_msg = msg;
722 len = msg->n_events + host->batch_msg->n_events;
723 events = realloc(host->batch_msg->events,
724 (len * sizeof(*host->batch_msg->events)));
725 if (events == NULL) {
726 pthread_mutex_unlock(&host->lock);
727 ERROR ("write_riemann plugin: out of memory");
728 riemann_msg_protobuf_free (msg);
731 host->batch_msg->events = events;
733 for (i = host->batch_msg->n_events; i < len; i++)
734 host->batch_msg->events[i] = msg->events[i - host->batch_msg->n_events];
736 host->batch_msg->n_events = len;
742 len = msg__get_packed_size(host->batch_msg);
744 if (len >= host->batch_max) {
745 ret = riemann_batch_flush_nolock(0, host);
748 pthread_mutex_unlock(&host->lock);
750 } /* }}} Msg *riemann_batch_add_value_list */
752 static int riemann_notification(const notification_t *n, user_data_t *ud) /* {{{ */
755 struct riemann_host *host = ud->data;
758 if (!host->notifications)
762 * Never batch for notifications, send them ASAP
764 msg = riemann_notification_to_protobuf (host, n);
768 status = riemann_send (host, msg);
770 ERROR ("write_riemann plugin: riemann_send failed with status %i",
773 riemann_msg_protobuf_free (msg);
775 } /* }}} int riemann_notification */
777 static int riemann_write(const data_set_t *ds, /* {{{ */
778 const value_list_t *vl,
782 int statuses[vl->values_len];
783 struct riemann_host *host = ud->data;
786 if (host->check_thresholds)
787 write_riemann_threshold_check(ds, vl, statuses);
789 if (host->use_tcp == 1 && host->batch_mode) {
791 riemann_batch_add_value_list (host, ds, vl, statuses);
796 msg = riemann_value_list_to_protobuf (host, ds, vl, statuses);
800 status = riemann_send (host, msg);
802 ERROR ("write_riemann plugin: riemann_send failed with status %i",
805 riemann_msg_protobuf_free (msg);
808 } /* }}} int riemann_write */
810 static void riemann_free(void *p) /* {{{ */
812 struct riemann_host *host = p;
817 pthread_mutex_lock (&host->lock);
819 host->reference_count--;
820 if (host->reference_count > 0)
822 pthread_mutex_unlock (&host->lock);
826 riemann_disconnect (host);
828 sfree(host->service);
829 pthread_mutex_destroy (&host->lock);
831 } /* }}} void riemann_free */
833 static int riemann_config_node(oconfig_item_t *ci) /* {{{ */
835 struct riemann_host *host = NULL;
838 oconfig_item_t *child;
839 char callback_name[DATA_MAX_NAME_LEN];
842 if ((host = calloc(1, sizeof (*host))) == NULL) {
843 ERROR ("write_riemann plugin: calloc failed.");
846 pthread_mutex_init (&host->lock, NULL);
847 host->reference_count = 1;
849 host->service = NULL;
850 host->notifications = 1;
851 host->check_thresholds = 0;
852 host->store_rates = 1;
853 host->always_append_ds = 0;
855 host->batch_mode = 1;
856 host->batch_max = RIEMANN_BATCH_MAX; /* typical MSS */
857 host->batch_init = cdtime();
858 host->ttl_factor = RIEMANN_TTL_FACTOR;
860 status = cf_util_get_string (ci, &host->name);
862 WARNING("write_riemann plugin: Required host name is missing.");
867 for (i = 0; i < ci->children_num; i++) {
869 * The code here could be simplified but makes room
870 * for easy adding of new options later on.
872 child = &ci->children[i];
875 if (strcasecmp ("Host", child->key) == 0) {
876 status = cf_util_get_string (child, &host->node);
879 } else if (strcasecmp ("Notifications", child->key) == 0) {
880 status = cf_util_get_boolean(child, &host->notifications);
883 } else if (strcasecmp ("EventServicePrefix", child->key) == 0) {
884 status = cf_util_get_string (child, &host->event_service_prefix);
887 } else if (strcasecmp ("CheckThresholds", child->key) == 0) {
888 status = cf_util_get_boolean(child, &host->check_thresholds);
891 } else if (strcasecmp ("Batch", child->key) == 0) {
892 status = cf_util_get_boolean(child, &host->batch_mode);
895 } else if (strcasecmp("BatchMaxSize", child->key) == 0) {
896 status = cf_util_get_int(child, &host->batch_max);
899 } else if (strcasecmp ("Port", child->key) == 0) {
900 status = cf_util_get_service (child, &host->service);
902 ERROR ("write_riemann plugin: Invalid argument "
903 "configured for the \"Port\" "
907 } else if (strcasecmp ("Protocol", child->key) == 0) {
909 status = cf_util_get_string_buffer (child,
913 ERROR ("write_riemann plugin: cf_util_get_"
914 "string_buffer failed with "
915 "status %i.", status);
919 if (strcasecmp ("UDP", tmp) == 0)
921 else if (strcasecmp ("TCP", tmp) == 0)
924 WARNING ("write_riemann plugin: The value "
925 "\"%s\" is not valid for the "
926 "\"Protocol\" option. Use "
927 "either \"UDP\" or \"TCP\".",
929 } else if (strcasecmp ("StoreRates", child->key) == 0) {
930 status = cf_util_get_boolean (child, &host->store_rates);
933 } else if (strcasecmp ("AlwaysAppendDS", child->key) == 0) {
934 status = cf_util_get_boolean (child,
935 &host->always_append_ds);
938 } else if (strcasecmp ("TTLFactor", child->key) == 0) {
940 status = cf_util_get_double (child, &tmp);
944 host->ttl_factor = tmp;
945 } else if (tmp >= 1.0) {
946 NOTICE ("write_riemann plugin: The configured "
947 "TTLFactor is very small "
948 "(%.1f). A value of 2.0 or "
949 "greater is recommended.",
951 host->ttl_factor = tmp;
952 } else if (tmp > 0.0) {
953 WARNING ("write_riemann plugin: The configured "
954 "TTLFactor is too small to be "
955 "useful (%.1f). I'll use it "
956 "since the user knows best, "
957 "but under protest.",
959 host->ttl_factor = tmp;
960 } else { /* zero, negative and NAN */
961 ERROR ("write_riemann plugin: The configured "
962 "TTLFactor is invalid (%.1f).",
966 WARNING("write_riemann plugin: ignoring unknown config "
967 "option: \"%s\"", child->key);
975 ssnprintf (callback_name, sizeof (callback_name), "write_riemann/%s",
978 ud.free_func = riemann_free;
980 pthread_mutex_lock (&host->lock);
982 status = plugin_register_write (callback_name, riemann_write, &ud);
984 if (host->use_tcp == 1 && host->batch_mode) {
986 plugin_register_flush(callback_name, riemann_batch_flush, &ud);
989 WARNING ("write_riemann plugin: plugin_register_write (\"%s\") "
990 "failed with status %i.",
991 callback_name, status);
993 host->reference_count++;
995 status = plugin_register_notification (callback_name,
996 riemann_notification, &ud);
998 WARNING ("write_riemann plugin: plugin_register_notification (\"%s\") "
999 "failed with status %i.",
1000 callback_name, status);
1002 host->reference_count++;
1004 if (host->reference_count <= 1)
1006 /* Both callbacks failed => free memory.
1007 * We need to unlock here, because riemann_free() will lock.
1008 * This is not a race condition, because we're the only one
1009 * holding a reference. */
1010 pthread_mutex_unlock (&host->lock);
1011 riemann_free (host);
1015 host->reference_count--;
1016 pthread_mutex_unlock (&host->lock);
1019 } /* }}} int riemann_config_node */
1021 static int riemann_config(oconfig_item_t *ci) /* {{{ */
1024 oconfig_item_t *child;
1027 for (i = 0; i < ci->children_num; i++) {
1028 child = &ci->children[i];
1030 if (strcasecmp("Node", child->key) == 0) {
1031 riemann_config_node (child);
1032 } else if (strcasecmp(child->key, "attribute") == 0) {
1036 if (child->values_num != 2) {
1037 WARNING("riemann attributes need both a key and a value.");
1040 if (child->values[0].type != OCONFIG_TYPE_STRING ||
1041 child->values[1].type != OCONFIG_TYPE_STRING) {
1042 WARNING("riemann attribute needs string arguments.");
1045 if ((key = strdup(child->values[0].value.string)) == NULL) {
1046 WARNING("cannot allocate memory for attribute key.");
1049 if ((val = strdup(child->values[1].value.string)) == NULL) {
1050 WARNING("cannot allocate memory for attribute value.");
1054 strarray_add(&riemann_attrs, &riemann_attrs_num, key);
1055 strarray_add(&riemann_attrs, &riemann_attrs_num, val);
1056 DEBUG("write_riemann: got attr: %s => %s", key, val);
1059 } else if (strcasecmp(child->key, "tag") == 0) {
1061 status = cf_util_get_string(child, &tmp);
1065 strarray_add (&riemann_tags, &riemann_tags_num, tmp);
1066 DEBUG("write_riemann plugin: Got tag: %s", tmp);
1069 WARNING ("write_riemann plugin: Ignoring unknown "
1070 "configuration option \"%s\" at top level.",
1075 } /* }}} int riemann_config */
1077 void module_register(void)
1079 plugin_register_complex_config ("write_riemann", riemann_config);
1082 /* vim: set sw=8 sts=8 ts=8 noet : */