return (0);
} /* int cache_flush */
-static int cache_check (const char *type, const value_list_t *vl)
+static int cache_check (const value_list_t *vl)
{
char key[1024];
time_t *value = NULL;
return (-1);
if (format_name (key, sizeof (key), vl->host, vl->plugin,
- vl->plugin_instance, type, vl->type_instance))
+ vl->plugin_instance, vl->type, vl->type_instance))
return (-1);
pthread_mutex_lock (&cache_lock);
int status;
value_list_t vl = VALUE_LIST_INIT;
- char type[DATA_MAX_NAME_LEN];
notification_t n;
DEBUG ("network plugin: parse_packet: buffer = %p; buffer_len = %i;",
buffer, buffer_len);
memset (&vl, '\0', sizeof (vl));
- memset (&type, '\0', sizeof (type));
memset (&n, '\0', sizeof (n));
status = 0;
if ((vl.time > 0)
&& (strlen (vl.host) > 0)
&& (strlen (vl.plugin) > 0)
- && (strlen (type) > 0)
- && (cache_check (type, &vl) == 0))
+ && (strlen (vl.type) > 0)
+ && (cache_check (&vl) == 0))
{
- plugin_dispatch_values (type, &vl);
+ plugin_dispatch_values (&vl);
}
else
{
else if (pkg_type == TYPE_TIME)
{
uint64_t tmp = 0;
- status = parse_part_number (&buffer, &buffer_len, &tmp);
+ status = parse_part_number (&buffer, &buffer_len,
+ &tmp);
if (status == 0)
{
vl.time = (time_t) tmp;
else if (pkg_type == TYPE_INTERVAL)
{
uint64_t tmp = 0;
- status = parse_part_number (&buffer, &buffer_len, &tmp);
+ status = parse_part_number (&buffer, &buffer_len,
+ &tmp);
if (status == 0)
vl.interval = (int) tmp;
}
{
status = parse_part_string (&buffer, &buffer_len,
vl.host, sizeof (vl.host));
- strncpy (n.host, vl.host, sizeof (n.host));
- n.host[sizeof (n.host) - 1] = '\0';
+ if (status == 0)
+ sstrncpy (n.host, vl.host, sizeof (n.host));
}
else if (pkg_type == TYPE_PLUGIN)
{
status = parse_part_string (&buffer, &buffer_len,
vl.plugin, sizeof (vl.plugin));
- strncpy (n.plugin, vl.plugin, sizeof (n.plugin));
- n.plugin[sizeof (n.plugin) - 1] = '\0';
+ if (status == 0)
+ sstrncpy (n.plugin, vl.plugin,
+ sizeof (n.plugin));
}
else if (pkg_type == TYPE_PLUGIN_INSTANCE)
{
status = parse_part_string (&buffer, &buffer_len,
vl.plugin_instance,
sizeof (vl.plugin_instance));
- strncpy (n.plugin_instance, vl.plugin_instance,
- sizeof (n.plugin_instance));
- n.plugin_instance[sizeof (n.plugin_instance) - 1] = '\0';
+ if (status == 0)
+ sstrncpy (n.plugin_instance,
+ vl.plugin_instance,
+ sizeof (n.plugin_instance));
}
else if (pkg_type == TYPE_TYPE)
{
status = parse_part_string (&buffer, &buffer_len,
- type, sizeof (type));
- strncpy (n.type, type, sizeof (n.type));
- n.type[sizeof (n.type) - 1] = '\0';
+ vl.type, sizeof (vl.type));
+ if (status == 0)
+ sstrncpy (n.type, vl.type, sizeof (n.type));
}
else if (pkg_type == TYPE_TYPE_INSTANCE)
{
status = parse_part_string (&buffer, &buffer_len,
vl.type_instance,
sizeof (vl.type_instance));
- strncpy (n.type_instance, vl.type_instance,
- sizeof (n.type_instance));
- n.type_instance[sizeof (n.type_instance) - 1] = '\0';
+ if (status == 0)
+ sstrncpy (n.type_instance, vl.type_instance,
+ sizeof (n.type_instance));
}
else if (pkg_type == TYPE_MESSAGE)
{
status = parse_part_string (&buffer, &buffer_len,
n.message, sizeof (n.message));
- if ((n.severity != NOTIF_FAILURE)
+ if (status != 0)
+ {
+ /* do nothing */
+ }
+ else if ((n.severity != NOTIF_FAILURE)
&& (n.severity != NOTIF_WARNING)
&& (n.severity != NOTIF_OKAY))
{
}
else
{
- /*
- * TODO: Let this do a separate thread so that
- * no packets are lost if this takes too long.
- */
plugin_dispatch_notification (&n);
}
}
else if (pkg_type == TYPE_SEVERITY)
{
uint64_t tmp = 0;
- status = parse_part_number (&buffer, &buffer_len, &tmp);
+ status = parse_part_number (&buffer, &buffer_len,
+ &tmp);
if (status == 0)
n.severity = (int) tmp;
}
strcpy (vl_def->plugin_instance, vl->plugin_instance);
}
- if (strcmp (type_def, ds->type) != 0)
+ if (strcmp (type_def, vl->type) != 0)
{
if (write_part_string (&buffer, &buffer_size, TYPE_TYPE,
- ds->type, strlen (ds->type)) != 0)
+ vl->type, strlen (vl->type)) != 0)
return (-1);
- strcpy (type_def, ds->type);
+ strcpy (type_def, vl->type);
}
if (strcmp (vl_def->type_instance, vl->type_instance) != 0)
/* If the value is already in the cache, we have received it via the
* network. We write it again if forwarding is activated. It's then in
* the cache and should we receive it again we will ignore it. */
- status = cache_check (ds->type, vl);
+ status = cache_check (vl);
if ((network_config_forward == 0)
&& (status != 0))
return (0);
return (0);
} /* int network_init */
+/* TODO: Implement flushing of single items. */
+static int network_flush (int timeout, const char *itentifier)
+{
+ pthread_mutex_lock (&send_buffer_lock);
+
+ if (((time (NULL) - cache_flush_last) >= timeout)
+ && (send_buffer_fill > 0))
+ {
+ flush_buffer ();
+ }
+
+ pthread_mutex_unlock (&send_buffer_lock);
+
+ return (0);
+} /* int network_flush */
+
void module_register (void)
{
plugin_register_config ("network", network_config,
config_keys, config_keys_num);
plugin_register_init ("network", network_init);
+ plugin_register_flush ("network", network_flush);
} /* void module_register */