Commit graph

96 commits

Author SHA1 Message Date
Sami Kerola
17d68b7e3e
various: tidy up variable scopes, and one name mismatch
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2019-03-26 21:26:51 +00:00
Sami Kerola
71714a0993
warnings: ensure optimal packing in structures
Add padding where needed and order structure when it makes alignment fall
naturally to better order, with a single padding at the end of structure.

Reference: http://www.catb.org/esr/structure-packing/
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2019-02-17 11:43:02 +00:00
Sami Kerola
3f85360c64
main: move output_format to state, and rename color_format
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2018-05-20 12:03:07 +01:00
Sami Kerola
e8e9d49ebb
main: move print_mac_addreses to state structure
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2018-05-20 11:47:30 +01: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
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
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
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
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
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
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
c55c823753
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>
2017-11-06 22:11:47 +00:00
Sami Kerola
344ed2900d
output: add color support to text output
When --warning or --critical thresholds are defined with text output lines
that exceed threshold will be either yellow (warning) or red (critical).

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-11-06 21:31:57 +00:00
Sami Kerola
48962004b8
output: add output helper functions
There is too much repetative confusing maths near printouts.  Move that
stuff to a function.

This change also fixes --snet-alarms option counting issue in range that
were not part of any shared network were ignored.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-11-05 16:21:20 +00:00
Sami Kerola
05f8208518
getdata: fix typo
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-11-05 10:01:07 +00:00
Sami Kerola
abf5d04736
output: make output_analysis() to be regular function
This commit makes it possible to define alarming thresholds at the same time
with other output formats.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-11-05 09:51:35 +00:00
Sami Kerola
bb0fa9adae
getdata: add cidr range support
This makes 'range6 123::/45' style cidr notation to be understood as address
range.  Earlier ranges that used cidr failed to parse completely.

Reported-by: Jeff Bailey <jeffrey.bailey@bt.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-09-17 00:03:06 +01:00
Boris Lytochkin
b9cff0d814
introduce -A arg: treat single subnets as shared-network with CIDR as their name
Current output makes some false-positives for situations when multiple
ranges are specified inside single network, for example:

subnet 10.0.0.0 netmask 255.255.254.0 {
	...
	range 10.0.0.1 10.0.0.254;
	range 10.0.1.1 10.0.1.253;
	...
}

An alert for range 10.0.0.1 - 10.0.0.254 will be raised even in situations
when range 10.0.1.1 - 10.0.1.253 is completely empty.  To cope with this
issue, an -A option is added to treat all single networks as shared-network.
This option changes output for both range and shared networks output if
specified.  Frankly saying, using network CIDR as network name is much more
sane for me than 'All Networks'.

Signed-off-by: Boris Lytochkin <lytboris@yandex-team.ru>
2017-07-15 17:26:15 +01:00
Sami Kerola
9a52619385
style: use same argument names in header and source file
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-04-07 22:56:19 +01:00
Sami Kerola
ea7fd91876
remove const and pure function attributes
Most of these functions take pointers as input argument, so they cannot be
considered neiter const or pure.  In same go fix few issues noticed when
compiling with smatch.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-01-06 23:14:28 +00:00
Sami Kerola
7740927721
build-sys: always use restrict found by autoconf
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-08-16 13:25:23 +01:00
Manuel Hachtkemper
32e2d399a0
alarming: add additional performance data
Options -p or --perfdata (in alarming mode) now enable the output of
additional performance data, i.e.  used, touched and backup addresses per
subnet.

Signed-off-by: Manuel Hachtkemper <hacman@math.uni-bonn.de>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-03-31 22:34:27 +01:00
Sami Kerola
f5cd7383e4
fix improve variable names
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-12-04 19:32:50 +00:00
Sami Kerola
98bcdf9378
simplify output format selection, and passing
Use of enum is a lot more readable than passing strings, and comparing
characters, around.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-12-01 23:25:54 +00:00
Sami Kerola
b524296016
use bitmap for booleans and other config that has known size
Bitmaps are more c style than bool coming from c++ land.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-12-01 23:24:14 +00:00
Sami Kerola
0369340710
remove upper limit of sort order definitions
Unlikely to be needed by anyone, but because arbitrary limits are from code
style point of view ugly.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-11-30 00:50:18 +00:00
Sami Kerola
327691f34a
use more descriptive names in limit bits enum definition
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-11-29 23:36:19 +00:00
Sami Kerola
4aff49ed80
correct return value FIXME items
Not all markups were quite right.  The output_* functions must return an
int.  The rest were as a matter of fact correct.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-11-28 21:03:38 +00:00
Sami Kerola
1299737d76
make html output to use Bootstrap and DataTables
This make the table output good looking, and allows users to click table
headings to sort data by column without rerunning the analysis.
Unfortunately this change is breaking change, meaning the old CSS tags are
no longer supported, nor partial html output that printed only the table.

Proposed-by: Aaron Paetznick <aaronp@critd.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-11-28 20:37:23 +00:00
Sami Kerola
5cede1ff31
add --warn-count and --crit-count options to suppress alarm noise
Alarm criteria based solely on percentage was found to be difficult to be
tricky to setup in environments that has small ranges and big shared-nets
mixed up together.  These two new options should help making alarming more
useful.

Requested-by: Frank Bulk <fbulk@mypremieronline.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-11-28 00:33:12 +00:00
Sami Kerola
7f3d553c7f
add --snet-alarms option to suppress excess range alarms
Some users may not want to have alarms about ranges that are part of a
shared-network, so allow them to suppress such.

Requested-by: Frank Bulk <fbulk@mypremieronline.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-11-27 23:42:23 +00:00
Sami Kerola
e09f655a7b add appropriate sorting function for struct leases_t
The HASH_SORT in analyze needs this.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-08-09 19:28:23 +01:00
Sami Kerola
965875d20b declare global variables only once
Global variable declarations belong near main, and the header has to have
extern reference to them.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-08-09 19:09:04 +01:00
Sami Kerola
4392a5b917 reindent all files
And update the indent.pro to match with the style I like.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-07-20 18:05:00 +01:00
Sami Kerola
eb55946595 output: use symbolic exit values for nagios commands
And ensure the exit values are set no matter how user will limit output.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-03-24 21:56:34 +00:00
Sami Kerola
d089a19fb5 generic: use pure and const function attributes when possible
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-11-17 18:25:52 +00:00
Sami Kerola
8da98bbc89 various: split functions to IPv4 and IPv6 versions
The code selection will be set with function pointer, which avoids
numerous IP version checks.  As a result with some inputs the analysis
runs quicker.  Most users will not notice much of difference.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-09-21 12:37:52 +01:00
Sami Kerola
97c6f0292f getdata: split busy function to segments used via function pointer
When it is known IPv4 is in use there is no need to spend time with if
statements checking whether IPv6 is in use.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-09-18 00:56:54 +01:00
Sami Kerola
5b8ad97611 getdata: memccpy() is better than own similar function
The memccpy() is maintained in libc so there is no reason to reimplement
similar functionality within this software.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-09-18 00:05:16 +01:00
Sami Kerola
5189333c95 analyze: remove unnecessary function
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-09-17 22:58:53 +01:00
Sami Kerola
06ffa5ed04 xstrstr: speed up analysis by avoiding string comparisons
With large input one should see cut 15% for overall run time.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-08-31 00:30:28 +01:00
Sami Kerola
28f1e8c54c output: allow user to ignore small ranges and shared networks
Some have configuration which combines small ranges such as one host, and
greater address ranges that are important to monitor.  Especially the one
host ranges tend to cause a lot of false-positive alarms, as they are
immediately 100% full when a machine requests an address.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-07-12 19:29:44 +01:00
Cheer Xiao
b858a4778b getdata: treat binding states abandoned, expired and release like free 2013-04-07 20:16:44 +08:00
Sami Kerola
23aae87356 include: add missing declarations to dhcpd-pool.h
This will fix eight warnings similar to the example below.

sort.c:104:5: warning: no previous declaration for 'comp_ip' [-Wmissing-declarations]

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-03-08 23:38:25 +00:00
Cheer Xiao
9c4184bd9a counting: Let get_range_size return double 2013-01-08 22:57:33 +08:00
Cheer Xiao
6820c9fc09 fix: Put prototype of field_selector back to dhcpd-pools.h
It's needed in main to check unknown field selectors.
2013-01-08 22:52:54 +08:00