Code

finish integration of lastupdate commmand ...
authoroetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa>
Wed, 17 Jan 2007 23:35:01 +0000 (23:35 +0000)
committeroetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa>
Wed, 17 Jan 2007 23:35:01 +0000 (23:35 +0000)
git-svn-id: svn://svn.oetiker.ch/rrdtool/branches/1.2@952 a5681a0c-68f1-0310-ab6d-d61299d08faa

program/netware/Makefile
program/src/rrd_lastupdate.c [new file with mode: 0644]
program/win32/Makefile

index df6a9b0694154b4e684028583d18ee2e6c85dce2..77fa960282d54a55571c403ea8b8445c700fc584 100644 (file)
@@ -207,6 +207,7 @@ RRDLIBOBJS  = \
        $(OBJDIR)/rrd_hw.o \
        $(OBJDIR)/rrd_info.o \
        $(OBJDIR)/rrd_last.o \
+       $(OBJDIR)/rrd_lastupdate.o \
        $(OBJDIR)/rrd_nan_inf.o \
        $(OBJDIR)/rrd_open.o \
        $(OBJDIR)/rrd_resize.o \
diff --git a/program/src/rrd_lastupdate.c b/program/src/rrd_lastupdate.c
new file mode 100644 (file)
index 0000000..3c0ab59
--- /dev/null
@@ -0,0 +1,54 @@
+/*****************************************************************************
+ * RRDtool 1.2.15  Copyright by Tobi Oetiker, 1997-2006
+ *****************************************************************************
+ * rrd_lastupdate  Get the last datum entered for each DS
+ *****************************************************************************/
+
+#include "rrd_tool.h"
+#include "rrd_rpncalc.h"
+#include <stdarg.h>
+
+int
+rrd_lastupdate(int argc, char **argv, time_t *last_update,
+                 unsigned long *ds_cnt, char ***ds_namv, char ***last_ds) {
+    unsigned long i=0;
+    char        *filename;
+    FILE         *in_file;
+    rrd_t        rrd;
+
+    if(argc < 2){
+        rrd_set_error("please specify an rrd");
+        return -1;
+    }
+    filename = argv[1];
+
+    if(rrd_open(filename,&in_file,&rrd, RRD_READONLY)==-1){
+       return(-1);
+    }
+    fclose(in_file);
+
+    *last_update=rrd.live_head->last_up;
+    *ds_cnt = rrd.stat_head->ds_cnt;
+    if (((*ds_namv) =
+               (char **) malloc(rrd.stat_head->ds_cnt * sizeof(char*)))==NULL){
+        rrd_set_error("malloc fetch ds_namv array");
+       rrd_free(&rrd);
+       return(-1);
+    } 
+
+    if (((*last_ds) =
+               (char **) malloc(rrd.stat_head->ds_cnt * sizeof(char*)))==NULL){
+        rrd_set_error("malloc fetch last_ds array");
+       rrd_free(&rrd);
+       free(*ds_namv);
+       return(-1);
+    } 
+
+    for(i=0;i<rrd.stat_head->ds_cnt;i++){
+       (*ds_namv)[i] = sprintf_alloc("%s", rrd.ds_def[i].ds_nam);
+       (*last_ds)[i] = sprintf_alloc("%s", rrd.pdp_prep[i].last_ds);
+    }
+
+    rrd_free(&rrd);
+    return(0); 
+}
index 5c086a580d058bead5052a714a492e089f032e4a..fada2c3363be36c52bd41e2a4cdb325588ba6bf8 100644 (file)
@@ -152,6 +152,7 @@ RRDLIBOBJS  = \
        $(OBJDIR)/rrd_hw.o \
        $(OBJDIR)/rrd_info.o \
        $(OBJDIR)/rrd_last.o \
+       $(OBJDIR)/rrd_lastupdate.o \
        $(OBJDIR)/rrd_nan_inf.o \
        $(OBJDIR)/rrd_open.o \
        $(OBJDIR)/rrd_resize.o \