/*****************************************************************************
- * RRDtool 1.3rc2 Copyright by Tobi Oetiker, 1997-2008
+ * RRDtool 1.3.1 Copyright by Tobi Oetiker, 1997-2008
*****************************************************************************
* rrd_dump Display a RRD
*****************************************************************************
*****************************************************************************/
#include "rrd_tool.h"
#include "rrd_rpncalc.h"
+#include "rrd_client.h"
#if !(defined(NETWARE) || defined(WIN32))
extern char *tzname[2];
int rrd_dump_opt_r(
const char *filename,
char *outname,
- int opt_noheader
-)
+ int opt_noheader)
{
unsigned int i, ii, ix, iii = 0;
time_t now;
out_file = stdout;
}
- if (opt_noheader){
- fputs("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n", out_file);
- fputs
- ("<!DOCTYPE rrd SYSTEM \"http://oss.oetiker.ch/rrdtool/rrdtool.dtd\">\n",
- out_file);
+ if (!opt_noheader) {
+ fputs("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n", out_file);
+ fputs
+ ("<!DOCTYPE rrd SYSTEM \"http://oss.oetiker.ch/rrdtool/rrdtool.dtd\">\n",
+ out_file);
}
fputs("<!-- Round Robin Database Dump -->", out_file);
fputs("<rrd>", out_file);
const char *filename,
char *outname)
{
- return rrd_dump_opt_r(filename,outname,0);
+ return rrd_dump_opt_r(filename, outname, 0);
}
int rrd_dump(
{
int rc;
int opt_noheader = 0;
+ char *opt_daemon = NULL;
+
/* init rrd clean */
optind = 0;
opterr = 0; /* initialize getopt */
-
+
while (42) {
- int opt;
+ 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;
- default:
+ default:
rrd_set_error("usage rrdtool %s [--no-header|-n] "
- "file.rrd [file.xml]", argv[0]);
+ "file.rrd [file.xml]", argv[0]);
return (-1);
break;
}
} /* while (42) */
- if ((argc - optind) < 2) {
+ if ((argc - optind) < 1 || (argc - optind) > 2) {
rrd_set_error("usage rrdtool %s [--no-header|-n] "
"file.rrd [file.xml]", argv[0]);
return (-1);
}
- if (argc == 3) {
- rc = rrd_dump_opt_r(argv[1], argv[2],opt_noheader);
+ 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 {
- rc = rrd_dump_opt_r(argv[1], NULL,opt_noheader);
+ rc = rrd_dump_opt_r(argv[optind], NULL, opt_noheader);
}
return rc;
}
-