return out;
}
+/* copies the RRD in to a new RRD and return it
+
+ In that process, data sources may be removed or added.
+
+ removeDS points to an array of strings, each naming a DS to be
+ removed. The list itself is NULL terminated. addDS points to a
+ similar list holding rrdcreate-style data source definitions to be
+ added.
+*/
+
static rrd_t *rrd_modify_r2(const rrd_t *in,
const char **removeDS,
const char **addDS,
return finalout;
}
-/* copies the RRD named by infilename to a new RRD called outfilename.
-
- In that process, data sources may be removed or added.
-
- removeDS points to an array of strings, each naming a DS to be
- removed. The list itself is NULL terminated. addDS points to a
- similar list holding rrdcreate-style data source definitions to be
- added.
-*/
-
-static int rrd_modify_r(const char *infilename,
- const char *outfilename,
- const char **removeDS,
- const char **addDS,
- rra_mod_op_t *rra_mod_ops, int rra_mod_ops_cnt,
- int newstep)
-{
- rrd_t in;
- rrd_t *out = NULL;
-
- int rc = -1;
- rrd_file_t *rrd_file = NULL;
- char *old_locale = NULL;
-
- old_locale = setlocale(LC_NUMERIC, "C");
-
- rrd_clear_error(); // reset error
-
- if (rrdc_is_any_connected()) {
- // is it a good idea to just ignore the error ????
- rrdc_flush(infilename);
- rrd_clear_error();
- }
-
- rrd_init(&in);
-
- rrd_file = rrd_open(infilename, &in, RRD_READONLY | RRD_READAHEAD | RRD_READVALUES);
- if (rrd_file == NULL) {
- // rrd error has been set
- goto done;
- }
-
- // now we have read the input RRD...
- unsigned long hashed_name = FnvHash(outfilename);
- out = rrd_modify_r2(&in, removeDS, addDS, rra_mod_ops, rra_mod_ops_cnt, newstep, hashed_name);
-
- if (out == NULL) {
- goto done;
- }
-
- rc = write_rrd(outfilename, out);
-
-done:
- setlocale(LC_NUMERIC, old_locale);
-
- rrd_free(&in);
- if (out) {
- rrd_memory_free(out);
- free(out);
- out = NULL;
- }
- if (rrd_file) {
- rrd_close(rrd_file);
- }
- rrd_free(&in);
-
- return rc;
-}
// prepare CDPs + values for new RRA
return rc;
}
-
-
-int rrd_modify (
- int argc,
- char **argv)
-{
- int rc = 9;
- int i;
- char *opt_daemon = NULL;
- int opt_newstep = -1;
-
- /* init rrd clean */
-
- optind = 0;
- opterr = 0; /* initialize getopt */
-
- while (42) {/* ha ha */
- int opt;
- int option_index = 0;
- static struct option long_options[] = {
- {"daemon", required_argument, 0, 'd'},
- {"newstep", required_argument, 0, 's'},
- {0, 0, 0, 0}
- };
-
- opt = getopt_long(argc, argv, "d:s:", long_options, &option_index);
-
- if (opt == EOF)
- break;
-
- switch (opt) {
- case 'd':
- if (opt_daemon != NULL)
- free (opt_daemon);
- opt_daemon = strdup (optarg);
- if (opt_daemon == NULL)
- {
- rrd_set_error ("strdup failed.");
- return (-1);
- }
- break;
- case 's': {
- char *ep = NULL;
- opt_newstep = strtoul(optarg, &ep, 0);
- break;
- }
- default:
- rrd_set_error("usage rrdtool %s"
- "in.rrd out.rrd", argv[0]);
- return (-1);
- break;
- }
- } /* while (42) */
-
- if ((argc - optind) < 2) {
- rrd_set_error("usage rrdtool %s"
- "in.rrd out.rrd", argv[0]);
- return (-1);
- }
-
- // connect to daemon (will take care of environment variable automatically)
- if (rrdc_connect(opt_daemon) != 0) {
- rrd_set_error("Cannot connect to daemon");
- return 1;
- }
-
- if (opt_daemon) {
- free(opt_daemon);
- opt_daemon = NULL;
- }
-
- // parse add/remove options
- const char **remove = NULL, **add = NULL;
- rra_mod_op_t *rra_ops = NULL;
- int rcnt = 0, acnt = 0, rraopcnt = 0;
-
- for (i = optind + 2 ; i < argc ; i++) {
- if (strncmp("DEL:", argv[i], 4) == 0 && strlen(argv[i]) > 4) {
- remove = realloc(remove, (rcnt + 2) * sizeof(char*));
- if (remove == NULL) {
- rrd_set_error("out of memory");
- rc = -1;
- goto done;
- }
-
- remove[rcnt] = strdup(argv[i] + 4);
- if (remove[rcnt] == NULL) {
- rrd_set_error("out of memory");
- rc = -1;
- goto done;
- }
-
- rcnt++;
- remove[rcnt] = NULL;
- } else if (strncmp("DS:", argv[i], 3) == 0 && strlen(argv[i]) > 3) {
- add = realloc(add, (acnt + 2) * sizeof(char*));
- if (add == NULL) {
- rrd_set_error("out of memory");
- rc = -1;
- goto done;
- }
-
- add[acnt] = strdup(argv[i]);
- if (add[acnt] == NULL) {
- rrd_set_error("out of memory");
- rc = -1;
- goto done;
- }
-
- acnt++;
- add[acnt] = NULL;
- } else if (strncmp("RRA#", argv[i], 4) == 0 && strlen(argv[i]) > 4) {
- rra_mod_op_t rra_mod = { .def = NULL };
- char sign;
- unsigned int number;
- unsigned int index;
-
- if (sscanf(argv[i] + 4, "%u:%c%u", &index, &sign, &number) != 3) {
- rrd_set_error("Failed to parse RRA# command");
- rc = -1;
- goto done;
- }
-
- rra_mod.index = index;
- switch (sign) {
- case '=':
- case '-':
- case '+':
- rra_mod.index = index;
- rra_mod.op = sign;
- rra_mod.row_count = number;
- rra_mod.final_row_count = 0;
- break;
- default:
- rrd_set_error("Failed to parse RRA# command: invalid operation: %c", sign);
- rc = -1;
- goto done;
- }
-
- rra_ops = copy_over_realloc(rra_ops, rraopcnt,
- &rra_mod, 0, sizeof(rra_mod));
- if (rra_ops == NULL) {
- rrd_set_error("out of memory");
- rc = -1;
- goto done;
- }
- rraopcnt++;
- } else if (strncmp("RRA:", argv[i], 4) == 0 && strlen(argv[i]) > 4) {
- rra_mod_op_t rra_mod;
- rra_mod.op = 'a';
- rra_mod.index = -1;
- rra_mod.def = strdup(argv[i]);
-
- if (rra_mod.def == NULL) {
- rrd_set_error("out of memory");
- rc = -1;
- goto done;
- }
-
- rra_ops = copy_over_realloc(rra_ops, rraopcnt,
- &rra_mod, 0, sizeof(rra_mod));
- if (rra_ops == NULL) {
- rrd_set_error("out of memory");
- rc = -1;
- goto done;
- }
- rraopcnt++;
- } else if (strncmp("DELRRA:", argv[i], 7) == 0 && strlen(argv[i]) > 7) {
- rra_mod_op_t rra_mod = { .def = NULL,
- .op = '=',
- .row_count = 0 // eg. deletion
- };
-
- rra_mod.index = atoi(argv[i] + 7);
- if (rra_mod.index < 0 ) {
- rrd_set_error("DELRRA requires a non-negative, integer argument");
- rc = -1;
- goto done;
- }
-
- rra_ops = copy_over_realloc(rra_ops, rraopcnt,
- &rra_mod, 0, sizeof(rra_mod));
- if (rra_ops == NULL) {
- rrd_set_error("out of memory");
- rc = -1;
- goto done;
- }
- rraopcnt++;
- } else {
- rrd_set_error("unparseable argument: %s", argv[i]);
- rc = -1;
- goto done;
- }
- }
-
- if ((argc - optind) >= 2) {
- rc = rrd_modify_r(argv[optind], argv[optind + 1],
- remove, add, rra_ops, rraopcnt, opt_newstep);
- } else {
- rrd_set_error("missing arguments");
- rc = 2;
- }
-
-done:
- if (remove) {
- for (const char **c = remove ; *c ; c++) {
- free((void*) *c);
- }
- free(remove);
- }
- if (add) {
- for (const char **c = add ; *c ; c++) {
- free((void*) *c);
- }
- free(add);
- }
- if (rra_ops) {
- for (i = 0 ; i < rraopcnt ; i++) {
- if (rra_ops[i].def) free(rra_ops[i].def);
- }
- free(rra_ops);
- }
- return rc;
-}
const char *help_list =
N_
("Valid commands: create, update, updatev, graph, graphv, dump, restore,\n"
- "\t\tlast, lastupdate, first, info, fetch, tune, modify,\n"
+ "\t\tlast, lastupdate, first, info, fetch, tune\n"
"\t\tresize, xport, flushcached\n");
const char *help_listremote =
"\t\t[--gamma adaptation-parameter]\n"
"\t\t[--gamma-deviation adaptation-parameter]\n"
"\t\t[--aberrant-reset ds-name]\n");
- const char *help_modify =
- N_(" * modify - add/remove datasources to/from an RRD\n\n"
- "\trrdtool modify in-filename out-filename\n"
- "\t\t???");
+ const char *help_tune3 =
+ N_("\t\t???"); // FIXME
const char *help_resize =
N_
(" * resize - alter the length of one of the RRAs in an RRD\n\n"
"For more information read the RRD manpages\n");
enum { C_NONE, C_CREATE, C_DUMP, C_INFO, C_RESTORE, C_LAST,
C_LASTUPDATE, C_FIRST, C_UPDATE, C_FETCH, C_GRAPH, C_GRAPHV,
- C_TUNE, C_MODIFY,
+ C_TUNE,
C_RESIZE, C_XPORT, C_QUIT, C_LS, C_CD, C_MKDIR, C_PWD,
C_UPDATEV, C_FLUSHCACHED
};
help_cmd = C_GRAPHV;
else if (!strcmp(cmd, "tune"))
help_cmd = C_TUNE;
- else if (!strcmp(cmd, "modify"))
- help_cmd = C_MODIFY;
else if (!strcmp(cmd, "resize"))
help_cmd = C_RESIZE;
else if (!strcmp(cmd, "xport"))
case C_TUNE:
puts(_(help_tune1));
puts(_(help_tune2));
- break;
- case C_MODIFY:
- puts(_(help_modify));
+ puts(_(help_tune3));
break;
case C_RESIZE:
puts(_(help_resize));
rrd_tune(argc - 1, &argv[1]);
else if (strcmp("flushcached", argv[1]) == 0)
rrd_flushcached(argc - 1, &argv[1]);
- else if (strcmp("modify", argv[1]) == 0)
- rrd_modify(argc - 1, &argv[1]);
else {
rrd_set_error("unknown function '%s'", argv[1]);
}