1 /*****************************************************************************
2 * RRDtool 1.2.23 Copyright by Tobi Oetiker, 1997-2007
3 *****************************************************************************
4 * rrd_lastupdate Get the last datum entered for each DS
5 *****************************************************************************/
7 #include "rrd_tool.h"
8 #include "rrd_rpncalc.h"
9 #include <stdarg.h>
11 int
12 rrd_lastupdate(int argc, char **argv, time_t *last_update,
13 unsigned long *ds_cnt, char ***ds_namv, char ***last_ds) {
14 unsigned long i=0;
15 char *filename;
16 rrd_t rrd;
17 rrd_file_t* rrd_file;
19 if(argc < 2){
20 rrd_set_error("please specify an rrd");
21 return -1;
22 }
23 filename = argv[1];
25 rrd_file = rrd_open(filename, &rrd, RRD_READONLY);
26 if (rrd_file == NULL)
27 return(-1);
29 *last_update=rrd.live_head->last_up;
30 *ds_cnt = rrd.stat_head->ds_cnt;
31 if (((*ds_namv) =
32 (char **) malloc(rrd.stat_head->ds_cnt * sizeof(char*)))==NULL){
33 rrd_set_error("malloc fetch ds_namv array");
34 rrd_free(&rrd);
35 return(-1);
36 }
38 if (((*last_ds) =
39 (char **) malloc(rrd.stat_head->ds_cnt * sizeof(char*)))==NULL){
40 rrd_set_error("malloc fetch last_ds array");
41 rrd_free(&rrd);
42 free(*ds_namv);
43 return(-1);
44 }
46 for(i=0;i<rrd.stat_head->ds_cnt;i++){
47 (*ds_namv)[i] = sprintf_alloc("%s", rrd.ds_def[i].ds_nam);
48 (*last_ds)[i] = sprintf_alloc("%s", rrd.pdp_prep[i].last_ds);
49 }
51 rrd_free(&rrd);
52 rrd_close(rrd_file);
53 return(0);
54 }