diff --git a/THANKS b/THANKS index 1302c03..8375381 100644 --- a/THANKS +++ b/THANKS @@ -38,3 +38,4 @@ Martijn van Brummelen Anton Tkachev Derrick Lin Ivanov Ivan +Manuel Hachtkemper diff --git a/man/dhcpd-pools.1.in b/man/dhcpd-pools.1.in index df78f84..88794d8 100644 --- a/man/dhcpd-pools.1.in +++ b/man/dhcpd-pools.1.in @@ -192,6 +192,12 @@ 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\-p\fR, \fB\-\-perfdata\fR +Print additional performance data, like lease count, touched leases and +backup leases. This option is meaningful only in context of alarming and +will print lots of data, if there are many networks. 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 d7f57f0..e3b775a 100644 --- a/src/dhcpd-pools.c +++ b/src/dhcpd-pools.c @@ -129,6 +129,7 @@ int main(int argc, char **argv) {"warn-count", required_argument, NULL, OPT_WARN_COUNT}, {"crit-count", required_argument, NULL, OPT_CRIT_COUNT}, {"minsize", required_argument, NULL, OPT_MINSIZE}, + {"perfdata", no_argument, NULL, 'p'}, {NULL, 0, NULL, 0} }; @@ -148,6 +149,7 @@ int main(int argc, char **argv) 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 */ + config.perfdata = false; /* File location defaults */ strncpy(config.dhcpdconf_file, DHCPDCONF_FILE, MAXLEN - 1); strncpy(config.dhcpdlease_file, DHCPDLEASE_FILE, MAXLEN - 1); @@ -165,7 +167,7 @@ int main(int argc, char **argv) while (1) { int c; - c = getopt_long(argc, argv, "c:l:f:o:s:rL:vh", long_options, &option_index); + c = getopt_long(argc, argv, "c:l:f:o:s:rL:pvh", long_options, &option_index); if (c == EOF) break; switch (c) { @@ -235,6 +237,10 @@ int main(int argc, char **argv) case OPT_MINSIZE: config.minsize = strtod_or_err(optarg, "illegal argument"); break; + case 'p': + /* Print additional performance data in alarming mode */ + config.perfdata = true; + break; case 'v': /* Print version */ print_version(); diff --git a/src/dhcpd-pools.h b/src/dhcpd-pools.h index c20b72f..4415d62 100644 --- a/src/dhcpd-pools.h +++ b/src/dhcpd-pools.h @@ -210,6 +210,7 @@ struct configuration_t { backups_found:1, snet_alarms:1, print_mac_addreses:1, + perfdata:1, header_limit:3, number_limit:3; }; diff --git a/src/other.c b/src/other.c index cd2cb3a..5e54367 100644 --- a/src/other.c +++ b/src/other.c @@ -474,6 +474,7 @@ void __attribute__ ((__noreturn__)) usage(int status) fputs( " --crit-count=NR a number of free leases before critical raised\n", out); fputs( " --minsize=size disable alarms for small ranges and shared-nets\n", out); fputs( " --snet-alarms suppress range alarms that are part of a shared-net\n", out); + fputs( " -p --perfdata print additional perfdata in alarming mode\n", out); fputs( " -v, --version output version information and exit\n", out); fputs( " -h, --help display this help and exit\n", out); fputs( "\n", out); diff --git a/src/output.c b/src/output.c index e220243..35af873 100644 --- a/src/output.c +++ b/src/output.c @@ -1014,6 +1014,29 @@ int output_alarming(void) if (ri != 0) { fprintf(outfile, " range_ignored=%d", ri); } + if (config.perfdata == 1 && config.number_limit & R_BIT) { + for (i = 0; i < num_ranges; i++) { + range_p--; + range_size = get_range_size(range_p); + if (config.minsize < range_size) { + fprintf(outfile, " %s_r=", + ntop_ipaddr(&range_p->first_ip)); + fprintf(outfile, "%g;%g;%g;0;%g", + range_p->count, + (range_size * config.warning / 100), + (range_size * config.critical / 100), + range_size); + fprintf(outfile, " %s_rt=%g", + ntop_ipaddr(&range_p->first_ip), + range_p->touched); + if (config.backups_found == 1) { + fprintf(outfile, " %s_rbu=%g", + ntop_ipaddr(&range_p->first_ip), + range_p->backups); + } + } + } + } fprintf(outfile, "\n"); } else { fprintf(outfile, " "); @@ -1025,7 +1048,29 @@ int output_alarming(void) } fprintf(outfile, "; | snet_crit=%d snet_warn=%d snet_ok=%d", sc, sw, so); if (si != 0) { - fprintf(outfile, " snet_ignored=%d\n", si); + fprintf(outfile, " snet_ignored=%d", si); + } + if (config.perfdata == 1 && config.header_limit & R_BIT) { + for (i = 0; i < num_shared_networks; i++) { + if (config.minsize < shared_p->available) { + fprintf(outfile, " '%s_s'=%g;%g;%g;0;%g", + shared_p->name, + shared_p->used, + (shared_p->available * config.warning / 100), + (shared_p->available * config.critical / 100), + shared_p->available); + fprintf(outfile, " '%s_st'=%g", + shared_p->name, + shared_p->touched); + if (config.backups_found == 1) { + fprintf(outfile, " '%s_sbu'=%g", + shared_p->name, + shared_p->backups); + } + } + shared_p--; + } + fprintf(outfile, "\n"); } } fprintf(outfile, "\n"); diff --git a/tests/Makemodule.am b/tests/Makemodule.am index 12d6907..46bac47 100644 --- a/tests/Makemodule.am +++ b/tests/Makemodule.am @@ -13,6 +13,7 @@ TESTS = \ tests/big-small \ tests/bootp \ tests/complete \ + tests/complete-perfdata \ tests/empty \ tests/full-json \ tests/full-xml \ @@ -22,7 +23,8 @@ TESTS = \ tests/same-twice \ tests/simple \ tests/sorts \ - tests/v6 + tests/v6 \ + tests/v6-perfdata EXTRA_DIST += \ tests/confs \ diff --git a/tests/complete-perfdata b/tests/complete-perfdata new file mode 100755 index 0000000..2765fd4 --- /dev/null +++ b/tests/complete-perfdata @@ -0,0 +1,16 @@ +#!/bin/sh +# +# Minimal regression test suite. + +IAM=$(basename $0) +TESTDATA=${IAM%-*} + +if [ ! -d tests/outputs ]; then + mkdir tests/outputs +fi + +dhcpd-pools -c $top_srcdir/tests/confs/$TESTDATA \ + -l $top_srcdir/tests/leases/$TESTDATA -o tests/outputs/$IAM \ + --warning 80 --perfdata +diff -u $top_srcdir/tests/expected/$IAM tests/outputs/$IAM +exit $? diff --git a/tests/expected/alarm-count-option b/tests/expected/alarm-count-option index 5b00b83..a535df7 100644 --- a/tests/expected/alarm-count-option +++ b/tests/expected/alarm-count-option @@ -9,7 +9,6 @@ Shared nets - crit: 1 warn: 0 ok: 1; | snet_crit=1 snet_warn=0 snet_ok=1 == minsize == OK: Ranges - crit: 0 warn: 0 ok: 0 ignored: 5; | range_crit=0 range_warn=0 range_ok=0 range_ignored=5 Shared nets - crit: 0 warn: 0 ok: 0 ignored: 2; | snet_crit=0 snet_warn=0 snet_ok=0 snet_ignored=2 - 0 == snet alarms == WARNING: dhcpd-pools: Ranges - crit: 0 warn: 0 ok: 0; | range_crit=0 range_warn=0 range_ok=0 diff --git a/tests/expected/complete-perfdata b/tests/expected/complete-perfdata new file mode 100644 index 0000000..d9219e9 --- /dev/null +++ b/tests/expected/complete-perfdata @@ -0,0 +1,3 @@ +OK: Ranges - crit: 0 warn: 0 ok: 5; | range_crit=0 range_warn=0 range_ok=5 10.4.0.1_r=5;16;18;0;20 10.4.0.1_rt=0 10.3.0.1_r=9;16;18;0;20 10.3.0.1_rt=0 10.2.0.1_r=8;16;18;0;20 10.2.0.1_rt=0 10.1.0.1_r=10;16;18;0;20 10.1.0.1_rt=0 10.0.0.1_r=11;16;18;0;20 10.0.0.1_rt=0 +Shared nets - crit: 0 warn: 0 ok: 2; | snet_crit=0 snet_warn=0 snet_ok=2 'example2_s'=17;32;36;0;40 'example2_st'=0 'example1_s'=21;32;36;0;40 'example1_st'=0 + diff --git a/tests/expected/v6-perfdata b/tests/expected/v6-perfdata new file mode 100644 index 0000000..50ea786 --- /dev/null +++ b/tests/expected/v6-perfdata @@ -0,0 +1,3 @@ +OK: Ranges - crit: 0 warn: 0 ok: 2; | range_crit=0 range_warn=0 range_ok=2 dead:abba:4000::2_r=1;203.2;228.6;0;254 dead:abba:4000::2_rt=0 dead:abba:1000::2_r=2;3.77789e+21;4.25013e+21;0;4.72237e+21 dead:abba:1000::2_rt=1 +Shared nets - crit: 0 warn: 0 ok: 0; | snet_crit=0 snet_warn=0 snet_ok=0 + diff --git a/tests/v6-perfdata b/tests/v6-perfdata new file mode 100755 index 0000000..2765fd4 --- /dev/null +++ b/tests/v6-perfdata @@ -0,0 +1,16 @@ +#!/bin/sh +# +# Minimal regression test suite. + +IAM=$(basename $0) +TESTDATA=${IAM%-*} + +if [ ! -d tests/outputs ]; then + mkdir tests/outputs +fi + +dhcpd-pools -c $top_srcdir/tests/confs/$TESTDATA \ + -l $top_srcdir/tests/leases/$TESTDATA -o tests/outputs/$IAM \ + --warning 80 --perfdata +diff -u $top_srcdir/tests/expected/$IAM tests/outputs/$IAM +exit $?