mirror of
git://git.code.sf.net/p/dhcpd-pools/code
synced 2025-12-16 07:47:00 +00:00
output: move shared net andn range status check to output_helper
Having same logic in many places is error prone if and when the logic needs maintenance. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
parent
15f08bbf02
commit
a64630aa49
3 changed files with 35 additions and 48 deletions
|
|
@ -336,9 +336,9 @@ extern double get_range_size_v4(const struct range_t *r);
|
|||
extern double get_range_size_v6(const struct range_t *r);
|
||||
|
||||
/* output.c */
|
||||
extern void range_output_helper(struct conf_t *state, struct output_helper_t *oh,
|
||||
extern int range_output_helper(struct conf_t *state, struct output_helper_t *oh,
|
||||
struct range_t *range_p);
|
||||
extern void shnet_output_helper(struct conf_t *state, struct output_helper_t *oh,
|
||||
extern int shnet_output_helper(struct conf_t *state, struct output_helper_t *oh,
|
||||
struct shared_network_t *shared_p);
|
||||
extern int output_analysis(struct conf_t *state, const char output_format);
|
||||
|
||||
|
|
|
|||
|
|
@ -211,8 +211,7 @@ static int must_next_range(void *closure)
|
|||
e->current--;
|
||||
if (e->current <= 0)
|
||||
return 0;
|
||||
range_output_helper(e->state, &e->oh, e->range_p);
|
||||
} while (e->state->skip_ok && e->oh.status == STATUS_OK);
|
||||
} while (range_output_helper(e->state, &e->oh, e->range_p));
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
@ -226,8 +225,7 @@ static int must_next_shnet(void *closure)
|
|||
e->shnet_p = e->shnet_p->next;
|
||||
if (e->shnet_p == NULL)
|
||||
break;
|
||||
shnet_output_helper(e->state, &e->oh, e->shnet_p);
|
||||
if (e->state->skip_ok && e->oh.status == STATUS_OK)
|
||||
if (shnet_output_helper(e->state, &e->oh, e->shnet_p))
|
||||
continue;
|
||||
else
|
||||
return 1;
|
||||
|
|
|
|||
65
src/output.c
65
src/output.c
|
|
@ -60,7 +60,8 @@
|
|||
#include "dhcpd-pools.h"
|
||||
|
||||
/*! \brief Calculate range percentages and such. */
|
||||
void range_output_helper(struct conf_t *state, struct output_helper_t *oh, struct range_t *range_p)
|
||||
int range_output_helper(struct conf_t *state, struct output_helper_t *oh,
|
||||
struct range_t *range_p)
|
||||
{
|
||||
/* counts and calculations */
|
||||
oh->range_size = get_range_size(range_p);
|
||||
|
|
@ -83,10 +84,13 @@ void range_output_helper(struct conf_t *state, struct output_helper_t *oh, struc
|
|||
else if (state->snet_alarms && range_p->shared_net != state->shared_net_root)
|
||||
oh->status = STATUS_SUPPRESSED;
|
||||
}
|
||||
if (state->skip_ok && oh->status == STATUS_OK)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*! \brief Calculate shared network percentages and such. */
|
||||
void shnet_output_helper(struct conf_t *state, struct output_helper_t *oh,
|
||||
int shnet_output_helper(struct conf_t *state, struct output_helper_t *oh,
|
||||
struct shared_network_t *shared_p)
|
||||
{
|
||||
/* counts and calculations */
|
||||
|
|
@ -104,23 +108,20 @@ void shnet_output_helper(struct conf_t *state, struct output_helper_t *oh,
|
|||
}
|
||||
}
|
||||
/* set status */
|
||||
if (oh->percent == NAN) {
|
||||
if (oh->percent == NAN)
|
||||
oh->status = STATUS_SUPPRESSED;
|
||||
return;
|
||||
}
|
||||
if (shared_p->available <= state->minsize) {
|
||||
else if (shared_p->available <= state->minsize)
|
||||
oh->status = STATUS_IGNORED;
|
||||
return;
|
||||
}
|
||||
if (state->critical < oh->percent && shared_p->used < state->crit_count) {
|
||||
else if (state->critical < oh->percent && shared_p->used < state->crit_count)
|
||||
oh->status = STATUS_CRIT;
|
||||
return;
|
||||
}
|
||||
if (state->warning < oh->percent && shared_p->used < state->warn_count) {
|
||||
else if (state->warning < oh->percent && shared_p->used < state->warn_count)
|
||||
oh->status = STATUS_WARN;
|
||||
return;
|
||||
}
|
||||
else
|
||||
oh->status = STATUS_OK;
|
||||
if (state->skip_ok && oh->status == STATUS_OK)
|
||||
return 1;
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
static int start_color(struct output_helper_t *oh, FILE *outfile)
|
||||
|
|
@ -206,8 +207,7 @@ static int output_txt(struct conf_t *state)
|
|||
for (i = 0; i < state->num_ranges; i++) {
|
||||
int color_set = 0;
|
||||
|
||||
range_output_helper(state, &oh, range_p);
|
||||
if (state->skip_ok && oh.status == STATUS_OK) {
|
||||
if (range_output_helper(state, &oh, range_p)) {
|
||||
range_p++;
|
||||
continue;
|
||||
}
|
||||
|
|
@ -258,8 +258,7 @@ static int output_txt(struct conf_t *state)
|
|||
for (shared_p = state->shared_net_root->next; shared_p; shared_p = shared_p->next) {
|
||||
int color_set = 0;
|
||||
|
||||
shnet_output_helper(state, &oh, shared_p);
|
||||
if (state->skip_ok && oh.status == STATUS_OK)
|
||||
if (shnet_output_helper(state, &oh, shared_p))
|
||||
continue;
|
||||
if (state->color_mode == color_on)
|
||||
color_set = start_color(&oh, outfile);
|
||||
|
|
@ -351,8 +350,7 @@ static int output_xml(struct conf_t *state, const int print_mac_addreses)
|
|||
|
||||
if (state->number_limit & R_BIT) {
|
||||
for (i = 0; i < state->num_ranges; i++) {
|
||||
range_output_helper(state, &oh, range_p);
|
||||
if (state->skip_ok && oh.status == STATUS_OK) {
|
||||
if (range_output_helper(state, &oh, range_p)) {
|
||||
range_p++;
|
||||
continue;
|
||||
}
|
||||
|
|
@ -376,8 +374,7 @@ static int output_xml(struct conf_t *state, const int print_mac_addreses)
|
|||
|
||||
if (state->number_limit & S_BIT) {
|
||||
for (shared_p = state->shared_net_root->next; shared_p; shared_p = shared_p->next) {
|
||||
shnet_output_helper(state, &oh, shared_p);
|
||||
if (state->skip_ok && oh.status == STATUS_OK)
|
||||
if (shnet_output_helper(state, &oh, shared_p))
|
||||
continue;
|
||||
fprintf(outfile, "<shared-network>\n");
|
||||
fprintf(outfile, "\t<location>%s</location>\n", shared_p->name);
|
||||
|
|
@ -452,8 +449,7 @@ static int output_json(struct conf_t *state, const int print_mac_addreses)
|
|||
}
|
||||
fprintf(outfile, " \"subnets\": [\n");
|
||||
for (i = 0; i < state->num_ranges; i++) {
|
||||
range_output_helper(state, &oh, range_p);
|
||||
if (state->skip_ok && oh.status == STATUS_OK) {
|
||||
if (range_output_helper(state, &oh, range_p)) {
|
||||
range_p++;
|
||||
continue;
|
||||
}
|
||||
|
|
@ -499,8 +495,7 @@ static int output_json(struct conf_t *state, const int print_mac_addreses)
|
|||
}
|
||||
fprintf(outfile, " \"shared-networks\": [\n");
|
||||
for (shared_p = state->shared_net_root->next; shared_p; shared_p = shared_p->next) {
|
||||
shnet_output_helper(state, &oh, shared_p);
|
||||
if (state->skip_ok && oh.status == STATUS_OK)
|
||||
if (shnet_output_helper(state, &oh, shared_p))
|
||||
continue;
|
||||
fprintf(outfile, " ");
|
||||
fprintf(outfile, "{ ");
|
||||
|
|
@ -777,8 +772,7 @@ static int output_html(struct conf_t *state)
|
|||
if (state->number_limit & S_BIT) {
|
||||
start_tag(outfile, "tbody");
|
||||
for (shared_p = state->shared_net_root->next; shared_p; shared_p = shared_p->next) {
|
||||
shnet_output_helper(state, &oh, shared_p);
|
||||
if (state->skip_ok && oh.status == STATUS_OK)
|
||||
if (shnet_output_helper(state, &oh, shared_p))
|
||||
continue;
|
||||
start_tag(outfile, "tr");
|
||||
output_line(outfile, "td", shared_p->name);
|
||||
|
|
@ -821,8 +815,7 @@ static int output_html(struct conf_t *state)
|
|||
if (state->number_limit & R_BIT) {
|
||||
start_tag(outfile, "tbody");
|
||||
for (i = 0; i < state->num_ranges; i++) {
|
||||
range_output_helper(state, &oh, range_p);
|
||||
if (state->skip_ok && oh.status == STATUS_OK) {
|
||||
if (range_output_helper(state, &oh, range_p)) {
|
||||
range_p++;
|
||||
continue;
|
||||
}
|
||||
|
|
@ -878,8 +871,7 @@ static int output_csv(struct conf_t *state)
|
|||
}
|
||||
if (state->number_limit & R_BIT) {
|
||||
for (i = 0; i < state->num_ranges; i++) {
|
||||
range_output_helper(state, &oh, range_p);
|
||||
if (state->skip_ok && oh.status == STATUS_OK) {
|
||||
if (range_output_helper(state, &oh, range_p)) {
|
||||
range_p++;
|
||||
continue;
|
||||
}
|
||||
|
|
@ -919,8 +911,7 @@ static int output_csv(struct conf_t *state)
|
|||
if (state->number_limit & S_BIT) {
|
||||
|
||||
for (shared_p = state->shared_net_root->next; shared_p; shared_p = shared_p->next) {
|
||||
shnet_output_helper(state, &oh, shared_p);
|
||||
if (state->skip_ok && oh.status == STATUS_OK)
|
||||
if (shnet_output_helper(state, &oh, shared_p))
|
||||
continue;
|
||||
fprintf(outfile,
|
||||
"\"%s\",\"%g\",\"%g\",\"%.3f\",\"%g\",\"%g\",\"%.3f\"",
|
||||
|
|
@ -1063,8 +1054,7 @@ static int output_alarming(struct conf_t *state)
|
|||
if (state->perfdata == 1 && state->number_limit & R_BIT) {
|
||||
for (i = 0; i < state->num_ranges; i++) {
|
||||
range_p--;
|
||||
range_output_helper(state, &oh, range_p);
|
||||
if (state->skip_ok && oh.status == STATUS_OK)
|
||||
if (range_output_helper(state, &oh, range_p))
|
||||
continue;
|
||||
if (state->minsize < oh.range_size) {
|
||||
fprintf(outfile, " %s_r=", ntop_ipaddr(&range_p->first_ip));
|
||||
|
|
@ -1097,8 +1087,7 @@ static int output_alarming(struct conf_t *state)
|
|||
}
|
||||
if (state->perfdata == 1 && state->header_limit & R_BIT) {
|
||||
for (shared_p = state->shared_net_root->next; shared_p; shared_p = shared_p->next) {
|
||||
shnet_output_helper(state, &oh, shared_p);
|
||||
if (state->skip_ok && oh.status == STATUS_OK)
|
||||
if (shnet_output_helper(state, &oh, shared_p))
|
||||
continue;
|
||||
if (state->minsize < shared_p->available) {
|
||||
fprintf(outfile, " '%s_s'=%g;%g;%g;0;%g",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue