mirror of
git://git.code.sf.net/p/dhcpd-pools/code
synced 2025-12-16 15:57:00 +00:00
alarming: add additional performance data
Options -p or --perfdata (in alarming mode) now enable the output of additional performance data, i.e. used, touched and backup addresses per subnet. Signed-off-by: Manuel Hachtkemper <hacman@math.uni-bonn.de> Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
parent
c305e2f82c
commit
32e2d399a0
12 changed files with 103 additions and 4 deletions
1
THANKS
1
THANKS
|
|
@ -38,3 +38,4 @@ Martijn van Brummelen
|
|||
Anton Tkachev
|
||||
Derrick Lin
|
||||
Ivanov Ivan
|
||||
Manuel Hachtkemper
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
47
src/output.c
47
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");
|
||||
|
|
|
|||
|
|
@ -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 \
|
||||
|
|
|
|||
16
tests/complete-perfdata
Executable file
16
tests/complete-perfdata
Executable file
|
|
@ -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 $?
|
||||
|
|
@ -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
|
||||
|
|
|
|||
3
tests/expected/complete-perfdata
Normal file
3
tests/expected/complete-perfdata
Normal file
|
|
@ -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
|
||||
|
||||
3
tests/expected/v6-perfdata
Normal file
3
tests/expected/v6-perfdata
Normal file
|
|
@ -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
|
||||
|
||||
16
tests/v6-perfdata
Executable file
16
tests/v6-perfdata
Executable file
|
|
@ -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 $?
|
||||
Loading…
Add table
Add a link
Reference in a new issue