6 #include "graph_config.h"
11 #include <fcgi_stdio.h>
18 graph_ident_t *select;
30 #define DEF_CONFIG_FIELD(field) \
31 static int def_config_##field (const oconfig_item_t *ci, graph_ident_t *ident) \
34 int status = graph_config_get_string (ci, &tmp); \
37 ident_set_##field (ident, tmp); \
40 } /* }}} int def_config_field */
42 DEF_CONFIG_FIELD (host);
43 DEF_CONFIG_FIELD (plugin);
44 DEF_CONFIG_FIELD (plugin_instance);
45 DEF_CONFIG_FIELD (type);
46 DEF_CONFIG_FIELD (type_instance);
48 #undef DEF_CONFIG_FIELD
53 graph_def_t *def_create (graph_config_t *cfg, graph_ident_t *ident, /* {{{ */
56 graph_ident_t *selector;
59 if ((cfg == NULL) || (ident == NULL) || (ds_name == NULL))
62 selector = gl_graph_get_selector (cfg);
66 ret = malloc (sizeof (*ret));
69 ident_destroy (selector);
72 memset (ret, 0, sizeof (*ret));
75 ret->ds_name = strdup (ds_name);
76 if (ret->ds_name == NULL)
78 ident_destroy (selector);
83 ret->color = get_random_color ();
86 ret->select = ident_copy_with_selector (selector, ident,
87 IDENT_FLAG_REPLACE_ALL);
88 if (ret->select == NULL)
90 ident_destroy (selector);
96 ident_destroy (selector);
98 } /* }}} graph_def_t *def_create */
100 void def_destroy (graph_def_t *def) /* {{{ */
109 ident_destroy (def->select);
116 } /* }}} void def_destroy */
118 int def_config (graph_config_t *cfg, const oconfig_item_t *ci) /* {{{ */
120 graph_ident_t *ident;
121 char *ds_name = NULL;
126 ident = gl_graph_get_selector (cfg);
130 for (i = 0; i < ci->children_num; i++)
132 oconfig_item_t *child;
134 #define HANDLE_FIELD(name,field) \
135 else if (strcasecmp (name, child->key) == 0) \
136 def_config_##field (child, ident)
138 child = ci->children + i;
139 if (strcasecmp ("DSName", child->key) == 0)
140 graph_config_get_string (child, &ds_name);
141 else if (strcasecmp ("Legend", child->key) == 0)
142 graph_config_get_string (child, &legend);
143 HANDLE_FIELD ("Host", host);
144 HANDLE_FIELD ("Plugin", plugin);
145 HANDLE_FIELD ("PluginInstance", plugin_instance);
146 HANDLE_FIELD ("Type", type);
147 HANDLE_FIELD ("TypeInstance", type_instance);
152 def = def_create (cfg, ident, ds_name);
155 fprintf (stderr, "def_config: def_create failed (ds_name = %s)\n",
156 (ds_name != NULL) ? ds_name : "(null)");
157 ident_destroy (ident);
161 def->legend = legend;
163 ident_destroy (ident);
166 return (gl_graph_add_def (cfg, def));
167 } /* }}} int def_config */
169 int def_append (graph_def_t *head, graph_def_t *def) /* {{{ */
173 if ((head == NULL) || (def == NULL))
177 while (ptr->next != NULL)
183 } /* }}} int def_append */
185 graph_def_t *def_search (graph_def_t *head, graph_ident_t *ident, /* {{{ */
190 if ((head == NULL) || (ident == NULL) || (ds_name == NULL))
193 for (ptr = head; ptr != NULL; ptr = ptr->next)
195 if (!ident_matches (ptr->select, ident))
198 if (strcmp (ptr->ds_name, ds_name) == 0)
203 } /* }}} graph_def_t *def_search */
205 _Bool def_matches (graph_def_t *def, graph_ident_t *ident) /* {{{ */
207 return (ident_matches (def->select, ident));
208 } /* }}} _Bool def_matches */
210 int def_foreach (graph_def_t *def, def_callback_t callback, /* {{{ */
215 if ((def == NULL) || (callback == NULL))
218 for (ptr = def; ptr != NULL; ptr = ptr->next)
222 status = (*callback) (ptr, user_data);
228 } /* }}} int def_foreach */
230 int def_get_rrdargs (graph_def_t *def, graph_ident_t *ident, /* {{{ */
236 if ((def == NULL) || (ident == NULL) || (args == NULL))
239 file = ident_to_file (ident);
242 DEBUG ("gl_ident_get_rrdargs: ident_to_file returned NULL.\n");
246 DEBUG ("gl_ident_get_rrdargs: file = %s;\n", file);
248 index = array_argc (args);
251 array_append_format (args, "DEF:def_%04i_min=%s:%s:MIN",
252 index, file, def->ds_name);
253 array_append_format (args, "DEF:def_%04i_avg=%s:%s:AVERAGE",
254 index, file, def->ds_name);
255 array_append_format (args, "DEF:def_%04i_max=%s:%s:MAX",
256 index, file, def->ds_name);
258 array_append_format (args, "VDEF:vdef_%04i_min=def_%04i_min,MINIMUM",
260 array_append_format (args, "VDEF:vdef_%04i_avg=def_%04i_avg,AVERAGE",
262 array_append_format (args, "VDEF:vdef_%04i_max=def_%04i_max,MAXIMUM",
264 array_append_format (args, "VDEF:vdef_%04i_lst=def_%04i_avg,LAST",
268 array_append_format (args, "LINE1:def_%04i_avg#%06"PRIx32":%s",
270 (def->legend != NULL) ? def->legend : def->ds_name);
271 array_append_format (args, "GPRINT:vdef_%04i_min:%%lg min,", index);
272 array_append_format (args, "GPRINT:vdef_%04i_avg:%%lg avg,", index);
273 array_append_format (args, "GPRINT:vdef_%04i_max:%%lg max,", index);
274 array_append_format (args, "GPRINT:vdef_%04i_lst:%%lg last\\l", index);
279 } /* }}} int def_get_rrdargs */
281 /* vim: set sw=2 sts=2 et fdm=marker : */