-static riemann_message_t *wrr_notification_to_message(struct riemann_host *host, /* {{{ */
- notification_t const *n)
-{
- riemann_message_t *msg;
- riemann_event_t *event;
- char service_buffer[6 * DATA_MAX_NAME_LEN];
- char const *severity;
- notification_meta_t *meta;
- size_t i;
-
- switch (n->severity)
- {
- case NOTIF_OKAY: severity = "ok"; break;
- case NOTIF_WARNING: severity = "warning"; break;
- case NOTIF_FAILURE: severity = "critical"; break;
- default: severity = "unknown";
- }
-
- format_name(service_buffer, sizeof(service_buffer),
- /* host = */ "", n->plugin, n->plugin_instance,
- n->type, n->type_instance);
-
- event = riemann_event_create(RIEMANN_EVENT_FIELD_HOST, n->host,
- RIEMANN_EVENT_FIELD_TIME, (int64_t) CDTIME_T_TO_TIME_T(n->time),
- RIEMANN_EVENT_FIELD_TAGS, "notification", NULL,
- RIEMANN_EVENT_FIELD_STATE, severity,
- RIEMANN_EVENT_FIELD_SERVICE, &service_buffer[1],
- RIEMANN_EVENT_FIELD_NONE);
-
- if (n->host[0] != 0)
- riemann_event_string_attribute_add(event, "host", n->host);
- if (n->plugin[0] != 0)
- riemann_event_string_attribute_add(event, "plugin", n->plugin);
- if (n->plugin_instance[0] != 0)
- riemann_event_string_attribute_add(event, "plugin_instance", n->plugin_instance);
-
- if (n->type[0] != 0)
- riemann_event_string_attribute_add(event, "type", n->type);
- if (n->type_instance[0] != 0)
- riemann_event_string_attribute_add(event, "type_instance", n->type_instance);
-
- for (i = 0; i < riemann_attrs_num; i += 2)
- riemann_event_string_attribute_add(event, riemann_attrs[i], riemann_attrs[i+1]);
-
- for (i = 0; i < riemann_tags_num; i++)
- riemann_event_tag_add(event, riemann_tags[i]);
-
- if (n->message[0] != 0)
- riemann_event_string_attribute_add(event, "description", n->message);
-
- /* Pull in values from threshold and add extra attributes */
- for (meta = n->meta; meta != NULL; meta = meta->next)
- {
- if (strcasecmp("CurrentValue", meta->name) == 0 && meta->type == NM_TYPE_DOUBLE)
- {
- riemann_event_set(event,
- RIEMANN_EVENT_FIELD_METRIC_D,
- (double) meta->nm_value.nm_double,
- RIEMANN_EVENT_FIELD_NONE);
- continue;
- }
-
- if (meta->type == NM_TYPE_STRING) {
- riemann_event_string_attribute_add(event, meta->name, meta->nm_value.nm_string);
- continue;
- }
- }
-
- msg = riemann_message_create_with_events(event, NULL);
- if (msg == NULL)
- {
- ERROR("write_riemann plugin: riemann_message_create_with_events() failed.");
- riemann_event_free (event);
- return (NULL);
- }
-
- DEBUG("write_riemann plugin: Successfully created message for notification: "
- "host = \"%s\", service = \"%s\", state = \"%s\"",
- event->host, event->service, event->state);
- return (msg);
-} /* }}} riemann_message_t *wrr_notification_to_message */
-
-static riemann_event_t *wrr_value_to_event(struct riemann_host const *host, /* {{{ */
- data_set_t const *ds,
- value_list_t const *vl, size_t index,
- gauge_t const *rates,
- int status)
-{
- riemann_event_t *event;
- char name_buffer[5 * DATA_MAX_NAME_LEN];
- char service_buffer[6 * DATA_MAX_NAME_LEN];
- size_t i;
-
- event = riemann_event_new();
- if (event == NULL)
- {
- ERROR("write_riemann plugin: riemann_event_new() failed.");
- return (NULL);
- }
-
- format_name(name_buffer, sizeof(name_buffer),
- /* host = */ "", vl->plugin, vl->plugin_instance,
- vl->type, vl->type_instance);
- if (host->always_append_ds || (ds->ds_num > 1))
- {
- if (host->event_service_prefix == NULL)
- ssnprintf(service_buffer, sizeof(service_buffer), "%s/%s",
- &name_buffer[1], ds->ds[index].name);
- else
- ssnprintf(service_buffer, sizeof(service_buffer), "%s%s/%s",
- host->event_service_prefix, &name_buffer[1], ds->ds[index].name);
- }
- else
- {
- if (host->event_service_prefix == NULL)
- sstrncpy(service_buffer, &name_buffer[1], sizeof(service_buffer));
- else
- ssnprintf(service_buffer, sizeof(service_buffer), "%s%s",
- host->event_service_prefix, &name_buffer[1]);
- }
-
- riemann_event_set(event,
- RIEMANN_EVENT_FIELD_HOST, vl->host,
- RIEMANN_EVENT_FIELD_TIME, (int64_t) CDTIME_T_TO_TIME_T(vl->time),
- RIEMANN_EVENT_FIELD_TTL, (float) CDTIME_T_TO_DOUBLE(vl->interval) * host->ttl_factor,
- RIEMANN_EVENT_FIELD_STRING_ATTRIBUTES,
- "plugin", vl->plugin,
- "type", vl->type,
- "ds_name", ds->ds[index].name,
- NULL,
- RIEMANN_EVENT_FIELD_SERVICE, service_buffer,
- RIEMANN_EVENT_FIELD_NONE);
-
- if (host->check_thresholds) {
- const char *state = NULL;
-
- switch (status) {
- case STATE_OKAY:
- state = "ok";
- break;
- case STATE_ERROR:
- state = "critical";
- break;
- case STATE_WARNING:
- state = "warning";
- break;
- case STATE_MISSING:
- state = "unknown";
- break;
- }
- if (state)
- riemann_event_set(event, RIEMANN_EVENT_FIELD_STATE, state,
- RIEMANN_EVENT_FIELD_NONE);
- }
-
- if (vl->plugin_instance[0] != 0)
- riemann_event_string_attribute_add(event, "plugin_instance", vl->plugin_instance);
- if (vl->type_instance[0] != 0)
- riemann_event_string_attribute_add(event, "type_instance", vl->type_instance);
-
- if ((ds->ds[index].type != DS_TYPE_GAUGE) && (rates != NULL))
- {
- char ds_type[DATA_MAX_NAME_LEN];
-
- ssnprintf(ds_type, sizeof(ds_type), "%s:rate",
- DS_TYPE_TO_STRING(ds->ds[index].type));
- riemann_event_string_attribute_add(event, "ds_type", ds_type);
- }
- else
- {
- riemann_event_string_attribute_add(event, "ds_type",
+static int wrr_send(struct riemann_host *host, riemann_message_t *msg) {
+ int status = 0;
+
+ pthread_mutex_lock(&host->lock);
+ status = wrr_send_nolock(host, msg);
+ pthread_mutex_unlock(&host->lock);
+ return status;
+}
+
+static riemann_message_t *wrr_notification_to_message(notification_t const *n) {
+ riemann_message_t *msg;
+ riemann_event_t *event;
+ char service_buffer[6 * DATA_MAX_NAME_LEN];
+ char const *severity;
+
+ switch (n->severity) {
+ case NOTIF_OKAY:
+ severity = "ok";
+ break;
+ case NOTIF_WARNING:
+ severity = "warning";
+ break;
+ case NOTIF_FAILURE:
+ severity = "critical";
+ break;
+ default:
+ severity = "unknown";
+ }
+
+ format_name(service_buffer, sizeof(service_buffer),
+ /* host = */ "", n->plugin, n->plugin_instance, n->type,
+ n->type_instance);
+
+ event = riemann_event_create(
+ RIEMANN_EVENT_FIELD_HOST, n->host, RIEMANN_EVENT_FIELD_TIME,
+ (int64_t)CDTIME_T_TO_TIME_T(n->time), RIEMANN_EVENT_FIELD_TAGS,
+ "notification", NULL, RIEMANN_EVENT_FIELD_STATE, severity,
+ RIEMANN_EVENT_FIELD_SERVICE, &service_buffer[1],
+ RIEMANN_EVENT_FIELD_NONE);
+
+#if RCC_VERSION_NUMBER >= 0x010A00
+ riemann_event_set(event, RIEMANN_EVENT_FIELD_TIME_MICROS,
+ (int64_t)CDTIME_T_TO_US(n->time));
+#endif
+
+ if (n->host[0] != 0)
+ riemann_event_string_attribute_add(event, "host", n->host);
+ if (n->plugin[0] != 0)
+ riemann_event_string_attribute_add(event, "plugin", n->plugin);
+ if (n->plugin_instance[0] != 0)
+ riemann_event_string_attribute_add(event, "plugin_instance",
+ n->plugin_instance);
+
+ if (n->type[0] != 0)
+ riemann_event_string_attribute_add(event, "type", n->type);
+ if (n->type_instance[0] != 0)
+ riemann_event_string_attribute_add(event, "type_instance",
+ n->type_instance);
+
+ for (size_t i = 0; i < riemann_attrs_num; i += 2)
+ riemann_event_string_attribute_add(event, riemann_attrs[i],
+ riemann_attrs[i + 1]);
+
+ for (size_t i = 0; i < riemann_tags_num; i++)
+ riemann_event_tag_add(event, riemann_tags[i]);
+
+ if (n->message[0] != 0)
+ riemann_event_string_attribute_add(event, "description", n->message);
+
+ /* Pull in values from threshold and add extra attributes */
+ for (notification_meta_t *meta = n->meta; meta != NULL; meta = meta->next) {
+ if (strcasecmp("CurrentValue", meta->name) == 0 &&
+ meta->type == NM_TYPE_DOUBLE) {
+ riemann_event_set(event, RIEMANN_EVENT_FIELD_METRIC_D,
+ (double)meta->nm_value.nm_double,
+ RIEMANN_EVENT_FIELD_NONE);
+ continue;
+ }
+
+ if (meta->type == NM_TYPE_STRING) {
+ riemann_event_string_attribute_add(event, meta->name,
+ meta->nm_value.nm_string);
+ continue;
+ }
+ }
+
+ msg = riemann_message_create_with_events(event, NULL);
+ if (msg == NULL) {
+ ERROR("write_riemann plugin: riemann_message_create_with_events() failed.");
+ riemann_event_free(event);
+ return NULL;
+ }
+
+ DEBUG("write_riemann plugin: Successfully created message for notification: "
+ "host = \"%s\", service = \"%s\", state = \"%s\"",
+ event->host, event->service, event->state);
+ return msg;
+}
+
+static riemann_event_t *
+wrr_value_to_event(struct riemann_host const *host, /* {{{ */
+ data_set_t const *ds, value_list_t const *vl, size_t index,
+ gauge_t const *rates, int status) {
+ riemann_event_t *event;
+ char name_buffer[5 * DATA_MAX_NAME_LEN];
+ char service_buffer[6 * DATA_MAX_NAME_LEN];
+ size_t i;
+
+ event = riemann_event_new();
+ if (event == NULL) {
+ ERROR("write_riemann plugin: riemann_event_new() failed.");
+ return NULL;
+ }
+
+ format_name(name_buffer, sizeof(name_buffer),
+ /* host = */ "", vl->plugin, vl->plugin_instance, vl->type,
+ vl->type_instance);
+ if (host->always_append_ds || (ds->ds_num > 1)) {
+ if (host->event_service_prefix == NULL)
+ snprintf(service_buffer, sizeof(service_buffer), "%s/%s", &name_buffer[1],
+ ds->ds[index].name);
+ else
+ snprintf(service_buffer, sizeof(service_buffer), "%s%s/%s",
+ host->event_service_prefix, &name_buffer[1], ds->ds[index].name);
+ } else {
+ if (host->event_service_prefix == NULL)
+ sstrncpy(service_buffer, &name_buffer[1], sizeof(service_buffer));
+ else
+ snprintf(service_buffer, sizeof(service_buffer), "%s%s",
+ host->event_service_prefix, &name_buffer[1]);
+ }
+
+ riemann_event_set(
+ event, RIEMANN_EVENT_FIELD_HOST, vl->host, RIEMANN_EVENT_FIELD_TIME,
+ (int64_t)CDTIME_T_TO_TIME_T(vl->time), RIEMANN_EVENT_FIELD_TTL,
+ (float)CDTIME_T_TO_DOUBLE(vl->interval) * host->ttl_factor,
+ RIEMANN_EVENT_FIELD_STRING_ATTRIBUTES, "plugin", vl->plugin, "type",
+ vl->type, "ds_name", ds->ds[index].name, NULL,
+ RIEMANN_EVENT_FIELD_SERVICE, service_buffer, RIEMANN_EVENT_FIELD_NONE);
+
+#if RCC_VERSION_NUMBER >= 0x010A00
+ riemann_event_set(event, RIEMANN_EVENT_FIELD_TIME_MICROS,
+ (int64_t)CDTIME_T_TO_US(vl->time));
+#endif
+
+ if (host->check_thresholds) {
+ const char *state = NULL;
+
+ switch (status) {
+ case STATE_OKAY:
+ state = "ok";
+ break;
+ case STATE_ERROR:
+ state = "critical";
+ break;
+ case STATE_WARNING:
+ state = "warning";
+ break;
+ case STATE_MISSING:
+ state = "unknown";
+ break;
+ }
+ if (state)
+ riemann_event_set(event, RIEMANN_EVENT_FIELD_STATE, state,
+ RIEMANN_EVENT_FIELD_NONE);
+ }
+
+ if (vl->plugin_instance[0] != 0)
+ riemann_event_string_attribute_add(event, "plugin_instance",
+ vl->plugin_instance);
+ if (vl->type_instance[0] != 0)
+ riemann_event_string_attribute_add(event, "type_instance",
+ vl->type_instance);
+
+ if ((ds->ds[index].type != DS_TYPE_GAUGE) && (rates != NULL)) {
+ char ds_type[DATA_MAX_NAME_LEN];
+
+ snprintf(ds_type, sizeof(ds_type), "%s:rate",
+ DS_TYPE_TO_STRING(ds->ds[index].type));
+ riemann_event_string_attribute_add(event, "ds_type", ds_type);
+ } else {
+ riemann_event_string_attribute_add(event, "ds_type",