mirror of
git://git.code.sf.net/p/dhcpd-pools/code
synced 2025-12-16 15:57:00 +00:00
output: add output helper functions
There is too much repetative confusing maths near printouts. Move that stuff to a function. This change also fixes --snet-alarms option counting issue in range that were not part of any shared network were ignored. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
parent
05f8208518
commit
48962004b8
3 changed files with 184 additions and 126 deletions
|
|
@ -121,6 +121,27 @@ struct range_t {
|
||||||
double touched;
|
double touched;
|
||||||
double backups;
|
double backups;
|
||||||
};
|
};
|
||||||
|
/*! \enum count_status_t
|
||||||
|
* \brief Enumeration of possible range and shared net statuses.
|
||||||
|
*/
|
||||||
|
enum count_status_t {
|
||||||
|
STATUS_OK,
|
||||||
|
STATUS_WARN,
|
||||||
|
STATUS_CRIT,
|
||||||
|
STATUS_IGNORED,
|
||||||
|
STATUS_SUPPRESSED
|
||||||
|
};
|
||||||
|
/*! \struct output_helper_t
|
||||||
|
* \brief Various per range and shared net temporary calculation results.
|
||||||
|
*/
|
||||||
|
struct output_helper_t {
|
||||||
|
int status;
|
||||||
|
double range_size;
|
||||||
|
double percent;
|
||||||
|
double tc;
|
||||||
|
double tcp;
|
||||||
|
double bup;
|
||||||
|
};
|
||||||
/*! \enum isc_conf_parser
|
/*! \enum isc_conf_parser
|
||||||
* \brief Configuration file parsing state flags.
|
* \brief Configuration file parsing state flags.
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
287
src/output.c
287
src/output.c
|
|
@ -58,13 +58,79 @@
|
||||||
|
|
||||||
#include "dhcpd-pools.h"
|
#include "dhcpd-pools.h"
|
||||||
|
|
||||||
|
/*! \brief Calculate range percentages and such. */
|
||||||
|
static void range_output_helper(struct output_helper_t *oh, struct range_t *range_p)
|
||||||
|
{
|
||||||
|
/* counts and calculations */
|
||||||
|
oh->range_size = get_range_size(range_p);
|
||||||
|
oh->percent = (double)(100 * range_p->count) / oh->range_size;
|
||||||
|
oh->tc = range_p->touched + range_p->count;
|
||||||
|
oh->tcp = (double)(100 * oh->tc) / oh->range_size;
|
||||||
|
if (config.backups_found == 1) {
|
||||||
|
oh->bup = (double)(100 * range_p->backups) / oh->range_size;
|
||||||
|
}
|
||||||
|
/* set status */
|
||||||
|
if (config.snet_alarms && range_p->shared_net != shared_networks) {
|
||||||
|
oh->status = STATUS_SUPPRESSED;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (oh->range_size <= config.minsize) {
|
||||||
|
oh->status = STATUS_IGNORED;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (config.critical < oh->percent
|
||||||
|
&& (oh->range_size - range_p->count) < config.crit_count) {
|
||||||
|
oh->status = STATUS_CRIT;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (config.warning < oh->percent
|
||||||
|
&& (oh->range_size - range_p->count) < config.warn_count) {
|
||||||
|
oh->status = STATUS_WARN;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
oh->status = STATUS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! \brief Calculate shared network percentages and such. */
|
||||||
|
static void shnet_output_helper(struct output_helper_t *oh, struct shared_network_t *shared_p)
|
||||||
|
{
|
||||||
|
/* counts and calculations */
|
||||||
|
oh->tc = shared_p->touched + shared_p->used;
|
||||||
|
if (shared_p->available == 0) {
|
||||||
|
oh->percent = NAN;
|
||||||
|
oh->tcp = NAN;
|
||||||
|
oh->bup = NAN;
|
||||||
|
} else {
|
||||||
|
oh->percent = (double)(100 * shared_p->used) / shared_p->available;
|
||||||
|
oh->tcp =
|
||||||
|
(double)((100 * (shared_p->touched + shared_p->used)) / shared_p->available);
|
||||||
|
if (config.backups_found == 1) {
|
||||||
|
oh->bup = (double)(100 * shared_p->backups) / shared_p->available;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* set status */
|
||||||
|
if (oh->percent == NAN || shared_p->available <= config.minsize) {
|
||||||
|
oh->status = STATUS_IGNORED;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (config.critical < oh->percent && shared_p->used < config.crit_count) {
|
||||||
|
oh->status = STATUS_CRIT;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (config.warning < oh->percent && shared_p->used < config.warn_count) {
|
||||||
|
oh->status = STATUS_WARN;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
oh->status = STATUS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
/*! \brief Text output format, which is the default. */
|
/*! \brief Text output format, which is the default. */
|
||||||
static int output_txt(void)
|
static int output_txt(void)
|
||||||
{
|
{
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
struct range_t *range_p;
|
struct range_t *range_p;
|
||||||
double range_size;
|
|
||||||
struct shared_network_t *shared_p;
|
struct shared_network_t *shared_p;
|
||||||
|
struct output_helper_t oh;
|
||||||
int ret;
|
int ret;
|
||||||
FILE *outfile;
|
FILE *outfile;
|
||||||
int max_ipaddr_length = config.ip_version == IPv6 ? 39 : 16;
|
int max_ipaddr_length = config.ip_version == IPv6 ? 39 : 16;
|
||||||
|
|
@ -79,7 +145,6 @@ static int output_txt(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
range_p = ranges;
|
range_p = ranges;
|
||||||
range_size = get_range_size(range_p);
|
|
||||||
shared_p = shared_networks;
|
shared_p = shared_networks;
|
||||||
|
|
||||||
if (config.header_limit & R_BIT) {
|
if (config.header_limit & R_BIT) {
|
||||||
|
|
@ -99,6 +164,7 @@ static int output_txt(void)
|
||||||
}
|
}
|
||||||
if (config.number_limit & R_BIT) {
|
if (config.number_limit & R_BIT) {
|
||||||
for (i = 0; i < num_ranges; i++) {
|
for (i = 0; i < num_ranges; i++) {
|
||||||
|
range_output_helper(&oh, range_p);
|
||||||
if (range_p->shared_net) {
|
if (range_p->shared_net) {
|
||||||
fprintf(outfile, "%-20s", range_p->shared_net->name);
|
fprintf(outfile, "%-20s", range_p->shared_net->name);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -113,20 +179,18 @@ static int output_txt(void)
|
||||||
" - %-*s %5g %5g %10.3f %5g %5g %9.3f",
|
" - %-*s %5g %5g %10.3f %5g %5g %9.3f",
|
||||||
max_ipaddr_length,
|
max_ipaddr_length,
|
||||||
ntop_ipaddr(&range_p->last_ip),
|
ntop_ipaddr(&range_p->last_ip),
|
||||||
range_size,
|
oh.range_size,
|
||||||
range_p->count,
|
range_p->count,
|
||||||
(float)(100 * range_p->count) / range_size,
|
oh.percent,
|
||||||
range_p->touched,
|
range_p->touched,
|
||||||
range_p->touched + range_p->count,
|
oh.tc,
|
||||||
(float)(100 * (range_p->touched + range_p->count)) / range_size);
|
oh.tcp);
|
||||||
if (config.backups_found == 1) {
|
if (config.backups_found == 1) {
|
||||||
fprintf(outfile, "%7g %8.3f",
|
fprintf(outfile, "%7g %8.3f",
|
||||||
range_p->backups,
|
range_p->backups, oh.bup);
|
||||||
(float)(100 * range_p->backups) / range_size);
|
|
||||||
}
|
}
|
||||||
fprintf(outfile, "\n");
|
fprintf(outfile, "\n");
|
||||||
range_p++;
|
range_p++;
|
||||||
range_size = get_range_size(range_p);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (config.number_limit & R_BIT && config.header_limit & S_BIT) {
|
if (config.number_limit & R_BIT && config.header_limit & S_BIT) {
|
||||||
|
|
@ -144,20 +208,20 @@ static int output_txt(void)
|
||||||
if (config.number_limit & S_BIT) {
|
if (config.number_limit & S_BIT) {
|
||||||
for (i = 0; i < num_shared_networks; i++) {
|
for (i = 0; i < num_shared_networks; i++) {
|
||||||
shared_p++;
|
shared_p++;
|
||||||
|
shnet_output_helper(&oh, shared_p);
|
||||||
fprintf(outfile,
|
fprintf(outfile,
|
||||||
"%-20s %5g %5g %10.3f %7g %6g %9.3f",
|
"%-20s %5g %5g %10.3f %7g %6g %9.3f",
|
||||||
shared_p->name, shared_p->available,
|
shared_p->name,
|
||||||
|
shared_p->available,
|
||||||
shared_p->used,
|
shared_p->used,
|
||||||
shared_p->available ==
|
oh.percent,
|
||||||
0 ? NAN : (float)(100 * shared_p->used) / shared_p->available,
|
shared_p->touched,
|
||||||
shared_p->touched, shared_p->touched + shared_p->used,
|
oh.tc,
|
||||||
shared_p->available ==
|
oh.tcp);
|
||||||
0 ? NAN : ((float)(100 * (shared_p->touched + shared_p->used)) /
|
|
||||||
shared_p->available));
|
|
||||||
if (config.backups_found == 1) {
|
if (config.backups_found == 1) {
|
||||||
fprintf(outfile, "%7g %8.3f",
|
fprintf(outfile, "%7g %8.3f",
|
||||||
shared_p->backups,
|
shared_p->backups,
|
||||||
(float)(100 * shared_p->backups) / shared_p->available);
|
oh.bup);
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(outfile, "\n");
|
fprintf(outfile, "\n");
|
||||||
|
|
@ -177,24 +241,20 @@ static int output_txt(void)
|
||||||
fprintf(outfile, "\n");
|
fprintf(outfile, "\n");
|
||||||
}
|
}
|
||||||
if (config.number_limit & A_BIT) {
|
if (config.number_limit & A_BIT) {
|
||||||
|
shnet_output_helper(&oh, shared_networks);
|
||||||
fprintf(outfile, "%-20s %5g %5g %10.3f %7g %6g %9.3f",
|
fprintf(outfile, "%-20s %5g %5g %10.3f %7g %6g %9.3f",
|
||||||
shared_networks->name,
|
shared_networks->name,
|
||||||
shared_networks->available,
|
shared_networks->available,
|
||||||
shared_networks->used,
|
shared_networks->used,
|
||||||
shared_networks->available ==
|
oh.percent,
|
||||||
0 ? NAN : (float)(100 * shared_networks->used) /
|
shared_networks->touched,
|
||||||
shared_networks->available, shared_networks->touched,
|
oh.tc,
|
||||||
shared_networks->touched + shared_networks->used,
|
oh.tcp);
|
||||||
shared_networks->available ==
|
|
||||||
0 ? NAN : (float)(100 *
|
|
||||||
(shared_networks->touched +
|
|
||||||
shared_networks->used)) / shared_networks->available);
|
|
||||||
|
|
||||||
if (config.backups_found == 1) {
|
if (config.backups_found == 1) {
|
||||||
fprintf(outfile, "%7g %8.3f",
|
fprintf(outfile, "%7g %8.3f",
|
||||||
shared_networks->available == 0 ? NAN : shared_networks->backups,
|
shared_networks->backups,
|
||||||
(float)(100 * shared_networks->backups) /
|
oh.bup);
|
||||||
shared_networks->available);
|
|
||||||
}
|
}
|
||||||
fprintf(outfile, "\n");
|
fprintf(outfile, "\n");
|
||||||
}
|
}
|
||||||
|
|
@ -599,8 +659,8 @@ static int output_html(void)
|
||||||
{
|
{
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
struct range_t *range_p;
|
struct range_t *range_p;
|
||||||
double range_size;
|
|
||||||
struct shared_network_t *shared_p;
|
struct shared_network_t *shared_p;
|
||||||
|
struct output_helper_t oh;
|
||||||
int ret;
|
int ret;
|
||||||
FILE *outfile;
|
FILE *outfile;
|
||||||
|
|
||||||
|
|
@ -614,7 +674,6 @@ static int output_html(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
range_p = ranges;
|
range_p = ranges;
|
||||||
range_size = get_range_size(range_p);
|
|
||||||
shared_p = shared_networks;
|
shared_p = shared_networks;
|
||||||
html_header(outfile);
|
html_header(outfile);
|
||||||
newsection(outfile, "Sum of all");
|
newsection(outfile, "Sum of all");
|
||||||
|
|
@ -639,27 +698,17 @@ static int output_html(void)
|
||||||
if (config.number_limit & A_BIT) {
|
if (config.number_limit & A_BIT) {
|
||||||
start_tag(outfile, "tbody");
|
start_tag(outfile, "tbody");
|
||||||
start_tag(outfile, "tr");
|
start_tag(outfile, "tr");
|
||||||
|
shnet_output_helper(&oh, shared_networks);
|
||||||
output_line(outfile, "td", shared_networks->name);
|
output_line(outfile, "td", shared_networks->name);
|
||||||
output_double(outfile, "td", shared_networks->available);
|
output_double(outfile, "td", shared_networks->available);
|
||||||
output_double(outfile, "td", shared_networks->used);
|
output_double(outfile, "td", shared_networks->used);
|
||||||
output_float(outfile, "td",
|
output_float(outfile, "td", oh.percent);
|
||||||
shared_networks->available ==
|
|
||||||
0 ? NAN : (float)(100 * shared_networks->used) /
|
|
||||||
shared_networks->available);
|
|
||||||
output_double(outfile, "td", shared_networks->touched);
|
output_double(outfile, "td", shared_networks->touched);
|
||||||
output_double(outfile, "td", shared_networks->touched + shared_networks->used);
|
output_double(outfile, "td", oh.tc);
|
||||||
output_float(outfile, "td",
|
output_float(outfile, "td", oh.tcp);
|
||||||
shared_networks->available == 0 ? NAN : (float)(100 *
|
|
||||||
(shared_networks->touched
|
|
||||||
+
|
|
||||||
shared_networks->used))
|
|
||||||
/ shared_networks->available);
|
|
||||||
if (config.backups_found == 1) {
|
if (config.backups_found == 1) {
|
||||||
output_double(outfile, "td", shared_networks->backups);
|
output_double(outfile, "td", shared_networks->backups);
|
||||||
output_float(outfile, "td",
|
output_float(outfile, "td", oh.tcp);
|
||||||
shared_networks->available == 0 ? NAN : (float)(100 *
|
|
||||||
shared_networks->backups)
|
|
||||||
/ shared_networks->available);
|
|
||||||
}
|
}
|
||||||
end_tag(outfile, "tr");
|
end_tag(outfile, "tr");
|
||||||
end_tag(outfile, "tbody");
|
end_tag(outfile, "tbody");
|
||||||
|
|
@ -688,27 +737,18 @@ static int output_html(void)
|
||||||
start_tag(outfile, "tbody");
|
start_tag(outfile, "tbody");
|
||||||
for (i = 0; i < num_shared_networks; i++) {
|
for (i = 0; i < num_shared_networks; i++) {
|
||||||
shared_p++;
|
shared_p++;
|
||||||
|
shnet_output_helper(&oh, shared_networks);
|
||||||
start_tag(outfile, "tr");
|
start_tag(outfile, "tr");
|
||||||
output_line(outfile, "td", shared_p->name);
|
output_line(outfile, "td", shared_p->name);
|
||||||
output_double(outfile, "td", shared_p->available);
|
output_double(outfile, "td", shared_p->available);
|
||||||
output_double(outfile, "td", shared_p->used);
|
output_double(outfile, "td", shared_p->used);
|
||||||
output_float(outfile, "td",
|
output_float(outfile, "td", oh.percent);
|
||||||
shared_p->available ==
|
|
||||||
0 ? NAN : (float)(100 * shared_p->used) /
|
|
||||||
shared_p->available);
|
|
||||||
output_double(outfile, "td", shared_p->touched);
|
output_double(outfile, "td", shared_p->touched);
|
||||||
output_double(outfile, "td", shared_p->touched + shared_p->used);
|
output_double(outfile, "td", oh.tc);
|
||||||
output_float(outfile, "td",
|
output_float(outfile, "td", oh.tcp);
|
||||||
shared_p->available == 0 ? NAN : (float)(100 *
|
|
||||||
(shared_p->touched +
|
|
||||||
shared_p->used)) /
|
|
||||||
shared_p->available);
|
|
||||||
if (config.backups_found == 1) {
|
if (config.backups_found == 1) {
|
||||||
output_double(outfile, "td", shared_p->backups);
|
output_double(outfile, "td", shared_p->backups);
|
||||||
output_float(outfile, "td",
|
output_float(outfile, "td", oh.bup);
|
||||||
shared_p->available == 0 ? NAN : (float)(100 *
|
|
||||||
shared_p->backups)
|
|
||||||
/ shared_p->available);
|
|
||||||
}
|
}
|
||||||
end_tag(outfile, "tr");
|
end_tag(outfile, "tr");
|
||||||
}
|
}
|
||||||
|
|
@ -739,6 +779,7 @@ static int output_html(void)
|
||||||
if (config.number_limit & R_BIT) {
|
if (config.number_limit & R_BIT) {
|
||||||
start_tag(outfile, "tbody");
|
start_tag(outfile, "tbody");
|
||||||
for (i = 0; i < num_ranges; i++) {
|
for (i = 0; i < num_ranges; i++) {
|
||||||
|
range_output_helper(&oh, range_p);
|
||||||
start_tag(outfile, "tr");
|
start_tag(outfile, "tr");
|
||||||
if (range_p->shared_net) {
|
if (range_p->shared_net) {
|
||||||
output_line(outfile, "td", range_p->shared_net->name);
|
output_line(outfile, "td", range_p->shared_net->name);
|
||||||
|
|
@ -747,22 +788,18 @@ static int output_html(void)
|
||||||
}
|
}
|
||||||
output_line(outfile, "td", ntop_ipaddr(&range_p->first_ip));
|
output_line(outfile, "td", ntop_ipaddr(&range_p->first_ip));
|
||||||
output_line(outfile, "td", ntop_ipaddr(&range_p->last_ip));
|
output_line(outfile, "td", ntop_ipaddr(&range_p->last_ip));
|
||||||
output_double(outfile, "td", range_size);
|
output_double(outfile, "td", oh.range_size);
|
||||||
output_double(outfile, "td", range_p->count);
|
output_double(outfile, "td", range_p->count);
|
||||||
output_float(outfile, "td", (float)(100 * range_p->count) / range_size);
|
output_float(outfile, "td", oh.percent);
|
||||||
output_double(outfile, "td", range_p->touched);
|
output_double(outfile, "td", range_p->touched);
|
||||||
output_double(outfile, "td", range_p->touched + range_p->count);
|
output_double(outfile, "td", oh.tc);
|
||||||
output_float(outfile, "td",
|
output_float(outfile, "td", oh.tcp);
|
||||||
(float)(100 *
|
|
||||||
(range_p->touched + range_p->count)) / range_size);
|
|
||||||
if (config.backups_found == 1) {
|
if (config.backups_found == 1) {
|
||||||
output_double(outfile, "td", range_p->backups);
|
output_double(outfile, "td", range_p->backups);
|
||||||
output_float(outfile, "td",
|
output_float(outfile, "td", oh.bup);
|
||||||
(float)(100 * range_p->backups) / range_size);
|
|
||||||
}
|
}
|
||||||
end_tag(outfile, "tr");
|
end_tag(outfile, "tr");
|
||||||
range_p++;
|
range_p++;
|
||||||
range_size = get_range_size(range_p);
|
|
||||||
}
|
}
|
||||||
end_tag(outfile, "tbody");
|
end_tag(outfile, "tbody");
|
||||||
}
|
}
|
||||||
|
|
@ -787,8 +824,8 @@ static int output_csv(void)
|
||||||
{
|
{
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
struct range_t *range_p;
|
struct range_t *range_p;
|
||||||
double range_size;
|
|
||||||
struct shared_network_t *shared_p;
|
struct shared_network_t *shared_p;
|
||||||
|
struct output_helper_t oh;
|
||||||
FILE *outfile;
|
FILE *outfile;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
|
@ -802,7 +839,6 @@ static int output_csv(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
range_p = ranges;
|
range_p = ranges;
|
||||||
range_size = get_range_size(range_p);
|
|
||||||
shared_p = shared_networks;
|
shared_p = shared_networks;
|
||||||
if (config.header_limit & R_BIT) {
|
if (config.header_limit & R_BIT) {
|
||||||
fprintf(outfile, "\"Ranges:\"\n");
|
fprintf(outfile, "\"Ranges:\"\n");
|
||||||
|
|
@ -816,6 +852,7 @@ static int output_csv(void)
|
||||||
}
|
}
|
||||||
if (config.number_limit & R_BIT) {
|
if (config.number_limit & R_BIT) {
|
||||||
for (i = 0; i < num_ranges; i++) {
|
for (i = 0; i < num_ranges; i++) {
|
||||||
|
range_output_helper(&oh, range_p);
|
||||||
if (range_p->shared_net) {
|
if (range_p->shared_net) {
|
||||||
fprintf(outfile, "\"%s\",", range_p->shared_net->name);
|
fprintf(outfile, "\"%s\",", range_p->shared_net->name);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -824,21 +861,21 @@ static int output_csv(void)
|
||||||
fprintf(outfile, "\"%s\",", ntop_ipaddr(&range_p->first_ip));
|
fprintf(outfile, "\"%s\",", ntop_ipaddr(&range_p->first_ip));
|
||||||
fprintf(outfile,
|
fprintf(outfile,
|
||||||
"\"%s\",\"%g\",\"%g\",\"%.3f\",\"%g\",\"%g\",\"%.3f\"",
|
"\"%s\",\"%g\",\"%g\",\"%.3f\",\"%g\",\"%g\",\"%.3f\"",
|
||||||
ntop_ipaddr(&range_p->last_ip), range_size,
|
ntop_ipaddr(&range_p->last_ip),
|
||||||
|
oh.range_size,
|
||||||
range_p->count,
|
range_p->count,
|
||||||
(float)(100 * range_p->count) / range_size,
|
oh.percent,
|
||||||
range_p->touched,
|
range_p->touched,
|
||||||
range_p->touched + range_p->count,
|
oh.tc,
|
||||||
(float)(100 * (range_p->touched + range_p->count)) / range_size);
|
oh.tcp);
|
||||||
if (config.backups_found == 1) {
|
if (config.backups_found == 1) {
|
||||||
fprintf(outfile, ",\"%g\",\"%.3f\"",
|
fprintf(outfile, ",\"%g\",\"%.3f\"",
|
||||||
range_p->backups,
|
range_p->backups,
|
||||||
(float)(100 * range_p->backups) / range_size);
|
oh.bup);
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(outfile, "\n");
|
fprintf(outfile, "\n");
|
||||||
range_p++;
|
range_p++;
|
||||||
range_size = get_range_size(range_p);
|
|
||||||
}
|
}
|
||||||
fprintf(outfile, "\n");
|
fprintf(outfile, "\n");
|
||||||
}
|
}
|
||||||
|
|
@ -855,23 +892,20 @@ static int output_csv(void)
|
||||||
|
|
||||||
for (i = 0; i < num_shared_networks; i++) {
|
for (i = 0; i < num_shared_networks; i++) {
|
||||||
shared_p++;
|
shared_p++;
|
||||||
|
shnet_output_helper(&oh, shared_p);
|
||||||
fprintf(outfile,
|
fprintf(outfile,
|
||||||
"\"%s\",\"%g\",\"%g\",\"%.3f\",\"%g\",\"%g\",\"%.3f\"",
|
"\"%s\",\"%g\",\"%g\",\"%.3f\",\"%g\",\"%g\",\"%.3f\"",
|
||||||
shared_p->name, shared_p->available,
|
shared_p->name,
|
||||||
|
shared_p->available,
|
||||||
shared_p->used,
|
shared_p->used,
|
||||||
shared_p->available == 0 ? NAN : (float)(100 * shared_p->used) /
|
oh.percent,
|
||||||
shared_p->available, shared_p->touched,
|
shared_p->touched,
|
||||||
shared_p->touched + shared_p->used,
|
oh.tc,
|
||||||
shared_p->available == 0 ? NAN : (float)(100 *
|
oh.tcp);
|
||||||
(shared_p->touched +
|
|
||||||
shared_p->used)) /
|
|
||||||
shared_p->available);
|
|
||||||
if (config.backups_found == 1) {
|
if (config.backups_found == 1) {
|
||||||
fprintf(outfile, ",\"%g\",\"%.3f\"",
|
fprintf(outfile, ",\"%g\",\"%.3f\"",
|
||||||
shared_p->backups,
|
shared_p->backups,
|
||||||
shared_p->available ==
|
oh.bup);
|
||||||
0 ? NAN : (float)(100 * shared_p->backups) /
|
|
||||||
shared_p->available);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(outfile, "\n");
|
fprintf(outfile, "\n");
|
||||||
|
|
@ -888,25 +922,20 @@ static int output_csv(void)
|
||||||
fprintf(outfile, "\n");
|
fprintf(outfile, "\n");
|
||||||
}
|
}
|
||||||
if (config.number_limit & A_BIT) {
|
if (config.number_limit & A_BIT) {
|
||||||
|
shnet_output_helper(&oh, shared_networks);
|
||||||
fprintf(outfile,
|
fprintf(outfile,
|
||||||
"\"%s\",\"%g\",\"%g\",\"%.3f\",\"%g\",\"%g\",\"%.3f\"",
|
"\"%s\",\"%g\",\"%g\",\"%.3f\",\"%g\",\"%g\",\"%.3f\"",
|
||||||
shared_networks->name, shared_networks->available,
|
shared_networks->name,
|
||||||
|
shared_networks->available,
|
||||||
shared_networks->used,
|
shared_networks->used,
|
||||||
shared_networks->available ==
|
oh.percent,
|
||||||
0 ? NAN : (float)(100 * shared_networks->used) /
|
shared_networks->touched,
|
||||||
shared_networks->available, shared_networks->touched,
|
oh.tc,
|
||||||
shared_networks->touched + shared_networks->used,
|
oh.tcp);
|
||||||
shared_networks->available ==
|
|
||||||
0 ? NAN : (float)(100 *
|
|
||||||
(shared_networks->touched +
|
|
||||||
shared_networks->used)) / shared_networks->available);
|
|
||||||
if (config.backups_found == 1) {
|
if (config.backups_found == 1) {
|
||||||
fprintf(outfile, "%7g %8.3f",
|
fprintf(outfile, "%7g %8.3f",
|
||||||
shared_networks->backups,
|
shared_networks->backups,
|
||||||
shared_networks->available ==
|
oh.bup);
|
||||||
0 ? NAN : (float)(100 * shared_networks->backups) /
|
|
||||||
shared_networks->available);
|
|
||||||
}
|
}
|
||||||
fprintf(outfile, "\n");
|
fprintf(outfile, "\n");
|
||||||
}
|
}
|
||||||
|
|
@ -931,8 +960,8 @@ static int output_alarming(void)
|
||||||
struct range_t *range_p;
|
struct range_t *range_p;
|
||||||
double range_size;
|
double range_size;
|
||||||
struct shared_network_t *shared_p;
|
struct shared_network_t *shared_p;
|
||||||
|
struct output_helper_t oh;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
float perc;
|
|
||||||
int rw = 0, rc = 0, ro = 0, ri = 0, sw = 0, sc = 0, so = 0, si = 0;
|
int rw = 0, rc = 0, ro = 0, ri = 0, sw = 0, sc = 0, so = 0, si = 0;
|
||||||
int ret_val, ret;
|
int ret_val, ret;
|
||||||
|
|
||||||
|
|
@ -951,39 +980,47 @@ static int output_alarming(void)
|
||||||
|
|
||||||
if (config.number_limit & R_BIT) {
|
if (config.number_limit & R_BIT) {
|
||||||
for (i = 0; i < num_ranges; i++) {
|
for (i = 0; i < num_ranges; i++) {
|
||||||
if (config.snet_alarms && range_p->shared_net != shared_networks) {
|
range_output_helper(&oh, range_p);
|
||||||
continue;
|
switch (oh.status) {
|
||||||
}
|
case STATUS_SUPPRESSED:
|
||||||
if (config.minsize < range_size) {
|
break;
|
||||||
perc = (float)(100 * range_p->count) / range_size;
|
case STATUS_IGNORED:
|
||||||
if (config.critical < perc && (range_size - range_p->count) < config.crit_count)
|
|
||||||
rc++;
|
|
||||||
else if (config.warning < perc && (range_size - range_p->count) < config.warn_count)
|
|
||||||
rw++;
|
|
||||||
else
|
|
||||||
ro++;
|
|
||||||
} else {
|
|
||||||
ri++;
|
ri++;
|
||||||
|
break;
|
||||||
|
case STATUS_CRIT:
|
||||||
|
rc++;
|
||||||
|
break;
|
||||||
|
case STATUS_WARN:
|
||||||
|
rw++;
|
||||||
|
break;
|
||||||
|
case STATUS_OK:
|
||||||
|
ro++;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
abort();
|
||||||
}
|
}
|
||||||
range_p++;
|
range_p++;
|
||||||
range_size = get_range_size(range_p);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (config.number_limit & S_BIT) {
|
if (config.number_limit & S_BIT) {
|
||||||
for (i = 0; i < num_shared_networks; i++) {
|
for (i = 0; i < num_shared_networks; i++) {
|
||||||
shared_p++;
|
shared_p++;
|
||||||
if (config.minsize < shared_p->available) {
|
shnet_output_helper(&oh, shared_p);
|
||||||
perc =
|
switch (oh.status) {
|
||||||
shared_p->available ==
|
case STATUS_IGNORED:
|
||||||
0 ? 100 : (float)(100 * shared_p->used) / shared_p->available;
|
|
||||||
if (config.critical < perc && shared_p->used < config.crit_count)
|
|
||||||
sc++;
|
|
||||||
else if (config.warning < perc && shared_p->used < config.warn_count)
|
|
||||||
sw++;
|
|
||||||
else
|
|
||||||
so++;
|
|
||||||
} else {
|
|
||||||
si++;
|
si++;
|
||||||
|
break;
|
||||||
|
case STATUS_CRIT:
|
||||||
|
sc++;
|
||||||
|
break;
|
||||||
|
case STATUS_WARN:
|
||||||
|
sw++;
|
||||||
|
break;
|
||||||
|
case STATUS_OK:
|
||||||
|
so++;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
abort();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,6 @@ OK: Ranges - crit: 0 warn: 0 ok: 0 ignored: 5; | range_crit=0 range_warn=0 range
|
||||||
Shared nets - crit: 0 warn: 0 ok: 0 ignored: 2; | snet_crit=0 snet_warn=0 snet_ok=0 snet_ignored=2
|
Shared nets - crit: 0 warn: 0 ok: 0 ignored: 2; | snet_crit=0 snet_warn=0 snet_ok=0 snet_ignored=2
|
||||||
0
|
0
|
||||||
== snet alarms ==
|
== snet alarms ==
|
||||||
WARNING: dhcpd-pools: Ranges - crit: 0 warn: 0 ok: 0; | range_crit=0 range_warn=0 range_ok=0
|
WARNING: dhcpd-pools: Ranges - crit: 0 warn: 0 ok: 1; | range_crit=0 range_warn=0 range_ok=1
|
||||||
Shared nets - crit: 0 warn: 2 ok: 0; | snet_crit=0 snet_warn=2 snet_ok=0
|
Shared nets - crit: 0 warn: 2 ok: 0; | snet_crit=0 snet_warn=2 snet_ok=0
|
||||||
1
|
1
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue