Commit graph

445 commits

Author SHA1 Message Date
Sami Kerola
447241e6c3
tests: improve coverage
Add error condition checks.  Add lease file binding states.  Check all
output formats.  Check leases file that is in mad order, cse all sorting
methods when checking this.  Use json output to check status classfications.
Add cidr range checks.  Add conf include and comment parsing input checks.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-11-26 15:14:49 +00:00
Sami Kerola
2849dde21b
build-sys: add coverage files to .gitignore
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-11-26 13:59:17 +00:00
Sami Kerola
813e320b68
webpage: add instructions how to get output you need
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-11-15 20:09:52 +00:00
Sami Kerola
e6e90b4d62
release: 3.0
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-11-15 13:29:46 +00:00
Sami Kerola
a1d2bd2cf7
usage: --skip=ignored is actually 'suppressed'
When making --skip to take arguments ignored was for moment a work name for
'suppressed' state, and that was accidentally left to usage() output.

Reference: 3369278fc0
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-11-14 22:30:07 +00:00
Sami Kerola
46ec42182b
output: add some trivia data to json output
These are software version, dhcpd conf and leases paths and mtime epoch
timestamps.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-11-14 20:24:15 +00:00
Sami Kerola
444815f964
orther: fix xstrstr_init() memcmp() return value usage
This is a bug.  The xstrstr_init initialized wrong IP version functions when
this function was the first to run and set function pointers.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-11-14 18:58:11 +00:00
Sami Kerola
6d737a7607
output: unify time stamp creations
Use iso time stamp in both mustach and html outputs.  Effectively this is a
removal of libc langinfo D_T_FMT format, that pulled a lot of gnulib stuff
to project almost unnecessarily.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-11-14 11:08:46 +00:00
Sami Kerola
ff3d9523e6
output: add more items to mustach tags
Base level printing; localstime, number of ranges and shared networks,
project version, and file paths and time stamps.

Also print error and stop template processing when unknown tag is
encountered.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-11-14 10:48:52 +00:00
Sami Kerola
d24313d25a
output: remove unused variable attribute
The closure is used.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-11-14 00:17:56 +00:00
Sami Kerola
c687f38ed6
docs: improve doxygen documentation
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-11-14 00:11:46 +00:00
Sami Kerola
887845df2a
misc: move couple enums from global scope to file scope
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-11-13 21:55:14 +00:00
Sami Kerola
74b697321f
misc: move command line option parsing to separate function
Earlier main() had lots of temporary variables related to command line
parsing.  By moving these to separate function runtime can forget these
variables when moving on.  If nothing else this makes running gdb nicer when
debugging crashes, but as said stack memory should also be spared for better
purpose.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-11-13 21:52:03 +00:00
Sami Kerola
3369278fc0
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>
2017-11-13 20:23:12 +00:00
Sami Kerola
e4f7259cf6
samples: add prometheus text file collector mustach template
Because prometheus needs timestamp information add that to mustach, and
update manual page what tags are available.

Reference: https://prometheus.io/docs/instrumenting/exposition_formats/
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-11-13 14:18:05 +00:00
Sami Kerola
eabaa8adc2
thanks: add Troy D. Hanson to credits about uthash
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-11-13 11:53:21 +00:00
Sami Kerola
8fba5c5e6b
clean up: fix couple compiler warnings
src/sort.c:255:5: warning: no previous prototype for 'merge'
src/sort.c:290:2: warning: ISO C90 forbids mixed declarations and code
src/mustach-dhcpd-pools.c:67:5: warning: no previous prototype for 'must_put_err'
src/output.c:109:26: warning: comparing floating point with == or != is unsafe (x5)

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-11-13 11:37:18 +00:00
Sami Kerola
88a3f1eb53
hash: include stdlib.h to avoid implicit declarations
Reported-by: Frank Bulk <fbulk@mypremieronline.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-11-13 11:37:15 +00:00
Sami Kerola
8ae5fbf489
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>
2017-11-13 10:16:34 +00:00
Sami Kerola
b2c764924b
output: shared net can be in suppressed state
Avoid calling abort() when this very unlikely situation happens.

Reference: 48962004b8
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-11-13 09:57:22 +00:00
Sami Kerola
242c58f45e
output: display more entries in html table by default
And add 'All' to 'Show number of entries' menu.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-11-12 23:14:23 +00:00
Sami Kerola
c029c7581a
output: make warning and critical colors work in html output
Users should combine this with --color=always to web pages to work
correctly.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-11-12 22:19:09 +00:00
Sami Kerola
a64630aa49
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>
2017-11-12 17:43:42 +00:00
Sami Kerola
15f08bbf02
output: make --skip-ok to effect --perfdata
Reported-by: Frank Bulk <fbulk@mypremieronline.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-11-12 17:31:01 +00:00
Sami Kerola
ef5421ed05
analysis: shared networks to be linked list
This way memory is allocated only for items that are in use, and walking
through shared network items is also more straightforward.

