summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 2cce6f0)
raw | patch | inline | side by side (parent: 2cce6f0)
author | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Thu, 31 May 2007 21:16:06 +0000 (23:16 +0200) | ||
committer | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Thu, 31 May 2007 21:16:06 +0000 (23:16 +0200) |
The new function `parse_values' in `common.c' can be used to parse
`time:value0:value1:...', as used by RRDTool, the unixsock plugin and, in the
very near future, the exec plugin.
`time:value0:value1:...', as used by RRDTool, the unixsock plugin and, in the
very near future, the exec plugin.
src/common.c | patch | blob | history | |
src/common.h | patch | blob | history | |
src/perl.c | patch | blob | history | |
src/unixsock.c | patch | blob | history |
diff --git a/src/common.c b/src/common.c
index 9a28cdbf7988d993a22be494f9c380e92413569f..1addb323673814a5d8375f3114efaa654fa652f5 100644 (file)
--- a/src/common.c
+++ b/src/common.c
return (-1);
return (0);
} /* int format_name */
+
+int parse_identifier (char *str, char **ret_host,
+ char **ret_plugin, char **ret_plugin_instance,
+ char **ret_type, char **ret_type_instance)
+{
+ char *hostname = NULL;
+ char *plugin = NULL;
+ char *plugin_instance = NULL;
+ char *type = NULL;
+ char *type_instance = NULL;
+
+ hostname = str;
+ if (hostname == NULL)
+ return (-1);
+
+ plugin = strchr (hostname, '/');
+ if (plugin == NULL)
+ return (-1);
+ *plugin = '\0'; plugin++;
+
+ type = strchr (plugin, '/');
+ if (type == NULL)
+ return (-1);
+ *type = '\0'; type++;
+
+ plugin_instance = strchr (plugin, '-');
+ if (plugin_instance != NULL)
+ {
+ *plugin_instance = '\0';
+ plugin_instance++;
+ }
+
+ type_instance = strchr (type, '-');
+ if (type_instance != NULL)
+ {
+ *type_instance = '\0';
+ type_instance++;
+ }
+
+ *ret_host = hostname;
+ *ret_plugin = plugin;
+ *ret_plugin_instance = plugin_instance;
+ *ret_type = type;
+ *ret_type_instance = type_instance;
+ return (0);
+} /* int parse_identifier */
+
+int parse_values (char *buffer, value_list_t *vl, const data_set_t *ds)
+{
+ int i;
+ char *dummy;
+ char *ptr;
+ char *saveptr;
+
+ i = -1;
+ dummy = buffer;
+ saveptr = NULL;
+ while ((ptr = strtok_r (dummy, ":", &saveptr)) != NULL)
+ {
+ dummy = NULL;
+
+ if (i >= vl->values_len)
+ break;
+
+ if (i == -1)
+ {
+ if (strcmp ("N", ptr) == 0)
+ vl->time = time (NULL);
+ else
+ vl->time = (time_t) atoi (ptr);
+ }
+ else
+ {
+ if (strcmp ("U", ptr) == 0)
+ vl->values[i].gauge = NAN;
+ else if (ds->ds[i].type == DS_TYPE_COUNTER)
+ vl->values[i].counter = atoll (ptr);
+ else if (ds->ds[i].type == DS_TYPE_GAUGE)
+ vl->values[i].gauge = atof (ptr);
+ }
+
+ i++;
+ } /* while (strtok_r) */
+
+ if ((ptr != NULL) || (i != vl->values_len))
+ return (-1);
+ return (0);
+} /* int parse_values */
diff --git a/src/common.h b/src/common.h
index 7808ac93e696684c1ae794fc25963667973636d3..b07db9d4b053682d276b60aa51f1b9e9b6fff90c 100644 (file)
--- a/src/common.h
+++ b/src/common.h
#define COMMON_H
#include "collectd.h"
+#include "plugin.h"
#define sfree(ptr) \
if((ptr) != NULL) { \
format_name (ret, ret_len, (vl)->host, (vl)->plugin, (vl)->plugin_instance, \
(ds)->type, (vl)->type_instance)
+int parse_identifier (char *str, char **ret_host,
+ char **ret_plugin, char **ret_plugin_instance,
+ char **ret_type, char **ret_type_instance);
+int parse_values (char *buffer, value_list_t *vl, const data_set_t *ds);
+
#endif /* COMMON_H */
diff --git a/src/perl.c b/src/perl.c
index bcf7bb17ed76add6ef8f680cf2511b3fbf123535..1ad72487cc329c487eef65cc65837edee74bfc31 100644 (file)
--- a/src/perl.c
+++ b/src/perl.c
*/
#include "collectd.h"
-#include "common.h"
#include "configfile.h"
/* ... while we want the definition found in plugin.h. */
#include "plugin.h"
+#include "common.h"
#define PLUGIN_INIT 0
#define PLUGIN_READ 1
diff --git a/src/unixsock.c b/src/unixsock.c
index 97936592394b34a397a14922d9aed2a1a7a8faa7..215abdd01ec1daeaf8819781bbdd79cac5cc4af9 100644 (file)
--- a/src/unixsock.c
+++ b/src/unixsock.c
/*
* Functions
*/
-static int parse_identifier (char *str, char **ret_host,
- char **ret_plugin, char **ret_plugin_instance,
- char **ret_type, char **ret_type_instance)
-{
- char *hostname = NULL;
- char *plugin = NULL;
- char *plugin_instance = NULL;
- char *type = NULL;
- char *type_instance = NULL;
-
- hostname = str;
- if (hostname == NULL)
- return (-1);
-
- plugin = strchr (hostname, '/');
- if (plugin == NULL)
- return (-1);
- *plugin = '\0'; plugin++;
-
- type = strchr (plugin, '/');
- if (type == NULL)
- return (-1);
- *type = '\0'; type++;
-
- plugin_instance = strchr (plugin, '-');
- if (plugin_instance != NULL)
- {
- *plugin_instance = '\0';
- plugin_instance++;
- }
-
- type_instance = strchr (type, '-');
- if (type_instance != NULL)
- {
- *type_instance = '\0';
- type_instance++;
- }
-
- *ret_host = hostname;
- *ret_plugin = plugin;
- *ret_plugin_instance = plugin_instance;
- *ret_type = type;
- *ret_type_instance = type_instance;
- return (0);
-} /* int parse_identifier */
-
static value_cache_t *cache_search (const char *name)
{
value_cache_t *vc;
return (-1);
}
- if ((strlen (hostname) > sizeof (vl.host))
- || (strlen (plugin) > sizeof (vl.plugin))
+ if ((strlen (hostname) >= sizeof (vl.host))
+ || (strlen (plugin) >= sizeof (vl.plugin))
|| ((plugin_instance != NULL)
- && (strlen (plugin_instance) > sizeof (vl.plugin_instance)))
+ && (strlen (plugin_instance) >= sizeof (vl.plugin_instance)))
|| ((type_instance != NULL)
- && (strlen (type_instance) > sizeof (vl.type_instance))))
+ && (strlen (type_instance) >= sizeof (vl.type_instance))))
{
fprintf (fh, "-1 Identifier too long.");
return (-1);