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 <kerolasa@iki.fi>
This commit is contained in:
Sami Kerola 2013-07-12 19:18:24 +01:00
parent 4becf97fb3
commit 28f1e8c54c
5 changed files with 48 additions and 18 deletions

View file

@ -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

View file

@ -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();

View file

@ -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.

View file

@ -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\

View file

@ -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) {