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 <sys/socket.h>
37 #include <arpa/inet.h>
43 #define RIEMANN_HOST "localhost"
44 #define RIEMANN_PORT "5555"
45 #define RIEMANN_TTL_FACTOR 2.0
46 #define RIEMANN_BATCH_MAX 8192
48 int write_riemann_threshold_check(const data_set_t *, const value_list_t *, int *);
52 char *event_service_prefix;
53 #define F_CONNECT 0x01
58 _Bool check_thresholds;
60 _Bool always_append_ds;
72 static char **riemann_tags;
73 static size_t riemann_tags_num;
74 static char **riemann_attrs;
75 static size_t riemann_attrs_num;
77 static void riemann_event_protobuf_free (Event *event) /* {{{ */
85 sfree (event->service);
87 sfree (event->description);
89 strarray_free (event->tags, event->n_tags);
93 for (i = 0; i < event->n_attributes; i++)
95 sfree (event->attributes[i]->key);
96 sfree (event->attributes[i]->value);
97 sfree (event->attributes[i]);
99 sfree (event->attributes);
100 event->n_attributes = 0;
103 } /* }}} void riemann_event_protobuf_free */
105 static void riemann_msg_protobuf_free(Msg *msg) /* {{{ */
112 for (i = 0; i < msg->n_events; i++)
114 riemann_event_protobuf_free (msg->events[i]);
115 msg->events[i] = NULL;
122 } /* }}} void riemann_msg_protobuf_free */
124 /* host->lock must be held when calling this function. */
125 static int riemann_connect(struct riemann_host *host) /* {{{ */
128 struct addrinfo *ai, *res, hints;
132 if (host->flags & F_CONNECT)
135 memset(&hints, 0, sizeof(hints));
136 memset(&service, 0, sizeof(service));
137 hints.ai_family = AF_UNSPEC;
138 hints.ai_socktype = host->use_tcp ? SOCK_STREAM : SOCK_DGRAM;
140 hints.ai_flags |= AI_ADDRCONFIG;
143 node = (host->node != NULL) ? host->node : RIEMANN_HOST;
144 service = (host->service != NULL) ? host->service : RIEMANN_PORT;
146 if ((e = getaddrinfo(node, service, &hints, &res)) != 0) {
147 ERROR ("write_riemann plugin: Unable to resolve host \"%s\": %s",
148 node, gai_strerror(e));
153 for (ai = res; ai != NULL; ai = ai->ai_next) {
154 if ((host->s = socket(ai->ai_family,
156 ai->ai_protocol)) == -1) {
160 if (connect(host->s, ai->ai_addr, ai->ai_addrlen) != 0) {
166 host->flags |= F_CONNECT;
167 DEBUG("write_riemann plugin: got a successful connection for: %s:%s",
175 WARNING("write_riemann plugin: Unable to connect to Riemann at %s:%s",
180 } /* }}} int riemann_connect */
182 /* host->lock must be held when calling this function. */
183 static int riemann_disconnect (struct riemann_host *host) /* {{{ */
185 if ((host->flags & F_CONNECT) == 0)
190 host->flags &= ~F_CONNECT;
193 } /* }}} int riemann_disconnect */
195 static int riemann_send_msg (struct riemann_host *host, const Msg *msg) /* {{{ */
198 u_char *buffer = NULL;
201 status = riemann_connect (host);
205 buffer_len = msg__get_packed_size(msg);
210 buffer = malloc (buffer_len);
211 if (buffer == NULL) {
212 ERROR ("write_riemann plugin: malloc failed.");
215 memset (buffer, 0, buffer_len);
219 uint32_t length = htonl ((uint32_t) (buffer_len - 4));
220 memcpy (buffer, &length, 4);
221 msg__pack(msg, buffer + 4);
225 msg__pack(msg, buffer);
228 status = (int) swrite (host->s, buffer, buffer_len);
232 ERROR ("write_riemann plugin: Sending to Riemann at %s:%s failed: %s",
233 (host->node != NULL) ? host->node : RIEMANN_HOST,
234 (host->service != NULL) ? host->service : RIEMANN_PORT,
235 sstrerror (errno, errbuf, sizeof (errbuf)));
242 } /* }}} int riemann_send_msg */
244 static int riemann_recv_ack(struct riemann_host *host) /* {{{ */
250 status = (int) sread (host->s, &header, 4);
255 size_t size = ntohl(header);
257 // Buffer on the stack since acknowledges are typically small.
259 memset (buffer, 0, size);
261 status = (int) sread (host->s, buffer, size);
266 msg = msg__unpack (NULL, size, buffer);
273 ERROR ("write_riemann plugin: Sending to Riemann at %s:%s acknowledgement message reported error: %s",
274 (host->node != NULL) ? host->node : RIEMANN_HOST,
275 (host->service != NULL) ? host->service : RIEMANN_PORT,
278 msg__free_unpacked(msg, NULL);
282 msg__free_unpacked (msg, NULL);
284 } /* }}} int riemann_recv_ack */
287 * Function to send messages (Msg) to riemann.
289 * Acquires the host lock, disconnects on errors.
291 static int riemann_send(struct riemann_host *host, Msg const *msg) /* {{{ */
294 pthread_mutex_lock (&host->lock);
296 status = riemann_send_msg(host, msg);
298 riemann_disconnect (host);
299 pthread_mutex_unlock (&host->lock);
304 * For TCP we need to receive message acknowledgemenent.
308 status = riemann_recv_ack(host);
312 riemann_disconnect (host);
313 pthread_mutex_unlock (&host->lock);
318 pthread_mutex_unlock (&host->lock);
320 } /* }}} int riemann_send */
322 static int riemann_event_add_tag (Event *event, char const *tag) /* {{{ */
324 return (strarray_add (&event->tags, &event->n_tags, tag));
325 } /* }}} int riemann_event_add_tag */
327 static int riemann_event_add_attribute(Event *event, /* {{{ */
328 char const *key, char const *value)
330 Attribute **new_attributes;
333 new_attributes = realloc (event->attributes,
334 sizeof (*event->attributes) * (event->n_attributes + 1));
335 if (new_attributes == NULL)
337 ERROR ("write_riemann plugin: realloc failed.");
340 event->attributes = new_attributes;
342 a = malloc (sizeof (*a));
345 ERROR ("write_riemann plugin: malloc failed.");
350 a->key = strdup (key);
352 a->value = strdup (value);
354 event->attributes[event->n_attributes] = a;
355 event->n_attributes++;
358 } /* }}} int riemann_event_add_attribute */
360 static Msg *riemann_notification_to_protobuf(struct riemann_host *host, /* {{{ */
361 notification_t const *n)
365 char service_buffer[6 * DATA_MAX_NAME_LEN];
366 char const *severity;
367 notification_meta_t *meta;
370 msg = malloc (sizeof (*msg));
373 ERROR ("write_riemann plugin: malloc failed.");
376 memset (msg, 0, sizeof (*msg));
379 msg->events = malloc (sizeof (*msg->events));
380 if (msg->events == NULL)
382 ERROR ("write_riemann plugin: malloc failed.");
387 event = malloc (sizeof (*event));
390 ERROR ("write_riemann plugin: malloc failed.");
395 memset (event, 0, sizeof (*event));
398 msg->events[0] = event;
401 event->host = strdup (n->host);
402 event->time = CDTIME_T_TO_TIME_T (n->time);
407 case NOTIF_OKAY: severity = "ok"; break;
408 case NOTIF_WARNING: severity = "warning"; break;
409 case NOTIF_FAILURE: severity = "critical"; break;
410 default: severity = "unknown";
412 event->state = strdup (severity);
414 riemann_event_add_tag (event, "notification");
416 riemann_event_add_attribute (event, "host", n->host);
417 if (n->plugin[0] != 0)
418 riemann_event_add_attribute (event, "plugin", n->plugin);
419 if (n->plugin_instance[0] != 0)
420 riemann_event_add_attribute (event, "plugin_instance",
424 riemann_event_add_attribute (event, "type", n->type);
425 if (n->type_instance[0] != 0)
426 riemann_event_add_attribute (event, "type_instance",
429 for (i = 0; i < riemann_attrs_num; i += 2)
430 riemann_event_add_attribute(event,
432 riemann_attrs[i +1]);
434 for (i = 0; i < riemann_tags_num; i++)
435 riemann_event_add_tag (event, riemann_tags[i]);
437 format_name (service_buffer, sizeof (service_buffer),
438 /* host = */ "", n->plugin, n->plugin_instance,
439 n->type, n->type_instance);
440 event->service = strdup (&service_buffer[1]);
442 if (n->message[0] != 0)
443 riemann_event_add_attribute (event, "description", n->message);
445 /* Pull in values from threshold and add extra attributes */
446 for (meta = n->meta; meta != NULL; meta = meta->next)
448 if (strcasecmp ("CurrentValue", meta->name) == 0 && meta->type == NM_TYPE_DOUBLE)
450 event->metric_d = meta->nm_value.nm_double;
451 event->has_metric_d = 1;
455 if (meta->type == NM_TYPE_STRING) {
456 riemann_event_add_attribute (event, meta->name, meta->nm_value.nm_string);
461 DEBUG ("write_riemann plugin: Successfully created protobuf for notification: "
462 "host = \"%s\", service = \"%s\", state = \"%s\"",
463 event->host, event->service, event->state);
465 } /* }}} Msg *riemann_notification_to_protobuf */
467 static Event *riemann_value_to_protobuf(struct riemann_host const *host, /* {{{ */
468 data_set_t const *ds,
469 value_list_t const *vl, size_t index,
470 gauge_t const *rates,
474 char name_buffer[5 * DATA_MAX_NAME_LEN];
475 char service_buffer[6 * DATA_MAX_NAME_LEN];
479 event = malloc (sizeof (*event));
482 ERROR ("write_riemann plugin: malloc failed.");
485 memset (event, 0, sizeof (*event));
488 event->host = strdup (vl->host);
489 event->time = CDTIME_T_TO_TIME_T (vl->time);
492 if (host->check_thresholds) {
495 event->state = strdup("ok");
498 event->state = strdup("critical");
501 event->state = strdup("warning");
504 event->state = strdup("unknown");
509 ttl = CDTIME_T_TO_DOUBLE (vl->interval) * host->ttl_factor;
510 event->ttl = (float) ttl;
513 riemann_event_add_attribute (event, "plugin", vl->plugin);
514 if (vl->plugin_instance[0] != 0)
515 riemann_event_add_attribute (event, "plugin_instance",
516 vl->plugin_instance);
518 riemann_event_add_attribute (event, "type", vl->type);
519 if (vl->type_instance[0] != 0)
520 riemann_event_add_attribute (event, "type_instance",
523 if ((ds->ds[index].type != DS_TYPE_GAUGE) && (rates != NULL))
525 char ds_type[DATA_MAX_NAME_LEN];
527 ssnprintf (ds_type, sizeof (ds_type), "%s:rate",
528 DS_TYPE_TO_STRING(ds->ds[index].type));
529 riemann_event_add_attribute (event, "ds_type", ds_type);
533 riemann_event_add_attribute (event, "ds_type",
534 DS_TYPE_TO_STRING(ds->ds[index].type));
536 riemann_event_add_attribute (event, "ds_name", ds->ds[index].name);
538 char ds_index[DATA_MAX_NAME_LEN];
540 ssnprintf (ds_index, sizeof (ds_index), "%zu", index);
541 riemann_event_add_attribute (event, "ds_index", ds_index);
544 for (i = 0; i < riemann_attrs_num; i += 2)
545 riemann_event_add_attribute(event,
547 riemann_attrs[i +1]);
549 for (i = 0; i < riemann_tags_num; i++)
550 riemann_event_add_tag (event, riemann_tags[i]);
552 if (ds->ds[index].type == DS_TYPE_GAUGE)
554 event->has_metric_d = 1;
555 event->metric_d = (double) vl->values[index].gauge;
557 else if (rates != NULL)
559 event->has_metric_d = 1;
560 event->metric_d = (double) rates[index];
564 event->has_metric_sint64 = 1;
565 if (ds->ds[index].type == DS_TYPE_DERIVE)
566 event->metric_sint64 = (int64_t) vl->values[index].derive;
567 else if (ds->ds[index].type == DS_TYPE_ABSOLUTE)
568 event->metric_sint64 = (int64_t) vl->values[index].absolute;
570 event->metric_sint64 = (int64_t) vl->values[index].counter;
573 format_name (name_buffer, sizeof (name_buffer),
574 /* host = */ "", vl->plugin, vl->plugin_instance,
575 vl->type, vl->type_instance);
576 if (host->always_append_ds || (ds->ds_num > 1))
578 if (host->event_service_prefix == NULL)
579 ssnprintf (service_buffer, sizeof (service_buffer), "%s/%s",
580 &name_buffer[1], ds->ds[index].name);
582 ssnprintf (service_buffer, sizeof (service_buffer), "%s%s/%s",
583 host->event_service_prefix, &name_buffer[1], ds->ds[index].name);
587 if (host->event_service_prefix == NULL)
588 sstrncpy (service_buffer, &name_buffer[1], sizeof (service_buffer));
590 ssnprintf (service_buffer, sizeof (service_buffer), "%s%s",
591 host->event_service_prefix, &name_buffer[1]);
594 event->service = strdup (service_buffer);
596 DEBUG ("write_riemann plugin: Successfully created protobuf for metric: "
597 "host = \"%s\", service = \"%s\"",
598 event->host, event->service);
600 } /* }}} Event *riemann_value_to_protobuf */
602 static Msg *riemann_value_list_to_protobuf (struct riemann_host const *host, /* {{{ */
603 data_set_t const *ds,
604 value_list_t const *vl,
609 gauge_t *rates = NULL;
611 /* Initialize the Msg structure. */
612 msg = malloc (sizeof (*msg));
615 ERROR ("write_riemann plugin: malloc failed.");
618 memset (msg, 0, sizeof (*msg));
621 /* Set up events. First, the list of pointers. */
622 msg->n_events = vl->values_len;
623 msg->events = calloc (msg->n_events, sizeof (*msg->events));
624 if (msg->events == NULL)
626 ERROR ("write_riemann plugin: calloc failed.");
627 riemann_msg_protobuf_free (msg);
631 if (host->store_rates)
633 rates = uc_get_rate (ds, vl);
636 ERROR ("write_riemann plugin: uc_get_rate failed.");
637 riemann_msg_protobuf_free (msg);
642 for (i = 0; i < msg->n_events; i++)
644 msg->events[i] = riemann_value_to_protobuf (host, ds, vl,
645 (int) i, rates, statuses[i]);
646 if (msg->events[i] == NULL)
648 riemann_msg_protobuf_free (msg);
656 } /* }}} Msg *riemann_value_list_to_protobuf */
660 * Always call while holding host->lock !
662 static int riemann_batch_flush_nolock (cdtime_t timeout,
663 struct riemann_host *host)
670 if ((host->batch_init + timeout) > now)
673 riemann_send_msg(host, host->batch_msg);
674 riemann_msg_protobuf_free(host->batch_msg);
676 if (host->use_tcp && ((status = riemann_recv_ack(host)) != 0))
677 riemann_disconnect (host);
679 host->batch_init = cdtime();
680 host->batch_msg = NULL;
684 static int riemann_batch_flush (cdtime_t timeout,
685 const char *identifier __attribute__((unused)),
686 user_data_t *user_data)
688 struct riemann_host *host;
691 if (user_data == NULL)
694 host = user_data->data;
695 pthread_mutex_lock (&host->lock);
696 status = riemann_batch_flush_nolock (timeout, host);
698 ERROR ("write_riemann plugin: riemann_send failed with status %i",
701 pthread_mutex_unlock(&host->lock);
705 static int riemann_batch_add_value_list (struct riemann_host *host, /* {{{ */
706 data_set_t const *ds,
707 value_list_t const *vl,
716 msg = riemann_value_list_to_protobuf (host, ds, vl, statuses);
720 pthread_mutex_lock(&host->lock);
722 if (host->batch_msg == NULL) {
723 host->batch_msg = msg;
725 len = msg->n_events + host->batch_msg->n_events;
726 events = realloc(host->batch_msg->events,
727 (len * sizeof(*host->batch_msg->events)));
728 if (events == NULL) {
729 pthread_mutex_unlock(&host->lock);
730 ERROR ("write_riemann plugin: out of memory");
731 riemann_msg_protobuf_free (msg);
734 host->batch_msg->events = events;
736 for (i = host->batch_msg->n_events; i < len; i++)
737 host->batch_msg->events[i] = msg->events[i - host->batch_msg->n_events];
739 host->batch_msg->n_events = len;
745 len = msg__get_packed_size(host->batch_msg);
747 if ((host->batch_max < 0) || (((size_t) host->batch_max) <= len)) {
748 ret = riemann_batch_flush_nolock(0, host);
751 pthread_mutex_unlock(&host->lock);
753 } /* }}} Msg *riemann_batch_add_value_list */
755 static int riemann_notification(const notification_t *n, user_data_t *ud) /* {{{ */
758 struct riemann_host *host = ud->data;
761 if (!host->notifications)
765 * Never batch for notifications, send them ASAP
767 msg = riemann_notification_to_protobuf (host, n);
771 status = riemann_send (host, msg);
773 ERROR ("write_riemann plugin: riemann_send failed with status %i",
776 riemann_msg_protobuf_free (msg);
778 } /* }}} int riemann_notification */
780 static int riemann_write(const data_set_t *ds, /* {{{ */
781 const value_list_t *vl,
785 int statuses[vl->values_len];
786 struct riemann_host *host = ud->data;
788 if (host->check_thresholds) {
789 status = write_riemann_threshold_check(ds, vl, statuses);
793 memset (statuses, 0, sizeof (statuses));
796 if (host->use_tcp == 1 && host->batch_mode) {
797 riemann_batch_add_value_list (host, ds, vl, statuses);
799 Msg *msg = riemann_value_list_to_protobuf (host, ds, vl, statuses);
803 status = riemann_send (host, msg);
805 ERROR ("write_riemann plugin: riemann_send failed with status %i", status);
807 riemann_msg_protobuf_free (msg);
811 } /* }}} int riemann_write */
813 static void riemann_free(void *p) /* {{{ */
815 struct riemann_host *host = p;
820 pthread_mutex_lock (&host->lock);
822 host->reference_count--;
823 if (host->reference_count > 0)
825 pthread_mutex_unlock (&host->lock);
829 riemann_disconnect (host);
831 sfree(host->service);
832 pthread_mutex_destroy (&host->lock);
834 } /* }}} void riemann_free */
836 static int riemann_config_node(oconfig_item_t *ci) /* {{{ */
838 struct riemann_host *host = NULL;
841 oconfig_item_t *child;
842 char callback_name[DATA_MAX_NAME_LEN];
845 if ((host = calloc(1, sizeof (*host))) == NULL) {
846 ERROR ("write_riemann plugin: calloc failed.");
849 pthread_mutex_init (&host->lock, NULL);
850 host->reference_count = 1;
852 host->service = NULL;
853 host->notifications = 1;
854 host->check_thresholds = 0;
855 host->store_rates = 1;
856 host->always_append_ds = 0;
858 host->batch_mode = 1;
859 host->batch_max = RIEMANN_BATCH_MAX; /* typical MSS */
860 host->batch_init = cdtime();
861 host->ttl_factor = RIEMANN_TTL_FACTOR;
863 status = cf_util_get_string (ci, &host->name);
865 WARNING("write_riemann plugin: Required host name is missing.");
870 for (i = 0; i < ci->children_num; i++) {
872 * The code here could be simplified but makes room
873 * for easy adding of new options later on.
875 child = &ci->children[i];
878 if (strcasecmp ("Host", child->key) == 0) {
879 status = cf_util_get_string (child, &host->node);
882 } else if (strcasecmp ("Notifications", child->key) == 0) {
883 status = cf_util_get_boolean(child, &host->notifications);
886 } else if (strcasecmp ("EventServicePrefix", child->key) == 0) {
887 status = cf_util_get_string (child, &host->event_service_prefix);
890 } else if (strcasecmp ("CheckThresholds", child->key) == 0) {
891 status = cf_util_get_boolean(child, &host->check_thresholds);
894 } else if (strcasecmp ("Batch", child->key) == 0) {
895 status = cf_util_get_boolean(child, &host->batch_mode);
898 } else if (strcasecmp("BatchMaxSize", child->key) == 0) {
899 status = cf_util_get_int(child, &host->batch_max);
902 } else if (strcasecmp ("Port", child->key) == 0) {
903 status = cf_util_get_service (child, &host->service);
905 ERROR ("write_riemann plugin: Invalid argument "
906 "configured for the \"Port\" "
910 } else if (strcasecmp ("Protocol", child->key) == 0) {
912 status = cf_util_get_string_buffer (child,
916 ERROR ("write_riemann plugin: cf_util_get_"
917 "string_buffer failed with "
918 "status %i.", status);
922 if (strcasecmp ("UDP", tmp) == 0)
924 else if (strcasecmp ("TCP", tmp) == 0)
927 WARNING ("write_riemann plugin: The value "
928 "\"%s\" is not valid for the "
929 "\"Protocol\" option. Use "
930 "either \"UDP\" or \"TCP\".",
932 } else if (strcasecmp ("StoreRates", child->key) == 0) {
933 status = cf_util_get_boolean (child, &host->store_rates);
936 } else if (strcasecmp ("AlwaysAppendDS", child->key) == 0) {
937 status = cf_util_get_boolean (child,
938 &host->always_append_ds);
941 } else if (strcasecmp ("TTLFactor", child->key) == 0) {
943 status = cf_util_get_double (child, &tmp);
947 host->ttl_factor = tmp;
948 } else if (tmp >= 1.0) {
949 NOTICE ("write_riemann plugin: The configured "
950 "TTLFactor is very small "
951 "(%.1f). A value of 2.0 or "
952 "greater is recommended.",
954 host->ttl_factor = tmp;
955 } else if (tmp > 0.0) {
956 WARNING ("write_riemann plugin: The configured "
957 "TTLFactor is too small to be "
958 "useful (%.1f). I'll use it "
959 "since the user knows best, "
960 "but under protest.",
962 host->ttl_factor = tmp;
963 } else { /* zero, negative and NAN */
964 ERROR ("write_riemann plugin: The configured "
965 "TTLFactor is invalid (%.1f).",
969 WARNING("write_riemann plugin: ignoring unknown config "
970 "option: \"%s\"", child->key);
978 ssnprintf (callback_name, sizeof (callback_name), "write_riemann/%s",
981 ud.free_func = riemann_free;
983 pthread_mutex_lock (&host->lock);
985 status = plugin_register_write (callback_name, riemann_write, &ud);
987 if (host->use_tcp == 1 && host->batch_mode) {
989 plugin_register_flush(callback_name, riemann_batch_flush, &ud);
992 WARNING ("write_riemann plugin: plugin_register_write (\"%s\") "
993 "failed with status %i.",
994 callback_name, status);
996 host->reference_count++;
998 status = plugin_register_notification (callback_name,
999 riemann_notification, &ud);
1001 WARNING ("write_riemann plugin: plugin_register_notification (\"%s\") "
1002 "failed with status %i.",
1003 callback_name, status);
1005 host->reference_count++;
1007 if (host->reference_count <= 1)
1009 /* Both callbacks failed => free memory.
1010 * We need to unlock here, because riemann_free() will lock.
1011 * This is not a race condition, because we're the only one
1012 * holding a reference. */
1013 pthread_mutex_unlock (&host->lock);
1014 riemann_free (host);
1018 host->reference_count--;
1019 pthread_mutex_unlock (&host->lock);
1022 } /* }}} int riemann_config_node */
1024 static int riemann_config(oconfig_item_t *ci) /* {{{ */
1027 oconfig_item_t *child;
1030 for (i = 0; i < ci->children_num; i++) {
1031 child = &ci->children[i];
1033 if (strcasecmp("Node", child->key) == 0) {
1034 riemann_config_node (child);
1035 } else if (strcasecmp(child->key, "attribute") == 0) {
1039 if (child->values_num != 2) {
1040 WARNING("riemann attributes need both a key and a value.");
1043 if (child->values[0].type != OCONFIG_TYPE_STRING ||
1044 child->values[1].type != OCONFIG_TYPE_STRING) {
1045 WARNING("riemann attribute needs string arguments.");
1048 if ((key = strdup(child->values[0].value.string)) == NULL) {
1049 WARNING("cannot allocate memory for attribute key.");
1052 if ((val = strdup(child->values[1].value.string)) == NULL) {
1053 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 : */