[rrd-developers] patch for getting at <last></last> via rrdcgi

steve rader rader at teak.wiscnet.net
Mon Oct 4 20:51:24 MEST 1999


 > *> For example: I think new users scanning the rrdcgi doc looking
 > *> to pretty-print 'rrdtool last some.rrd' will skip right past
 > *> "<RRD::TIMESTR>".
 > *> 
 > *> If I scan rrdcgi doc and see "<RRD::TIME::TIMESTR>", I think my
 > *> reaction would be "ahh, for printing time strings" and my reaction
 > *> to "<RRD::TIME::LAST>" would be "cool, for printing the last update
 > *> time for an RRD".
 > 
 > From: Tobias Oetiker
 > OK got a point there ... 
 > OK lets do it like that ...

A patch for <RRD::TIME::LAST> is enclosed and at [1]...

  bash% grep "Last data update" fu.cgi
     Last data update was <RRD::TIME::LAST fu.rrd "%A, %b %d %Y %H:%M %Z">

  bash% echo | ./fu.cgi | grep "Last data update"
     Last data update was Monday, Sep 27 1999 11:55 CDT

To those on, er, from the other side of the pond: please
accept my apologies you find my "imperialist" date format
(above) offensive!

later
steve
- - -
systems guy
wiscnet.net

 [1] ftp://teak.wiscnet.net/pub/src/rrd-1.0.8-RRD-TIME-LAST.patch



-- Attached file included as plaintext by Listar --
-- Desc: rrd-1.0.8-RRD-TIME-LAST.patch

--- rrdtool-1.0.8.orig/src/rrd_cgi.c	Fri Aug 27 14:20:05 1999
+++ rrdtool-1.0.8/src/rrd_cgi.c	Sun Oct  3 15:01:00 1999
@@ -38,6 +38,9 @@
 /* return PRINT functions from last rrd_graph call */
 char* drawprint(long, char **);
 
+/* pretty-print the <last></last> value for some.rrd via strftime() */
+char* printtimelast(long, char **);
+
 /* set an evironment variable */
 char* rrdsetenv(long, char **);
 
@@ -139,6 +142,7 @@
     i += parse(&buffer,i,"<RRD::SETENV ",rrdsetenv);
     i += parse(&buffer,i,"<RRD::GRAPH ",drawgraph);
     i += parse(&buffer,i,"<RRD::PRINT ",drawprint);
+    i += parse(&buffer,i,"<RRD::TIME::LAST ",printtimelast);
   }
 
   if (filter==0){
@@ -339,6 +343,23 @@
       return calcpr[atol(args[0])+1];    
   }
   return stralloc("[ERROR: RRD::PRINT argument error]");
+}
+
+char* printtimelast(long argc, char **args) {
+  time_t last;
+  struct tm tm_last;
+  char *buf;
+  if ( argc == 2 ) {
+    buf = malloc(255);
+    last = rrd_last(argc+1, args-1); 
+    tm_last = *localtime(&last);
+    strftime(buf,255,args[1],&tm_last);
+    return buf;
+  }
+  if ( argc < 2 ) {
+    return stralloc("[ERROR: too few arguments for RRD::TIME::LAST]");
+  }
+  return stralloc("[ERROR: not enough arguments for RRD::TIME::LAST]");
 }
 
 /* scan aLine until an unescaped '>' arives */


--
* To unsubscribe from the rrd-developers mailing list, send a message with the
  subject: unsubscribe to rrd-developers-request at list.ee.ethz.ch



More information about the rrd-developers mailing list