Code

new options --enumds and --unknwonaszero for xport
authoroetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa>
Mon, 31 Jul 2006 22:48:45 +0000 (22:48 +0000)
committeroetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa>
Mon, 31 Jul 2006 22:48:45 +0000 (22:48 +0000)
git-svn-id: svn://svn.oetiker.ch/rrdtool/branches/1.2@862 a5681a0c-68f1-0310-ab6d-d61299d08faa

program/doc/rrdxport.pod
program/src/rrd_tool.c
program/src/rrd_xport.c

index 62a96259f8357ca45189f575bb4a2f03981fbe8a..f5738154b937e17e7e29eb7f84389da6e47ab05e 100644 (file)
@@ -48,6 +48,16 @@ for details.
 
 See L<rrdgraph> documentation.
 
+=item B<--enumds> 
+
+The generated xml should contain the data values in enumerated tags.
+
+ <v0>val</v0><v1>val</v1>
+
+=item B<--unknwonaszero>
+
+Turn UNKNWON into '0' on output.
+
 =item B<DEF:>I<vname>B<=>I<rrd>B<:>I<ds-name>B<:>I<CF>
 
 See I<rrdgraph> documentation.
index f56b90ccb6c21e68e42678aaf77578b42cfa224b..a331df7c57ca043f3492f68de3760813d58d1102 100644 (file)
@@ -159,6 +159,8 @@ void PrintUsage(char *cmd)
           "\trrdtool xport [-s|--start seconds] [-e|--end seconds]\n"
           "\t\t[-m|--maxrows rows]\n"
           "\t\t[--step seconds]\n"        
+          "\t\t[--enumds]\n"      
+          "\t\t[--unknownaszero]\n"       
           "\t\t[DEF:vname=rrd:ds-name:CF]\n"
           "\t\t[CDEF:vname=rpn-expression]\n"
            "\t\t[XPORT:vname:legend]\n\n";
@@ -647,13 +649,25 @@ int HandleInputLine(int argc, char **argv, FILE* out)
            free (data);
        }
     } else if (strcmp("xport", argv[1]) == 0) {
-       int xxsize;
+        int xxsize;
        unsigned long int j = 0;
        time_t        start,end, ti;
        unsigned long step, col_cnt,row_cnt;
        rrd_value_t   *data,*ptr;
        char          **legend_v;
-       if(rrd_xport(argc-1, &argv[1], &xxsize,&start,&end,&step,&col_cnt,&legend_v,&data) != -1) {
+        int           enumds = 0;
+        int           unknownaszero = 0;
+        int           i;
+        char *vtag = NULL;
+        vtag = malloc( strlen(COL_DATA_TAG)+10);
+       for ( i = 2; i < argc; i++){
+               if (strcmp("--enumds", argv[i]) == 0)
+                       enumds = 1;
+               if (strcmp("--unknownaszero", argv[i]) == 0)
+                       unknownaszero = 1;
+       }
+
+        if(rrd_xport(argc-1, &argv[1], &xxsize,&start,&end,&step,&col_cnt,&legend_v,&data) != -1) {
          row_cnt = (end-start)/step;
          ptr = data;
          printf("<?xml version=\"1.0\" encoding=\"%s\"?>\n\n", XML_ENCODING);
@@ -679,12 +693,20 @@ int HandleInputLine(int argc, char **argv, FILE* out)
            printf ("    <%s>", DATA_ROW_TAG);
            printf ("<%s>%lu</%s>", COL_TIME_TAG, ti, COL_TIME_TAG);
            for (j = 0; j < col_cnt; j++) {
+              if (enumds == 1)
+               snprintf(vtag,15,"%s%lu", COL_DATA_TAG, j);
+             else
+               snprintf(vtag,15,"%s",COL_DATA_TAG);
+              
              rrd_value_t newval = DNAN;
              newval = *ptr;
              if(isnan(newval)){
-               printf("<%s>NaN</%s>", COL_DATA_TAG, COL_DATA_TAG);
+                 if (unknownaszero == 1) 
+                     printf("<%s>0</%s>", vtag,vtag);
+                 else
+                     printf("<%s>NaN</%s>", vtag,vtag);
              } else {
-               printf("<%s>%0.10e</%s>", COL_DATA_TAG, newval, COL_DATA_TAG);
+               printf("<%s>%0.10e</%s>", vtag, newval, vtag);
              };
              ptr++;
            }
@@ -694,6 +716,7 @@ int HandleInputLine(int argc, char **argv, FILE* out)
          printf("  </%s>\n", DATA_TAG);
          printf("</%s>\n", ROOT_TAG);
        }
+        free(vtag);
     }
     else if (strcmp("graph", argv[1]) == 0) {
        char **calcpr;
index fee2c36837f98bb79648e62324e7a835a9182aae..f427762f60f3eb1b6270f10a5ba94c1b9424924d 100644 (file)
@@ -61,6 +61,8 @@ rrd_xport(int argc, char **argv, int UNUSED(*xsize),
            {"end",        required_argument, 0,  'e'},
            {"maxrows",    required_argument, 0,  'm'},
            {"step",       required_argument, 0,   261},
+           {"enumds",     no_argument,       0,   262}, /* these are handled in the frontend ... */
+           {"unknownaszero",  no_argument,       0,   263}, /* just ignore them here */
            {0,0,0,0}
        };
        int option_index = 0;
@@ -76,6 +78,9 @@ rrd_xport(int argc, char **argv, int UNUSED(*xsize),
        case 261:
            im.step =  atoi(optarg);
            break;
+       case 262:
+       case 263:
+           break;
        case 's':
            if ((parsetime_error = parsetime(optarg, &start_tv))) {
                rrd_set_error( "start time: %s", parsetime_error );
@@ -96,7 +101,7 @@ rrd_xport(int argc, char **argv, int UNUSED(*xsize),
            }
            break;
        case '?':
-           rrd_set_error("unknown option '%c'", optopt);
+            rrd_set_error("unknown option '%s'",argv[optind-1]);
             return -1;
        }
     }