jonathanio / monitoring-nagios-haproxy

Nagios plugin (suitable for Nagios Check-compatible programs) for monitoring HAProxy services.
GNU General Public License v2.0
16 stars 19 forks source link

Use zero values for thresholds #8

Closed jouir closed 6 years ago

jouir commented 6 years ago

Zero values are replaced by hardcoded limits in defaults and by defaults in overrides arguments.

This pull request implements #7.

Given this HAProxy configuration:

listen read-write
    bind *:8000
    mode http
    server instance1 127.0.0.1:8001 check 
    server instance2 127.0.0.1:8002 check

listen read-only
    bind *:9000
    mode http
    server instance1 127.0.0.1:9001 check 
    server instance2 127.0.0.1:9002 check
    server read-write 127.0.0.1:8000 backup

The important part is when all servers in the read-only backend are down, there is still a backup server pointing to the read-write port:

$ curl -I -XGET http://127.0.0.1:9000/
HTTP/1.0 200 OK

The situation isn't critical because it still works but it would be nice to be notified because something is wrong with the read-only backend. For defaults, we could set u,2,1 for thresholds to warn when available servers go below count of 2 and crit below 1. It works. For the special read-only backend, we could set u,1,0 to warn below 1 host down and "ignore" critical as it will never go strictly below 0:

$ ./check_haproxy -S /run/haproxy/admin.sock --defaults 'C<u,2,1,80,90>' --overrides read-only:'u,1,0'
HAPROXY CRITICAL: BACKEND read-only has fallen below 1 available server(s) (0 up, 0 down, 0 disabled) (check_haproxy 1.0.3)

Critical. It's because perl considers 0 as absence of value so check_haproxy falls back to defaults:

build_checks{} setting defaults to u,2.00,1.00,0.80,0.90
build_checks{} processing override read-only:u,1,0
build_checks{} setting override for read-only to u,1,1,0.80,0.90
check_backends{} found 0 up, 0 down, 0 disabled (3 total)
check_pass{} UP: 0 >= 1

Overrides go from u,1,0 to u,1,1,0.80,0.90 and not u,1,0,0.80,0.90.

This pull request fixes this behaviour:

$ ./check_haproxy -S /run/haproxy/admin.sock --defaults 'C<u,2,1,80,90>' --overrides read-only:'u,1,0'
HAPROXY WARNING: BACKEND read-only has fallen below 1 available server(s) (0 up, 2 down, 0 disabled) (check_haproxy 1.0.3)
jonathanio commented 6 years ago

Thanks for this pull request!