2 * collection4 - data_provider.h
3 * Copyright (C) 2010 Florian octo Forster
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301 USA
21 * Florian octo Forster <ff at octo.it>
24 #include "graph_types.h"
25 #include "graph_ident.h"
26 #include "graph_list.h"
27 #include "data_provider.h"
28 #include "filesystem.h"
41 typedef struct dp_rrdtool_s dp_rrdtool_t;
43 struct dp_get_idents_data_s
46 dp_get_idents_callback callback;
49 typedef struct dp_get_idents_data_s dp_get_idents_data_t;
51 static int scan_type_cb (__attribute__((unused)) const char *base_dir,
52 const char *sub_dir, void *ud)
54 dp_get_idents_data_t *data = ud;
59 sub_dir_len = strlen (sub_dir);
63 /* Ignore files that don't end in ".rrd". */
64 if (strcasecmp (".rrd", sub_dir + (sub_dir_len - 4)) != 0)
67 strncpy (type_copy, sub_dir, sizeof (type_copy));
68 type_copy[sub_dir_len - 4] = 0;
70 type_inst = strchr (type_copy, '-');
71 if (type_inst != NULL)
81 ident_set_type (data->ident, type_copy);
82 ident_set_type_instance (data->ident, type_inst);
84 return (data->callback (data->ident, data->user_data));
85 } /* }}} int scan_type_cb */
87 static int scan_plugin_cb (const char *base_dir,
88 const char *sub_dir, void *ud)
90 char plugin_copy[1024];
93 dp_get_idents_data_t *data = ud;
94 char abs_dir[PATH_MAX + 1];
96 strncpy (plugin_copy, sub_dir, sizeof (plugin_copy));
97 plugin_copy[sizeof (plugin_copy) - 1] = 0;
99 plugin_inst = strchr (plugin_copy, '-');
100 if (plugin_inst != NULL)
110 ident_set_plugin (data->ident, plugin_copy);
111 ident_set_plugin_instance (data->ident, plugin_inst);
113 snprintf (abs_dir, sizeof (abs_dir), "%s/%s", base_dir, sub_dir);
114 abs_dir[sizeof (abs_dir) - 1] = 0;
116 return (fs_foreach_file (abs_dir, scan_type_cb, data));
117 } /* }}} int scan_host_cb */
119 static int scan_host_cb (const char *base_dir,
120 const char *sub_dir, void *ud)
122 dp_get_idents_data_t *data = ud;
123 char abs_dir[PATH_MAX + 1];
125 ident_set_host (data->ident, sub_dir);
127 snprintf (abs_dir, sizeof (abs_dir), "%s/%s", base_dir, sub_dir);
128 abs_dir[sizeof (abs_dir) - 1] = 0;
130 return (fs_foreach_dir (abs_dir, scan_plugin_cb, data));
131 } /* }}} int scan_host_cb */
133 static int get_idents (void *priv,
134 dp_get_idents_callback cb, void *ud)
136 dp_rrdtool_t *config = priv;
137 dp_get_idents_data_t data;
140 data.ident = ident_create ("", "", "", "", "");
141 if (data.ident == NULL)
146 status = fs_foreach_dir (config->data_dir, scan_host_cb, &data);
148 ident_destroy (data.ident);
150 } /* }}} int get_idents */
152 static int get_ident_ds_names (void *priv, graph_ident_t *ident,
153 dp_list_get_ident_ds_names_callback cb, void *ud)
160 } /* }}} int get_ident_ds_names */
162 static int get_ident_data (void *priv,
163 graph_ident_t *ident, const char *ds_name,
164 dp_time_t begin, dp_time_t end,
165 dp_get_ident_data_callback cb, void *ud)
167 dp_rrdtool_t *config = priv;
179 } /* }}} int get_ident_data */
181 static int print_graph (void *priv,
182 graph_config_t *cfg, graph_instance_t *inst)
189 } /* }}} int print_graph */
191 int dp_rrdtool_config (oconfig_item_t *ci)
201 /* private_data = */ NULL
204 /* FIXME: Actuelly do config parsing here. */
205 ci = NULL; /* FIXME */
206 conf = malloc (sizeof (dp_rrdtool_t));
207 conf->data_dir = strdup ("/var/lib/collectd/rrd");
209 dp.private_data = conf;
211 gl_register_data_provider ("rrdtool", &dp);
214 } /* }}} int dp_rrdtool_config */
216 /* vim: set sw=2 sts=2 et fdm=marker : */