diff --git a/man/dhcpd-pools.1.in b/man/dhcpd-pools.1.in index c7febb4..5541cfe 100644 --- a/man/dhcpd-pools.1.in +++ b/man/dhcpd-pools.1.in @@ -159,6 +159,12 @@ coloring thresholds can be changed, but one must also use .B \-\-format=text to avoid turning on alarting mode. .TP +\fB\-\-skip\-ok +Do not print ranges that are within thresholds of +.B \-\-warning +or +.BR \-\-critical . +.TP \fB\-\-warning\fR=\fIpercent\fR Turn on alarm output format, and specify percentage number which will cause an alarm. If either a range or shared network will exceed diff --git a/src/dhcpd-pools.c b/src/dhcpd-pools.c index 1edd9e9..2213ba8 100644 --- a/src/dhcpd-pools.c +++ b/src/dhcpd-pools.c @@ -111,6 +111,7 @@ int main(int argc, char **argv) OPT_WARN_COUNT, OPT_CRIT_COUNT, OPT_COLOR, + OPT_SKIP_OK, OPT_SET_IPV }; int ret_val; @@ -119,6 +120,7 @@ int main(int argc, char **argv) {"config", required_argument, NULL, 'c'}, {"leases", required_argument, NULL, 'l'}, {"color", required_argument, NULL, OPT_COLOR}, + {"skip-ok", no_argument, NULL, OPT_SKIP_OK}, {"format", required_argument, NULL, 'f'}, {"sort", required_argument, NULL, 's'}, {"reverse", no_argument, NULL, 'r'}, @@ -228,6 +230,9 @@ int main(int argc, char **argv) if (config.color_mode == color_unknown) error(EXIT_FAILURE, errno, "unknown color mode: %s", quote(optarg)); break; + case OPT_SKIP_OK: + config.skip_ok = 1; + break; case OPT_SNET_ALARMS: config.snet_alarms = 1; break; diff --git a/src/dhcpd-pools.h b/src/dhcpd-pools.h index b160094..d3b2d75 100644 --- a/src/dhcpd-pools.h +++ b/src/dhcpd-pools.h @@ -238,6 +238,7 @@ struct configuration_t { all_as_shared:1, header_limit:3, number_limit:3, + skip_ok:1, color_mode:2; }; diff --git a/src/output.c b/src/output.c index 6c1d67b..9a65144 100644 --- a/src/output.c +++ b/src/output.c @@ -189,6 +189,10 @@ static int output_txt(void) for (i = 0; i < num_ranges; i++) { int color_set = 0; range_output_helper(&oh, range_p); + if (config.skip_ok && oh.status == STATUS_OK) { + range_p++; + continue; + } if (config.color_mode == color_on) color_set = start_color(&oh, outfile); if (range_p->shared_net) { @@ -238,6 +242,8 @@ static int output_txt(void) int color_set = 0; shared_p++; shnet_output_helper(&oh, shared_p); + if (config.skip_ok && oh.status == STATUS_OK) + continue; if (config.color_mode == color_on) color_set = start_color(&oh, outfile); fprintf(outfile, @@ -317,6 +323,7 @@ static int output_xml(const int print_mac_addreses) struct range_t *range_p; double range_size; struct shared_network_t *shared_p; + struct output_helper_t oh; int ret; FILE *outfile; @@ -353,6 +360,11 @@ static int output_xml(const int print_mac_addreses) if (config.number_limit & R_BIT) { for (i = 0; i < num_ranges; i++) { + range_output_helper(&oh, range_p); + if (config.skip_ok && oh.status == STATUS_OK) { + range_p++; + continue; + } fprintf(outfile, "\n"); if (range_p->shared_net) { fprintf(outfile, @@ -375,6 +387,9 @@ static int output_xml(const int print_mac_addreses) if (config.number_limit & S_BIT) { for (i = 0; i < num_shared_networks; i++) { shared_p++; + shnet_output_helper(&oh, shared_p); + if (config.skip_ok && oh.status == STATUS_OK) + continue; fprintf(outfile, "\n"); fprintf(outfile, "\t%s\n", shared_p->name); fprintf(outfile, "\t%g\n", shared_p->available); @@ -470,6 +485,10 @@ static int output_json(const int print_mac_addreses) fprintf(outfile, " \"subnets\": [\n"); for (i = 0; i < num_ranges; i++) { range_output_helper(&oh, range_p); + if (config.skip_ok && oh.status == STATUS_OK) { + range_p++; + continue; + } fprintf(outfile, " "); fprintf(outfile, "{ "); if (range_p->shared_net) { @@ -510,9 +529,11 @@ static int output_json(const int print_mac_addreses) } fprintf(outfile, " \"shared-networks\": [\n"); for (i = 0; i < num_shared_networks; i++) { - shnet_output_helper(&oh, shared_p); - fprintf(outfile, " "); shared_p++; + shnet_output_helper(&oh, shared_p); + if (config.skip_ok && oh.status == STATUS_OK) + continue; + fprintf(outfile, " "); fprintf(outfile, "{ "); fprintf(outfile, "\"location\":\"%s\", ", shared_p->name); fprintf(outfile, "\"defined\":%g, ", shared_p->available); @@ -801,6 +822,8 @@ static int output_html(void) for (i = 0; i < num_shared_networks; i++) { shared_p++; shnet_output_helper(&oh, shared_networks); + if (config.skip_ok && oh.status == STATUS_OK) + continue; start_tag(outfile, "tr"); output_line(outfile, "td", shared_p->name); output_double(outfile, "td", shared_p->available); @@ -843,6 +866,10 @@ static int output_html(void) start_tag(outfile, "tbody"); for (i = 0; i < num_ranges; i++) { range_output_helper(&oh, range_p); + if (config.skip_ok && oh.status == STATUS_OK) { + range_p++; + continue; + } start_tag(outfile, "tr"); if (range_p->shared_net) { output_line(outfile, "td", range_p->shared_net->name); @@ -916,6 +943,10 @@ static int output_csv(void) if (config.number_limit & R_BIT) { for (i = 0; i < num_ranges; i++) { range_output_helper(&oh, range_p); + if (config.skip_ok && oh.status == STATUS_OK) { + range_p++; + continue; + } if (range_p->shared_net) { fprintf(outfile, "\"%s\",", range_p->shared_net->name); } else { @@ -956,6 +987,8 @@ static int output_csv(void) for (i = 0; i < num_shared_networks; i++) { shared_p++; shnet_output_helper(&oh, shared_p); + if (config.skip_ok && oh.status == STATUS_OK) + continue; fprintf(outfile, "\"%s\",\"%g\",\"%g\",\"%.3f\",\"%g\",\"%g\",\"%.3f\"", shared_p->name,