output: improve html table

Update DataTables and Bootstrap versions.  Add free IP counts to table.
Replace yellow as warning with magenta that is easier to read from white
background.  Use italic and bold to emphasis warning and critical.  Remove
strips.  Use ascent percent sort by default.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
Sami Kerola 2017-11-13 10:10:20 +00:00
parent b2c764924b
commit 8ae5fbf489
No known key found for this signature in database
GPG key ID: A9553245FDE9B739
2 changed files with 23 additions and 21 deletions

View file

@ -61,11 +61,11 @@
static const char *color_tags[][NUM_OF_OUT_FORMS] = {
[STATUS_OK] = { "", "" },
[STATUS_WARN] = { "\033[1;33m", "<font color=\"yellow\">" },
[STATUS_CRIT] = { "\033[1;31m", "<font color=\"red\">" },
[STATUS_IGNORED] = { "\033[1;32m", "<font color=\"green\">" },
[STATUS_SUPPRESSED] = { "\033[1;34m", "<font color=\"blue\">" },
[COLOR_RESET] = { "\033[0m", "</font>" }
[STATUS_WARN] = { "\033[1;33m", " style=\"color:magenta;font-style:italic\"" },
[STATUS_CRIT] = { "\033[1;31m", " style=\"color:red;font-weight:bold\"" },
[STATUS_IGNORED] = { "\033[1;32m", " style=\"color:green\"" },
[STATUS_SUPPRESSED] = { "\033[1;34m", " style=\"color:blue\"" },
[COLOR_RESET] = { "\033[0m", "" }
};
@ -586,8 +586,8 @@ static void html_header(struct conf_t *state, FILE *restrict f)
fprintf(f, "<meta charset=\"utf-8\">\n");
fprintf(f, "<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">\n");
fprintf(f, "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n");
fprintf(f, "<link rel=\"stylesheet\" href=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css\" type=\"text/css\">\n");
fprintf(f, "<link rel=\"stylesheet\" href=\"https://cdn.datatables.net/1.10.10/css/jquery.dataTables.min.css\" type=\"text/css\">");
fprintf(f, "<link rel=\"stylesheet\" href=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css\" type=\"text/css\">\n");
fprintf(f, "<link rel=\"stylesheet\" type=\"text/css\" href=\"https://cdn.datatables.net/v/bs/jq-3.2.1/dt-1.10.16/datatables.min.css\">\n");
fprintf(f, "<style type=\"text/css\">\n");
fprintf(f, "table.dhcpd-pools th { text-transform: capitalize }\n");
fprintf(f, "</style>\n");
@ -609,11 +609,10 @@ static void html_footer(FILE *restrict f)
fprintf(f, "<small>Generated using %s<br />\n", PACKAGE_STRING);
fprintf(f, "More info at <a href=\"%s\">%s</a>\n", PACKAGE_URL, PACKAGE_URL);
fprintf(f, "</small></div></div>\n");
fprintf(f, "<script src=\"https://code.jquery.com/jquery-2.1.4.min.js\" type=\"text/javascript\"></script>\n");
fprintf(f, "<script src=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js\" type=\"text/javascript\"></script>\n");
fprintf(f, "<script src=\"https://cdn.datatables.net/1.10.10/js/jquery.dataTables.min.js\" type=\"text/javascript\"></script>\n");
fprintf(f, "<script type=\"text/javascript\" class=\"init\">$(document).ready(function() { $('#s').DataTable({ \"iDisplayLength\": 50, \"lengthMenu\": [ [25, 50, 100, -1], [25, 50, 100, \"All\"] ]} ); } );</script>\n");
fprintf(f, "<script type=\"text/javascript\" class=\"init\">$(document).ready(function() { $('#r').DataTable({ \"iDisplayLength\": 100, \"lengthMenu\": [ [25, 50, 100, -1], [25, 50, 100, \"All\"] ]} ); } );</script>\n");
fprintf(f, "<script src=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js\" type=\"text/javascript\"></script>\n");
fprintf(f, "<script type=\"text/javascript\" src=\"https://cdn.datatables.net/v/bs/jq-3.2.1/dt-1.10.16/datatables.min.js\"></script>\n");
fprintf(f, "<script type=\"text/javascript\" class=\"init\">$(document).ready(function() { $('#s').DataTable({ \"iDisplayLength\": 50, \"lengthMenu\": [ [25, 50, 100, -1], [25, 50, 100, \"All\"] ], \"order\": [[ 4, \"desc\" ]] } ); } );</script>\n");
fprintf(f, "<script type=\"text/javascript\" class=\"init\">$(document).ready(function() { $('#r').DataTable({ \"iDisplayLength\": 100, \"lengthMenu\": [ [25, 50, 100, -1], [25, 50, 100, \"All\"] ], \"order\": [[ 6, \"desc\" ]] } ); } );</script>\n");
fprintf(f, "</body></html>\n");
}
@ -671,14 +670,10 @@ static void output_double_color(struct conf_t *state,
struct output_helper_t *oh, FILE *restrict f,
char const *restrict type)
{
int color_set = 0;
fprintf(f, "<%s>", type);
fprintf(f, "<%s", type);
if (state->color_mode == color_on)
color_set = start_color(state, oh, f);
fprintf(f, "%g", oh->percent);
if (color_set)
fputs(color_tags[COLOR_RESET][state->output_format], f);
start_color(state, oh, f);
fprintf(f, ">%g", oh->percent);
fprintf(f, "</%s>\n", type);
}
@ -699,7 +694,7 @@ static void output_float(FILE *restrict f, char const *restrict type, float fl)
*/
static void table_start(FILE *restrict f, char const *restrict id, char const *restrict summary)
{
fprintf(f, "<table id=\"%s\" class=\"dhcpd-pools order-column table table-striped table-hover\" summary=\"%s\">\n", id, summary);
fprintf(f, "<table id=\"%s\" class=\"dhcpd-pools order-column table table-hover\" summary=\"%s\">\n", id, summary);
}
/*! \brief End table in html output format.
@ -741,6 +736,7 @@ static int output_html(struct conf_t *state)
output_line(outfile, "th", "name");
output_line(outfile, "th", "max");
output_line(outfile, "th", "cur");
output_line(outfile, "th", "free");
output_line(outfile, "th", "percent");
output_line(outfile, "th", "touch");
output_line(outfile, "th", "t+c");
@ -759,6 +755,7 @@ static int output_html(struct conf_t *state)
output_line(outfile, "td", state->shared_net_root->name);
output_double(outfile, "td", state->shared_net_root->available);
output_double(outfile, "td", state->shared_net_root->used);
output_double(outfile, "td", state->shared_net_root->available - state->shared_net_root->used);
output_float(outfile, "td", oh.percent);
output_double(outfile, "td", state->shared_net_root->touched);
output_double(outfile, "td", oh.tc);
@ -779,6 +776,7 @@ static int output_html(struct conf_t *state)
output_line(outfile, "th", "name");
output_line(outfile, "th", "max");
output_line(outfile, "th", "cur");
output_line(outfile, "th", "free");
output_line(outfile, "th", "percent");
output_line(outfile, "th", "touch");
output_line(outfile, "th", "t+c");
@ -799,6 +797,7 @@ static int output_html(struct conf_t *state)
output_line(outfile, "td", shared_p->name);
output_double(outfile, "td", shared_p->available);
output_double(outfile, "td", shared_p->used);
output_double(outfile, "td", shared_p->available - shared_p->used);
output_double_color(state, &oh, outfile, "td");
output_double(outfile, "td", shared_p->touched);
output_double(outfile, "td", oh.tc);
@ -822,7 +821,8 @@ static int output_html(struct conf_t *state)
output_line(outfile, "th", "last ip");
output_line(outfile, "th", "max");
output_line(outfile, "th", "cur");
output_double_color(state, &oh, outfile, "td");
output_line(outfile, "th", "free");
output_line(outfile, "th", "percent");
output_line(outfile, "th", "touch");
output_line(outfile, "th", "t+c");
output_line(outfile, "th", "t+c perc");
@ -850,6 +850,7 @@ static int output_html(struct conf_t *state)
output_line(outfile, "td", ntop_ipaddr(&range_p->last_ip));
output_double(outfile, "td", oh.range_size);
output_double(outfile, "td", range_p->count);
output_double(outfile, "td", oh.range_size - range_p->count);
output_double_color(state, &oh, outfile, "td");
output_double(outfile, "td", range_p->touched);
output_double(outfile, "td", oh.tc);