diff --git a/src/dhcpd-pools.c b/src/dhcpd-pools.c index fc835c9..89070e2 100644 --- a/src/dhcpd-pools.c +++ b/src/dhcpd-pools.c @@ -120,6 +120,7 @@ int main(int argc, char **argv) /* Default sort order is by IPs small to big */ config.reverse_order = false; + config.backups_found = false; /* Parse command line options */ while (1) { diff --git a/src/dhcpd-pools.h b/src/dhcpd-pools.h index 65d5d06..a429398 100644 --- a/src/dhcpd-pools.h +++ b/src/dhcpd-pools.h @@ -44,6 +44,7 @@ # include # include +# include # include # include # include @@ -101,6 +102,7 @@ struct configuration_t { int reverse_order; char *output_file; int output_limit[2]; + bool backups_found; double warning; double critical; }; @@ -173,12 +175,6 @@ struct range_t *ranges; unsigned int num_ranges; /* \var leases Pointer holding all leases. */ struct leases_t *leases; -/* \var num_leases FIXME: not in use, remove */ -unsigned long int num_leases; -/* \var num_touches FIXME: not in use, remove */ -unsigned long int num_touches; -/* \var num_backups FIXME: not in use, remove */ -unsigned long int num_backups; /* Function prototypes */ int prepare_memory(void); diff --git a/src/getdata.c b/src/getdata.c index 661bdb7..bbd17bf 100644 --- a/src/getdata.c +++ b/src/getdata.c @@ -99,8 +99,6 @@ int parse_leases(void) int ethernets = false; struct leases_t *lease; - num_touches = num_leases = num_backups = 0; - dhcpd_leases = fopen(config.dhcpdlease_file, "r"); if (dhcpd_leases == NULL) { err(EXIT_FAILURE, "parse_leases: %s", config.dhcpdlease_file); @@ -180,6 +178,7 @@ int parse_leases(void) delete_lease(lease); } add_lease(&addr, BACKUP); + config.backups_found = true; continue; } if (ethernets && (xstrstr(line, " hardware ethernet", 19))) { diff --git a/src/output.c b/src/output.c index 809ec23..36ba850 100644 --- a/src/output.c +++ b/src/output.c @@ -45,6 +45,7 @@ #include #include #include +#include #include #include #include @@ -90,7 +91,7 @@ int output_txt(void) max_ipaddr_length, "last ip", "max", "cur", "percent", "touch", "t+c", "t+c perc"); - if (0 < num_backups) { + if (config.backups_found == true) { fprintf(outfile, " bu bu perc"); } fprintf(outfile, "\n"); @@ -121,7 +122,7 @@ int output_txt(void) (float)(100 * (range_p->touched + range_p->count)) / range_size); - if (0 < num_backups) { + if (config.backups_found == true) { fprintf(outfile, "%7lu %8.3f", range_p->backups, (float)(100 * range_p->backups) / @@ -140,7 +141,7 @@ int output_txt(void) fprintf(outfile, "Shared networks:\n"); fprintf(outfile, "name max cur percent touch t+c t+c perc"); - if (0 < num_backups) { + if (config.backups_found == true) { fprintf(outfile, " bu bu perc"); } fprintf(outfile, "\n"); @@ -159,7 +160,7 @@ int output_txt(void) (shared_p->touched + shared_p->used)) / shared_p->available); - if (0 < num_backups) { + if (config.backups_found == true) { fprintf(outfile, "%7lu %8.3f", shared_p->backups, (float)(100 * shared_p->backups) / @@ -178,7 +179,7 @@ int output_txt(void) fprintf(outfile, "name max cur percent touch t+c t+c perc"); - if (0 < num_backups) { + if (config.backups_found == true) { fprintf(outfile, " bu bu perc"); } fprintf(outfile, "\n"); @@ -197,7 +198,7 @@ int output_txt(void) shared_networks->used)) / shared_networks->available); - if (0 < num_backups) { + if (config.backups_found == true) { fprintf(outfile, "%7lu %8.3f", shared_networks->backups, (float)(100 * shared_networks->backups) / @@ -710,7 +711,7 @@ int output_html(void) output_line(outfile, "th", "ralign", "touch"); output_line(outfile, "th", "ralign", "t+c"); output_line(outfile, "th", "ralign", "t+c perc"); - if (0 < num_backups) { + if (config.backups_found == true) { output_line(outfile, "th", "ralign", "bu"); output_line(outfile, "th", "ralign", "bu perc"); } @@ -742,7 +743,7 @@ int output_html(void) (float)(100 * (range_p->touched + range_p->count)) / range_size); - if (0 < num_backups) { + if (config.backups_found == true) { output_long(outfile, "td", range_p->backups); output_float(outfile, "td", (float)(100 * @@ -766,7 +767,7 @@ int output_html(void) output_line(outfile, "th", "ralign", "touch"); output_line(outfile, "th", "ralign", "t+c"); output_line(outfile, "th", "ralign", "t+c perc"); - if (0 < num_backups) { + if (config.backups_found == true) { output_line(outfile, "th", "ralign", "bu"); output_line(outfile, "th", "ralign", "bu perc"); } @@ -790,7 +791,7 @@ int output_html(void) (shared_p->touched + shared_p->used)) / shared_p->available); - if (0 < num_backups) { + if (config.backups_found == true) { output_long(outfile, "td", shared_p->backups); output_float(outfile, "td", (float)(100 * @@ -811,7 +812,7 @@ int output_html(void) output_line(outfile, "th", "ralign", "touch"); output_line(outfile, "th", "ralign", "t+c"); output_line(outfile, "th", "ralign", "t+c perc"); - if (0 < num_backups) { + if (config.backups_found == true) { output_line(outfile, "th", "ralign", "bu"); output_line(outfile, "th", "ralign", "bu perc"); } @@ -834,7 +835,7 @@ int output_html(void) (shared_networks->touched + shared_networks->used)) / shared_networks->available); - if (0 < num_backups) { + if (config.backups_found == true) { output_long(outfile, "td", shared_networks->backups); output_float(outfile, "td", (float)(100 * @@ -889,7 +890,7 @@ int output_csv(void) fprintf (outfile, "\"shared net name\",\"first ip\",\"last ip\",\"max\",\"cur\",\"percent\",\"touch\",\"t+c\",\"t+c perc\""); - if (0 < num_backups) { + if (config.backups_found == true) { fprintf(outfile, ",\"bu\",\"bu perc\""); } fprintf(outfile, "\n"); @@ -914,7 +915,7 @@ int output_csv(void) (float)(100 * (range_p->touched + range_p->count)) / range_size); - if (0 < num_backups) { + if (config.backups_found == true) { fprintf(outfile, ",\"%lu\",\"%.3f\"", range_p->backups, (float)(100 * range_p->backups) / @@ -931,7 +932,7 @@ int output_csv(void) fprintf(outfile, "\"Shared networks:\"\n"); fprintf(outfile, "\"name\",\"max\",\"cur\",\"percent\",\"touch\",\"t+c\",\"t+c perc\""); - if (0 < num_backups) { + if (config.backups_found == true) { fprintf(outfile, ",\"bu\",\"bu perc\""); } fprintf(outfile, "\n"); @@ -951,7 +952,7 @@ int output_csv(void) (shared_p->touched + shared_p->used)) / shared_p->available); - if (0 < num_backups) { + if (config.backups_found == true) { fprintf(outfile, ",\"%lu\",\"%.3f\"", shared_p->backups, (float)(100 * shared_p->backups) / @@ -966,7 +967,7 @@ int output_csv(void) fprintf(outfile, "\"Sum of all ranges:\"\n"); fprintf(outfile, "\"name\",\"max\",\"cur\",\"percent\",\"touch\",\"t+c\",\"t+c perc\""); - if (0 < num_backups) { + if (config.backups_found == true) { fprintf(outfile, ",\"bu\",\"bu perc\""); } fprintf(outfile, "\n"); @@ -985,7 +986,7 @@ int output_csv(void) (shared_networks->touched + shared_networks->used)) / shared_networks->available); - if (0 < num_backups) { + if (config.backups_found == true) { fprintf(outfile, "%7lu %8.3f", shared_networks->backups, (float)(100 * shared_networks->backups) /