prevent duplicate chart names when streaming; fixes #2718
Costa Tsaousis (ktsaou) committed
Sep 17, 2017 at 12:09 UTC
16881ebd2d3e0af7a6dd7e1c1d945e18ada7ceda
1 file changed
+33
-19
src/plugins_d.c
+33
-19
@@ -217,34 +217,48 @@ inline size_t pluginsd_process(RRDHOST *host, struct plugind *cd, FILE *fp, int
217
st = NULL;
218
}
219
else if(likely(hash == CHART_HASH && !strcmp(s, PLUGINSD_KEYWORD_CHART))) {
220
- int noname = 0;
220
st = NULL;
221
223
- if((words[1]) != NULL && (words[2]) != NULL && strcmp(words[1], words[2]) == 0)
224
- noname = 1;
222
+ char *type = words[1];
223
+ char *name = words[2];
224
+ char *title = words[3];
225
+ char *units = words[4];
226
+ char *family = words[5];
227
+ char *context = words[6];
228
+ char *chart = words[7];
229
+ char *priority_s = words[8];
230
+ char *update_every_s = words[9];
231
+ char *options = words[10];
232
226
- char *type = words[1];
233
+ // parse the id from type
234
char *id = NULL;
228
- if(likely(type)) {
229
- id = strchr(type, '.');
230
- if(likely(id)) { *id = '\0'; id++; }
235
+ if(likely(type && (id = strchr(type, '.')))) {
236
+ *id = '\0';
237
+ id++;
238
}
232
- char *name = words[2];
233
- char *title = words[3];
234
- char *units = words[4];
235
- char *family = words[5];
236
- char *context = words[6];
237
- char *chart = words[7];
238
- char *priority_s = words[8];
239
- char *update_every_s = words[9];
240
- char *options = words[10];
239
240
+ // make sure we have the required variables
241
if(unlikely(!type || !*type || !id || !*id)) {
242
error("PLUGINSD: '%s' is requesting a CHART, without a type.id, on host '%s'. Disabling it.", cd->fullfilename, host->hostname);
243
enabled = 0;
244
break;
245
}
246
247
+ // parse the name, and make sure it does not include 'type.'
248
+ if(unlikely(name && *name)) {
249
+ // when data are coming from slaves
250
+ // name will be type.name
251
+ // so we have to remove 'type.' from name too
252
+ size_t len = strlen(type);
253
+ if(strncmp(type, name, len) == 0 && name[len] == '.')
254
+ name = &name[len + 1];
255
+
256
+ // if the name is the same with the id,
257
+ // or is just 'NULL', clear it.
258
+ if(unlikely(strcmp(name, id) == 0 || strcasecmp(name, "NULL") == 0 || strcasecmp(name, "(NULL)") == 0))
259
+ name = NULL;
260
+ }
261
+
262
int priority = 1000;
263
if(likely(priority_s && *priority_s)) priority = str2i(priority_s);
264
@@ -255,9 +269,9 @@ inline size_t pluginsd_process(RRDHOST *host, struct plugind *cd, FILE *fp, int
269
RRDSET_TYPE chart_type = RRDSET_TYPE_LINE;
270
if(unlikely(chart)) chart_type = rrdset_type_id(chart);
271
258
- if(unlikely(noname || !name || !*name || strcasecmp(name, "NULL") == 0 || strcasecmp(name, "(NULL)") == 0)) name = NULL;
259
- if(unlikely(!family || !*family)) family = NULL;
260
- if(unlikely(!context || !*context)) context = NULL;
272
+ if(unlikely(name && !*name)) name = NULL;
273
+ if(unlikely(family && !*family)) family = NULL;
274
+ if(unlikely(context && !*context)) context = NULL;
275
if(unlikely(!title)) title = "";
276
if(unlikely(!units)) units = "unknown";
277