From: oetiker Date: Wed, 17 Jan 2007 23:35:01 +0000 (+0000) Subject: finish integration of lastupdate commmand ... X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=1b9d3db37e1cdc2205bda742bd1818eb14ade84b;p=rrdtool.git finish integration of lastupdate commmand ... git-svn-id: svn://svn.oetiker.ch/rrdtool/branches/1.2/program@952 a5681a0c-68f1-0310-ab6d-d61299d08faa --- diff --git a/netware/Makefile b/netware/Makefile index df6a9b0..77fa960 100644 --- a/netware/Makefile +++ b/netware/Makefile @@ -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/src/rrd_lastupdate.c b/src/rrd_lastupdate.c new file mode 100644 index 0000000..3c0ab59 --- /dev/null +++ b/src/rrd_lastupdate.c @@ -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 + +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;ids_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); +} diff --git a/win32/Makefile b/win32/Makefile index 5c086a5..fada2c3 100644 --- a/win32/Makefile +++ b/win32/Makefile @@ -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 \