diff --git a/man/dhcpd-pools.1.in b/man/dhcpd-pools.1.in index 9964dd8..e55f5b6 100644 --- a/man/dhcpd-pools.1.in +++ b/man/dhcpd-pools.1.in @@ -161,6 +161,27 @@ is If critical percentage is not specified it defaults to .BR @ALARM_CRIT@ . .TP +\fB\-\-warn\-count\fR=\fInumber\fR +A +.I number +of free leases before alarm is raised. When specified both \-\-warning +.I percent +and count +.I number +are required to be exceeded in order to alarm criteria being fulfilled. +.IP +This option is intented to be used in setup where very large and small +shared-networks and ranges co-exists. In such environments percent based +alarming can lead to either flood of alarms about small ranges, or way too +great overhead of free addresses in large shared-networks. Suggested usage +is to set percentage to a level that makes small ranges to ring, and set the +count to match level when an enormous shared-network is too few free leases. +.IP +Defaults to 2^32, that is size of entire IPv4 address space. +.TP +\fB\-\-crit\-count\fR=\fInumber\fR +Same as \-\-warn\-count, but for critical alarms. +.TP \fB\-\-snet\-alarms Suppress range alarms that are part of shared networks. Use of this option will keep alarm criteria applied to ranges that are not part of shared-net diff --git a/src/dhcpd-pools.c b/src/dhcpd-pools.c index 3aef093..7b765d7 100644 --- a/src/dhcpd-pools.c +++ b/src/dhcpd-pools.c @@ -97,7 +97,9 @@ int main(int argc, char **argv) OPT_SNET_ALARMS = CHAR_MAX + 1, OPT_WARN, OPT_CRIT, - OPT_MINSIZE + OPT_MINSIZE, + OPT_WARN_COUNT, + OPT_CRIT_COUNT }; int ret_val; @@ -114,6 +116,8 @@ int main(int argc, char **argv) {"snet-alarms", no_argument, NULL, OPT_SNET_ALARMS}, {"warning", required_argument, NULL, OPT_WARN}, {"critical", required_argument, NULL, OPT_CRIT}, + {"warn-count", required_argument, NULL, OPT_WARN_COUNT}, + {"crit-count", required_argument, NULL, OPT_CRIT_COUNT}, {"minsize", required_argument, NULL, OPT_MINSIZE}, {NULL, 0, NULL, 0} }; @@ -132,6 +136,8 @@ int main(int argc, char **argv) config.snet_alarms = false; config.warning = ALARM_WARN; config.critical = ALARM_CRIT; + config.warn_count = 0x100000000; /* == 2^32 that is the entire IPv4 space */ + config.crit_count = 0x100000000; /* basically turns off the count criteria */ /* File location defaults */ strncpy(config.dhcpdconf_file, DHCPDCONF_FILE, MAXLEN - 1); strncpy(config.dhcpdlease_file, DHCPDLEASE_FILE, MAXLEN - 1); @@ -208,6 +214,14 @@ int main(int argc, char **argv) strcpy(config.output_format, "a"); config.critical = strtod_or_err(optarg, "illegal argument"); break; + case OPT_WARN_COUNT: + strcpy(config.output_format, "a"); + config.warn_count = strtod_or_err(optarg, "illegal argument"); + break; + case OPT_CRIT_COUNT: + strcpy(config.output_format, "a"); + config.crit_count = strtod_or_err(optarg, "illegal argument"); + break; case OPT_MINSIZE: config.minsize = strtod_or_err(optarg, "illegal argument"); break; diff --git a/src/dhcpd-pools.h b/src/dhcpd-pools.h index f24b150..79335fb 100644 --- a/src/dhcpd-pools.h +++ b/src/dhcpd-pools.h @@ -133,6 +133,8 @@ struct configuration_t { bool snet_alarms; double warning; double critical; + double warn_count; + double crit_count; double minsize; }; /*! \struct shared_network_t diff --git a/src/output.c b/src/output.c index 78a9cc7..0828646 100644 --- a/src/output.c +++ b/src/output.c @@ -1005,9 +1005,9 @@ int output_alarming(void) } if (config.minsize < range_size) { perc = (float)(100 * range_p->count) / range_size; - if (config.critical < perc) + if (config.critical < perc && (range_size - range_p->count) < config.crit_count) rc++; - else if (config.warning < perc) + else if (config.warning < perc && (range_size - range_p->count) < config.warn_count) rw++; else ro++; @@ -1025,9 +1025,9 @@ int output_alarming(void) perc = shared_p->available == 0 ? 100 : (float)(100 * shared_p->used) / shared_p->available; - if (config.critical < perc) + if (config.critical < perc && shared_p->available < config.crit_count) sc++; - else if (config.warning < perc) + else if (config.warning < perc && shared_p->available < config.warn_count) sw++; else so++;