summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 55e53e1)
raw | patch | inline | side by side (parent: 55e53e1)
author | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Sun, 1 Feb 2009 14:46:27 +0000 (15:46 +0100) | ||
committer | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Sun, 1 Feb 2009 14:46:27 +0000 (15:46 +0100) |
Probably not that useful, but the output written to STDOUT by the csv
plugin is not in the form accepted by the exec plugin. This makes some
potentially interesting hacks possible ;)
plugin is not in the form accepted by the exec plugin. This makes some
potentially interesting hacks possible ;)
src/Makefile.am | patch | blob | history | |
src/csv.c | patch | blob | history | |
src/utils_parse_option.c | patch | blob | history | |
src/utils_parse_option.h | patch | blob | history |
diff --git a/src/Makefile.am b/src/Makefile.am
index cd36deba76b91cae9e5b2d4ce1e6fe77dd81e721..500b389566d72fe33d599c02002abd9e4207de96 100644 (file)
--- a/src/Makefile.am
+++ b/src/Makefile.am
utils_complain.c utils_complain.h \
utils_ignorelist.c utils_ignorelist.h \
utils_llist.c utils_llist.h \
+ utils_parse_option.c utils_parse_option.h \
utils_tail_match.c utils_tail_match.h \
utils_match.c utils_match.h \
utils_mount.c utils_mount.h \
if BUILD_PLUGIN_EXEC
pkglib_LTLIBRARIES += exec.la
exec_la_SOURCES = exec.c \
- utils_parse_option.h utils_parse_option.c \
utils_cmd_putnotif.c utils_cmd_putnotif.h \
utils_cmd_putval.c utils_cmd_putval.h
exec_la_LDFLAGS = -module -avoid-version
if BUILD_PLUGIN_UNIXSOCK
pkglib_LTLIBRARIES += unixsock.la
unixsock_la_SOURCES = unixsock.c \
- utils_parse_option.h utils_parse_option.c \
utils_cmd_flush.h utils_cmd_flush.c \
utils_cmd_getval.h utils_cmd_getval.c \
utils_cmd_listval.h utils_cmd_listval.c \
diff --git a/src/csv.c b/src/csv.c
index b5333b436faa1ceb236d1b114e6905875b9316b2..352557a8046de0021681d3f6cf0b578f11a23f36 100644 (file)
--- a/src/csv.c
+++ b/src/csv.c
/**
* collectd - src/csv.c
- * Copyright (C) 2007 Florian octo Forster
+ * Copyright (C) 2007-2009 Florian octo Forster
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
#include "plugin.h"
#include "common.h"
#include "utils_cache.h"
+#include "utils_parse_option.h"
/*
* Private variables
if (use_stdio)
{
+ size_t i;
+
+ escape_string (filename, sizeof (filename));
+
+ /* Replace commas by colons for PUTVAL compatible output. */
+ for (i = 0; i < sizeof (values); i++)
+ {
+ if (values[i] == 0)
+ break;
+ else if (values[i] == ',')
+ values[i] = ':';
+ }
+
fprintf (use_stdio == 1 ? stdout : stderr,
- "%s=%s\n", filename, values);
+ "PUTVAL %s interval=%i %s\n",
+ filename, interval_g, values);
return (0);
}
index d94c1400919c5b4ce0ce8c2956cd91ce4c219c71..2168cd1af3d624801146905b853adb0c92db3d7b 100644 (file)
--- a/src/utils_parse_option.c
+++ b/src/utils_parse_option.c
return (0);
} /* int parse_option */
+int escape_string (char *buffer, size_t buffer_size)
+{
+ char *temp;
+ size_t i;
+ size_t j;
+
+ /* Check if we need to escape at all first */
+ temp = strpbrk (buffer, " \t\"\\");
+ if (temp == NULL)
+ return (0);
+
+ temp = (char *) malloc (buffer_size);
+ if (temp == NULL)
+ return (-1);
+ memset (temp, 0, buffer_size);
+
+ temp[0] = '"';
+ j = 1;
+
+ for (i = 0; i < buffer_size; i++)
+ {
+ if (buffer[i] == 0)
+ {
+ break;
+ }
+ else if ((buffer[i] == '"') || (buffer[i] == '\\'))
+ {
+ if (j > (buffer_size - 4))
+ break;
+ temp[j] = '\\';
+ temp[j + 1] = buffer[i];
+ j += 2;
+ }
+ else
+ {
+ if (j > (buffer_size - 3))
+ break;
+ temp[j] = buffer[i];
+ j++;
+ }
+ }
+
+ assert ((j + 1) < buffer_size);
+ temp[j] = '"';
+ temp[j + 1] = 0;
+
+ sstrncpy (buffer, temp, buffer_size);
+ sfree (temp);
+ return (0);
+} /* int escape_string */
+
/* vim: set sw=2 ts=8 tw=78 et : */
index cb7f6d32112582e1fe1b069508b13d92e419847a..1dfb3ae949e82573b951ae43e1ac914d1fa453ac 100644 (file)
--- a/src/utils_parse_option.h
+++ b/src/utils_parse_option.h
int parse_string (char **ret_buffer, char **ret_string);
int parse_option (char **ret_buffer, char **ret_key, char **ret_value);
+int escape_string (char *buffer, size_t buffer_size);
+
#endif /* UTILS_PARSE_OPTION */
/* vim: set sw=2 ts=8 tw=78 et : */