X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Frrd_update.c;h=ffbcebb56dda96ea3ec4f1736a5ff01f32171284;hb=50afe234200b92cee92dafde94b578acb466be4f;hp=585fa29e357cd0abe76ef8456dae822f4f860106;hpb=8d278938aef5adefa2915dd446abc028cc764550;p=rrdtool.git diff --git a/src/rrd_update.c b/src/rrd_update.c index 585fa29..ffbcebb 100644 --- a/src/rrd_update.c +++ b/src/rrd_update.c @@ -1,6 +1,7 @@ /***************************************************************************** - * RRDtool 1.3rc7 Copyright by Tobi Oetiker, 1997-2008 + * RRDtool 1.3.0 Copyright by Tobi Oetiker, 1997-2008 + * Copyright by Florian Forster, 2008 ***************************************************************************** * rrd_update.c RRD Update Function ***************************************************************************** @@ -23,6 +24,8 @@ #include "rrd_is_thread_safe.h" #include "unused.h" +#include "rrd_client.h" + #if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__CYGWIN32__) /* * WIN32 does not have gettimeofday and struct timeval. This is a quick and dirty @@ -104,7 +107,7 @@ static int process_arg( char **updvals, long *tmpl_idx, unsigned long tmpl_cnt, - rrd_info_t **pcdp_summary, + rrd_info_t ** pcdp_summary, int version, unsigned long *skip_update, int *schedule_smooth); @@ -258,7 +261,7 @@ static int write_to_rras( unsigned long *rra_current, time_t current_time, unsigned long *skip_update, - rrd_info_t **pcdp_summary); + rrd_info_t ** pcdp_summary); static int write_RRA_row( rrd_file_t *rrd_file, @@ -266,7 +269,7 @@ static int write_RRA_row( unsigned long rra_idx, unsigned long *rra_current, unsigned short CDP_scratch_idx, - rrd_info_t **pcdp_summary, + rrd_info_t ** pcdp_summary, time_t rra_time); static int smooth_all_rras( @@ -322,7 +325,7 @@ rrd_info_t *rrd_update_v( char **argv) { char *tmplt = NULL; - rrd_info_t *result = NULL; + rrd_info_t *result = NULL; rrd_infoval_t rc; struct option long_options[] = { {"template", required_argument, 0, 't'}, @@ -374,18 +377,20 @@ int rrd_update( { struct option long_options[] = { {"template", required_argument, 0, 't'}, + {"daemon", required_argument, 0, 'd'}, {0, 0, 0, 0} }; int option_index = 0; int opt; char *tmplt = NULL; int rc = -1; + char *daemon = NULL; optind = 0; opterr = 0; /* initialize getopt */ while (1) { - opt = getopt_long(argc, argv, "t:", long_options, &option_index); + opt = getopt_long(argc, argv, "t:d:", long_options, &option_index); if (opt == EOF) break; @@ -395,6 +400,17 @@ int rrd_update( tmplt = strdup(optarg); break; + case 'd': + if (daemon != NULL) + free (daemon); + daemon = strdup (optarg); + if (daemon == NULL) + { + rrd_set_error("strdup failed."); + goto out; + } + break; + case '?': rrd_set_error("unknown option '%s'", argv[optind - 1]); goto out; @@ -407,10 +423,75 @@ int rrd_update( goto out; } + if ((tmplt != NULL) && (daemon != NULL)) + { + rrd_set_error("The caching daemon cannot be used together with " + "templates yet."); + goto out; + } + + if ((tmplt == NULL) && (daemon == NULL)) + { + char *temp; + + temp = getenv (ENV_RRDCACHED_ADDRESS); + if (temp != NULL) + { + daemon = strdup (temp); + if (daemon == NULL) + { + rrd_set_error("strdup failed."); + goto out; + } + } + } + + if (daemon != NULL) + { + int status; + + status = rrdc_connect (daemon); + if (status != 0) + { + rrd_set_error("Unable to connect to daemon: %s", + (status < 0) + ? "Internal error" + : rrd_strerror (status)); + goto out; + } + + status = rrdc_update (/* file = */ argv[optind], + /* values_num = */ argc - optind - 1, + /* values = */ (void *) (argv + optind + 1)); + if (status != 0) + { + rrd_set_error("Failed sending the values to the daemon: %s", + (status < 0) + ? "Internal error" + : rrd_strerror (status)); + } + else + { + rc = 0; + } + + rrdc_disconnect (); + goto out; + } /* if (daemon != NULL) */ + rc = rrd_update_r(argv[optind], tmplt, argc - optind - 1, (const char **) (argv + optind + 1)); out: - free(tmplt); + if (tmplt != NULL) + { + free(tmplt); + tmplt = NULL; + } + if (daemon != NULL) + { + free (daemon); + daemon = NULL; + } return rc; } @@ -428,7 +509,7 @@ int _rrd_update( const char *tmplt, int argc, const char **argv, - rrd_info_t *pcdp_summary) + rrd_info_t * pcdp_summary) { int arg_i = 2; @@ -502,6 +583,15 @@ int _rrd_update( rra_step_cnt, updvals, tmpl_idx, tmpl_cnt, &pcdp_summary, version, skip_update, &schedule_smooth) == -1) { + if (rrd_test_error()) { /* Should have error string always here */ + char *save_error; + + /* Prepend file name to error message */ + if ((save_error = strdup(rrd_get_error())) != NULL) { + rrd_set_error("%s: %s", filename, save_error); + free(save_error); + } + } free(arg_copy); break; } @@ -750,7 +840,7 @@ static int process_arg( char **updvals, long *tmpl_idx, unsigned long tmpl_cnt, - rrd_info_t **pcdp_summary, + rrd_info_t ** pcdp_summary, int version, unsigned long *skip_update, int *schedule_smooth) @@ -1855,7 +1945,7 @@ static int write_to_rras( unsigned long *rra_current, time_t current_time, unsigned long *skip_update, - rrd_info_t **pcdp_summary) + rrd_info_t ** pcdp_summary) { unsigned long rra_idx; unsigned long rra_start; @@ -1963,7 +2053,7 @@ static int write_RRA_row( unsigned long rra_idx, unsigned long *rra_current, unsigned short CDP_scratch_idx, - rrd_info_t **pcdp_summary, + rrd_info_t ** pcdp_summary, time_t rra_time) { unsigned long ds_idx, cdp_idx; @@ -1981,14 +2071,12 @@ static int write_RRA_row( iv.u_val = rrd->cdp_prep[cdp_idx].scratch[CDP_scratch_idx].u_val; /* append info to the return hash */ *pcdp_summary = rrd_info_push(*pcdp_summary, - sprintf_alloc("[%d]RRA[%s][%lu]DS[%s]", - rra_time, - rrd->rra_def[rra_idx]. - cf_nam, - rrd->rra_def[rra_idx]. - pdp_cnt, - rrd->ds_def[ds_idx]. - ds_nam), RD_I_VAL, iv); + sprintf_alloc + ("[%d]RRA[%s][%lu]DS[%s]", rra_time, + rrd->rra_def[rra_idx].cf_nam, + rrd->rra_def[rra_idx].pdp_cnt, + rrd->ds_def[ds_idx].ds_nam), + RD_I_VAL, iv); } if (rrd_write(rrd_file, &(rrd->cdp_prep[cdp_idx].scratch[CDP_scratch_idx].