mirror of
git://git.code.sf.net/p/dhcpd-pools/code
synced 2025-12-17 16:26:59 +00:00
output: make --skip to take arguments what will be skipped
Accidental typo in usage() caused realisation making skipping to fully controllable is good idea. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
parent
e4f7259cf6
commit
3369278fc0
9 changed files with 216 additions and 23 deletions
|
|
@ -85,6 +85,49 @@ static void prepare_memory(struct conf_t *state)
|
|||
state->shared_net_head = state->shared_net_root;
|
||||
}
|
||||
|
||||
/*! \brief The --skip option argument parser. */
|
||||
static void skip_arg_parse(struct conf_t *state, char *optarg)
|
||||
{
|
||||
enum {
|
||||
OPT_ARG_OK = 0,
|
||||
OPT_ARG_WARNING,
|
||||
OPT_ARG_CRITICAL,
|
||||
OPT_ARG_MINSIZE,
|
||||
OPT_ARG_SUPRESSED
|
||||
};
|
||||
char *const tokens[] = {
|
||||
[OPT_ARG_OK] = "ok",
|
||||
[OPT_ARG_WARNING] = "warning",
|
||||
[OPT_ARG_CRITICAL] = "critical",
|
||||
[OPT_ARG_MINSIZE] = "minsize",
|
||||
[OPT_ARG_SUPRESSED] = "suppressed",
|
||||
NULL
|
||||
};
|
||||
char *value;
|
||||
|
||||
while (*optarg != '\0') {
|
||||
switch(getsubopt(&optarg, tokens, &value)) {
|
||||
case OPT_ARG_OK:
|
||||
state->skip_ok = 1;
|
||||
break;
|
||||
case OPT_ARG_WARNING:
|
||||
state->skip_warning = 1;
|
||||
break;
|
||||
case OPT_ARG_CRITICAL:
|
||||
state->skip_critical = 1;
|
||||
break;
|
||||
case OPT_ARG_MINSIZE:
|
||||
state->skip_minsize = 1;
|
||||
break;
|
||||
case OPT_ARG_SUPRESSED:
|
||||
state->skip_suppressed = 1;
|
||||
break;
|
||||
default:
|
||||
error(EXIT_FAILURE, 0, "unknown --skip specifier: %s", value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*! \brief Start of execution. Parse options, and call other other
|
||||
* functions one after another. At the moment adding threading support
|
||||
* would be difficult, but there does not seem to be valid reason to
|
||||
|
|
@ -120,7 +163,7 @@ int main(int argc, char **argv)
|
|||
OPT_WARN_COUNT,
|
||||
OPT_CRIT_COUNT,
|
||||
OPT_COLOR,
|
||||
OPT_SKIP_OK,
|
||||
OPT_SKIP,
|
||||
OPT_SET_IPV,
|
||||
OPT_MUSTACH
|
||||
};
|
||||
|
|
@ -130,7 +173,7 @@ int main(int argc, char **argv)
|
|||
{"config", required_argument, NULL, 'c'},
|
||||
{"leases", required_argument, NULL, 'l'},
|
||||
{"color", required_argument, NULL, OPT_COLOR},
|
||||
{"skip-ok", no_argument, NULL, OPT_SKIP_OK},
|
||||
{"skip", required_argument, NULL, OPT_SKIP},
|
||||
{"format", required_argument, NULL, 'f'},
|
||||
{"sort", required_argument, NULL, 's'},
|
||||
{"reverse", no_argument, NULL, 'r'},
|
||||
|
|
@ -223,8 +266,8 @@ int main(int argc, char **argv)
|
|||
if (state.color_mode == color_unknown)
|
||||
error(EXIT_FAILURE, errno, "unknown color mode: %s", quote(optarg));
|
||||
break;
|
||||
case OPT_SKIP_OK:
|
||||
state.skip_ok = 1;
|
||||
case OPT_SKIP:
|
||||
skip_arg_parse(&state, optarg);
|
||||
break;
|
||||
case OPT_SNET_ALARMS:
|
||||
state.snet_alarms = 1;
|
||||
|
|
|
|||
|
|
@ -267,6 +267,10 @@ struct conf_t {
|
|||
header_limit:4,
|
||||
number_limit:3,
|
||||
skip_ok:1,
|
||||
skip_warning:1,
|
||||
skip_critical:1,
|
||||
skip_minsize:1,
|
||||
skip_suppressed:1,
|
||||
color_mode:2;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -567,7 +567,7 @@ void __attribute__ ((__noreturn__)) usage(int status)
|
|||
fputs( " J for json with active lease details\n", out);
|
||||
fputs( " c for comma separated values\n", out);
|
||||
#ifdef BUILD_MUSTACH
|
||||
fputs( " --mustach=tmpl output using mustach template file\n", out);
|
||||
fputs( " --mustach=FILE output using mustach template file\n", out);
|
||||
#endif
|
||||
fputs( " -s, --sort=[nimcptTe] sort ranges by\n", out);
|
||||
fputs( " n name\n", out);
|
||||
|
|
@ -582,9 +582,10 @@ void __attribute__ ((__noreturn__)) usage(int status)
|
|||
fputs( " -o, --output=FILE output into a file\n", out);
|
||||
fputs( " -L, --limit=NR output limit mask 77 - 00\n", out);
|
||||
fputs( " --color=WHEN use colors 'always', 'never', or 'auto'\n", out);
|
||||
fputs( " --skip=ok do not print items below alarm threshold\n", out);
|
||||
fputs( " --warning=PERC set warning alarming limit\n", out);
|
||||
fputs( " --critical=PERC set critical alarming limit\n", out);
|
||||
fputs( " --warning=PERC set warning alarming threshold\n", out);
|
||||
fputs( " --critical=PERC set critical alarming threshold\n", out);
|
||||
fputs( " --skip=WHAT do not print threshold 'ok', 'warning', 'critical',\n", out);
|
||||
fputs( " 'minsize', or 'ignored'\n", out);
|
||||
fputs( " --warn-count=NR a number of free leases before warning raised\n", out);
|
||||
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);
|
||||
|
|
|
|||
34
src/output.c
34
src/output.c
|
|
@ -90,12 +90,19 @@ int range_output_helper(struct conf_t *state, struct output_helper_t *oh,
|
|||
&& (oh->range_size - range_p->count) < state->warn_count)
|
||||
oh->status = STATUS_WARN;
|
||||
if (oh->status != STATUS_OK) {
|
||||
if (oh->range_size <= state->minsize)
|
||||
if (oh->range_size <= state->minsize) {
|
||||
oh->status = STATUS_IGNORED;
|
||||
else if (state->snet_alarms && range_p->shared_net != state->shared_net_root)
|
||||
if (state->skip_minsize)
|
||||
return 1;
|
||||
} else if (state->snet_alarms && range_p->shared_net != state->shared_net_root) {
|
||||
oh->status = STATUS_SUPPRESSED;
|
||||
if (state->skip_suppressed)
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
if (state->skip_ok && oh->status == STATUS_OK)
|
||||
if ((state->skip_ok && oh->status == STATUS_OK) ||
|
||||
(state->skip_warning && oh->status == STATUS_WARN) ||
|
||||
(state->skip_critical && oh->status == STATUS_CRIT))
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -111,6 +118,8 @@ int shnet_output_helper(struct conf_t *state, struct output_helper_t *oh,
|
|||
oh->tcp = NAN;
|
||||
oh->bup = NAN;
|
||||
oh->status = STATUS_SUPPRESSED;
|
||||
if (state->skip_suppressed)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -120,16 +129,23 @@ int shnet_output_helper(struct conf_t *state, struct output_helper_t *oh,
|
|||
oh->bup = (double)(100 * shared_p->backups) / shared_p->available;
|
||||
|
||||
/* set status */
|
||||
if (shared_p->available <= state->minsize)
|
||||
if (shared_p->available <= state->minsize) {
|
||||
oh->status = STATUS_IGNORED;
|
||||
else if (state->critical < oh->percent && shared_p->used < state->crit_count)
|
||||
if (state->skip_minsize)
|
||||
return 1;
|
||||
} else if (state->critical < oh->percent && shared_p->used < state->crit_count) {
|
||||
oh->status = STATUS_CRIT;
|
||||
else if (state->warning < oh->percent && shared_p->used < state->warn_count)
|
||||
if (state->skip_critical)
|
||||
return 1;
|
||||
} else if (state->warning < oh->percent && shared_p->used < state->warn_count) {
|
||||
oh->status = STATUS_WARN;
|
||||
else
|
||||
if (state->skip_warning)
|
||||
return 1;
|
||||
} else {
|
||||
oh->status = STATUS_OK;
|
||||
if (state->skip_ok && oh->status == STATUS_OK)
|
||||
return 1;
|
||||
if (state->skip_ok)
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue