]> granicus.if.org Git - vnstat/commitdiff
add data time range to image output
authorTeemu Toivola <git@humdi.net>
Sat, 24 Mar 2018 17:53:23 +0000 (19:53 +0200)
committerTeemu Toivola <git@humdi.net>
Sat, 24 Mar 2018 17:53:23 +0000 (19:53 +0200)
src/image.c
src/image.h
src/vnstati.c

index 32fc525a23ff0e00634ef4be7b0bd6abfabd6e4e..92df829cfa0944caa5506bd28dbf1b1b771e0439 100644 (file)
@@ -11,6 +11,8 @@ void initimagecontent(IMAGECONTENT *ic)
        ic->showlegend = 1;
        ic->altdate = 0;
        ic->headertext[0] = '\0';
+       ic->databegin[0] = '\0';
+       ic->dataend[0] = '\0';
 }
 
 void drawimage(IMAGECONTENT *ic)
@@ -467,6 +469,9 @@ void drawlist(IMAGECONTENT *ic, const char *listname)
                strncpy_nt(stampformat, cfg.tformat, 64);
                limit = cfg.listtop;
                offsetx = 30;
+               /* TODO: should data range selection be supported here? */
+               ic->databegin[0] = '\0';
+               ic->dataend[0] = '\0';
        } else if (strcmp(listname, "hour") == 0) {
                listtype = 5;
                strncpy_nt(colname, listname, 8);
@@ -490,7 +495,7 @@ void drawlist(IMAGECONTENT *ic, const char *listname)
        daybuff[0] = '\0';
        e_rx = e_tx = 0;
 
-       if (!db_getdata(&datalist, &datainfo, ic->interface.name, listname, (uint32_t)limit)) {
+       if (!db_getdata_range(&datalist, &datainfo, ic->interface.name, listname, (uint32_t)limit, ic->databegin, ic->dataend)) {
                printf("Error: Failed to fetch %s data.\n", "day");
                return;
        }
index f2fc1cb623154ce32e9fc003793edc1db1848f28..cfd92bac2038b75f9342671bf2a4a4277da122af 100644 (file)
@@ -21,7 +21,7 @@ typedef struct {
        interfaceinfo interface;
        int cbackground, cedge, cheader, cheadertitle, cheaderdate, ctext, cline, clinel, cvnstat;
        int crx, crxd, ctx, ctxd, cbgoffset, showheader, showedge, showlegend, altdate;
-       char headertext[65];
+       char headertext[65], databegin[18], dataend[18];
        time_t current;
 } IMAGECONTENT;
 
index b30e6c72332cf1e9db63d146f27d0367c67f60a0..ee1046c25a3ae15046f9d6e70da5021241dec08f 100644 (file)
@@ -19,6 +19,7 @@ vnStat image output - Copyright (c) 2007-2018 Teemu Toivola <tst@iki.fi>
 #include "dbsql.h"
 #include "image.h"
 #include "cfg.h"
+#include "misc.h"
 #include "vnstati.h"
 
 int main(int argc, char *argv[])
@@ -265,6 +266,30 @@ int main(int argc, char *argv[])
                                if (debug)
                                        printf("Rateunit changed: %d\n", cfg.rateunit);
                        }
+               } else if ((strcmp(argv[currentarg],"-b")==0) || (strcmp(argv[currentarg],"--begin")==0)) {
+                       if (currentarg+1<argc) {
+                               if (!validatedatetime(argv[currentarg+1])) {
+                                       printf("Error: Invalid date format, expected YYYY-MM-DD HH:MM, YYYY-MM-DD or YYYY-MM.\n");
+                                       return 1;
+                               }
+                               strncpy_nt(ic.databegin, argv[currentarg+1], 18);
+                               currentarg++;
+                       } else {
+                               printf("Error: Date for %s missing.\n", argv[currentarg]);
+                               return 1;
+                       }
+               } else if ((strcmp(argv[currentarg],"-e")==0) || (strcmp(argv[currentarg],"--end")==0)) {
+                       if (currentarg+1<argc) {
+                               if (!validatedatetime(argv[currentarg+1])) {
+                                       printf("Error: Invalid date format, expected YYYY-MM-DD HH:MM, YYYY-MM-DD or YYYY-MM.\n");
+                                       return 1;
+                               }
+                               strncpy_nt(ic.dataend, argv[currentarg+1], 18);
+                               currentarg++;
+                       } else {
+                               printf("Error: Date for %s missing.\n", argv[currentarg]);
+                               return 1;
+                       }
                } else if ((strcmp(argv[currentarg],"-v")==0) || (strcmp(argv[currentarg],"--version"))==0) {
                        printf("vnStat image output %s by Teemu Toivola <tst at iki dot fi>\n", getversion());
                        return 0;