int rrd_fetch_r( const char *filename, /* name of the rrd */ const char *cf, /* which consolidation function ? */ time_t *start, time_t *end, /* which time frame do you want ? * will be changed to represent reality */ unsigned long *step, /* which stepsize do you want? * will be changed to represent reality */ unsigned long *ds_cnt, /* number of data sources in file */ char ***ds_namv, /* names of data_sources */ rrd_value_t **data) { /* two dimensional array containing the data */ enum cf_en cf_idx; if ((int) (cf_idx = cf_conv(cf)) == -1) { return -1; } return (rrd_fetch_fn (filename, cf_idx, start, end, step, ds_cnt, ds_namv, data)); } /* int rrd_fetch_r */
int rrd_fetch(int argc, char **argv, time_t *start, time_t *end, /* which time frame do you want ? * will be changed to represent reality */ unsigned long *step, /* which stepsize do you want? * will be changed to represent reality */ unsigned long *ds_cnt, /* number of data sources in file */ char ***ds_namv, /* names of data sources */ rrd_value_t **data) /* two dimensional array containing the data */ { long step_tmp =1; time_t start_tmp=0, end_tmp=0; enum cf_en cf_idx; struct rrd_time_value start_tv, end_tv; char *parsetime_error = NULL; optind = 0; opterr = 0; /* initialize getopt */ /* init start and end time */ parsetime("end-24h", &start_tv); parsetime("now", &end_tv); while (1){ static struct option long_options[] = { {"resolution", required_argument, 0, 'r'}, {"start", required_argument, 0, 's'}, {"end", required_argument, 0, 'e'}, {0,0,0,0} }; int option_index = 0; int opt; opt = getopt_long(argc, argv, "r:s:e:", long_options, &option_index); if (opt == EOF) break; switch(opt) { case 's': if ((parsetime_error = parsetime(optarg, &start_tv))) { rrd_set_error( "start time: %s", parsetime_error ); return -1; } break; case 'e': if ((parsetime_error = parsetime(optarg, &end_tv))) { rrd_set_error( "end time: %s", parsetime_error ); return -1; } break; case 'r': step_tmp = atol(optarg); break; case '?': rrd_set_error("unknown option '-%c'",optopt); return(-1); } } if (proc_start_end(&start_tv,&end_tv,&start_tmp,&end_tmp) == -1){ return -1; } if (start_tmp < 3600*24*365*10){ rrd_set_error("the first entry to fetch should be after 1980"); return(-1); } if (end_tmp < start_tmp) { rrd_set_error("start (%ld) should be less than end (%ld)", start_tmp, end_tmp); return(-1); } *start = start_tmp; *end = end_tmp; if (step_tmp < 1) { rrd_set_error("step must be >= 1 second"); return -1; } *step = step_tmp; if (optind + 1 >= argc){ rrd_set_error("not enough arguments"); return -1; } if ((int)(cf_idx=cf_conv(argv[optind+1])) == -1 ){ return -1; } if (rrd_fetch_fn(argv[optind],cf_idx,start,end,step,ds_cnt,ds_namv,data) == -1) return(-1); return (0); }