X-Git-Url: https://git.octo.it/?p=rrdtool.git;a=blobdiff_plain;f=src%2Frrd_xport.c;h=4457b60f9478dbe13159137b3ec7b50ddd3baf0d;hp=c4173e4c9f570799b7453d6eaf32e82426134322;hb=d85e6bdfe82fdc4d16898df43f8a5371503816ae;hpb=598d28c0200dddef0e3a8309e95958a5980bd2ea diff --git a/src/rrd_xport.c b/src/rrd_xport.c index c4173e4..4457b60 100644 --- a/src/rrd_xport.c +++ b/src/rrd_xport.c @@ -18,7 +18,6 @@ #include #endif - int rrd_xport( int, char **, @@ -40,7 +39,20 @@ int rrd_xport_fn( rrd_value_t **, int); +/* helper function for buffer handling */ +typedef struct stringbuffer_t { + size_t allocated; + size_t len; + unsigned char* data; + FILE *file; +} stringbuffer_t; +int addToBuffer(stringbuffer_t *,char*,size_t); +void escapeJSON(char*,size_t); +int rrd_graph_xport(image_desc_t *); +int rrd_xport_format_xmljson(int,stringbuffer_t *,image_desc_t*,time_t, time_t, unsigned long, unsigned long, char**, rrd_value_t*); +int rrd_xport_format_sv(char,stringbuffer_t *,image_desc_t*,time_t, time_t, unsigned long, unsigned long, char**, rrd_value_t*); +int rrd_xport_format_addprints(int,stringbuffer_t *,image_desc_t *); int rrd_xport( int argc, @@ -79,6 +91,9 @@ int rrd_xport( rrd_parsetime("end-24h", &start_tv); rrd_parsetime("now", &end_tv); + int enumds=0; + int json=0; + while (1) { int option_index = 0; int opt; @@ -93,6 +108,10 @@ int rrd_xport( im.step = atoi(optarg); break; case 262: + enumds=1; + break; + case 263: + json=1; break; case 's': if ((parsetime_error = rrd_parsetime(optarg, &start_tv))) { @@ -179,6 +198,18 @@ int rrd_xport( return -1; } + /* and create the export */ + if (!xsize) { + int flags=0; + if (json) { flags|=1; } + if (enumds) { flags|=4; } + stringbuffer_t buffer={0,0,NULL,stdout}; + rrd_xport_format_xmljson(flags,&buffer,&im, + *start, *end, *step, + *col_cnt, *legend_v, + *data); + } + im_free(&im); return 0; } @@ -341,21 +372,6 @@ int rrd_xport_fn( } -/* helper function for buffer handling */ -typedef struct stringbuffer_t { - size_t allocated; - size_t len; - unsigned char* data; - FILE *file; -} stringbuffer_t; -int addToBuffer(stringbuffer_t *,char*,size_t); -void escapeJSON(char*,size_t); - -int rrd_graph_xport(image_desc_t *); -int rrd_xport_format_xmljson(int,stringbuffer_t *,image_desc_t*,time_t, time_t, unsigned long, unsigned long, char**, rrd_value_t*); -int rrd_xport_format_sv(char,stringbuffer_t *,image_desc_t*,time_t, time_t, unsigned long, unsigned long, char**, rrd_value_t*); -int rrd_xport_format_addprints(int,stringbuffer_t *,image_desc_t *); - int rrd_graph_xport(image_desc_t *im) { /* prepare the data for processing */ unsigned long col_cnt=0; @@ -690,9 +706,11 @@ int rrd_xport_format_xmljson(int flags,stringbuffer_t *buffer,image_desc_t *im,t if (rrd_xport_format_addprints(json,buffer,im)) {return -1;} /* if we have got a trailing , then kill it */ - if (buffer->data[buffer->len-2]==',') { - buffer->data[buffer->len-2]=buffer->data[buffer->len-1]; - buffer->len--; + if (buffer->data) { + if (buffer->data[buffer->len-2]==',') { + buffer->data[buffer->len-2]=buffer->data[buffer->len-1]; + buffer->len--; + } } /* end meta */