]> git.itanic.dy.fi Git - rrdd/commitdiff
rrd images: Make the timestamp string configurable
authorTimo Kokkonen <timo.t.kokkonen@iki.fi>
Sun, 28 Oct 2012 10:45:01 +0000 (12:45 +0200)
committerTimo Kokkonen <timo.t.kokkonen@iki.fi>
Sun, 28 Oct 2012 10:45:01 +0000 (12:45 +0200)
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 <timo.t.kokkonen@iki.fi>
config.c
rrdtool.c
rrdtool.h

index 28ef208f98e6d3e747688b4f386136ed12d925c8..8e9a3605eec414f5117a463877f65b908eef0df3 100644 (file)
--- 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;
index 6c740f0f17d9a2002955470748842369733b7516..f889d90eb4a4749edfeffeea61cdfa8c09e296c5 100644 (file)
--- 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;
 
index b57a276855be8beff4386c7c254a1b79ed9ccf54..4b8bc65258ceba6e5cbc5124908af445e37b08cf 100644 (file)
--- 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 {