summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 0e08ac6)
raw | patch | inline | side by side (parent: 0e08ac6)
author | Florian Forster <octo@noris.net> | |
Tue, 18 Jan 2011 15:49:40 +0000 (16:49 +0100) | ||
committer | Florian Forster <octo@noris.net> | |
Tue, 18 Jan 2011 15:49:40 +0000 (16:49 +0100) |
src/data_provider.c | patch | blob | history | |
src/graph_ident.c | patch | blob | history |
diff --git a/src/data_provider.c b/src/data_provider.c
index 02364431e3fd05bf567471cf4779afe16e5a5c50..73630f208cce6ff470939a3b9d33a07efabdace9 100644 (file)
--- a/src/data_provider.c
+++ b/src/data_provider.c
/**
* collection4 - data_provider.c
* Copyright (C) 2010 Florian octo Forster
/**
* collection4 - data_provider.c
* Copyright (C) 2010 Florian octo Forster
+ * Copyright (C) 2011 noris network AG
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
**/
#include <stdlib.h>
**/
#include <stdlib.h>
+#include <string.h>
#include <errno.h>
#include <errno.h>
+#include <assert.h>
#include "data_provider.h"
#include "dp_rrdtool.h"
#include "data_provider.h"
#include "dp_rrdtool.h"
+#include "graph_ident.h"
#include <fcgiapp.h>
#include <fcgi_stdio.h>
#include <fcgiapp.h>
#include <fcgi_stdio.h>
+#include <collectd/client.h>
+
/* TODO: Turn this into an array for multiple data providers. */
static data_provider_t *data_provider = NULL;
/* TODO: Turn this into an array for multiple data providers. */
static data_provider_t *data_provider = NULL;
+static lcc_connection_t *collectd_connection = NULL;
+
+static int data_provider_ident_flush (const graph_ident_t *ident) /* {{{ */
+{
+ char *ident_str;
+ lcc_identifier_t ident_lcc;
+ int status;
+
+ if (ident == NULL)
+ return (EINVAL);
+
+ ident_str = ident_to_string (ident);
+ if (ident_str == NULL)
+ return (ENOMEM);
+
+ if (collectd_connection == NULL)
+ {
+ /* TODO: Make socket path configurable */
+ status = lcc_connect (/* path = */ "/var/run/collectd-unixsock",
+ &collectd_connection);
+ if (status != 0)
+ {
+ assert (collectd_connection == NULL);
+ fprintf (stderr, "data_provider_ident_flush: lcc_connect failed "
+ "with status %i.\n", status);
+ return (status);
+ }
+ assert (collectd_connection != NULL);
+ }
+
+ memset (&ident_lcc, 0, sizeof (ident_lcc));
+ status = lcc_string_to_identifier (collectd_connection,
+ &ident_lcc, ident_str);
+ if (status != 0)
+ {
+ fprintf (stderr, "data_provider_ident_flush: lcc_string_to_identifier "
+ "failed: %s (%i)\n",
+ lcc_strerror (collectd_connection), status);
+ free (ident_str);
+ return (status);
+ }
+
+ status = lcc_flush (collectd_connection,
+ /* write-plugin = */ NULL,
+ /* identifier = */ &ident_lcc,
+ /* timeout = */ -1);
+ if (status != 0)
+ {
+ fprintf (stderr, "data_provider_ident_flush: lcc_flush (\"%s\") failed: %s (%i)\n",
+ ident_str, lcc_strerror (collectd_connection), status);
+ free (ident_str);
+
+ lcc_disconnect (collectd_connection);
+ collectd_connection = NULL;
+
+ return (status);
+ }
+
+ /* fprintf (stderr, "data_provider_ident_flush: lcc_flush (\"%s\") succeeded.\n", ident_str); */
+ free (ident_str);
+ return (0);
+} /* }}} int data_provider_ident_flush */
+
int data_provider_config (const oconfig_item_t *ci) /* {{{ */
{
/* FIXME: Actually determine which data provider to call. */
int data_provider_config (const oconfig_item_t *ci) /* {{{ */
{
/* FIXME: Actually determine which data provider to call. */
if (data_provider == NULL)
return (EINVAL);
if (data_provider == NULL)
return (EINVAL);
+ data_provider_ident_flush (ident);
+
return (data_provider->get_ident_data (data_provider->private_data,
ident, ds_name, begin, end, callback, user_data));
} /* }}} int data_provider_get_ident_data */
return (data_provider->get_ident_data (data_provider->private_data,
ident, ds_name, begin, end, callback, user_data));
} /* }}} int data_provider_get_ident_data */
diff --git a/src/graph_ident.c b/src/graph_ident.c
index abf396de3ba4417518cb52a49a53a534433f5039..5c513ec03ca678bce5ff4520fcd4cee34bf70b43 100644 (file)
--- a/src/graph_ident.c
+++ b/src/graph_ident.c
{
char buffer[PATH_MAX];
{
char buffer[PATH_MAX];
+ if (ident == NULL)
+ return (NULL);
+
buffer[0] = 0;
strlcat (buffer, ident->host, sizeof (buffer));
buffer[0] = 0;
strlcat (buffer, ident->host, sizeof (buffer));