return (!received);
} /* }}} _Bool check_send_okay */
+static _Bool check_notify_received (const notification_t *n) /* {{{ */
+{
+ notification_meta_t *ptr;
+
+ for (ptr = n->meta; ptr != NULL; ptr = ptr->next)
+ if ((strcmp ("network:received", ptr->name) == 0)
+ && (ptr->type == NM_TYPE_BOOLEAN))
+ return ((_Bool) ptr->nm_value.nm_boolean);
+
+ return (0);
+} /* }}} _Bool check_notify_received */
+
+static _Bool check_send_notify_okay (const notification_t *n) /* {{{ */
+{
+ static c_complain_t complain_forwarding = C_COMPLAIN_INIT_STATIC;
+ _Bool received = 0;
+
+ if (n->meta == NULL)
+ return (1);
+
+ received = check_notify_received (n);
+
+ if (network_config_forward && received)
+ {
+ c_complain_once (LOG_ERR, &complain_forwarding,
+ "network plugin: A notification has been received via the network "
+ "forwarding if enabled. Forwarding of notifications is currently "
+ "not supported, because there is not loop-deteciton available. "
+ "Please contact the collectd mailing list if you need this "
+ "feature.");
+ }
+
+ /* By default, only *send* value lists that were not *received* by the
+ * network plugin. */
+ return (!received);
+} /* }}} _Bool check_send_notify_okay */
+
static int network_dispatch_values (value_list_t *vl, /* {{{ */
const char *username)
{
return (0);
} /* }}} int network_dispatch_values */
+static int network_dispatch_notification (notification_t *n) /* {{{ */
+{
+ int status;
+
+ assert (n->meta == NULL);
+
+ status = plugin_notification_meta_add_boolean (n, "network:received", 1);
+ if (status != 0)
+ {
+ ERROR ("network plugin: plugin_notification_meta_add_boolean failed.");
+ plugin_notification_meta_free (n->meta);
+ n->meta = NULL;
+ return (status);
+ }
+
+ status = plugin_dispatch_notification (n);
+
+ plugin_notification_meta_free (n->meta);
+ n->meta = NULL;
+
+ return (status);
+} /* }}} int network_dispatch_notification */
+
#if HAVE_LIBGCRYPT
static gcry_cipher_hd_t network_get_aes256_cypher (sockent_t *se, /* {{{ */
const void *iv, size_t iv_size, const char *username)
}
else
{
- plugin_dispatch_notification (&n);
+ network_dispatch_notification (&n);
}
}
else if (pkg_type == TYPE_SEVERITY)
} /* }}} int network_config */
static int network_notification (const notification_t *n,
- user_data_t __attribute__((unused)) *user_data)
+ user_data_t __attribute__((unused)) *user_data)
{
char buffer[network_config_packet_size];
char *buffer_ptr = buffer;
int buffer_free = sizeof (buffer);
int status;
- memset (buffer, '\0', sizeof (buffer));
+ if (!check_send_notify_okay (n))
+ return (0);
+ memset (buffer, 0, sizeof (buffer));
status = write_part_number (&buffer_ptr, &buffer_free, TYPE_TIME,
(uint64_t) n->time);
if (strlen (n->host) > 0)
{
status = write_part_string (&buffer_ptr, &buffer_free, TYPE_HOST,
- n->host, strlen (n->host));
+ n->host, strlen (n->host));
if (status != 0)
return (-1);
}
if (strlen (n->plugin) > 0)
{
status = write_part_string (&buffer_ptr, &buffer_free, TYPE_PLUGIN,
- n->plugin, strlen (n->plugin));
+ n->plugin, strlen (n->plugin));
if (status != 0)
return (-1);
}
if (strlen (n->plugin_instance) > 0)
{
status = write_part_string (&buffer_ptr, &buffer_free,
- TYPE_PLUGIN_INSTANCE,
- n->plugin_instance, strlen (n->plugin_instance));
+ TYPE_PLUGIN_INSTANCE,
+ n->plugin_instance, strlen (n->plugin_instance));
if (status != 0)
return (-1);
}
if (strlen (n->type) > 0)
{
status = write_part_string (&buffer_ptr, &buffer_free, TYPE_TYPE,
- n->type, strlen (n->type));
+ n->type, strlen (n->type));
if (status != 0)
return (-1);
}
if (strlen (n->type_instance) > 0)
{
status = write_part_string (&buffer_ptr, &buffer_free, TYPE_TYPE_INSTANCE,
- n->type_instance, strlen (n->type_instance));
+ n->type_instance, strlen (n->type_instance));
if (status != 0)
return (-1);
}