summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 12213f8)
raw | patch | inline | side by side (parent: 12213f8)
author | Florian Forster <octo@collectd.org> | |
Fri, 23 Mar 2012 21:21:43 +0000 (22:21 +0100) | ||
committer | Florian Forster <octo@collectd.org> | |
Fri, 23 Mar 2012 21:21:43 +0000 (22:21 +0100) |
The network plugin would send out all notifications it got through its
callback, even the ones it received itself and even when forwarding was
disabled.
With this patch the network plugin will only transmit notifications created
locally -- forwarding of notifications is not implemented due to missing
loop-detection. For loop-detection we would have to keep track of the last
timestamp of each notifications, and since each host/plugin/type/-instance
field may be empty, this is not as straight forward as with value lists. If
someone needs this, they will need to invest some work I'm afraid.
callback, even the ones it received itself and even when forwarding was
disabled.
With this patch the network plugin will only transmit notifications created
locally -- forwarding of notifications is not implemented due to missing
loop-detection. For loop-detection we would have to keep track of the last
timestamp of each notifications, and since each host/plugin/type/-instance
field may be empty, this is not as straight forward as with value lists. If
someone needs this, they will need to invest some work I'm afraid.
src/network.c | patch | blob | history |
diff --git a/src/network.c b/src/network.c
index f7f47c7ac4a6d2086f368463b1a13f11bcd60c1d..339a5011c29f177cc2151980196081f37c43f259 100644 (file)
--- a/src/network.c
+++ b/src/network.c
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);
}