From 36ac6fa3d220a5b9a0fa098371d7fdf21ae3d344 Mon Sep 17 00:00:00 2001 From: alarig Date: Tue, 9 Oct 2018 17:46:38 +0200 Subject: [PATCH] Adding case where there is no import route limit --- README.md | 5 ++++- check_bgp | 17 ++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index be17ee8..5722cf6 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ # nrpe-bird -Collection of scripts used to monitor bird sessions and route limits \ No newline at end of file +Collection of scripts used to monitor bird sessions and route limits + +It’s not well tested against bird2 yet, but using -4 for either IPv4 and IPv6 +should be sufficient. diff --git a/check_bgp b/check_bgp index 426813b..8b7fbd5 100755 --- a/check_bgp +++ b/check_bgp @@ -99,11 +99,26 @@ STATE="$($birdc show protocol ${SESSION} | \ ROUTE_LIMIT_IN="$($birdc show protocol all ${SESSION} | \ awk '/Receive limit/ { print $3 }')" + +# Test if we are on a bird2 +if [ -z ${ROUTE_LIMIT_IN} ]; then + ROUTE_LIMIT_IN="$($birdc show protocol all ${SESSION} | \ + awk '/Import limit/ { print $3 }')" +fi + +# There is no import limit, so no ratio either +if [ -z ${ROUTE_LIMIT_IN} ]; then + RATIO_IN=0 +fi + ROUTES_IMPORTED="$($birdc show protocol all ${SESSION} | grep 'Routes:' | \ sed -Ee '/imported/{ s/^.* ([0-9]+) imported.*$/\1/; p;}' -e d)" ROUTE_HIT_IN="$($birdc show protocol all ${SESSION} | \ grep -E 'Receive limit:.*HIT')" -RATIO_IN=$(echo "(${ROUTES_IMPORTED}*100)/${ROUTE_LIMIT_IN}" | bc) + +if [ ! -z ${ROUTE_LIMIT_IN} ]; then + RATIO_IN=$(echo "(${ROUTES_IMPORTED}*100)/${ROUTE_LIMIT_IN}" | bc) +fi ROUTE_HIT_OUT="$($birdc show protocol all ${SESSION} | \ grep -E 'Export limit:.*HIT')"