2 * collection4 - data_provider.c
3 * Copyright (C) 2010 Florian octo Forster
4 * Copyright (C) 2011 noris network AG
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301 USA
22 * Florian octo Forster <ff at octo.it>
30 #include "data_provider.h"
31 #include "dp_rrdtool.h"
32 #include "graph_ident.h"
35 #include <fcgi_stdio.h>
37 #include <collectd/client.h>
39 /* TODO: Turn this into an array for multiple data providers. */
40 static data_provider_t *data_provider = NULL;
42 static lcc_connection_t *collectd_connection = NULL;
44 static int data_provider_ident_flush (const graph_ident_t *ident) /* {{{ */
47 lcc_identifier_t ident_lcc;
53 ident_str = ident_to_string (ident);
54 if (ident_str == NULL)
57 if (collectd_connection == NULL)
59 /* TODO: Make socket path configurable */
60 status = lcc_connect (/* path = */ "/var/run/collectd-unixsock",
61 &collectd_connection);
64 assert (collectd_connection == NULL);
65 fprintf (stderr, "data_provider_ident_flush: lcc_connect failed "
66 "with status %i.\n", status);
69 assert (collectd_connection != NULL);
72 memset (&ident_lcc, 0, sizeof (ident_lcc));
73 status = lcc_string_to_identifier (collectd_connection,
74 &ident_lcc, ident_str);
77 fprintf (stderr, "data_provider_ident_flush: lcc_string_to_identifier "
79 lcc_strerror (collectd_connection), status);
84 status = lcc_flush (collectd_connection,
85 /* write-plugin = */ NULL,
86 /* identifier = */ &ident_lcc,
90 fprintf (stderr, "data_provider_ident_flush: lcc_flush (\"%s\") failed: %s (%i)\n",
91 ident_str, lcc_strerror (collectd_connection), status);
94 lcc_disconnect (collectd_connection);
95 collectd_connection = NULL;
100 /* fprintf (stderr, "data_provider_ident_flush: lcc_flush (\"%s\") succeeded.\n", ident_str); */
103 } /* }}} int data_provider_ident_flush */
105 int data_provider_config (const oconfig_item_t *ci) /* {{{ */
107 /* FIXME: Actually determine which data provider to call. */
108 return (dp_rrdtool_config (ci));
109 } /* }}} int data_provider_config */
111 int data_provider_register (const char *name, data_provider_t *p) /* {{{ */
113 fprintf (stderr, "data_provider_register (name = %s, ptr = %p)\n",
116 if (data_provider == NULL)
117 data_provider = malloc (sizeof (*data_provider));
118 if (data_provider == NULL)
124 } /* }}} int data_provider_register */
126 int data_provider_get_idents (dp_get_idents_callback callback, /* {{{ */
131 if (data_provider == NULL)
134 /* TODO: Iterate over all data providers */
135 status = data_provider->get_idents (data_provider->private_data,
136 callback, user_data);
139 } /* }}} int data_provider_get_idents */
141 int data_provider_get_ident_ds_names (graph_ident_t *ident, /* {{{ */
142 dp_list_get_ident_ds_names_callback callback, void *user_data)
144 if (data_provider == NULL)
147 return (data_provider->get_ident_ds_names (data_provider->private_data,
148 ident, callback, user_data));
149 } /* }}} int data_provider_get_ident_ds_names */
151 int data_provider_get_ident_data (graph_ident_t *ident, /* {{{ */
153 dp_time_t begin, dp_time_t end,
154 dp_get_ident_data_callback callback, void *user_data)
156 if (data_provider == NULL)
159 data_provider_ident_flush (ident);
161 return (data_provider->get_ident_data (data_provider->private_data,
162 ident, ds_name, begin, end, callback, user_data));
163 } /* }}} int data_provider_get_ident_data */
165 /* vim: set sw=2 sts=2 et fdm=marker : */