From 28f1e8c54cf554e9e1ebcaa2346fbb70991aecc7 Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Fri, 12 Jul 2013 19:18:24 +0100 Subject: [PATCH] output: allow user to ignore small ranges and shared networks Some have configuration which combines small ranges such as one host, and greater address ranges that are important to monitor. Especially the one host ranges tend to cause a lot of false-positive alarms, as they are immediately 100% full when a machine requests an address. Signed-off-by: Sami Kerola --- man/dhcpd-pools.1.in | 6 ++++++ src/dhcpd-pools.c | 8 +++++++- src/dhcpd-pools.h | 1 + src/other.c | 3 ++- src/output.c | 48 +++++++++++++++++++++++++++++--------------- 5 files changed, 48 insertions(+), 18 deletions(-) diff --git a/man/dhcpd-pools.1.in b/man/dhcpd-pools.1.in index d75d81f..eeb7e99 100644 --- a/man/dhcpd-pools.1.in +++ b/man/dhcpd-pools.1.in @@ -159,6 +159,12 @@ is If critical percentage is not specified it defaults to .BR @ALARM_CRIT@ . .TP +\fB\-\-minsize\fR=\fIsize\f +Ignore ranges and shared networks that are smaller or equal to the +defined size. This option is meaningful only in context of alarming, and +will intented to supress for example single host ranges. By default this +option is not in use. +.TP \fB\-v\fR, \fB\-\-version\fR Print version information to standard output and exit successfully. .TP diff --git a/src/dhcpd-pools.c b/src/dhcpd-pools.c index 754f6fc..06641d6 100644 --- a/src/dhcpd-pools.c +++ b/src/dhcpd-pools.c @@ -72,7 +72,8 @@ int main(int argc, char **argv) struct range_t *tmp_ranges; enum { OPT_WARN = CHAR_MAX + 1, - OPT_CRIT + OPT_CRIT, + OPT_MINSIZE }; int ret_val; @@ -89,6 +90,7 @@ int main(int argc, char **argv) {"help", no_argument, NULL, 'h'}, {"warning", required_argument, NULL, OPT_WARN}, {"critical", required_argument, NULL, OPT_CRIT}, + {"minsize", required_argument, NULL, OPT_MINSIZE}, {NULL, 0, NULL, 0} }; @@ -192,6 +194,10 @@ int main(int argc, char **argv) config.critical = strtod_or_err(optarg, "illegal argument"); break; + case OPT_MINSIZE: + config.minsize = + strtod_or_err(optarg, "illegal argument"); + break; case 'v': /* Print version */ print_version(); diff --git a/src/dhcpd-pools.h b/src/dhcpd-pools.h index 0fb295c..3578319 100644 --- a/src/dhcpd-pools.h +++ b/src/dhcpd-pools.h @@ -110,6 +110,7 @@ struct configuration_t { bool backups_found; double warning; double critical; + double minsize; }; /*! \struct shared_network_t * \brief Counters for an individual shared network. diff --git a/src/other.c b/src/other.c index 397c697..e31b3bb 100644 --- a/src/other.c +++ b/src/other.c @@ -314,7 +314,8 @@ This is ISC dhcpd pools usage analyzer.\n\ -L, --limit=NR output limit mask 77 - 00\n"); fprintf(out, "\ --warning=PERC set warning alarming limit\n\ - --critical=PERC set critical alarming limit\n"); + --critical=PERC set critical alarming limit\n\ + --minsize=size disable alarms for small ranges and shared-nets\n"); fprintf(out, "\ -v, --version version information\n\ -h, --help this screen\n\ diff --git a/src/output.c b/src/output.c index e45acaf..bc94b74 100644 --- a/src/output.c +++ b/src/output.c @@ -1018,7 +1018,7 @@ int output_alarming(void) struct shared_network_t *shared_p; unsigned int i; float perc; - int rw = 0, rc = 0, ro = 0, sw = 0, sc = 0, so = 0; + int rw = 0, rc = 0, ro = 0, ri = 0, sw = 0, sc = 0, so = 0, si = 0; int ret_val, ret; range_p = ranges; @@ -1037,27 +1037,36 @@ int output_alarming(void) if (config.output_limit[1] & BIT1) { for (i = 0; i < num_ranges; i++) { - perc = (float)(100 * range_p->count) / range_size; - if (config.critical < perc) - rc++; - else if (config.warning < perc) - rw++; - else - ro++; + if (config.minsize < range_size) { + perc = + (float)(100 * range_p->count) / range_size; + if (config.critical < perc) + rc++; + else if (config.warning < perc) + rw++; + else + ro++; + } else { + ri++; + } range_p++; range_size = get_range_size(range_p); } } if (config.output_limit[1] & BIT2) { for (i = 0; i < num_shared_networks; i++) { - perc = (float)(100 * shared_p->used) / - shared_p->available; - if (config.critical < perc) - sc++; - else if (config.warning < perc) - sw++; - else - so++; + if (config.minsize < shared_p->available) { + perc = (float)(100 * shared_p->used) / + shared_p->available; + if (config.critical < perc) + sc++; + else if (config.warning < perc) + sw++; + else + so++; + } else { + si++; + } shared_p++; } } @@ -1079,10 +1088,17 @@ int output_alarming(void) if (config.output_limit[0] & BIT1) { fprintf(outfile, "Ranges; crit: %d warn: %d ok: %d ", rc, rw, ro); + if (ri != 0) { + fprintf(outfile, "ignored: %d ", ri); + } + } if (config.output_limit[0] & BIT2) { fprintf(outfile, "Shared nets; crit: %d warn: %d ok: %d", sc, sw, so); + if (si != 0) { + fprintf(outfile, "ignored: %d ", si); + } } fprintf(outfile, "\n"); if (outfile == stdout) {