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:
Manuel Hachtkemper 2016-03-29 14:49:06 +02:00 committed by Sami Kerola
parent c305e2f82c
commit 32e2d399a0
No known key found for this signature in database
GPG key ID: A9553245FDE9B739
12 changed files with 103 additions and 4 deletions

View file

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

View file

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

View file

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

View file

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