]> git.ipfire.org Git - thirdparty/rrdtool-1.x.git/commitdiff
Fix JSON and JSONTIME export with gprints or rules
authorOlivier Doucet <webmaster@ajeux.com>
Fri, 6 Nov 2015 18:50:07 +0000 (19:50 +0100)
committerTobias Oetiker <tobi@oetiker.ch>
Tue, 10 Nov 2015 16:07:36 +0000 (17:07 +0100)
When you have gprints or rules, json is not formated correctly : a comma is inserted after each block, making two mistakes :
- there is no comma between "legend" and "gprints" block
- there is a trailing comma in "meta" block

I decided to rewrite this part and add the comma before each block, so this works in all cases : when you don't have any block, only one of them or both.

src/rrd_xport.c

index 610cded99d0eedc375cfb00d58ffed8b9f51c726..6f64f539e6608762e7f1431b838a6976be13eee5 100644 (file)
@@ -1061,10 +1061,10 @@ int rrd_xport_format_addprints(int flags,stringbuffer_t *buffer,image_desc_t *im
   /* now add gprints */
   if (gprints.len) {
     if (json){
-      snprintf(buf,sizeof(buf),"    \"%s\": [\n","gprints");
+      snprintf(buf,sizeof(buf),"    ,\"%s\": [\n","gprints");
       addToBuffer(buffer,buf,0);
       addToBuffer(buffer,(char*)gprints.data+2,gprints.len-2);
-      addToBuffer(buffer,"\n        ],\n",0);
+      addToBuffer(buffer,"\n        ]\n",0);
     } else {
       snprintf(buf,sizeof(buf),"    <%s>\n", "gprints");
       addToBuffer(buffer,buf,0);
@@ -1077,10 +1077,10 @@ int rrd_xport_format_addprints(int flags,stringbuffer_t *buffer,image_desc_t *im
   /* now add rules */
   if (rules.len) {
     if (json){
-      snprintf(buf,sizeof(buf),"    \"%s\": [\n","rules");
+      snprintf(buf,sizeof(buf),"    ,\"%s\": [\n","rules");
       addToBuffer(buffer,buf,0);
       addToBuffer(buffer,(char*)rules.data+2,rules.len-2);
-      addToBuffer(buffer,"\n        ],\n",0);
+      addToBuffer(buffer,"\n        ]\n",0);
     } else {
       snprintf(buf,sizeof(buf),"    <%s>\n", "rules");
       addToBuffer(buffer,buf,0);