output: include earlier missing data to json output

This commit adds all the data that is in text output to json output.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
Sami Kerola 2017-11-05 20:03:59 +00:00
parent 344ed2900d
commit e079cc16e0
No known key found for this signature in database
GPG key ID: A9553245FDE9B739
2 changed files with 40 additions and 10 deletions

View file

@ -418,8 +418,8 @@ static int output_json(const int print_mac_addreses)
{ {
unsigned int i = 0; unsigned int i = 0;
struct range_t *range_p; struct range_t *range_p;
double range_size;
struct shared_network_t *shared_p; struct shared_network_t *shared_p;
struct output_helper_t oh;
int ret; int ret;
FILE *outfile; FILE *outfile;
unsigned int sep; unsigned int sep;
@ -434,7 +434,6 @@ static int output_json(const int print_mac_addreses)
} }
range_p = ranges; range_p = ranges;
range_size = get_range_size(range_p);
shared_p = shared_networks; shared_p = shared_networks;
sep = 0; sep = 0;
@ -470,6 +469,7 @@ static int output_json(const int print_mac_addreses)
} }
fprintf(outfile, " \"subnets\": [\n"); fprintf(outfile, " \"subnets\": [\n");
for (i = 0; i < num_ranges; i++) { for (i = 0; i < num_ranges; i++) {
range_output_helper(&oh, range_p);
fprintf(outfile, " "); fprintf(outfile, " ");
fprintf(outfile, "{ "); fprintf(outfile, "{ ");
if (range_p->shared_net) { if (range_p->shared_net) {
@ -481,12 +481,20 @@ static int output_json(const int print_mac_addreses)
fprintf(outfile, "\"range\":\"%s", ntop_ipaddr(&range_p->first_ip)); fprintf(outfile, "\"range\":\"%s", ntop_ipaddr(&range_p->first_ip));
fprintf(outfile, " - %s\", ", ntop_ipaddr(&range_p->last_ip)); fprintf(outfile, " - %s\", ", ntop_ipaddr(&range_p->last_ip));
fprintf(outfile, "\"defined\":%g, ", range_size); fprintf(outfile, "\"defined\":%g, ", oh.range_size);
fprintf(outfile, "\"used\":%g, ", range_p->count); fprintf(outfile, "\"used\":%g, ", range_p->count);
fprintf(outfile, "\"touched\":%g, ", range_p->touched); fprintf(outfile, "\"touched\":%g, ", range_p->touched);
fprintf(outfile, "\"free\":%g ", range_size - range_p->count); fprintf(outfile, "\"free\":%g, ", oh.range_size - range_p->count);
fprintf(outfile, "\"percent\":%g, ", oh.percent);
fprintf(outfile, "\"touch_count\":%g, ", oh.tc);
fprintf(outfile, "\"touch_percent\":%g, ", oh.tcp);
if (config.backups_found == 1) {
fprintf(outfile, "\"backup_count\":%g, ", range_p->backups);
fprintf(outfile, "\"backup_percent\":%g, ", oh.bup);
}
fprintf(outfile, "\"status\":%d ", oh.status);
range_p++; range_p++;
range_size = get_range_size(range_p);
if (i + 1 < num_ranges) if (i + 1 < num_ranges)
fprintf(outfile, "},\n"); fprintf(outfile, "},\n");
else else
@ -502,6 +510,7 @@ static int output_json(const int print_mac_addreses)
} }
fprintf(outfile, " \"shared-networks\": [\n"); fprintf(outfile, " \"shared-networks\": [\n");
for (i = 0; i < num_shared_networks; i++) { for (i = 0; i < num_shared_networks; i++) {
shnet_output_helper(&oh, shared_p);
fprintf(outfile, " "); fprintf(outfile, " ");
shared_p++; shared_p++;
fprintf(outfile, "{ "); fprintf(outfile, "{ ");
@ -509,7 +518,15 @@ static int output_json(const int print_mac_addreses)
fprintf(outfile, "\"defined\":%g, ", shared_p->available); fprintf(outfile, "\"defined\":%g, ", shared_p->available);
fprintf(outfile, "\"used\":%g, ", shared_p->used); fprintf(outfile, "\"used\":%g, ", shared_p->used);
fprintf(outfile, "\"touched\":%g, ", shared_p->touched); fprintf(outfile, "\"touched\":%g, ", shared_p->touched);
fprintf(outfile, "\"free\":%g ", shared_p->available - shared_p->used); fprintf(outfile, "\"free\":%g, ", shared_p->available - shared_p->used);
fprintf(outfile, "\"percent\":%g, ", oh.percent);
fprintf(outfile, "\"touch_count\":%g, ", oh.tc);
fprintf(outfile, "\"touch_percent\":%g, ", oh.tcp);
if (config.backups_found == 1) {
fprintf(outfile, "\"backup_count\":%g, ", shared_p->backups);
fprintf(outfile, "\"backup_percent\":%g, ", oh.bup);
}
fprintf(outfile, "\"status\":%d ", oh.status);
if (i + 1 < num_shared_networks) if (i + 1 < num_shared_networks)
fprintf(outfile, "},\n"); fprintf(outfile, "},\n");
else else
@ -520,6 +537,7 @@ static int output_json(const int print_mac_addreses)
} }
if (config.header_limit & A_BIT) { if (config.header_limit & A_BIT) {
shnet_output_helper(&oh, shared_networks);
if (sep) { if (sep) {
fprintf(outfile, ",\n"); fprintf(outfile, ",\n");
} }
@ -528,8 +546,16 @@ static int output_json(const int print_mac_addreses)
fprintf(outfile, " \"defined\":%g,\n", shared_networks->available); fprintf(outfile, " \"defined\":%g,\n", shared_networks->available);
fprintf(outfile, " \"used\":%g,\n", shared_networks->used); fprintf(outfile, " \"used\":%g,\n", shared_networks->used);
fprintf(outfile, " \"touched\":%g,\n", shared_networks->touched); fprintf(outfile, " \"touched\":%g,\n", shared_networks->touched);
fprintf(outfile, " \"free\":%g\n", fprintf(outfile, " \"free\":%g,\n",
shared_networks->available - shared_networks->used); shared_networks->available - shared_networks->used);
fprintf(outfile, " \"percent\":%g,\n", oh.percent);
fprintf(outfile, " \"touch_count\":%g,\n", oh.tc);
fprintf(outfile, " \"touch_percent\":%g,\n", oh.tcp);
if (config.backups_found == 1) {
fprintf(outfile, " \"backup_count\":%g,\n", shared_p->backups);
fprintf(outfile, " \"backup_percent\":%g,\n", oh.bup);
}
fprintf(outfile, " \"status\":%d\n", oh.status);
fprintf(outfile, " }"); /* end of summary */ fprintf(outfile, " }"); /* end of summary */
} }

View file

@ -3,7 +3,7 @@
{ "ip":"10.0.0.5", "macaddress":"00:00:00:00:00:00" } { "ip":"10.0.0.5", "macaddress":"00:00:00:00:00:00" }
], ],
"subnets": [ "subnets": [
{ "location":"All networks", "range":"10.0.0.1 - 10.0.0.10", "defined":10, "used":1, "touched":0, "free":9 } { "location":"All networks", "range":"10.0.0.1 - 10.0.0.10", "defined":10, "used":1, "touched":0, "free":9, "percent":10, "touch_count":1, "touch_percent":10, "status":0 }
], ],
"shared-networks": [ "shared-networks": [
], ],
@ -12,6 +12,10 @@
"defined":10, "defined":10,
"used":1, "used":1,
"touched":0, "touched":0,
"free":9 "free":9,
"percent":10,
"touch_count":1,
"touch_percent":10,
"status":0
} }
} }