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 = calloc (1, buffer_len);
209 if (buffer == NULL) {
210 ERROR ("write_riemann plugin: calloc failed.");
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 = calloc (1, sizeof (*msg));
370 ERROR ("write_riemann plugin: calloc failed.");
375 msg->events = malloc (sizeof (*msg->events));
376 if (msg->events == NULL)
378 ERROR ("write_riemann plugin: malloc failed.");
383 event = calloc (1, sizeof (*event));
386 ERROR ("write_riemann plugin: calloc failed.");
393 msg->events[0] = event;
396 event->host = strdup (n->host);
397 event->time = CDTIME_T_TO_TIME_T (n->time);
402 case NOTIF_OKAY: severity = "ok"; break;
403 case NOTIF_WARNING: severity = "warning"; break;
404 case NOTIF_FAILURE: severity = "critical"; break;
405 default: severity = "unknown";
407 event->state = strdup (severity);
409 riemann_event_add_tag (event, "notification");
411 riemann_event_add_attribute (event, "host", n->host);
412 if (n->plugin[0] != 0)
413 riemann_event_add_attribute (event, "plugin", n->plugin);
414 if (n->plugin_instance[0] != 0)
415 riemann_event_add_attribute (event, "plugin_instance",
419 riemann_event_add_attribute (event, "type", n->type);
420 if (n->type_instance[0] != 0)
421 riemann_event_add_attribute (event, "type_instance",
424 for (i = 0; i < riemann_attrs_num; i += 2)
425 riemann_event_add_attribute(event,
427 riemann_attrs[i +1]);
429 for (i = 0; i < riemann_tags_num; i++)
430 riemann_event_add_tag (event, riemann_tags[i]);
432 format_name (service_buffer, sizeof (service_buffer),
433 /* host = */ "", n->plugin, n->plugin_instance,
434 n->type, n->type_instance);
435 event->service = strdup (&service_buffer[1]);
437 if (n->message[0] != 0)
438 riemann_event_add_attribute (event, "description", n->message);
440 /* Pull in values from threshold and add extra attributes */
441 for (meta = n->meta; meta != NULL; meta = meta->next)
443 if (strcasecmp ("CurrentValue", meta->name) == 0 && meta->type == NM_TYPE_DOUBLE)
445 event->metric_d = meta->nm_value.nm_double;
446 event->has_metric_d = 1;
450 if (meta->type == NM_TYPE_STRING) {
451 riemann_event_add_attribute (event, meta->name, meta->nm_value.nm_string);
456 DEBUG ("write_riemann plugin: Successfully created protobuf for notification: "
457 "host = \"%s\", service = \"%s\", state = \"%s\"",
458 event->host, event->service, event->state);
460 } /* }}} Msg *riemann_notification_to_protobuf */
462 static Event *riemann_value_to_protobuf(struct riemann_host const *host, /* {{{ */
463 data_set_t const *ds,
464 value_list_t const *vl, size_t index,
465 gauge_t const *rates,
469 char name_buffer[5 * DATA_MAX_NAME_LEN];
470 char service_buffer[6 * DATA_MAX_NAME_LEN];
474 event = calloc (1, sizeof (*event));
477 ERROR ("write_riemann plugin: calloc failed.");
482 event->host = strdup (vl->host);
483 event->time = CDTIME_T_TO_TIME_T (vl->time);
486 if (host->check_thresholds) {
489 event->state = strdup("ok");
492 event->state = strdup("critical");
495 event->state = strdup("warning");
498 event->state = strdup("unknown");
503 ttl = CDTIME_T_TO_DOUBLE (vl->interval) * host->ttl_factor;
504 event->ttl = (float) ttl;
507 riemann_event_add_attribute (event, "plugin", vl->plugin);
508 if (vl->plugin_instance[0] != 0)
509 riemann_event_add_attribute (event, "plugin_instance",
510 vl->plugin_instance);
512 riemann_event_add_attribute (event, "type", vl->type);
513 if (vl->type_instance[0] != 0)
514 riemann_event_add_attribute (event, "type_instance",
517 if ((ds->ds[index].type != DS_TYPE_GAUGE) && (rates != NULL))
519 char ds_type[DATA_MAX_NAME_LEN];
521 ssnprintf (ds_type, sizeof (ds_type), "%s:rate",
522 DS_TYPE_TO_STRING(ds->ds[index].type));
523 riemann_event_add_attribute (event, "ds_type", ds_type);
527 riemann_event_add_attribute (event, "ds_type",
528 DS_TYPE_TO_STRING(ds->ds[index].type));
530 riemann_event_add_attribute (event, "ds_name", ds->ds[index].name);
532 char ds_index[DATA_MAX_NAME_LEN];
534 ssnprintf (ds_index, sizeof (ds_index), "%zu", index);
535 riemann_event_add_attribute (event, "ds_index", ds_index);
538 for (i = 0; i < riemann_attrs_num; i += 2)
539 riemann_event_add_attribute(event,
541 riemann_attrs[i +1]);
543 for (i = 0; i < riemann_tags_num; i++)
544 riemann_event_add_tag (event, riemann_tags[i]);
546 if (ds->ds[index].type == DS_TYPE_GAUGE)
548 event->has_metric_d = 1;
549 event->metric_d = (double) vl->values[index].gauge;
551 else if (rates != NULL)
553 event->has_metric_d = 1;
554 event->metric_d = (double) rates[index];
558 event->has_metric_sint64 = 1;
559 if (ds->ds[index].type == DS_TYPE_DERIVE)
560 event->metric_sint64 = (int64_t) vl->values[index].derive;
561 else if (ds->ds[index].type == DS_TYPE_ABSOLUTE)
562 event->metric_sint64 = (int64_t) vl->values[index].absolute;
564 event->metric_sint64 = (int64_t) vl->values[index].counter;
567 format_name (name_buffer, sizeof (name_buffer),
568 /* host = */ "", vl->plugin, vl->plugin_instance,
569 vl->type, vl->type_instance);
570 if (host->always_append_ds || (ds->ds_num > 1))
572 if (host->event_service_prefix == NULL)
573 ssnprintf (service_buffer, sizeof (service_buffer), "%s/%s",
574 &name_buffer[1], ds->ds[index].name);
576 ssnprintf (service_buffer, sizeof (service_buffer), "%s%s/%s",
577 host->event_service_prefix, &name_buffer[1], ds->ds[index].name);
581 if (host->event_service_prefix == NULL)
582 sstrncpy (service_buffer, &name_buffer[1], sizeof (service_buffer));
584 ssnprintf (service_buffer, sizeof (service_buffer), "%s%s",
585 host->event_service_prefix, &name_buffer[1]);
588 event->service = strdup (service_buffer);
590 DEBUG ("write_riemann plugin: Successfully created protobuf for metric: "
591 "host = \"%s\", service = \"%s\"",
592 event->host, event->service);
594 } /* }}} Event *riemann_value_to_protobuf */
596 static Msg *riemann_value_list_to_protobuf (struct riemann_host const *host, /* {{{ */
597 data_set_t const *ds,
598 value_list_t const *vl,
603 gauge_t *rates = NULL;
605 /* Initialize the Msg structure. */
606 msg = calloc (1, sizeof (*msg));
609 ERROR ("write_riemann plugin: calloc failed.");
614 /* Set up events. First, the list of pointers. */
615 msg->n_events = vl->values_len;
616 msg->events = calloc (msg->n_events, sizeof (*msg->events));
617 if (msg->events == NULL)
619 ERROR ("write_riemann plugin: calloc failed.");
620 riemann_msg_protobuf_free (msg);
624 if (host->store_rates)
626 rates = uc_get_rate (ds, vl);
629 ERROR ("write_riemann plugin: uc_get_rate failed.");
630 riemann_msg_protobuf_free (msg);
635 for (i = 0; i < msg->n_events; i++)
637 msg->events[i] = riemann_value_to_protobuf (host, ds, vl,
638 (int) i, rates, statuses[i]);
639 if (msg->events[i] == NULL)
641 riemann_msg_protobuf_free (msg);
649 } /* }}} Msg *riemann_value_list_to_protobuf */
653 * Always call while holding host->lock !
655 static int riemann_batch_flush_nolock (cdtime_t timeout,
656 struct riemann_host *host)
663 if ((host->batch_init + timeout) > now)
666 riemann_send_msg(host, host->batch_msg);
667 riemann_msg_protobuf_free(host->batch_msg);
669 if (host->use_tcp && ((status = riemann_recv_ack(host)) != 0))
670 riemann_disconnect (host);
672 host->batch_init = cdtime();
673 host->batch_msg = NULL;
677 static int riemann_batch_flush (cdtime_t timeout,
678 const char *identifier __attribute__((unused)),
679 user_data_t *user_data)
681 struct riemann_host *host;
684 if (user_data == NULL)
687 host = user_data->data;
688 pthread_mutex_lock (&host->lock);
689 status = riemann_batch_flush_nolock (timeout, host);
691 ERROR ("write_riemann plugin: riemann_send failed with status %i",
694 pthread_mutex_unlock(&host->lock);
698 static int riemann_batch_add_value_list (struct riemann_host *host, /* {{{ */
699 data_set_t const *ds,
700 value_list_t const *vl,
709 msg = riemann_value_list_to_protobuf (host, ds, vl, statuses);
713 pthread_mutex_lock(&host->lock);
715 if (host->batch_msg == NULL) {
716 host->batch_msg = msg;
718 len = msg->n_events + host->batch_msg->n_events;
719 events = realloc(host->batch_msg->events,
720 (len * sizeof(*host->batch_msg->events)));
721 if (events == NULL) {
722 pthread_mutex_unlock(&host->lock);
723 ERROR ("write_riemann plugin: out of memory");
724 riemann_msg_protobuf_free (msg);
727 host->batch_msg->events = events;
729 for (i = host->batch_msg->n_events; i < len; i++)
730 host->batch_msg->events[i] = msg->events[i - host->batch_msg->n_events];
732 host->batch_msg->n_events = len;
738 len = msg__get_packed_size(host->batch_msg);
740 if ((host->batch_max < 0) || (((size_t) host->batch_max) <= len)) {
741 ret = riemann_batch_flush_nolock(0, host);
744 pthread_mutex_unlock(&host->lock);
746 } /* }}} Msg *riemann_batch_add_value_list */
748 static int riemann_notification(const notification_t *n, user_data_t *ud) /* {{{ */
751 struct riemann_host *host = ud->data;
754 if (!host->notifications)
758 * Never batch for notifications, send them ASAP
760 msg = riemann_notification_to_protobuf (host, n);
764 status = riemann_send (host, msg);
766 ERROR ("write_riemann plugin: riemann_send failed with status %i",
769 riemann_msg_protobuf_free (msg);
771 } /* }}} int riemann_notification */
773 static int riemann_write(const data_set_t *ds, /* {{{ */
774 const value_list_t *vl,
778 int statuses[vl->values_len];
779 struct riemann_host *host = ud->data;
781 if (host->check_thresholds) {
782 status = write_riemann_threshold_check(ds, vl, statuses);
786 memset (statuses, 0, sizeof (statuses));
789 if (host->use_tcp == 1 && host->batch_mode) {
790 riemann_batch_add_value_list (host, ds, vl, statuses);
792 Msg *msg = riemann_value_list_to_protobuf (host, ds, vl, statuses);
796 status = riemann_send (host, msg);
798 ERROR ("write_riemann plugin: riemann_send failed with status %i", status);
800 riemann_msg_protobuf_free (msg);
804 } /* }}} int riemann_write */
806 static void riemann_free(void *p) /* {{{ */
808 struct riemann_host *host = p;
813 pthread_mutex_lock (&host->lock);
815 host->reference_count--;
816 if (host->reference_count > 0)
818 pthread_mutex_unlock (&host->lock);
822 riemann_disconnect (host);
824 sfree(host->service);
825 pthread_mutex_destroy (&host->lock);
827 } /* }}} void riemann_free */
829 static int riemann_config_node(oconfig_item_t *ci) /* {{{ */
831 struct riemann_host *host = NULL;
834 oconfig_item_t *child;
835 char callback_name[DATA_MAX_NAME_LEN];
838 if ((host = calloc(1, sizeof (*host))) == NULL) {
839 ERROR ("write_riemann plugin: calloc failed.");
842 pthread_mutex_init (&host->lock, NULL);
843 host->reference_count = 1;
845 host->service = NULL;
846 host->notifications = 1;
847 host->check_thresholds = 0;
848 host->store_rates = 1;
849 host->always_append_ds = 0;
851 host->batch_mode = 1;
852 host->batch_max = RIEMANN_BATCH_MAX; /* typical MSS */
853 host->batch_init = cdtime();
854 host->ttl_factor = RIEMANN_TTL_FACTOR;
856 status = cf_util_get_string (ci, &host->name);
858 WARNING("write_riemann plugin: Required host name is missing.");
863 for (i = 0; i < ci->children_num; i++) {
865 * The code here could be simplified but makes room
866 * for easy adding of new options later on.
868 child = &ci->children[i];
871 if (strcasecmp ("Host", child->key) == 0) {
872 status = cf_util_get_string (child, &host->node);
875 } else if (strcasecmp ("Notifications", child->key) == 0) {
876 status = cf_util_get_boolean(child, &host->notifications);
879 } else if (strcasecmp ("EventServicePrefix", child->key) == 0) {
880 status = cf_util_get_string (child, &host->event_service_prefix);
883 } else if (strcasecmp ("CheckThresholds", child->key) == 0) {
884 status = cf_util_get_boolean(child, &host->check_thresholds);
887 } else if (strcasecmp ("Batch", child->key) == 0) {
888 status = cf_util_get_boolean(child, &host->batch_mode);
891 } else if (strcasecmp("BatchMaxSize", child->key) == 0) {
892 status = cf_util_get_int(child, &host->batch_max);
895 } else if (strcasecmp ("Port", child->key) == 0) {
896 status = cf_util_get_service (child, &host->service);
898 ERROR ("write_riemann plugin: Invalid argument "
899 "configured for the \"Port\" "
903 } else if (strcasecmp ("Protocol", child->key) == 0) {
905 status = cf_util_get_string_buffer (child,
909 ERROR ("write_riemann plugin: cf_util_get_"
910 "string_buffer failed with "
911 "status %i.", status);
915 if (strcasecmp ("UDP", tmp) == 0)
917 else if (strcasecmp ("TCP", tmp) == 0)
920 WARNING ("write_riemann plugin: The value "
921 "\"%s\" is not valid for the "
922 "\"Protocol\" option. Use "
923 "either \"UDP\" or \"TCP\".",
925 } else if (strcasecmp ("StoreRates", child->key) == 0) {
926 status = cf_util_get_boolean (child, &host->store_rates);
929 } else if (strcasecmp ("AlwaysAppendDS", child->key) == 0) {
930 status = cf_util_get_boolean (child,
931 &host->always_append_ds);
934 } else if (strcasecmp ("TTLFactor", child->key) == 0) {
936 status = cf_util_get_double (child, &tmp);
940 host->ttl_factor = tmp;
941 } else if (tmp >= 1.0) {
942 NOTICE ("write_riemann plugin: The configured "
943 "TTLFactor is very small "
944 "(%.1f). A value of 2.0 or "
945 "greater is recommended.",
947 host->ttl_factor = tmp;
948 } else if (tmp > 0.0) {
949 WARNING ("write_riemann plugin: The configured "
950 "TTLFactor is too small to be "
951 "useful (%.1f). I'll use it "
952 "since the user knows best, "
953 "but under protest.",
955 host->ttl_factor = tmp;
956 } else { /* zero, negative and NAN */
957 ERROR ("write_riemann plugin: The configured "
958 "TTLFactor is invalid (%.1f).",
962 WARNING("write_riemann plugin: ignoring unknown config "
963 "option: \"%s\"", child->key);
971 ssnprintf (callback_name, sizeof (callback_name), "write_riemann/%s",
974 ud.free_func = riemann_free;
976 pthread_mutex_lock (&host->lock);
978 status = plugin_register_write (callback_name, riemann_write, &ud);
980 if (host->use_tcp == 1 && host->batch_mode) {
982 plugin_register_flush(callback_name, riemann_batch_flush, &ud);
985 WARNING ("write_riemann plugin: plugin_register_write (\"%s\") "
986 "failed with status %i.",
987 callback_name, status);
989 host->reference_count++;
991 status = plugin_register_notification (callback_name,
992 riemann_notification, &ud);
994 WARNING ("write_riemann plugin: plugin_register_notification (\"%s\") "
995 "failed with status %i.",
996 callback_name, status);
998 host->reference_count++;
1000 if (host->reference_count <= 1)
1002 /* Both callbacks failed => free memory.
1003 * We need to unlock here, because riemann_free() will lock.
1004 * This is not a race condition, because we're the only one
1005 * holding a reference. */
1006 pthread_mutex_unlock (&host->lock);
1007 riemann_free (host);
1011 host->reference_count--;
1012 pthread_mutex_unlock (&host->lock);
1015 } /* }}} int riemann_config_node */
1017 static int riemann_config(oconfig_item_t *ci) /* {{{ */
1020 oconfig_item_t *child;
1023 for (i = 0; i < ci->children_num; i++) {
1024 child = &ci->children[i];
1026 if (strcasecmp("Node", child->key) == 0) {
1027 riemann_config_node (child);
1028 } else if (strcasecmp(child->key, "attribute") == 0) {
1032 if (child->values_num != 2) {
1033 WARNING("riemann attributes need both a key and a value.");
1036 if (child->values[0].type != OCONFIG_TYPE_STRING ||
1037 child->values[1].type != OCONFIG_TYPE_STRING) {
1038 WARNING("riemann attribute needs string arguments.");
1041 if ((key = strdup(child->values[0].value.string)) == NULL) {
1042 WARNING("cannot allocate memory for attribute key.");
1045 if ((val = strdup(child->values[1].value.string)) == NULL) {
1046 WARNING("cannot allocate memory for attribute value.");
1050 strarray_add(&riemann_attrs, &riemann_attrs_num, key);
1051 strarray_add(&riemann_attrs, &riemann_attrs_num, val);
1052 DEBUG("write_riemann: got attr: %s => %s", key, val);
1055 } else if (strcasecmp(child->key, "tag") == 0) {
1057 status = cf_util_get_string(child, &tmp);
1061 strarray_add (&riemann_tags, &riemann_tags_num, tmp);
1062 DEBUG("write_riemann plugin: Got tag: %s", tmp);
1065 WARNING ("write_riemann plugin: Ignoring unknown "
1066 "configuration option \"%s\" at top level.",
1071 } /* }}} int riemann_config */
1073 void module_register(void)
1075 plugin_register_complex_config ("write_riemann", riemann_config);
1078 /* vim: set sw=8 sts=8 ts=8 noet : */