]> git.ipfire.org Git - thirdparty/rrdtool-1.x.git/commitdiff
Fix JSON and JSONTIME export with gprints or rules 685/head
authorOlivier Doucet <webmaster@ajeux.com>
Fri, 6 Nov 2015 18:50:07 +0000 (19:50 +0100)
committerOlivier Doucet <webmaster@ajeux.com>
Fri, 6 Nov 2015 18:50:07 +0000 (19:50 +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 629b118e626e1602c593dce1e8aab5f28aba9ee0..971a7b5a6255298b8d0efc4301a53316e34eb7e8 100644 (file)
@@ -1067,10 +1067,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);
@@ -1083,10 +1083,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);