From: Timo Kokkonen Date: Sun, 28 Oct 2012 10:45:01 +0000 (+0200) Subject: rrd images: Make the timestamp string configurable X-Git-Url: http://git.itanic.dy.fi/?p=rrdd;a=commitdiff_plain;h=d5c899de72475b042eaca85e7748bf422c6a6c2f rrd images: Make the timestamp string configurable Make it possible to replace the "Last update ..." string with something that fits better for the needs of the end user. The string is passed through strftime so one can use arbitrary timestamp formats. Signed-off-by: Timo Kokkonen --- diff --git a/config.c b/config.c index 28ef208..8e9a360 100644 --- a/config.c +++ b/config.c @@ -37,6 +37,7 @@ static int parse_images(config_setting_t *list, struct rrd_database *db) const char *database = NULL, *filename = NULL, *timestart = NULL; const char *timeend = NULL, *imageformat = NULL; const char **options = NULL, **text = NULL; + const char *updatestr = NULL; int width = 0, height = 0, text_lead = 0; count = config_setting_length(list); @@ -111,6 +112,9 @@ static int parse_images(config_setting_t *list, struct rrd_database *db) return -1; } + config_setting_lookup_string(image, "update_string", + &updatestr); + str_list = config_setting_get_member(image, "options"); if (str_list) read_strings_from_list(str_list, &options); @@ -133,6 +137,9 @@ static int parse_images(config_setting_t *list, struct rrd_database *db) db->images[i]->options = options; db->images[i]->text_lead = text_lead; db->images[i]->text = text; + + if (updatestr) + db->images[i]->updatestr = strdup(updatestr); } return 0; diff --git a/rrdtool.c b/rrdtool.c index 6c740f0..f889d90 100644 --- a/rrdtool.c +++ b/rrdtool.c @@ -38,9 +38,10 @@ int rrdtool_draw_image(struct rrd_image *image) char *args[512], argstr[ARGSTR_LEN]; int idx = 0, argcnt = 0, i,j; char timestamp[256]; - char tmp[256]; + char tmp[sizeof(timestamp)]; char tmpfile[256]; time_t t = time(0); + const char *updatestr = "Last update %d.%m.%Y %T (%Z)"; pid = do_fork_limited(); if (pid) @@ -52,8 +53,11 @@ int rrdtool_draw_image(struct rrd_image *image) strncat(tmpfile, image->image_filename, sizeof(tmp) - strlen(tmp) - 1); strncat(tmpfile, ".tmp", sizeof(tmp) - strlen(tmp) - 1); - strftime(tmp, 256, "%d.%m.%Y %T (%Z) ", localtime(&t)); - for (i = 0, j = 0; j < 256;) { + if (image->updatestr) + updatestr = image->updatestr; + + strftime(tmp, sizeof(tmp), updatestr, localtime(&t)); + for (i = 0, j = 0; j < sizeof(tmp);) { if (tmp[i] == ':') { timestamp[j++] = '\\'; } @@ -87,7 +91,7 @@ int rrdtool_draw_image(struct rrd_image *image) args[argcnt++] = (char *)image->text[i]; } - add_arg(args, argcnt, argstr, idx, "COMMENT:Last update %s\\c", timestamp); + add_arg(args, argcnt, argstr, idx, "COMMENT: %s\\c", timestamp); args[argcnt] = 0; diff --git a/rrdtool.h b/rrdtool.h index b57a276..4b8bc65 100644 --- a/rrdtool.h +++ b/rrdtool.h @@ -14,6 +14,7 @@ struct rrd_image { const char **options; /* Null terminated list of rrdgraph options */ int text_lead; /* Number of spaces at the beginning of line */ const char **text; /* Null terminated list of text lines */ + const char *updatestr; /* "Last update" string comment */ }; struct rrd_data_source {