- Fix: JSON output syntax during first day of newly created databases
(pull request by Stefan Merettig)
- - Add optional mode parameter to --json for limiting the output to only
- selected information
+ - Add optional mode parameter to --json and --xml for limiting the output
+ to only selected information
1.13 / 18-Jan-2015
.B \-\-weeks
] [
.B \-\-xml
+.I mode
]
.SH DESCRIPTION
Show traffic for 7 days, current and previous week.
.TP
-.B "--xml"
+.BI "--xml " mode
Show database content for selected interface or all interfaces in xml format. All
-traffic values in the output are in KiB.
+traffic values in the output are in KiB. An optional
+.I mode
+parameter can be used for limiting the output to only selected information.
+Everything is shown by default. Setting
+.I mode
+to 'h' will output only hours, 'd' days, 'm' months and 't' the top 10.
.TP
.B "-?, --help"
#include "common.h"
#include "dbxml.h"
-void showxml(void)
+void showxml(char mode)
{
printf(" <interface id=\"%s\">\n", data.interface);
printf(" <traffic>\n");
printf(" <total><rx>%"PRIu64"</rx><tx>%"PRIu64"</tx></total>\n", (data.totalrx*1024)+data.totalrxk, (data.totaltx*1024)+data.totaltxk);
- xmldays();
- xmlmonths();
- xmltops();
- xmlhours();
+ switch (mode) {
+ case 'd':
+ xmldays();
+ break;
+ case 'm':
+ xmlmonths();
+ break;
+ case 't':
+ xmltops();
+ break;
+ case 'h':
+ xmlhours();
+ break;
+ case 'a':
+ default:
+ xmldays();
+ printf(",");
+ xmlmonths();
+ printf(",");
+ xmltops();
+ printf(",");
+ xmlhours();
+ break;
+ }
printf(" </traffic>\n");
printf(" </interface>\n");
#ifndef DBXML_H
#define DBXML_H
-void showxml(void);
+void showxml(char mode);
void xmldays(void);
void xmlmonths(void);
void xmltops(void);
} else if (strcmp(argv[currentarg],"--oneline")==0) {
cfg.qmode=9;
} else if (strcmp(argv[currentarg],"--xml")==0) {
+ if (currentarg+1<argc && argv[currentarg+1][0]!='-') {
+ p.xmlmode = argv[currentarg+1][0];
+ if (strlen(argv[currentarg+1])!=1 || strchr("ahdmt", p.xmlmode)==NULL) {
+ printf("Error: Invalid mode parameter \"%s\" for --xml.\n", argv[currentarg+1]);
+ printf(" Valid parameters:\n");
+ printf(" a - all (default)\n");
+ printf(" h - only hours\n");
+ printf(" d - only days\n");
+ printf(" m - only months\n");
+ printf(" t - only top 10\n");
+ return 1;
+ }
+ currentarg++;
+ }
cfg.qmode=8;
} else if (strcmp(argv[currentarg],"--json")==0) {
if (currentarg+1<argc && argv[currentarg+1][0]!='-') {
+ p.jsonmode = argv[currentarg+1][0];
if (strlen(argv[currentarg+1])!=1 || strchr("ahdmt", p.jsonmode)==NULL) {
printf("Error: Invalid mode parameter \"%s\" for --json.\n", argv[currentarg+1]);
printf(" Valid parameters:\n");
printf(" t - only top 10\n");
return 1;
}
- p.jsonmode = argv[currentarg+1][0];
currentarg++;
}
cfg.qmode=10;
p->ifacelist = NULL;
p->cfgfile[0] = '\0';
p->jsonmode = 'a';
+ p->xmlmode = 'a';
}
int synccounters(const char *iface, const char *dirname)
if (cfg.qmode==0) {
showdb(5);
} else if (cfg.qmode==8) {
- showxml();
+ showxml(p->xmlmode);
} else if (cfg.qmode==10) {
showjson(dbcount, p->jsonmode);
}
showdb(cfg.qmode);
} else if (cfg.qmode==8) {
xmlheader();
- showxml();
+ showxml(p->xmlmode);
xmlfooter();
} else if (cfg.qmode==10) {
jsonheader();
int create, active, files, force, cleartop, rebuildtotal, traffic;
int livetraffic, defaultiface, delete, livemode;
char interface[32], dirname[512], nick[32], filename[512];
- char definterface[32], cfgfile[512], *ifacelist, jsonmode;
+ char definterface[32], cfgfile[512], *ifacelist, jsonmode, xmlmode;
} PARAMS;
void initparams(PARAMS *p);