|
|
@@ -62,8 +62,10 @@ void dp_events_stats(dp_conf *conf) { |
|
|
|
char tmpfile[PATH_MAX+4]; |
|
|
|
dp_dhcpv4_stats *stats4; |
|
|
|
dp_dhcpv6_stats *stats6; |
|
|
|
dp_blacklist *blacklists, *bl, *tmp; |
|
|
|
FILE *fh; |
|
|
|
int i; |
|
|
|
int first = 1; |
|
|
|
|
|
|
|
snprintf(tmpfile, sizeof(tmpfile), "%s.tmp", conf->stats_file); |
|
|
|
|
|
|
@@ -75,43 +77,47 @@ void dp_events_stats(dp_conf *conf) { |
|
|
|
fprintf(fh,"{ \"dhcpv4\": { "); |
|
|
|
|
|
|
|
for(i=0; i<DP_DHCPV4_CODE_LEN; i++) { |
|
|
|
if ( stats4->relcnt[i]>0 ) { |
|
|
|
if ( stats4->relcnt[i]>0 || stats4->abscnt[i]>0 ) { |
|
|
|
if ( !first ) fprintf(fh, ", "); |
|
|
|
fprintf(fh, "\"%s\": { ", dp_dhcpv4_code[i]); |
|
|
|
fprintf(fh, "\"rel\": %llu, \"abs\": %llu }", stats4->relcnt[i], stats4->abscnt[i]); |
|
|
|
first=0; |
|
|
|
} |
|
|
|
else if ( stats4->abscnt[i]>0 ) { |
|
|
|
fprintf(fh, "\"%s\": { ", dp_dhcpv4_code[i]); |
|
|
|
fprintf(fh, "\"abs\": %llu }", stats4->abscnt[i]); |
|
|
|
} |
|
|
|
|
|
|
|
if ( ( stats4->relcnt[i]>0 || stats4->abscnt[i]>0 ) && i+1 != DP_DHCPV4_CODE_LEN ) |
|
|
|
fprintf(fh, ", "); |
|
|
|
|
|
|
|
stats4->relcnt[i]=0; |
|
|
|
} |
|
|
|
|
|
|
|
first=1; |
|
|
|
|
|
|
|
stats6 = dp_dhcpv6_cnt(0); |
|
|
|
|
|
|
|
fprintf(fh, "}, \"dhcpv6\" : { "); |
|
|
|
|
|
|
|
for(i=0; i<DP_DHCPV6_CODE_LEN; i++) { |
|
|
|
if ( stats6->relcnt[i]>0 ) { |
|
|
|
if ( stats6->relcnt[i]>0 || stats6->abscnt[i]>0 ) { |
|
|
|
if ( !first ) fprintf(fh, ", "); |
|
|
|
fprintf(fh, "\"%s\": { ", dp_dhcpv6_code[i]); |
|
|
|
fprintf(fh, "\"rel\": %llu, \"abs\": %llu }", stats6->relcnt[i], stats6->abscnt[i]); |
|
|
|
} |
|
|
|
else if ( stats6->abscnt[i]>0 ) { |
|
|
|
fprintf(fh, "\"%s\": { ", dp_dhcpv6_code[i]); |
|
|
|
fprintf(fh, "\"abs\": %llu }", stats6->abscnt[i]); |
|
|
|
first=0; |
|
|
|
} |
|
|
|
|
|
|
|
if ( ( stats6->relcnt[i]>0 || stats6->abscnt[i]>0 ) && i+1 != DP_DHCPV6_CODE_LEN ) |
|
|
|
fprintf(fh, ", "); |
|
|
|
|
|
|
|
stats6->relcnt[i]=0; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fprintf(fh, "} }"); |
|
|
|
fprintf(fh, "}, \"blacklist\": ["); |
|
|
|
|
|
|
|
blacklists = dp_blacklist_get(); |
|
|
|
|
|
|
|
first=1; |
|
|
|
HASH_ITER(hh, blacklists, bl, tmp) { |
|
|
|
if ( bl->expire > time(NULL) ) { |
|
|
|
if ( !first ) fprintf(fh, ", "); |
|
|
|
fprintf(fh, "{ \"id\": \"%s\", \"expire\": %i }", dp_printid(bl->remoteid, bl->len), (int)(bl->expire - time(NULL))); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
fprintf(fh, "] }\n"); |
|
|
|
|
|
|
|
fclose(fh); |
|
|
|
|