summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: d1125cb)
raw | patch | inline | side by side (parent: d1125cb)
author | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Sat, 8 Nov 2008 16:55:28 +0000 (17:55 +0100) | ||
committer | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Sat, 8 Nov 2008 16:55:28 +0000 (17:55 +0100) |
src/libcollectdclient/client.c | patch | blob | history | |
src/libcollectdclient/client.h | patch | blob | history |
index deda6eb88f76f1c34d78f483b0a55d3772cf2ade..768554494ea96bb7c521b9e4c651e2dc5e7494d7 100644 (file)
#include "client.h"
#define SSTRCPY(d,s) do { \
- strncpy ((d), (s), sizeof (d)); \
- (d)[sizeof (d) - 1] = 0; \
-} while (0)
+ strncpy ((d), (s), sizeof (d)); \
+ (d)[sizeof (d) - 1] = 0; \
+ } while (0)
+
+#define SSTRCAT(d,s) do { \
+ strncat ((d), (s), sizeof (d)); \
+ (d)[sizeof (d) - 1] = 0; \
+ } while (0)
+
+#define SSTRCATF(d, ...) do { \
+ char _b[sizeof (d)]; \
+ snprintf (_b, sizeof (_b), __VA_ARGS__); \
+ _b[sizeof (_b) - 1] = 0; \
+ SSTRCAT ((d), _b); \
+ } while (0)
+
#define LCC_SET_ERRSTR(c, ...) do { \
snprintf ((c)->errbuf, sizeof ((c)->errbuf), __VA_ARGS__); \
if (res.status != 0)
{
LCC_SET_ERRSTR (c, "Server error: %s", res.message);
+ lcc_response_free (&res);
return (-1);
}
return (0);
} /* }}} int lcc_getval */
-/* TODO: Implement lcc_putval */
-int lcc_putval (lcc_connection_t *c, const lcc_value_list_t *vl);
+int lcc_putval (lcc_connection_t *c, const lcc_value_list_t *vl) /* {{{ */
+{
+ char ident_str[6 * LCC_NAME_LEN];
+ char ident_esc[12 * LCC_NAME_LEN];
+ char command[1024];
+ lcc_response_t res;
+ int status;
+ size_t i;
+
+ if ((c == NULL) || (vl == NULL) || (vl->values_len < 1)
+ || (vl->values == NULL) || (vl->values_types == NULL))
+ {
+ lcc_set_errno (c, EINVAL);
+ return (-1);
+ }
+
+ status = lcc_identifier_to_string (c, ident_str, sizeof (ident_str),
+ &vl->identifier);
+ if (status != 0)
+ return (status);
+
+ snprintf (command, sizeof (command), "PUTVAL %s",
+ lcc_strescape (ident_esc, ident_str, sizeof (ident_esc)));
+ command[sizeof (command) - 1] = 0;
+
+ if (vl->interval > 0)
+ {
+ char option[64];
+
+ snprintf (option, sizeof (option), " interval=%i", vl->interval);
+ option[sizeof (option) - 1] = 0;
+
+ SSTRCAT (command, option);
+ }
+
+ if (vl->time > 0)
+ SSTRCATF (command, "%u", (unsigned int) vl->time);
+ else
+ SSTRCAT (command, "N");
+
+ for (i = 0; i < vl->values_len; i++)
+ {
+ if (vl->values_types[i] == LCC_TYPE_COUNTER)
+ SSTRCATF (command, ":%"PRIu64, vl->values[i].counter);
+ else if (vl->values_types[i] == LCC_TYPE_GAUGE)
+ {
+ if (isnan (vl->values[i].gauge))
+ SSTRCPY (command, ":U");
+ else
+ SSTRCATF (command, ":%g", vl->values[i].gauge);
+ }
+ } /* for (i = 0; i < vl->values_len; i++) */
+
+ status = lcc_sendreceive (c, command, &res);
+ if (status != 0)
+ return (status);
+
+ if (res.status != 0)
+ {
+ LCC_SET_ERRSTR (c, "Server error: %s", res.message);
+ lcc_response_free (&res);
+ return (-1);
+ }
+
+ lcc_response_free (&res);
+ return (0);
+} /* }}} int lcc_putval */
/* TODO: Implement lcc_flush */
int lcc_flush (lcc_connection_t *c, lcc_identifier_t *ident, int timeout);
if (res.status != 0)
{
LCC_SET_ERRSTR (c, "Server error: %s", res.message);
+ lcc_response_free (&res);
return (-1);
}
index e4aa759df1a8c0131bdc8fd155b0b3dd554ecc65..c54e3b7a670adb7cfa69c34aa139018c2ee9c09d 100644 (file)
/*
* Types
*/
+#define LCC_TYPE_COUNTER 0
+#define LCC_TYPE_GAUGE 1
+
typedef uint64_t counter_t;
typedef double gauge_t;
struct lcc_value_list_s
{
value_t *values;
+ int *values_types;
size_t values_len;
time_t time;
int interval;