mirror of
git://git.code.sf.net/p/dhcpd-pools/code
synced 2025-12-16 07:47:00 +00:00
output: add --skip-ok option
Omit ranges and shared networks that do not exceed warning or critical thresholds. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
parent
e079cc16e0
commit
c55c823753
4 changed files with 47 additions and 2 deletions
|
|
@ -159,6 +159,12 @@ coloring thresholds can be changed, but one must also use
|
||||||
.B \-\-format=text
|
.B \-\-format=text
|
||||||
to avoid turning on alarting mode.
|
to avoid turning on alarting mode.
|
||||||
.TP
|
.TP
|
||||||
|
\fB\-\-skip\-ok
|
||||||
|
Do not print ranges that are within thresholds of
|
||||||
|
.B \-\-warning
|
||||||
|
or
|
||||||
|
.BR \-\-critical .
|
||||||
|
.TP
|
||||||
\fB\-\-warning\fR=\fIpercent\fR
|
\fB\-\-warning\fR=\fIpercent\fR
|
||||||
Turn on alarm output format, and specify percentage number which will
|
Turn on alarm output format, and specify percentage number which will
|
||||||
cause an alarm. If either a range or shared network will exceed
|
cause an alarm. If either a range or shared network will exceed
|
||||||
|
|
|
||||||
|
|
@ -111,6 +111,7 @@ int main(int argc, char **argv)
|
||||||
OPT_WARN_COUNT,
|
OPT_WARN_COUNT,
|
||||||
OPT_CRIT_COUNT,
|
OPT_CRIT_COUNT,
|
||||||
OPT_COLOR,
|
OPT_COLOR,
|
||||||
|
OPT_SKIP_OK,
|
||||||
OPT_SET_IPV
|
OPT_SET_IPV
|
||||||
};
|
};
|
||||||
int ret_val;
|
int ret_val;
|
||||||
|
|
@ -119,6 +120,7 @@ int main(int argc, char **argv)
|
||||||
{"config", required_argument, NULL, 'c'},
|
{"config", required_argument, NULL, 'c'},
|
||||||
{"leases", required_argument, NULL, 'l'},
|
{"leases", required_argument, NULL, 'l'},
|
||||||
{"color", required_argument, NULL, OPT_COLOR},
|
{"color", required_argument, NULL, OPT_COLOR},
|
||||||
|
{"skip-ok", no_argument, NULL, OPT_SKIP_OK},
|
||||||
{"format", required_argument, NULL, 'f'},
|
{"format", required_argument, NULL, 'f'},
|
||||||
{"sort", required_argument, NULL, 's'},
|
{"sort", required_argument, NULL, 's'},
|
||||||
{"reverse", no_argument, NULL, 'r'},
|
{"reverse", no_argument, NULL, 'r'},
|
||||||
|
|
@ -228,6 +230,9 @@ int main(int argc, char **argv)
|
||||||
if (config.color_mode == color_unknown)
|
if (config.color_mode == color_unknown)
|
||||||
error(EXIT_FAILURE, errno, "unknown color mode: %s", quote(optarg));
|
error(EXIT_FAILURE, errno, "unknown color mode: %s", quote(optarg));
|
||||||
break;
|
break;
|
||||||
|
case OPT_SKIP_OK:
|
||||||
|
config.skip_ok = 1;
|
||||||
|
break;
|
||||||
case OPT_SNET_ALARMS:
|
case OPT_SNET_ALARMS:
|
||||||
config.snet_alarms = 1;
|
config.snet_alarms = 1;
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -238,6 +238,7 @@ struct configuration_t {
|
||||||
all_as_shared:1,
|
all_as_shared:1,
|
||||||
header_limit:3,
|
header_limit:3,
|
||||||
number_limit:3,
|
number_limit:3,
|
||||||
|
skip_ok:1,
|
||||||
color_mode:2;
|
color_mode:2;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
37
src/output.c
37
src/output.c
|
|
@ -189,6 +189,10 @@ static int output_txt(void)
|
||||||
for (i = 0; i < num_ranges; i++) {
|
for (i = 0; i < num_ranges; i++) {
|
||||||
int color_set = 0;
|
int color_set = 0;
|
||||||
range_output_helper(&oh, range_p);
|
range_output_helper(&oh, range_p);
|
||||||
|
if (config.skip_ok && oh.status == STATUS_OK) {
|
||||||
|
range_p++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (config.color_mode == color_on)
|
if (config.color_mode == color_on)
|
||||||
color_set = start_color(&oh, outfile);
|
color_set = start_color(&oh, outfile);
|
||||||
if (range_p->shared_net) {
|
if (range_p->shared_net) {
|
||||||
|
|
@ -238,6 +242,8 @@ static int output_txt(void)
|
||||||
int color_set = 0;
|
int color_set = 0;
|
||||||
shared_p++;
|
shared_p++;
|
||||||
shnet_output_helper(&oh, shared_p);
|
shnet_output_helper(&oh, shared_p);
|
||||||
|
if (config.skip_ok && oh.status == STATUS_OK)
|
||||||
|
continue;
|
||||||
if (config.color_mode == color_on)
|
if (config.color_mode == color_on)
|
||||||
color_set = start_color(&oh, outfile);
|
color_set = start_color(&oh, outfile);
|
||||||
fprintf(outfile,
|
fprintf(outfile,
|
||||||
|
|
@ -317,6 +323,7 @@ static int output_xml(const int print_mac_addreses)
|
||||||
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;
|
||||||
int ret;
|
int ret;
|
||||||
FILE *outfile;
|
FILE *outfile;
|
||||||
|
|
||||||
|
|
@ -353,6 +360,11 @@ static int output_xml(const int print_mac_addreses)
|
||||||
|
|
||||||
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 (config.skip_ok && oh.status == STATUS_OK) {
|
||||||
|
range_p++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
fprintf(outfile, "<subnet>\n");
|
fprintf(outfile, "<subnet>\n");
|
||||||
if (range_p->shared_net) {
|
if (range_p->shared_net) {
|
||||||
fprintf(outfile,
|
fprintf(outfile,
|
||||||
|
|
@ -375,6 +387,9 @@ static int output_xml(const int print_mac_addreses)
|
||||||
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);
|
||||||
|
if (config.skip_ok && oh.status == STATUS_OK)
|
||||||
|
continue;
|
||||||
fprintf(outfile, "<shared-network>\n");
|
fprintf(outfile, "<shared-network>\n");
|
||||||
fprintf(outfile, "\t<location>%s</location>\n", shared_p->name);
|
fprintf(outfile, "\t<location>%s</location>\n", shared_p->name);
|
||||||
fprintf(outfile, "\t<defined>%g</defined>\n", shared_p->available);
|
fprintf(outfile, "\t<defined>%g</defined>\n", shared_p->available);
|
||||||
|
|
@ -470,6 +485,10 @@ static int output_json(const int print_mac_addreses)
|
||||||
fprintf(outfile, " \"subnets\": [\n");
|
fprintf(outfile, " \"subnets\": [\n");
|
||||||
for (i = 0; i < num_ranges; i++) {
|
for (i = 0; i < num_ranges; i++) {
|
||||||
range_output_helper(&oh, range_p);
|
range_output_helper(&oh, range_p);
|
||||||
|
if (config.skip_ok && oh.status == STATUS_OK) {
|
||||||
|
range_p++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
fprintf(outfile, " ");
|
fprintf(outfile, " ");
|
||||||
fprintf(outfile, "{ ");
|
fprintf(outfile, "{ ");
|
||||||
if (range_p->shared_net) {
|
if (range_p->shared_net) {
|
||||||
|
|
@ -510,9 +529,11 @@ static int output_json(const int print_mac_addreses)
|
||||||
}
|
}
|
||||||
fprintf(outfile, " \"shared-networks\": [\n");
|
fprintf(outfile, " \"shared-networks\": [\n");
|
||||||
for (i = 0; i < num_shared_networks; i++) {
|
for (i = 0; i < num_shared_networks; i++) {
|
||||||
shnet_output_helper(&oh, shared_p);
|
|
||||||
fprintf(outfile, " ");
|
|
||||||
shared_p++;
|
shared_p++;
|
||||||
|
shnet_output_helper(&oh, shared_p);
|
||||||
|
if (config.skip_ok && oh.status == STATUS_OK)
|
||||||
|
continue;
|
||||||
|
fprintf(outfile, " ");
|
||||||
fprintf(outfile, "{ ");
|
fprintf(outfile, "{ ");
|
||||||
fprintf(outfile, "\"location\":\"%s\", ", shared_p->name);
|
fprintf(outfile, "\"location\":\"%s\", ", shared_p->name);
|
||||||
fprintf(outfile, "\"defined\":%g, ", shared_p->available);
|
fprintf(outfile, "\"defined\":%g, ", shared_p->available);
|
||||||
|
|
@ -801,6 +822,8 @@ static int output_html(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_networks);
|
shnet_output_helper(&oh, shared_networks);
|
||||||
|
if (config.skip_ok && oh.status == STATUS_OK)
|
||||||
|
continue;
|
||||||
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);
|
||||||
|
|
@ -843,6 +866,10 @@ static int output_html(void)
|
||||||
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);
|
range_output_helper(&oh, range_p);
|
||||||
|
if (config.skip_ok && oh.status == STATUS_OK) {
|
||||||
|
range_p++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
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);
|
||||||
|
|
@ -916,6 +943,10 @@ 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);
|
range_output_helper(&oh, range_p);
|
||||||
|
if (config.skip_ok && oh.status == STATUS_OK) {
|
||||||
|
range_p++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
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 {
|
||||||
|
|
@ -956,6 +987,8 @@ 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);
|
shnet_output_helper(&oh, shared_p);
|
||||||
|
if (config.skip_ok && oh.status == STATUS_OK)
|
||||||
|
continue;
|
||||||
fprintf(outfile,
|
fprintf(outfile,
|
||||||
"\"%s\",\"%g\",\"%g\",\"%.3f\",\"%g\",\"%g\",\"%.3f\"",
|
"\"%s\",\"%g\",\"%g\",\"%.3f\",\"%g\",\"%g\",\"%.3f\"",
|
||||||
shared_p->name,
|
shared_p->name,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue