summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: e6cc0dc)
raw | patch | inline | side by side (parent: e6cc0dc)
author | oetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa> | |
Tue, 20 May 2003 20:51:04 +0000 (20:51 +0000) | ||
committer | oetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa> | |
Tue, 20 May 2003 20:51:04 +0000 (20:51 +0000) |
you to re-format start and end-time at-style times using strftime. This
allows easy timespans in the graph (e.g. -2weeks) to be formatted into more
usual times. -- "Erskine, Thomas" <terskine@NRCan.gc.ca>
git-svn-id: svn://svn.oetiker.ch/rrdtool/trunk/program@207 a5681a0c-68f1-0310-ab6d-d61299d08faa
allows easy timespans in the graph (e.g. -2weeks) to be formatted into more
usual times. -- "Erskine, Thomas" <terskine@NRCan.gc.ca>
git-svn-id: svn://svn.oetiker.ch/rrdtool/trunk/program@207 a5681a0c-68f1-0310-ab6d-d61299d08faa
doc/rrdcgi.pod | patch | blob | history | |
src/rrd_cgi.c | patch | blob | history |
diff --git a/doc/rrdcgi.pod b/doc/rrdcgi.pod
index 96008ade990777cc91bdc8a22d6b89563a8eaaa2..cfa79a511b092015d9ebdf672ea3f476844017aa 100644 (file)
--- a/doc/rrdcgi.pod
+++ b/doc/rrdcgi.pod
E<lt>RRD:: tags. B<rrdcgi> will interpret and act according to these tags.
In the end it will printout a web page including the necessary CGI headers.
-B<rrdcgi> parses the contents of the template in 2 steps. In each step it looks
+B<rrdcgi> parses the contents of the template in 3 steps. In each step it looks
only for a subset of tags. This allows to nest tags.
The argument parser uses the same semantics as you are used from your c shell.
This gets replaced by the current time of day. The
time is I<strftime>-formated with the string specified in the argument.
+=item RRD::TIME::STRFTIME I<START|END> I<start-spec> I<end-spec> I<strftime-format>
+
+This gets replaced by a strftime-formatted time using the format
+I<strftime-format> on either I<start-spec> or I<end-spec> depending on
+whether I<START> or I<END> is specified. Both I<start-spec> and I<end-spec>
+must be supplied as either could be relative to the other. This is intended
+to allow pretty titles on graphs with times that are easier for non rrdtool
+folks to figure out than "-2weeks".
+
=back
=head2 Pass 3
diff --git a/src/rrd_cgi.c b/src/rrd_cgi.c
index 53c104f08aaa2797bf9fa766b4d8cc4ec861def2..a5237067eca806b5927117c17dac3acd13b9aba4 100644 (file)
--- a/src/rrd_cgi.c
+++ b/src/rrd_cgi.c
/* for how long is the output of the cgi valid ? */
char* rrdgoodfor(long, char **);
+/* format at-time specified times using strftime */
+char* printstrftime(long, char**);
+
/** http protocol needs special format, and GMT time **/
char *http_time(time_t *);
i += parse(&buffer,i,"<RRD::INCLUDE",includefile);
i += parse(&buffer,i,"<RRD::TIME::LAST",printtimelast);
i += parse(&buffer,i,"<RRD::TIME::NOW",printtimenow);
+ i += parse(&buffer,i,"<RRD::TIME::STRFTIME",printstrftime);
}
/* pass 3 */
return stralloc("");
}
+/* Format start or end times using strftime. We always need both the
+ * start and end times, because, either might be relative to the other.
+ * */
+#define MAX_STRFTIME_SIZE 256
+char* printstrftime(long argc, char **args){
+ struct time_value start_tv, end_tv;
+ char *parsetime_error = NULL;
+ char formatted[MAX_STRFTIME_SIZE];
+ struct tm *the_tm;
+ time_t start_tmp, end_tmp;
+
+ /* Make sure that we were given the right number of args */
+ if( argc != 4) {
+ rrd_set_error( "wrong number of args %d", argc);
+ return (char *) -1;
+ }
+
+ /* Init start and end time */
+ parsetime("end-24h", &start_tv);
+ parsetime("now", &end_tv);
+
+ /* Parse the start and end times we were given */
+ if( (parsetime_error = parsetime( args[1], &start_tv))) {
+ rrd_set_error( "start time: %s", parsetime_error);
+ return (char *) -1;
+ }
+ if( (parsetime_error = parsetime( args[2], &end_tv))) {
+ rrd_set_error( "end time: %s", parsetime_error);
+ return (char *) -1;
+ }
+ if( proc_start_end( &start_tv, &end_tv, &start_tmp, &end_tmp) == -1) {
+ return (char *) -1;
+ }
+
+ /* Do we do the start or end */
+ if( strcasecmp( args[0], "START") == 0) {
+ the_tm = localtime( &start_tmp);
+ }
+ else if( strcasecmp( args[0], "END") == 0) {
+ the_tm = localtime( &end_tmp);
+ }
+ else {
+ rrd_set_error( "start/end not found in '%s'", args[0]);
+ return (char *) -1;
+ }
+
+ /* now format it */
+ if( strftime( formatted, MAX_STRFTIME_SIZE, args[3], the_tm)) {
+ return( stralloc( formatted));
+ }
+ else {
+ rrd_set_error( "strftime failed");
+ return (char *) -1;
+ }
+}
+
char* includefile(long argc, char **args){
char *buffer;
if (argc >= 1) {