X-Git-Url: https://git.octo.it/?p=rrdtool.git;a=blobdiff_plain;f=src%2Frrd_dump.c;h=ea28245a63d6c497f5cf6a3b6518a83b3435c081;hp=247e912bcc87f64456b3ce2809895f20656d0d3f;hb=210e991460e82d01d086f853e65485040eb2fffb;hpb=d49e24866f6f989a0e3a00a29281f1f9a1a1d54c diff --git a/src/rrd_dump.c b/src/rrd_dump.c index 247e912..ea28245 100644 --- a/src/rrd_dump.c +++ b/src/rrd_dump.c @@ -43,6 +43,7 @@ *****************************************************************************/ #include "rrd_tool.h" #include "rrd_rpncalc.h" +#include "rrd_client.h" #if !(defined(NETWARE) || defined(WIN32)) extern char *tzname[2]; @@ -441,6 +442,7 @@ int rrd_dump( { int rc; int opt_noheader = 0; + char *opt_daemon = NULL; /* init rrd clean */ @@ -451,16 +453,28 @@ int rrd_dump( int opt; int option_index = 0; static struct option long_options[] = { + {"daemon", required_argument, 0, 'd'}, {"no-header", no_argument, 0, 'n'}, {0, 0, 0, 0} }; - opt = getopt_long(argc, argv, "n", long_options, &option_index); + opt = getopt_long(argc, argv, "d:n", 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 'n': opt_noheader = 1; break; @@ -479,6 +493,44 @@ int rrd_dump( return (-1); } + if (opt_daemon == NULL) + { + char *temp; + + temp = getenv (ENV_RRDCACHED_ADDRESS); + if (temp != NULL) + { + opt_daemon = strdup (temp); + if (opt_daemon == NULL) + { + rrd_set_error("strdup failed."); + return (-1); + } + } + } + + if (opt_daemon != NULL) + { + int status; + + status = rrdc_connect (opt_daemon); + if (status != 0) + { + rrd_set_error ("rrdc_connect failed with status %i.", status); + return (-1); + } + + status = rrdc_flush (argv[optind]); + if (status != 0) + { + rrd_set_error ("rrdc_flush (%s) failed with status %i.", + argv[optind], status); + return (-1); + } + + rrdc_disconnect (); + } /* if (opt_daemon) */ + if ((argc - optind) == 2) { rc = rrd_dump_opt_r(argv[optind], argv[optind + 1], opt_noheader); } else {