As an unfortunate side effect in --perfdata output shared networks are no
longer printed in reverse order.  This should be a cosmetic issue.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-11-12 16:54:00 +00:00
Sami Kerola
a237c11d5a
output: improve mustach template parsing error
Following error did not inform clearly what is wrong.

$ ./dhcpd-pools -l samples/dhcpd.leases -c samples/dhcpd.conf -fm
./dhcpd-pools: must_read_template: open: (null): Bad address

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-11-12 15:22:46 +00:00
Sami Kerola
5a8c178924
other: add Jose Bollo to version output credits
Be also a little bit more verbose about licenses in version output.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-11-12 15:12:16 +00:00
Sami Kerola
d25e7afa1c
analyze: bug fix shared networks counts
This also fixes backup state counts that were added to shared networks
twice, making the numbers to be much greater than they really where.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-11-12 15:12:16 +00:00
Sami Kerola
7cd381ed83
all files: re-indent
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-11-12 15:12:16 +00:00
Sami Kerola
1875a13733
all files: replace global variables with runtime config state structure
Earlier variables magically appeared to scope of functions that took void as
argument.  One could figure out perhaps they were globals, but programs that
do that are unnessarily hard to follow.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-11-12 15:12:15 +00:00
Sami Kerola
adda925c1e
clean up: remove unused variable
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-11-11 23:59:13 +00:00
Sami Kerola
3dda0a77a5
output: deduplicate file closing code
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-11-11 23:09:33 +00:00
Sami Kerola
7575294c36
usage: add error message informing mustach support is not available
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-11-11 21:15:36 +00:00
Sami Kerola
39b2811aa7
build-sys: omit mustach compilation when it cannot work
For example mac does not have open_memstream(3), and strndupa(3) can also be
missing.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-11-11 16:13:14 +00:00
Sami Kerola
b96f8cd8ad
gnulib: use nstrftime instead of strftime
The strftime module is obsolete.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-11-11 15:37:07 +00:00
Sami Kerola
54cedc1001
output: include stdlib.h to avoid compilation error
The stdlib.h has EXIT_FAILURE and free(3).

Reported-by: Sebastián Cramatte <scramatte@nixus.es>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-11-11 14:29:00 +00:00
Sami Kerola
e4baff79bd
output: add must_put_err() utility function
This function deals situation when mustach put happens before enter, that is
a sign of an invalid input template.  Good side of adding this function is
that dhcpd-pools does not need to modify code provided by Jose.

Reference: 66183bc7c7
Proposed-by: José Bollo <jobol@nonadev.net>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-11-11 09:00:33 +00:00
Sami Kerola
4fc4bcd083
output: save and reuse output helper results
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-11-11 08:39:50 +00:00
Sami Kerola
d5ae2a80c0
output: do not skip over first range in mustach output
Off by one that is caused by must_next_range() advancing pointer, and moving
over the first range.  Fix by setting indexes one step backwards, that is
not excellent but better than copying skip_ok stuff to must_enter().

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-11-11 08:20:10 +00:00
Sami Kerola
50fc4ebe9d
output: avoid mixing ntop_ipaddr() output buffers
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-11-11 08:19:56 +00:00
Sami Kerola
66183bc7c7
output: make mustach processing more robust
Fix issues found with afl-fuzz.  It is a pity I had to change mustach.c it
is no longer exactly the same as upstream.  Lets see if Jose will accept
these changes.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-11-09 19:49:37 +00:00
Sami Kerola
2ec953858b
tests: add mustach check
Use samples directory data as input to ensure they do not break.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-11-09 19:49:17 +00:00
Sami Kerola
39e6e65201
docs: add mustach sample files
Include samples to installation, and give a hint to user where it can be
found in manual page.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-11-09 19:49:17 +00:00
Sami Kerola
74fdf90980
output: add separate first_ip and last_ip to json and mustach outputs
This give greater liberty to people who are using these formats to do what
ever they need to.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-11-09 19:49:17 +00:00
Sami Kerola
7d9a5b5561
output: add mustach templating support
Based on José Bollo's mustache C implementation.  This adaptation uses
project specific data structures to avoid overhead with json parsing.

Reference: https://gitlab.com/jobol/mustach.git
Commit: d84608a69033d38c81b8fcff0cb272e225dd5428
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-11-09 19:49:13 +00:00
Sami Kerola
fe847bb9b1
output: use range_output_helper() value in output_xml()
Earlier commit started to use range_output_helper() in output_xml() so
remove the unnecessary calls to get_range_size().

Reference: c55c823753
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-11-08 23:04:28 +00:00
Sami Kerola
1182ec4cc9
include: use project specific header guard
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-11-07 13:45:17 +00:00
Sami Kerola
e9736f74e7
getdata: do not use 'else' after 'continue'
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-11-07 13:44:50 +00:00
Sami Kerola
e5cd46e4e9
other: do not use 'else' after 'return'
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-11-07 13:12:37 +00:00
Sami Kerola
eb7547c742
output: json nan values need quoting
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-11-07 10:41:53 +00:00